DaFuWeng/assets/Script/UIRoot.ts

176 lines
4.8 KiB
TypeScript
Raw Normal View History

2024-03-18 10:55:21 +08:00
import {
_decorator,
Component,
Director,
director,
Node,
UITransform,
} from "cc";
2024-03-19 18:03:50 +08:00
import { CharacterType, GamerNode } from "./UINode/GamerNode";
2024-03-18 10:55:21 +08:00
import { BaseSprite } from "../GlobalScript/CommonComponent/BaseSprite";
import { NpkImage } from "../Tool/NPKImage";
import { AnimationNode } from "../GlobalScript/Animation/AnimationNode";
import { BaseButtonState } from "../GlobalScript/CommonComponent/BaseButton";
2024-03-19 18:03:50 +08:00
import { DiceButtonNode } from "./UINode/DiceButtonNode";
import { OtherWinNode, otherWinType } from "./UINode/OtherWinNode";
2024-03-18 10:55:21 +08:00
import { BoardRoot } from "./BoardRoot";
2024-03-19 18:03:50 +08:00
import { StartGameUINode } from "./StartGameNode/StartGameUINode";
2024-03-22 21:19:27 +08:00
import { GameRootSingleton } from "./GameRootController";
2024-03-25 19:50:16 +08:00
import { SelectNumberNode } from "./DialogNode/SelectNumberNode";
const { ccclass } = _decorator;
2024-03-09 13:17:48 +08:00
2024-03-18 10:55:21 +08:00
@ccclass("UIRoot")
2024-03-09 13:17:48 +08:00
export class UIRoot extends Component {
2024-03-18 10:55:21 +08:00
/// 等待玩家
private awaitGamerNode: Node;
/// 玩家一
private gamerOne: GamerNode;
/// 玩家二
private gamerTwo: GamerNode;
/// 玩家三
private gamerThree: GamerNode;
/// 投骰子按钮
private diceButton: DiceButtonNode;
/// 其他胜利条件
private otherWinNode: OtherWinNode;
2024-03-22 21:19:27 +08:00
//* 初始化开始游戏界面的UI
2024-03-18 10:55:21 +08:00
initStartGameUI() {
const startGameUINode = new StartGameUINode();
startGameUINode.addComponent(UITransform).setContentSize(1067, 600);
this.node.addChild(startGameUINode);
}
2024-03-22 21:19:27 +08:00
//* 初始化游戏界面UI
2024-03-18 10:55:21 +08:00
initGameUI() {
/// 玩家UI
this.initGamerUI();
/// 右下骰子操作按钮
this.initDiceButton();
/// 等待玩家加载
this.initAwaitGamerUI();
/// 其他胜利条件
2024-03-22 21:19:27 +08:00
this.initOtherWinNode();
2024-03-18 10:55:21 +08:00
}
2024-03-22 21:19:27 +08:00
//* 初始化玩家UI
2024-03-18 10:55:21 +08:00
initGamerUI() {
this.gamerOne = new GamerNode("玩家一");
this.gamerOne.setPosition(0, -540);
this.gamerOne.charchterType = CharacterType.JianHun;
this.node.addChild(this.gamerOne);
this.gamerTwo = new GamerNode("");
this.gamerTwo.setPosition(877, 0);
this.node.addChild(this.gamerTwo);
this.gamerThree = new GamerNode("");
this.node.addChild(this.gamerThree);
}
2024-03-22 21:19:27 +08:00
//* 初始化等待玩家加载UI
2024-03-18 10:55:21 +08:00
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;
2024-03-22 21:19:27 +08:00
2024-03-25 19:50:16 +08:00
2024-03-22 21:19:27 +08:00
//todo 自动跳过,接入网络后修改
// 1秒后 结束加载
2024-03-18 10:55:21 +08:00
setTimeout(() => {
/// 这一帧结束之后销毁
director.once(Director.EVENT_END_FRAME, () => {
// 销毁
this.awaitGamerNode.destroy();
2024-03-22 21:19:27 +08:00
// todo 开发时跳过倒计时动画
2024-03-18 10:55:21 +08:00
/// 初始化开始倒计时动画
// this.initCountFontAni(5);
});
2024-03-22 21:19:27 +08:00
// todo 开发时跳过倒计时动画
2024-03-18 10:55:21 +08:00
this.aniDone();
2024-03-22 21:19:27 +08:00
}, 1000);
2024-03-18 10:55:21 +08:00
}
2024-03-22 21:19:27 +08:00
//* 初始化倒计时动画
2024-03-18 10:55:21 +08:00
initCountFontAni(index: number) {
2024-03-22 21:19:27 +08:00
const ani = new AnimationNode('ani/count_font.ani',()=>{
/// 这一帧结束之后销毁
2024-03-18 10:55:21 +08:00
director.once(Director.EVENT_END_FRAME, () => {
2024-03-22 21:19:27 +08:00
// 销毁
2024-03-18 10:55:21 +08:00
ani.destroy();
});
2024-03-22 21:19:27 +08:00
/// 动画结束
2024-03-18 10:55:21 +08:00
this.aniDone();
2024-03-22 21:19:27 +08:00
})
ani.setPosition(500, -200);
2024-03-18 10:55:21 +08:00
this.node.addChild(ani);
}
2024-03-25 19:50:16 +08:00
//* 初始化骰子节点
2024-03-18 10:55:21 +08:00
initDiceButton() {
this.diceButton = new DiceButtonNode();
this.diceButton.setPosition(849, -453);
this.node.addChild(this.diceButton);
/// 显示其他胜利条件
this.diceButton.winButtonBlock = () => {
this.otherWinNode.active = true;
};
}
2024-03-22 21:19:27 +08:00
//* 初始化其他胜利条件
initOtherWinNode() {
2024-03-18 10:55:21 +08:00
this.otherWinNode = new OtherWinNode(otherWinType.longRun);
this.node.addChild(this.otherWinNode);
this.otherWinNode.active = false;
}
2024-03-22 21:19:27 +08:00
//* 动画结束 显示选择顺序
2024-03-18 10:55:21 +08:00
aniDone() {
/// 恢复其他胜利按钮的状态
this.diceButton.winButtonComponent.ButtonState = BaseButtonState.Normal;
/// 显示其他胜利条件
this.otherWinNode.active = true;
const boardNode = this.node.parent.getChildByName("BoardRoot");
/// 显示最底层的地图块
const board = boardNode.getComponent(BoardRoot);
board.initMapTile();
2024-03-22 21:19:27 +08:00
//* 1秒后自动关闭胜利条件显示,并显示顺序选择
setTimeout(() => {
//* 显示顺序选择node
this.otherWinNode.active = false;
2024-03-25 19:50:16 +08:00
const select = GameRootSingleton.getInstance().DialogRoot.initSelectNumberNode();
select.doneFunc = ()=>{
// todo 开发阶段在选择顺序结束后,恢复骰子按钮状态
this.diceButton.diceButtonComponent.ButtonState = BaseButtonState.Normal;
};
2024-03-22 21:19:27 +08:00
}, 1000);
2024-03-18 10:55:21 +08:00
}
start() {
this.node.addComponent(UITransform).setContentSize(1067, 600);
this.initStartGameUI();
}
update(deltaTime: number) {}
2024-03-09 13:17:48 +08:00
}