import { _decorator, Component, Director, director, Node, UITransform, } from "cc"; import { GamerCardNode } from "./../Gamer/GamerCardNode"; import { BaseSprite } from "../../GlobalScript/CommonComponent/BaseSprite"; import { NpkImage } from "../../Tool/NPKImage"; import { AnimationNode } from "../../GlobalScript/Animation/AnimationNode"; import { BaseButtonState } from "../../GlobalScript/CommonComponent/BaseButton"; import { DiceButtonNode } from "../UIRoot/DiceButtonNode"; import { OtherWinNode, otherWinType } from "../UIRoot/OtherWinNode"; import { BoardRoot } from "../BoardRoot"; import { StartGameUINode } from "../StartGameNode/StartGameUINode"; import { GamerRoleType } from "../Gamer/GamerRoleType"; import { SelectNumberNode } from "../DialogRoot/SelectNumberNode"; const { ccclass } = _decorator; @ccclass("UIRoot") /** * @description: UIRoot节点的 UI 初始化 */ export class UIRoot extends Component { /** 玩家一 */ private gamerCardOne: GamerCardNode; /** 玩家二 */ private gamerCardTwo: GamerCardNode; /** 玩家三 */ private gamerCardThree: GamerCardNode; /** 等待玩家 */ awaitGamerNode: Node; /** 投骰子按钮 */ diceButton: DiceButtonNode; /** 其他胜利条件 */ otherWinNode: OtherWinNode; // ─── 初始化ui ─────────────────────────────────────────────────────────────────── /** 初始化开始游戏界面的UI */ initStartGameUI() { const startGameUINode = new StartGameUINode(); startGameUINode.addComponent(UITransform).setContentSize(1067, 600); this.node.addChild(startGameUINode); } /** 初始化游戏界面UI */ initGameUI() { /// 玩家UI this.initGamerUI(); /// 右下骰子操作按钮 this.initDiceButton(); /// 等待玩家加载 this.initAwaitGamerUI(); } /** 初始化玩家卡片 UI */ private initGamerUI() { this.gamerCardOne = new GamerCardNode("玩家一"); this.gamerCardOne.setPosition(0, -540); this.gamerCardOne.charchterType = GamerRoleType.JianHun; this.node.addChild(this.gamerCardOne); this.gamerCardTwo = new GamerCardNode(""); this.gamerCardTwo.setPosition(877, 0); this.node.addChild(this.gamerCardTwo); this.gamerCardThree = new GamerCardNode(""); this.node.addChild(this.gamerCardThree); } /** 初始化骰子节点 */ private initDiceButton() { this.diceButton = new DiceButtonNode(); this.diceButton.setPosition(849, -453); this.node.addChild(this.diceButton); /// 显示其他胜利条件 this.diceButton.winButtonBlock = () => { this.otherWinNode.active = true; }; this.diceButton.diceUpBlock = () => {}; } /** 初始化其他胜利条件 */ initOtherWinNode(type: otherWinType) { if (!this.otherWinNode) { this.otherWinNode = new OtherWinNode(type); this.node.addChild(this.otherWinNode); this.otherWinNode.active = false; } } /** 初始化并显示顺序选择node */ initSelectNumberNode(): SelectNumberNode { const selectNode = new SelectNumberNode(); this.node.addChild(selectNode); return selectNode; } // ─── 动画初始化 ────────────────────────────────────────────────────────── /** 初始化等待玩家加载UI */ initAwaitGamerUI() { const node = new Node(); node.setPosition(177.5, -244.5); this.node.addChild(node); const spr = node.addComponent(BaseSprite); spr.updateSpriteFrame(NpkImage.loading_loop, 0); const ani = new AnimationNode("ani/loading_loop01.ani"); ani.setPosition(350, -110); node.addChild(ani); this.awaitGamerNode = node; } /** 初始化倒计时动画 */ initCountDownFontAni(index: number) { const ani = new AnimationNode("ani/count_font.ani", () => { /// 这一帧结束之后销毁 director.once(Director.EVENT_END_FRAME, () => { // 销毁 ani.destroy(); }); /// 动画结束 this.countDownAniDone(); }); ani.setPosition(500, -200); this.node.addChild(ani); } /** 倒计时动画结束 */ countDownAniDone() { /// 恢复其他胜利按钮的状态 this.diceButton.winButtonComponent.ButtonState = BaseButtonState.Normal; /// 显示其他胜利条件 this.otherWinNode.active = true; const boardNode = this.node.parent.getChildByName("BoardRoot"); /// 显示最底层的地图块 const board = boardNode.getComponent(BoardRoot); board.initMapTile(); // 1秒后自动关闭胜利条件显示,并显示顺序选择 setTimeout(() => { // 隐藏其他胜利条件 node this.otherWinNode.active = false; const select = this.initSelectNumberNode(); select.doneFunc = () => { // todo 开发阶段在选择顺序结束后,恢复骰子按钮状态 this.diceButton.diceButtonComponent.ButtonState = BaseButtonState.Normal; }; }, 1000); } // ─── 生命周期 ──────────────────────────────────────────────────────────── start() { this.node.addComponent(UITransform).setContentSize(1067, 600); /// 初始化 开始游戏 的 UI this.initStartGameUI(); } update(deltaTime: number) {} }