Commit d70ae0ee authored by Chunchi Che's avatar Chunchi Che

finish select logic

parent 83f4f98e
Pipeline #27000 passed with stages
in 12 minutes and 12 seconds
...@@ -26,6 +26,7 @@ export default async ({ ...@@ -26,6 +26,7 @@ export default async ({
if (card) { if (card) {
matStore.selectUnselectInfo.selectableList.push(info.location); matStore.selectUnselectInfo.selectableList.push(info.location);
card.selectInfo.selectable = true; card.selectInfo.selectable = true;
card.selectInfo.response = info.response;
} }
} }
for (const info of selectedCards) { for (const info of selectedCards) {
......
...@@ -84,7 +84,6 @@ const initialState: Omit<MatState, "reset"> = { ...@@ -84,7 +84,6 @@ const initialState: Omit<MatState, "reset"> = {
}, },
tossResult: undefined, tossResult: undefined,
selectUnselectInfo: { selectUnselectInfo: {
processing: false,
finishable: false, finishable: false,
cancelable: false, cancelable: false,
selectableList: [], selectableList: [],
...@@ -132,7 +131,6 @@ class MatStore implements MatState, NeosStore { ...@@ -132,7 +131,6 @@ class MatStore implements MatState, NeosStore {
this.handResults.op = 0; this.handResults.op = 0;
this.tossResult = undefined; this.tossResult = undefined;
this.selectUnselectInfo = { this.selectUnselectInfo = {
processing: false,
finishable: false, finishable: false,
cancelable: false, cancelable: false,
selectableList: [], selectableList: [],
......
...@@ -35,7 +35,6 @@ export interface MatState { ...@@ -35,7 +35,6 @@ export interface MatState {
tossResult?: string; // 骰子/硬币结果 tossResult?: string; // 骰子/硬币结果
selectUnselectInfo: { selectUnselectInfo: {
processing: boolean; // 是否在进行SelectUnselect流程
finishable: boolean; // 是否可以完成选择 finishable: boolean; // 是否可以完成选择
cancelable: boolean; // 是否可以取消当前选择 cancelable: boolean; // 是否可以取消当前选择
selectableList: ygopro.CardLocation[]; // 记录当前可以选择的卡列表 selectableList: ygopro.CardLocation[]; // 记录当前可以选择的卡列表
......
...@@ -4,7 +4,7 @@ import classnames from "classnames"; ...@@ -4,7 +4,7 @@ import classnames from "classnames";
import React, { type CSSProperties, useEffect, useRef, useState } from "react"; import React, { type CSSProperties, useEffect, useRef, useState } from "react";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { type CardMeta, Region } from "@/api"; import { type CardMeta, Region, sendSelectMultiResponse } from "@/api";
import { import {
fetchStrings, fetchStrings,
getCardStr, getCardStr,
...@@ -21,7 +21,11 @@ import { ...@@ -21,7 +21,11 @@ import {
displayOptionModal, displayOptionModal,
displaySimpleSelectCardsModal, displaySimpleSelectCardsModal,
} from "../../Message"; } from "../../Message";
import { interactTypeToIcon, interactTypeToString } from "../../utils"; import {
clearSelectInfo,
interactTypeToIcon,
interactTypeToString,
} from "../../utils";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { import {
attack, attack,
...@@ -234,6 +238,15 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -234,6 +238,15 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
const onClick = () => { const onClick = () => {
const onCardClick = (card: CardType) => { const onCardClick = (card: CardType) => {
if (card.selectInfo.selectable) {
if (card.selectInfo.response !== undefined) {
sendSelectMultiResponse([card.selectInfo.response]);
clearSelectInfo();
} else {
console.error("card is selectable but the response is undefined!");
}
}
// 中央弹窗展示选中卡牌信息 // 中央弹窗展示选中卡牌信息
// TODO: 同一张卡片,是否重复点击会关闭CardModal? // TODO: 同一张卡片,是否重复点击会关闭CardModal?
displayCardModal(card); displayCardModal(card);
......
...@@ -22,6 +22,7 @@ import { useSnapshot } from "valtio"; ...@@ -22,6 +22,7 @@ import { useSnapshot } from "valtio";
import { import {
sendSelectBattleCmdResponse, sendSelectBattleCmdResponse,
sendSelectIdleCmdResponse, sendSelectIdleCmdResponse,
sendSelectSingleResponse,
sendSurrender, sendSurrender,
ygopro, ygopro,
} from "@/api"; } from "@/api";
...@@ -30,6 +31,7 @@ import { IconFont } from "@/ui/Shared"; ...@@ -30,6 +31,7 @@ import { IconFont } from "@/ui/Shared";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import PhaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType; import PhaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType;
import { clearSelectInfo } from "../../utils";
import { openChatBox } from "../ChatBox"; import { openChatBox } from "../ChatBox";
const { useToken } = theme; const { useToken } = theme;
...@@ -39,6 +41,8 @@ const clearAllIdleInteractivities = () => { ...@@ -39,6 +41,8 @@ const clearAllIdleInteractivities = () => {
} }
}; };
const FINISH_CANCEL_RESPONSE = -1;
// PhaseType, 中文, response, 是否显示,是否禁用 // PhaseType, 中文, response, 是否显示,是否禁用
const initialPhaseBind: [ const initialPhaseBind: [
phase: PhaseType, phase: PhaseType,
...@@ -247,11 +251,19 @@ const ChainIcon: React.FC<{ chainSetting: ChainSetting }> = ({ ...@@ -247,11 +251,19 @@ const ChainIcon: React.FC<{ chainSetting: ChainSetting }> = ({
}; };
const SelectManager: React.FC = () => { const SelectManager: React.FC = () => {
const { finishable, cancelable } = useSnapshot(matStore.selectUnselectInfo);
const onFinishOrCancel = () => {
sendSelectSingleResponse(FINISH_CANCEL_RESPONSE);
clearSelectInfo();
};
return ( return (
<div className={styles["select-manager"]}> <div className={styles["select-manager"]}>
<Button className={styles.btn}>完成选择</Button> <Button
<Button className={classNames(styles.btn, { [styles.cancle]: true })}> className={classNames(styles.btn, { [styles.cancle]: cancelable })}
取消选择 disabled={!cancelable && !finishable}
onClick={onFinishOrCancel}
>
{finishable ? "完成选择" : "取消选择"}
</Button> </Button>
</div> </div>
); );
......
import { cardStore, matStore } from "@/stores";
export function clearSelectInfo() {
const selectUnselectInfo = matStore.selectUnselectInfo;
for (const location of selectUnselectInfo.selectableList) {
const card = cardStore.find(location);
if (card) {
card.selectInfo.selectable = false;
card.selectInfo.response = undefined;
}
}
for (const location of selectUnselectInfo.selectedList) {
const card = cardStore.find(location);
if (card) {
card.selectInfo.selected = false;
}
}
matStore.selectUnselectInfo.finishable = false;
matStore.selectUnselectInfo.cancelable = false;
matStore.selectUnselectInfo.selectableList = [];
matStore.selectUnselectInfo.selectedList = [];
}
export * from "./clearSelectInfo";
export * from "./groupBy"; export * from "./groupBy";
export * from "./interactTypeToStringIcon"; export * from "./interactTypeToStringIcon";
export * from "./zip"; export * from "./zip";
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