GameRoot节点控制和注销修改

This commit is contained in:
WoNiu 2024-03-22 21:19:27 +08:00
parent 3accbc5f3a
commit d94ea3f4a9
7 changed files with 145 additions and 49 deletions

4
.gitignore vendored
View File

@ -22,4 +22,6 @@ node_modules/
#//////////////////////////
# WebStorm
#//////////////////////////
.idea/
.idea/
assets/ImagePack/!幻想模拟战.NPK
assets/ImagePack/!幻想模拟战.NPK.meta

View File

@ -1,14 +1,37 @@
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('DialogRoot')
export class DialogRoot extends Component {
start() {
}
update(deltaTime: number) {
}
}
import { _decorator, Component, Director, director, Node } from 'cc';
import { SelectNumberNode } from './DialogNode/SelectNumberNode';
const { ccclass, property } = _decorator;
@ccclass('DialogRoot')
export class DialogRoot extends Component {
start() {
}
update(deltaTime: number) {
}
//* 初始化并显示顺序选择node
initSelectNumberNode(){
const selectNode = new SelectNumberNode();
selectNode.name = 'SelectNumberNode';
this.node.addChild(selectNode);
}
//* 销毁顺序选择node
destroySelectNumberNode(){
/// 一帧结束之后销毁
director.once(Director.EVENT_END_FRAME,()=>{
// 销毁
this.node.getChildByName('SelectNumberNode').destroy();
});
}
}

View File

