Commit 44c8a183 authored by Chunchi Che's avatar Chunchi Che

finish magic select place ui

parent 920559e8
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace; import MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace;
import { addMonsterPlaceSelectAble, addMagicPlaceSelectAble } from "../../reducers/duel/mod"; import {
addMonsterPlaceSelectAble,
addMagicPlaceSelectAble,
} from "../../reducers/duel/mod";
export default (selectPlace: MsgSelectPlace, dispatch: AppDispatch) => { export default (selectPlace: MsgSelectPlace, dispatch: AppDispatch) => {
if (selectPlace.count != 1) { if (selectPlace.count != 1) {
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import { infoInit, setSelfType, initMonsters, initMagics } from "../../reducers/duel/mod"; import {
infoInit,
setSelfType,
initMonsters,
initMagics,
} from "../../reducers/duel/mod";
export default ( export default (
start: ygopro.StocGameMessage.MsgStart, start: ygopro.StocGameMessage.MsgStart,
......
import * as BABYLON from "@babylonjs/core"; import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "../../config/ui"; import * as CONFIG from "../../config/ui";
import { selectMeMagics } from "../../reducers/duel/magicSlice";
import { useClick } from "./hook";
import { Magic } from "../../reducers/duel/util";
import { store } from "../../store";
import { useAppSelector } from "../../hook";
import { useRef } from "react";
import { sendSelectPlaceResponse } from "../../api/ocgcore/ocgHelper";
import { clearMagicSelectInfo } from "../../reducers/duel/mod";
// TODO: use config // TODO: use config
const left = -2.15; const left = -2.15;
const gap = 1.05; const gap = 1.05;
const Magics = () => { const Magics = () => {
const magics = useAppSelector(selectMeMagics).magics;
return ( return (
<> <>
{[0, 1, 2, 3, 4].map((idx) => { {magics.map((magic) => {
return <Magic idx={idx} />; return <CMagic state={magic} />;
})} })}
</> </>
); );
}; };
const Magic = (props: { idx: number }) => { const CMagic = (props: { state: Magic }) => {
const state = props.state;
const planeRef = useRef(null);
const shape = CONFIG.CardSlotShape(); const shape = CONFIG.CardSlotShape();
const position = new BABYLON.Vector3( const position = new BABYLON.Vector3(
left + gap * props.idx, left + gap * state.sequence,
shape.depth / 2 + CONFIG.Floating, shape.depth / 2 + CONFIG.Floating,
-2.6 -2.6
); );
const rotation = CONFIG.CardSlotRotation(); const rotation = CONFIG.CardSlotRotation();
const edgesWidth = 2.0;
const edgesColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Yellow());
const dispatch = store.dispatch;
useClick(
(_event) => {
if (state.selectInfo) {
sendSelectPlaceResponse(state.selectInfo.response);
dispatch(clearMagicSelectInfo(0));
dispatch(clearMagicSelectInfo(1));
}
},
planeRef,
[state]
);
return ( return (
<plane <plane
name={`magic-${props.idx}`} name={`magic-${state.sequence}`}
ref={planeRef}
width={shape.width} width={shape.width}
height={shape.height} height={shape.height}
position={position} position={position}
rotation={rotation} rotation={rotation}
enableEdgesRendering
edgesWidth={state.selectInfo ? edgesWidth : 0}
edgesColor={edgesColor}
> >
<standardMaterial <standardMaterial
name={`magic-mat-${props.idx}`} name={`magic-mat-${props.state.sequence}`}
diffuseTexture={ diffuseTexture={
new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`) state.occupant
? new BABYLON.Texture(`http://localhost:3030/images/card_back.jpg`)
: new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`)
} }
alpha={0.2} alpha={0.2}
></standardMaterial> ></standardMaterial>
......
...@@ -42,7 +42,7 @@ const CommonMonster = (props: { state: Monster }) => { ...@@ -42,7 +42,7 @@ const CommonMonster = (props: { state: Monster }) => {
useClick( useClick(
(_event) => { (_event) => {
if (props.state.selectInfo) { if (props.state.selectInfo) {
sendSelectPlaceResponse(props.state.selectInfo?.response); sendSelectPlaceResponse(props.state.selectInfo.response);
dispatch(clearMonsterSelectInfo(0)); dispatch(clearMonsterSelectInfo(0));
dispatch(clearMonsterSelectInfo(1)); dispatch(clearMonsterSelectInfo(1));
} }
......
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