Commit 041f33c1 authored by Chunchi Che's avatar Chunchi Che

update monster ui

parent 749e0dbd
...@@ -2,6 +2,7 @@ import { judgeSelf, Monster, InteractType } from "./util"; ...@@ -2,6 +2,7 @@ import { judgeSelf, Monster, InteractType } from "./util";
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit"; import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { RootState } from "../../store";
export interface MonsterState { export interface MonsterState {
monsters: Monster[]; monsters: Monster[];
...@@ -13,28 +14,30 @@ export const initMonstersImpl: CaseReducer<DuelState, PayloadAction<number>> = ( ...@@ -13,28 +14,30 @@ export const initMonstersImpl: CaseReducer<DuelState, PayloadAction<number>> = (
action action
) => { ) => {
const player = action.payload; const player = action.payload;
let monsters = judgeSelf(player, state) ? state.meMonsters : state.opMonsters; const monsters = {
monsters: [
{
sequence: 0,
},
{
sequence: 1,
},
{
sequence: 2,
},
{
sequence: 3,
},
{
sequence: 4,
},
],
};
if (!monsters) { if (judgeSelf(player, state)) {
monsters = { state.meMonsters = monsters;
monsters: [ } else {
{ state.opMonsters = monsters;
sequence: 0,
},
{
sequence: 1,
},
{
sequence: 2,
},
{
sequence: 3,
},
{
sequence: 4,
},
],
};
} }
}; };
...@@ -78,3 +81,6 @@ export const clearMonsterSelectInfoImpl: CaseReducer< ...@@ -78,3 +81,6 @@ export const clearMonsterSelectInfoImpl: CaseReducer<
monsters.monsters = []; monsters.monsters = [];
} }
}; };
export const selectMeMonsters = (state: RootState) =>
state.duel.meMonsters || { monsters: [] };
...@@ -21,6 +21,7 @@ import { selectCurrentPlayer } from "../../reducers/duel/turnSlice"; ...@@ -21,6 +21,7 @@ import { selectCurrentPlayer } from "../../reducers/duel/turnSlice";
import CardModal from "./cardModal"; import CardModal from "./cardModal";
import HintNotification from "./hintNotification"; import HintNotification from "./hintNotification";
import { selectMeHands } from "../../reducers/duel/handsSlice"; import { selectMeHands } from "../../reducers/duel/handsSlice";
import { selectMeMonsters } from "../../reducers/duel/monstersSlice";
// CONFIG // CONFIG
...@@ -28,6 +29,7 @@ const Duel = () => { ...@@ -28,6 +29,7 @@ const Duel = () => {
// ----- 数据获取 ----- // ----- 数据获取 -----
const hands = useAppSelector(selectMeHands).cards; const hands = useAppSelector(selectMeHands).cards;
const monsters = useAppSelector(selectMeMonsters).monsters;
const currentPlayer = useAppSelector(selectCurrentPlayer); const currentPlayer = useAppSelector(selectCurrentPlayer);
// ----- WebGL渲染 ----- // ----- WebGL渲染 -----
...@@ -60,7 +62,7 @@ const Duel = () => { ...@@ -60,7 +62,7 @@ const Duel = () => {
renderMagics(scene); renderMagics(scene);
// 怪兽区 // 怪兽区
renderMonsters(scene); renderMonsters(monsters, scene);
// 创建额外怪兽区 // 创建额外怪兽区
renderExtraMonsters(scene); renderExtraMonsters(scene);
...@@ -105,7 +107,7 @@ const Duel = () => { ...@@ -105,7 +107,7 @@ const Duel = () => {
engine.runRenderLoop(() => { engine.runRenderLoop(() => {
scene.render(); scene.render();
}); });
}, [canvasRef, hands, currentPlayer]); }, [canvasRef, hands, monsters, currentPlayer]); // FIXME: 这里需要优化,应该分组件按需渲染
useEffect(() => { useEffect(() => {
// 监听状态变化,并实现动画 // 监听状态变化,并实现动画
......
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 { Monster } from "../../reducers/duel/util";
export default (scene: BABYLON.Scene) => { export default (monsters: Monster[], scene: BABYLON.Scene) => {
const left = -2.15; const left = -2.15;
const gap = 1.05; const gap = 1.05;
const shape = CONFIG.CardSlotShape(); const shape = CONFIG.CardSlotShape();
for (let i = 0; i < 5; i++) { for (const monster of monsters) {
const slot = BABYLON.MeshBuilder.CreatePlane(`monster${i}`, shape, scene); const sequence = monster.sequence;
const slot = BABYLON.MeshBuilder.CreatePlane(
`monster${sequence}`,
shape,
scene
);
// 位置 // 位置
slot.position = new BABYLON.Vector3( slot.position = new BABYLON.Vector3(
left + gap * i, left + gap * sequence,
shape.depth / 2 + CONFIG.Floating, shape.depth / 2 + CONFIG.Floating,
-1.35 -1.35
); );
...@@ -21,10 +27,20 @@ export default (scene: BABYLON.Scene) => { ...@@ -21,10 +27,20 @@ export default (scene: BABYLON.Scene) => {
"monsterMaterial", "monsterMaterial",
scene scene
); );
monsterMaterial.diffuseTexture = new BABYLON.Texture( monsterMaterial.diffuseTexture = monster.occupant
`http://localhost:3030/images/card_slot.png` ? new BABYLON.Texture(
); `https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${monster.occupant.id}.jpg`
)
: new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`);
monsterMaterial.diffuseTexture.hasAlpha = true; monsterMaterial.diffuseTexture.hasAlpha = true;
slot.material = monsterMaterial; slot.material = monsterMaterial;
if (monster.selectInfo) {
slot.enableEdgesRendering();
slot.edgesWidth = 2.0;
slot.edgesColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Yellow());
} else {
slot.disableEdgesRendering();
}
} }
}; };
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