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 MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
import { displayAnnounceModal } from "@/ui/Duel/Message/AnnounceModal";
export default async (announce: MsgAnnounce) => {
const type_ = announce.announce_type;
......@@ -38,17 +39,7 @@ export default async (announce: MsgAnnounce) => {
break;
}
case MsgAnnounce.AnnounceType.Card: {
const options = [];
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);
await displayAnnounceModal(announce.options.map((option) => option.code));
break;
}
......
......@@ -5,8 +5,4 @@
.input {
display: flex;
}
.list {
}
}
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 { proxy, useSnapshot } from "valtio";
import { CardMeta, searchCards, sendSelectOptionResponse } from "@/api";
import { isToken } from "@/common";
import { isDeclarable, isToken } from "@/common";
import { emptySearchConditions } from "@/middleware/sqlite/fts";
import { getCardImgUrl } from "@/ui/Shared";
......@@ -36,8 +36,13 @@ export const AnnounceModal: React.FC = () => {
const result = searchCards({
query: searchWord,
conditions: emptySearchConditions,
}).filter((card) => !isToken(card.data.type ?? 0));
}).filter(
(card) =>
isDeclarable(card, store.opcodes) && !isToken(card.data.type ?? 0),
);
// 清掉之前选中的记录
setSelected(undefined);
setCardList(result);
};
const onSummit = () => {
......@@ -84,7 +89,23 @@ export const AnnounceModal: React.FC = () => {
}}
dataSource={cardList}
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
avatar={<Avatar src={getCardImgUrl(item.id)} />}
title={<a>{item.text.name}</a>}
......@@ -99,3 +120,11 @@ export const AnnounceModal: React.FC = () => {
};
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