@ -0,0 +1,57 @@
import { _decorator,Component, Node } from 'cc';
import { BoardRoot } from './BoardRoot';
import { UIRoot } from './UIRoot';
import { DialogRoot } from './DialogRoot';
const { ccclass, property } = _decorator;
export class GameRootSingleton {
private static readonly _instance: GameRootSingleton = new GameRootSingleton();
private constructor() {}
public static getInstance(): GameRootSingleton {
return GameRootSingleton._instance;
}
boardRootNode:Node;
UIRootNode: Node;
DialogRootNode: Node;
boardRoot: BoardRoot;
UIRoot: UIRoot;
DialogRoot: DialogRoot;
}
@ccclass('GameRootController')
export class GameRootController extends Component {
@property(Node) boardRootNode:Node;
@property(Node) UIRootNode: Node;
@property(Node) DialogRootNode: Node;
start() {
/// 给三个图层添加 root 根脚本
const game = GameRootSingleton.getInstance();
game.boardRootNode = this.boardRootNode;
game.UIRootNode = this.UIRootNode;
game.DialogRootNode = this.DialogRootNode;
/// 给三个图层添加 root 根脚本
game.boardRoot = this.boardRootNode.getComponent(BoardRoot);
game.UIRoot = this.UIRootNode.getComponent(UIRoot);
game.DialogRoot = this.DialogRootNode.getComponent(DialogRoot);
}
update(deltaTime: number) {
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "949ead83-9b0e-4202-8007-c50ab2ceeeb5",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -5,6 +5,7 @@ import { BaseButton } from '../../GlobalScript/CommonComponent/BaseButton';
import { AnimationNode } from '../../GlobalScript/Animation/AnimationNode';
import { UIRoot } from '../UIRoot';
import {CloseButtonNode } from '../Common/CloseButtonNode';
import { GameRootSingleton } from '../GameRootController';
const { ccclass } = _decorator;
/// 开始游戏按钮界面
@ -12,18 +13,7 @@ const { ccclass } = _decorator;
export class StartGameUINode extends Node {
/// 玩法介绍
private _pressenNode: Node;
set pressenNode(node: Node){
if (this._pressenNode){
this._pressenNode.destroy();
this._pressenNode = null;
}
this._pressenNode = node;
}
get pressenNode(): Node{
return this._pressenNode;
}
private pressenNode: Node;
constructor(){
super();
@ -156,7 +146,7 @@ export class StartGameUINode extends Node {
/// 开始游戏
startOnTouchEnd(event:Event){
const uiroot = this.parent.getComponent( UIRoot );
const uiroot = GameRootSingleton.getInstance().UIRoot;
uiroot.initGameUI();
/// 一帧结束之后销毁

View File

@ -15,6 +15,8 @@ import { DiceButtonNode } from "./UINode/DiceButtonNode";
import { OtherWinNode, otherWinType } from "./UINode/OtherWinNode";
import { BoardRoot } from "./BoardRoot";
import { StartGameUINode } from "./StartGameNode/StartGameUINode";
import { SelectNumberNode } from "./DialogNode/SelectNumberNode";
import { GameRootSingleton } from "./GameRootController";
const { ccclass } = _decorator;
@ccclass("UIRoot")
@ -32,14 +34,14 @@ export class UIRoot extends Component {
/// 其他胜利条件
private otherWinNode: OtherWinNode;
/// 初始化开始游戏界面的UI
//* 初始化开始游戏界面的UI
initStartGameUI() {
const startGameUINode = new StartGameUINode();
startGameUINode.addComponent(UITransform).setContentSize(1067, 600);
this.node.addChild(startGameUINode);
}
/// 初始化游戏界面UI
//* 初始化游戏界面UI
initGameUI() {
/// 玩家UI
this.initGamerUI();
@ -48,10 +50,10 @@ export class UIRoot extends Component {
/// 等待玩家加载
this.initAwaitGamerUI();
/// 其他胜利条件
this.initOtherNode();
this.initOtherWinNode();
}
/// 初始化玩家UI
//* 初始化玩家UI
initGamerUI() {
this.gamerOne = new GamerNode("玩家一");
this.gamerOne.setPosition(0, -540);
@ -68,7 +70,7 @@ export class UIRoot extends Component {
this.initDiceButton();
}
/// 初始化等待玩家加载UI
//* 初始化等待玩家加载UI
initAwaitGamerUI() {
const node = new Node();
node.setPosition(177.5, -244.5);
@ -83,40 +85,43 @@ export class UIRoot extends Component {
this.awaitGamerNode = node;
/// 2秒后 结束加载
//todo 自动跳过,接入网络后修改
// 1秒后 结束加载
setTimeout(() => {
/// 这一帧结束之后销毁
director.once(Director.EVENT_END_FRAME, () => {
// 销毁
this.awaitGamerNode.destroy();
// todo 开发时跳过倒计时动画
/// 初始化开始倒计时动画
// this.initCountFontAni(5);
});
// todo 开发时跳过倒计时动画
this.aniDone();
}, 2000);
}, 1000);
}
/// 初始化倒计时动画
//* 初始化倒计时动画
initCountFontAni(index: number) {
const ani = new AnimationNode("ani/dnf_quiz_" + index + ".ani", () => {
const ani = new AnimationNode('ani/count_font.ani',()=>{
/// 这一帧结束之后销毁
director.once(Director.EVENT_END_FRAME, () => {
// 销毁
ani.destroy();
});
if (index > 1) {
this.initCountFontAni(index - 1);
} else {
/// 动画结束
/// 动画结束
this.aniDone();
}
});
ani.setPosition(420, -180);
})
ani.setPosition(500, -200);
this.node.addChild(ani);
}
/// 初始化投骰子按钮
//* 初始化投骰子按钮
initDiceButton() {
this.diceButton = new DiceButtonNode();
this.diceButton.setPosition(849, -453);
@ -128,15 +133,15 @@ export class UIRoot extends Component {
};
}
/// 初始化其他胜利条件
initOtherNode() {
//* 初始化其他胜利条件
initOtherWinNode() {
this.otherWinNode = new OtherWinNode(otherWinType.longRun);
this.node.addChild(this.otherWinNode);
this.otherWinNode.active = false;
}
/// 动画结束
//* 动画结束 显示选择顺序
aniDone() {
/// 恢复其他胜利按钮的状态
this.diceButton.winButtonComponent.ButtonState = BaseButtonState.Normal;
@ -146,6 +151,15 @@ export class UIRoot extends Component {
/// 显示最底层的地图块
const board = boardNode.getComponent(BoardRoot);
board.initMapTile();
//* 1秒后自动关闭胜利条件显示,并显示顺序选择
setTimeout(() => {
//* 显示顺序选择node
this.otherWinNode.active = false;
GameRootSingleton.getInstance().DialogRoot.initSelectNumberNode();
}, 1000);
}
start() {

View File

@ -5,5 +5,6 @@
"width": 1067,
"height": 600
}
}
},
"custom_joint_texture_layouts": []
}