DaFuWeng/assets/Script/UIRoot.ts

158 lines
4.2 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";
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;
/// 初始化开始游戏界面的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();
/// 其他胜利条件
2024-03-18 10:55:21 +08:00
this.initOtherNode();
}
/// 初始化玩家UI
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);
this.initDiceButton();
}
2024-03-19 18:03:50 +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;
/// 2秒后 结束加载
setTimeout(() => {
/// 这一帧结束之后销毁
director.once(Director.EVENT_END_FRAME, () => {
// 销毁
this.awaitGamerNode.destroy();
/// 初始化开始倒计时动画
// this.initCountFontAni(5);
});
this.aniDone();
}, 2000);
}
/// 初始化倒计时动画
initCountFontAni(index: number) {
const ani = new AnimationNode("ani/dnf_quiz_" + index + ".ani", () => {
director.once(Director.EVENT_END_FRAME, () => {
ani.destroy();
});
if (index > 1) {
this.initCountFontAni(index - 1);
} else {
/// 动画结束
this.aniDone();
}
});
ani.setPosition(420, -180);
this.node.addChild(ani);
}
/// 初始化投骰子按钮
initDiceButton() {
this.diceButton = new DiceButtonNode();
this.diceButton.setPosition(849, -453);
this.node.addChild(this.diceButton);
/// 显示其他胜利条件
this.diceButton.winButtonBlock = () => {
this.otherWinNode.active = true;
};
}
/// 初始化其他胜利条件
initOtherNode() {
this.otherWinNode = new OtherWinNode(otherWinType.longRun);
this.node.addChild(this.otherWinNode);
this.otherWinNode.active = false;
}
2024-03-19 18:03:50 +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();
}
start() {
this.node.addComponent(UITransform).setContentSize(1067, 600);
this.initStartGameUI();
}
update(deltaTime: number) {}
2024-03-09 13:17:48 +08:00
}