Commit d7e1f353 authored by chechunchi's avatar chechunchi

migrate checkcounter modal

parent 93439c46
Pipeline #22410 failed with stages
in 14 minutes and 5 seconds
...@@ -215,7 +215,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -215,7 +215,7 @@ async function _handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "select_counter": { case "select_counter": {
onMsgSelectCounter(msg.select_counter); await onMsgSelectCounter(msg.select_counter);
break; break;
} }
......
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import { cardStore, messageStore } from "@/stores"; import { cardStore } from "@/stores";
import { displayCheckCounterModal } from "@/ui/Duel/Message";
type MsgSelectCounter = ygopro.StocGameMessage.MsgSelectCounter; type MsgSelectCounter = ygopro.StocGameMessage.MsgSelectCounter;
export default (selectCounter: MsgSelectCounter) => { export default async (selectCounter: MsgSelectCounter) => {
messageStore.checkCounterModal.counterType = selectCounter.counter_type; await displayCheckCounterModal({
messageStore.checkCounterModal.min = selectCounter.min; counterType: selectCounter.counter_type,
messageStore.checkCounterModal.options = selectCounter.options!.map( min: selectCounter.min,
({ location, code, counter_count }) => { options: selectCounter.options!.map(({ location, code, counter_count }) => {
const id = cardStore.find(location)?.code; const id = cardStore.find(location)?.code;
const newCode = code ? code : id || 0; const newCode = code ? code : id || 0;
...@@ -14,7 +15,6 @@ export default (selectCounter: MsgSelectCounter) => { ...@@ -14,7 +15,6 @@ export default (selectCounter: MsgSelectCounter) => {
code: newCode, code: newCode,
max: counter_count!, max: counter_count!,
}; };
} }),
); });
messageStore.checkCounterModal.isOpen = true;
}; };
...@@ -3,10 +3,6 @@ import { proxy } from "valtio"; ...@@ -3,10 +3,6 @@ import { proxy } from "valtio";
import type { ModalState } from "./types"; import type { ModalState } from "./types";
export const messageStore = proxy<ModalState>({ export const messageStore = proxy<ModalState>({
checkCounterModal: {
isOpen: false,
options: [],
},
announceModal: { announceModal: {
isOpen: false, isOpen: false,
min: 1, min: 1,
......
export interface ModalState { export interface ModalState {
// 指示器选择弹窗
checkCounterModal: {
isOpen: boolean;
counterType?: number;
min?: number;
options: {
code: number;
max: number;
}[];
};
// 宣言弹窗 // 宣言弹窗
announceModal: { announceModal: {
isOpen: boolean; isOpen: boolean;
......
// 指示器选择弹窗
import { Omit } from "@react-spring/web";
import { Button, Card, Col, InputNumber, Row } from "antd"; import { Button, Card, Col, InputNumber, Row } from "antd";
import React, { useState } from "react"; import React, { useState } from "react";
import { useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { fetchStrings, sendSelectCounterResponse } from "@/api"; import { fetchStrings, sendSelectCounterResponse } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { messageStore } from "@/stores";
import { DragModal } from "./DragModal"; import { NeosModal } from "./NeosModal";
const { checkCounterModal } = messageStore; interface CheckCounterModalProps {
isOpen: boolean;
counterType?: number;
min?: number;
options: {
code: number;
max: number;
}[];
}
const defaultProps = {
isOpen: false,
options: [],
};
const localStore = proxy<CheckCounterModalProps>(defaultProps);
const NeosConfig = useConfig(); const NeosConfig = useConfig();
export const CheckCounterModal = () => { export const CheckCounterModal = () => {
const snapCheckCounterModal = useSnapshot(checkCounterModal); const snapCheckCounterModal = useSnapshot(localStore);
const isOpen = snapCheckCounterModal.isOpen; const isOpen = snapCheckCounterModal.isOpen;
const min = snapCheckCounterModal.min || 0; const min = snapCheckCounterModal.min || 0;
...@@ -28,14 +43,11 @@ export const CheckCounterModal = () => { ...@@ -28,14 +43,11 @@ export const CheckCounterModal = () => {
const onFinish = () => { const onFinish = () => {
sendSelectCounterResponse(selected); sendSelectCounterResponse(selected);
messageStore.checkCounterModal.isOpen = false; rs();
messageStore.checkCounterModal.min = undefined;
messageStore.checkCounterModal.counterType = undefined;
messageStore.checkCounterModal.options = [];
}; };
return ( return (
<DragModal <NeosModal
title={`请移除${min}个${counterName}`} title={`请移除${min}个${counterName}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
...@@ -75,6 +87,23 @@ export const CheckCounterModal = () => { ...@@ -75,6 +87,23 @@ export const CheckCounterModal = () => {
); );
})} })}
</Row> </Row>
</DragModal> </NeosModal>
); );
}; };
let rs: (arg?: any) => void = () => {};
export const displayCheckCounterModal = async (
args: Omit<CheckCounterModalProps, "isOpen">
) => {
Object.entries(args).forEach(([key, value]) => {
// @ts-ignore
localStore[key] = value;
});
localStore.isOpen = true;
await new Promise<void>((resolve) => (rs = resolve)); // 等待在组件内resolve
localStore.isOpen = false;
localStore.options = [];
localStore.min = undefined;
localStore.counterType = undefined;
};
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