Commit a2e3a130 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/card_modal/effect' into 'main'

Feat/card modal/effect

See merge request mycard/Neos!185
parents a47e1e93 46c3c9fa
...@@ -3,7 +3,6 @@ import MsgSelectOption = ygopro.StocGameMessage.MsgSelectOption; ...@@ -3,7 +3,6 @@ import MsgSelectOption = ygopro.StocGameMessage.MsgSelectOption;
import { messageStore } from "@/stores"; import { messageStore } from "@/stores";
export default async (selectOption: MsgSelectOption) => { export default async (selectOption: MsgSelectOption) => {
const player = selectOption.player;
const options = selectOption.options; const options = selectOption.options;
await Promise.all( await Promise.all(
......
...@@ -18,7 +18,7 @@ export interface ModalState { ...@@ -18,7 +18,7 @@ export interface ModalState {
cardModal: { cardModal: {
isOpen: boolean; isOpen: boolean;
meta?: CardMeta; meta?: CardMeta;
interactivies: { desc: string; response: number }[]; interactivies: { desc: string; response: number; effectCode?: number }[];
counters: { [type: number]: number }; counters: { [type: number]: number };
}; };
// 卡牌列表弹窗 // 卡牌列表弹窗
......
...@@ -4,7 +4,7 @@ import classnames from "classnames"; ...@@ -4,7 +4,7 @@ import classnames from "classnames";
import React from "react"; import React from "react";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { fetchStrings, sendSelectIdleCmdResponse } from "@/api"; import { fetchStrings, getCardStr, sendSelectIdleCmdResponse } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { import {
clearAllIdleInteractivities as clearAllIdleInteractivities, clearAllIdleInteractivities as clearAllIdleInteractivities,
...@@ -40,7 +40,12 @@ export const CardModal = () => { ...@@ -40,7 +40,12 @@ export const CardModal = () => {
const imgUrl = meta?.id const imgUrl = meta?.id
? `${NeosConfig.cardImgUrl}/${meta.id}.jpg` ? `${NeosConfig.cardImgUrl}/${meta.id}.jpg`
: undefined; : undefined;
const interactivies = snap.interactivies; const nonEffectInteractivies = snap.interactivies.filter(
(item) => item.desc != "发动效果"
);
const effectInteractivies = snap.interactivies.filter(
(item) => item.desc == "发动效果"
);
return ( return (
<div <div
...@@ -63,7 +68,7 @@ export const CardModal = () => { ...@@ -63,7 +68,7 @@ export const CardModal = () => {
<AtkLine atk={atk} def={def} /> <AtkLine atk={atk} def={def} />
<CounterLine counters={counters} /> <CounterLine counters={counters} />
<div className="card-modal-effect">{desc}</div> <div className="card-modal-effect">{desc}</div>
{interactivies.map((interactive, idx) => { {nonEffectInteractivies.map((interactive, idx) => {
return ( return (
<button <button
key={idx} key={idx}
...@@ -79,6 +84,47 @@ export const CardModal = () => { ...@@ -79,6 +84,47 @@ export const CardModal = () => {
</button> </button>
); );
})} })}
{effectInteractivies.length > 0 ? (
effectInteractivies.length == 1 ? (
// 如果只有一个效果,点击直接触发
<button
className="card-modal-btn"
onClick={() => {
sendSelectIdleCmdResponse(effectInteractivies[0].response);
cardModal.isOpen = false;
clearAllIdleInteractivities(0);
clearAllIdleInteractivities(1);
}}
>
{effectInteractivies[0].desc}
</button>
) : (
// 如果有多个效果,点击后进入`OptionModal`选择
<button
className="card-modal-btn"
onClick={() => {
for (const effect of effectInteractivies) {
const effectMsg =
meta && effect.effectCode
? getCardStr(meta, effect.effectCode & 0xf) ?? "[:?]"
: "[:?]";
messageStore.optionModal.options.push({
msg: effectMsg,
response: effect.response,
});
}
cardModal.isOpen = false;
clearAllIdleInteractivities(0);
clearAllIdleInteractivities(1);
messageStore.optionModal.isOpen = true;
}}
>
发动效果
</button>
)
) : (
<></>
)}
</div> </div>
</div> </div>
); );
......
...@@ -247,6 +247,7 @@ const onCardClick = (state: CardState) => () => { ...@@ -247,6 +247,7 @@ const onCardClick = (state: CardState) => () => {
messageStore.cardModal.interactivies = state.idleInteractivities.map( messageStore.cardModal.interactivies = state.idleInteractivities.map(
(interactivity) => ({ (interactivity) => ({
desc: interactTypeToString(interactivity.interactType), desc: interactTypeToString(interactivity.interactType),
effectCode: interactivity.activateIndex,
response: interactivity.response, response: interactivity.response,
}) })
); );
......
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