Commit 78a03e35 authored by Chunchi Che's avatar Chunchi Che

finish AnnounceModal

parent bcfa9ca4
Pipeline #26760 passed with stages
in 8 minutes and 22 seconds
import { fetchCard, fetchStrings, Region, ygopro } from "@/api"; import { fetchStrings, Region, ygopro } from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message"; import { displayOptionModal } from "@/ui/Duel/Message";
import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce; import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
import { displayAnnounceModal } from "@/ui/Duel/Message/AnnounceModal";
export default async (announce: MsgAnnounce) => { export default async (announce: MsgAnnounce) => {
const type_ = announce.announce_type; const type_ = announce.announce_type;
...@@ -38,17 +39,7 @@ export default async (announce: MsgAnnounce) => { ...@@ -38,17 +39,7 @@ export default async (announce: MsgAnnounce) => {
break; break;
} }
case MsgAnnounce.AnnounceType.Card: { case MsgAnnounce.AnnounceType.Card: {
const options = []; await displayAnnounceModal(announce.options.map((option) => option.code));
for (const option of announce.options) {
const meta = fetchCard(option.code);
if (meta.text.name) {
options.push({
info: meta.text.name,
response: option.response,
});
}
}
await displayOptionModal(fetchStrings(Region.System, 564), options, min);
break; break;
} }
......
...@@ -5,8 +5,4 @@ ...@@ -5,8 +5,4 @@
.input { .input {
display: flex; display: flex;
} }
.list {
}
} }
import { SearchOutlined } from "@ant-design/icons"; import { SearchOutlined } from "@ant-design/icons";
import { Avatar, Button, Input, List } from "antd"; import { Avatar, Button, Checkbox, Input, List } from "antd";
import React, { useState } from "react"; import React, { useState } from "react";
import { proxy, useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { CardMeta, searchCards, sendSelectOptionResponse } from "@/api"; import { CardMeta, searchCards, sendSelectOptionResponse } from "@/api";
import { isToken } from "@/common"; import { isDeclarable, isToken } from "@/common";
import { emptySearchConditions } from "@/middleware/sqlite/fts"; import { emptySearchConditions } from "@/middleware/sqlite/fts";
import { getCardImgUrl } from "@/ui/Shared"; import { getCardImgUrl } from "@/ui/Shared";
...@@ -36,8 +36,13 @@ export const AnnounceModal: React.FC = () => { ...@@ -36,8 +36,13 @@ export const AnnounceModal: React.FC = () => {
const result = searchCards({ const result = searchCards({
query: searchWord, query: searchWord,
conditions: emptySearchConditions, conditions: emptySearchConditions,
}).filter((card) => !isToken(card.data.type ?? 0)); }).filter(
(card) =>
isDeclarable(card, store.opcodes) && !isToken(card.data.type ?? 0),
);
// 清掉之前选中的记录
setSelected(undefined);
setCardList(result); setCardList(result);
}; };
const onSummit = () => { const onSummit = () => {
...@@ -84,7 +89,23 @@ export const AnnounceModal: React.FC = () => { ...@@ -84,7 +89,23 @@ export const AnnounceModal: React.FC = () => {
}} }}
dataSource={cardList} dataSource={cardList}
renderItem={(item, index) => ( renderItem={(item, index) => (
<List.Item key={index}> <List.Item
key={index}
actions={[
<Checkbox
checked={item.id === selected}
onClick={() => {
if (item.id === selected) {
// 之前选的就是这个,则取消选中
setSelected(undefined);
} else {
// 选中
setSelected(item.id);
}
}}
/>,
]}
>
<List.Item.Meta <List.Item.Meta
avatar={<Avatar src={getCardImgUrl(item.id)} />} avatar={<Avatar src={getCardImgUrl(item.id)} />}
title={<a>{item.text.name}</a>} title={<a>{item.text.name}</a>}
...@@ -99,3 +120,11 @@ export const AnnounceModal: React.FC = () => { ...@@ -99,3 +120,11 @@ export const AnnounceModal: React.FC = () => {
}; };
let rs: (v?: any) => void = () => {}; let rs: (v?: any) => void = () => {};
export const displayAnnounceModal = async (opcodes: number[]) => {
store.opcodes = opcodes;
store.isOpen = true;
await new Promise((resolve) => (rs = resolve));
store.isOpen = false;
store.opcodes = [];
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment