Commit a2519c13 authored by Chunchi Che's avatar Chunchi Che

update hand slice and hand ui

parent 5020a162
Pipeline #18942 passed with stages
in 2 minutes and 38 seconds
...@@ -8,7 +8,6 @@ import { DuelState } from "./mod"; ...@@ -8,7 +8,6 @@ import { DuelState } from "./mod";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { fetchCard, CardMeta } from "../../api/cards"; import { fetchCard, CardMeta } from "../../api/cards";
import { judgeSelf, Hand, Interactivity } from "./util"; import { judgeSelf, Hand, Interactivity } from "./util";
import * as UICONFIG from "../../config/ui";
export interface Hands { export interface Hands {
// 注意:手牌的位置顺序是有约束的 // 注意:手牌的位置顺序是有约束的
...@@ -56,7 +55,6 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -56,7 +55,6 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => {
} else { } else {
state.meHands = { cards }; state.meHands = { cards };
} }
setHandsTransform(state.meHands.cards);
} else { } else {
if (state.opHands) { if (state.opHands) {
state.opHands.cards = state.opHands.cards.concat(cards); state.opHands.cards = state.opHands.cards.concat(cards);
...@@ -83,27 +81,6 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -83,27 +81,6 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => {
}); });
}; };
// 更新手牌的位置和旋转信息
//
// TODO: 兼容对方手牌
function setHandsTransform(hands: Hand[]): void {
const groundShape = UICONFIG.GroundShape();
const handShape = UICONFIG.HandShape();
const gap = groundShape.width / (hands.length - 1);
const left = -(groundShape.width / 2);
hands.forEach((hand, idx, _) => {
hand.transform.position = {
x: left + gap * idx,
y: handShape.height / 2,
z: -(groundShape.height / 2) - 1,
};
const rotation = UICONFIG.HandRotation();
hand.transform.rotation = { x: rotation.x, y: rotation.y, z: rotation.z };
});
}
// 清空手牌互动性 // 清空手牌互动性
export const clearHandsInteractivityImpl: CaseReducer< export const clearHandsInteractivityImpl: CaseReducer<
DuelState, DuelState,
......
...@@ -27,23 +27,9 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean { ...@@ -27,23 +27,9 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean {
export interface Hand { export interface Hand {
meta: CardMeta; meta: CardMeta;
transform: CardTransform;
interactivities: Interactivity<number>[]; interactivities: Interactivity<number>[];
} }
interface CardTransform {
position?: {
x: number;
y: number;
z: number;
};
rotation?: {
x: number;
y: number;
z: number;
};
}
export enum InteractType { export enum InteractType {
// 可普通召唤 // 可普通召唤
SUMMON = 1, SUMMON = 1,
......
...@@ -8,7 +8,10 @@ import { ...@@ -8,7 +8,10 @@ import {
selectCardModalImgUrl, selectCardModalImgUrl,
selectCardModalInteractivies, selectCardModalInteractivies,
} from "../../reducers/duel/modalSlice"; } from "../../reducers/duel/modalSlice";
import { setCardModalIsOpen } from "../../reducers/duel/mod"; import {
setCardModalIsOpen,
clearHandsInteractivity,
} from "../../reducers/duel/mod";
import { Modal, Card, Button } from "antd"; import { Modal, Card, Button } from "antd";
import { sendSelectIdleCmdResponse } from "../../api/ocgcore/ocgHelper"; import { sendSelectIdleCmdResponse } from "../../api/ocgcore/ocgHelper";
...@@ -45,6 +48,7 @@ const CardModal = () => { ...@@ -45,6 +48,7 @@ const CardModal = () => {
onClick={() => { onClick={() => {
sendSelectIdleCmdResponse(interactive.response); sendSelectIdleCmdResponse(interactive.response);
dispatch(setCardModalIsOpen(false)); dispatch(setCardModalIsOpen(false));
dispatch(clearHandsInteractivity(0));
}} }}
> >
{interactive.desc} {interactive.desc}
......
...@@ -14,20 +14,37 @@ import { useHover } from "react-babylonjs"; ...@@ -14,20 +14,37 @@ import { useHover } from "react-babylonjs";
import { useClick } from "./hook"; import { useClick } from "./hook";
import { useState, useRef } from "react"; import { useState, useRef } from "react";
const groundShape = CONFIG.GroundShape();
const left = -(groundShape.width / 2);
const Hands = () => { const Hands = () => {
const hands = useAppSelector(selectMeHands).cards; const hands = useAppSelector(selectMeHands).cards;
return ( return (
<> <>
{hands.map((hand, idx) => { {hands.map((hand, idx) => {
return <CHand state={hand} idx={idx} key={idx} />; return (
<CHand
state={hand}
idx={idx}
key={idx}
gap={groundShape.width / (hands.length - 1)}
/>
);
})} })}
</> </>
); );
}; };
const CHand = (props: { state: Hand; idx: number }) => { const CHand = (props: { state: Hand; idx: number; gap: number }) => {
const handShape = CONFIG.HandShape(); const handShape = CONFIG.HandShape();
const position = new BABYLON.Vector3(
left + props.gap * props.idx,
handShape.height / 2,
-(groundShape.height / 2) - 1
);
const rotation = CONFIG.HandRotation();
const hoverScale = CONFIG.HandHoverScaling(); const hoverScale = CONFIG.HandHoverScaling();
const defaultScale = new BABYLON.Vector3(1, 1, 1); const defaultScale = new BABYLON.Vector3(1, 1, 1);
const planeRef = useRef(null); const planeRef = useRef(null);
...@@ -72,20 +89,8 @@ const CHand = (props: { state: Hand; idx: number }) => { ...@@ -72,20 +89,8 @@ const CHand = (props: { state: Hand; idx: number }) => {
width={handShape.width} width={handShape.width}
height={handShape.height} height={handShape.height}
scaling={hovered ? hoverScale : defaultScale} scaling={hovered ? hoverScale : defaultScale}
position={ position={position}
new BABYLON.Vector3( rotation={rotation}
state.transform.position?.x,
state.transform.position?.y,
state.transform.position?.z
)
}
rotation={
new BABYLON.Vector3(
state.transform.rotation?.x,
state.transform.rotation?.y,
state.transform.rotation?.z
)
}
> >
<standardMaterial <standardMaterial
name={`hand-mat-${idx}`} name={`hand-mat-${idx}`}
......
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