157 lines
5.2 KiB
TypeScript
157 lines
5.2 KiB
TypeScript
|
import { _decorator, Component, Node } from 'cc';
|
||
|
import { HPBar } from './HPBar';
|
||
|
import { GameGlobalData } from '../global/GameGlobalData';
|
||
|
import { EGAME_STATE, GameDefine } from '../config/GameDefine';
|
||
|
import { Button } from 'cc';
|
||
|
import { UmClientEvent } from '../../../cc-common/cc-util/UmOneToMultiListener';
|
||
|
import { director } from 'cc';
|
||
|
import { Label } from 'cc';
|
||
|
import { GameWinLayout } from './GameWinLayout';
|
||
|
import { LevelUpLayout } from './LevelUpLayout';
|
||
|
import { UmLog } from '../../../cc-common/cc-util/UmLog';
|
||
|
import { JoyStick } from '../../Test/JoyStick';
|
||
|
const { ccclass, property } = _decorator;
|
||
|
|
||
|
@ccclass('GameUI')
|
||
|
export class GameUI extends Component {
|
||
|
@property(Node) gameWinPopup: Node = null!;
|
||
|
@property(Node) gameLosePopup: Node = null!;
|
||
|
@property(Node) levelUpLayout: Node = null!;
|
||
|
@property(Node) topLayout: Node = null!;
|
||
|
@property(Node) bottomLayout: Node = null!;
|
||
|
|
||
|
@property(HPBar) bossHPBar: HPBar = null!;
|
||
|
@property(HPBar) heroHPBar: HPBar = null!;
|
||
|
@property(HPBar) expBar: HPBar = null!;
|
||
|
@property(Button) btnConfig: Button = null!;
|
||
|
@property(Button) btnStart: Button = null!;
|
||
|
@property(Node) layoutConfig: Node = null!;
|
||
|
@property(Label) expLevelTitle: Label = null!;
|
||
|
@property(Label) txtSkillCollectDebug: Label = null!;
|
||
|
@property(Label) txtBuildVer: Label = null!;
|
||
|
|
||
|
protected onLoad(): void {
|
||
|
this.btnConfig?.node.on(Button.EventType.CLICK, this.showLayoutConfig, this);
|
||
|
this.btnStart?.node.on(Button.EventType.CLICK, this.onBtnStartClicked, this);
|
||
|
}
|
||
|
|
||
|
protected start(): void {
|
||
|
GameGlobalData.Instance.changeState(EGAME_STATE.INIT);
|
||
|
this.btnStart?.node.setNodeActive(true);
|
||
|
this.gameWinPopup.setNodeActive(false);
|
||
|
this.gameLosePopup.setNodeActive(false);
|
||
|
this.levelUpLayout.setNodeActive(false);
|
||
|
this.setTopBottomLayoutActive(false);
|
||
|
this.getBossHPBar().node.setNodeActive(false);
|
||
|
this.debugSkillCollectedDebug();
|
||
|
|
||
|
this.txtBuildVer.string = GameDefine.BUILD_VER;
|
||
|
|
||
|
JoyStick.Instance.hideJoySitck();
|
||
|
|
||
|
}
|
||
|
|
||
|
public getBossHPBar(): HPBar
|
||
|
{
|
||
|
return this.bossHPBar;
|
||
|
}
|
||
|
|
||
|
public getHeroHPBar(): HPBar {
|
||
|
return this.heroHPBar;
|
||
|
}
|
||
|
|
||
|
public getExpbar(): HPBar {
|
||
|
return this.expBar;
|
||
|
}
|
||
|
|
||
|
public setExpLevelTitle(content: string)
|
||
|
{
|
||
|
if (!this.expLevelTitle)
|
||
|
return;
|
||
|
|
||
|
this.expLevelTitle.string = content;
|
||
|
}
|
||
|
|
||
|
private onBtnStartClicked(btn: Button)
|
||
|
{
|
||
|
this.btnStart?.node.setNodeActive(false);
|
||
|
this.setTopBottomLayoutActive(true);
|
||
|
|
||
|
this.displayStatsDataOnStartGame();
|
||
|
|
||
|
UmClientEvent.dispatchEvent(GameDefine.EVENT_START_GAME);
|
||
|
JoyStick.Instance.showJoystick();
|
||
|
}
|
||
|
|
||
|
public setTopBottomLayoutActive(isActive: boolean)
|
||
|
{
|
||
|
this.bottomLayout?.setNodeActive(isActive);
|
||
|
this.topLayout?.setNodeActive(isActive);
|
||
|
}
|
||
|
|
||
|
public showLayoutConfig()
|
||
|
{
|
||
|
this.layoutConfig?.setNodeActive(true);
|
||
|
}
|
||
|
|
||
|
public displayStatsDataOnStartGame()
|
||
|
{
|
||
|
var expLevel = GameGlobalData.Instance.getExpInlevelNeed();
|
||
|
var level = GameGlobalData.Instance.level;
|
||
|
this.setExpLevelTitle(`Exp Level ${level}`);
|
||
|
this.getExpbar().setHPValue(GameGlobalData.Instance.userDataSaver.expInLevel, expLevel);
|
||
|
this.debugSkillCollectedDebug();
|
||
|
}
|
||
|
|
||
|
public updateExpProgressBar(expCollectRunTime: number)
|
||
|
{
|
||
|
var currentExp = expCollectRunTime + GameGlobalData.Instance.userDataSaver.expInLevel;
|
||
|
// UmLog.log("updateExpProgressBar => ", currentExp, GameGlobalData.Instance.getExpInlevelNeed());
|
||
|
this.getExpbar().setHPValue(currentExp, GameGlobalData.Instance.getExpInlevelNeed());
|
||
|
}
|
||
|
|
||
|
|
||
|
public showGameLose()
|
||
|
{
|
||
|
JoyStick.Instance.hideJoySitck();
|
||
|
GameGlobalData.Instance.changeState(EGAME_STATE.FINISH);
|
||
|
this.gameLosePopup.setNodeActive(true);
|
||
|
}
|
||
|
|
||
|
public showGameWin(rewardData)
|
||
|
{
|
||
|
GameGlobalData.Instance.changeState(EGAME_STATE.FINISH);
|
||
|
this.gameWinPopup.setNodeActive(true);
|
||
|
this.gameWinPopup.getComponent(GameWinLayout)?.showWin(rewardData, () => {
|
||
|
GameGlobalData.Instance.newGame();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
checkLevelUp()
|
||
|
{
|
||
|
UmLog.log("checkLevelUp");
|
||
|
if (!GameGlobalData.Instance.checkLevelUpWithSessionExpCollected(GameGlobalData.Instance.expCollected))
|
||
|
{
|
||
|
UmLog.log("checkLevelUp => NO");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this.setExpLevelTitle(`Exp Level ${GameGlobalData.Instance.level}`);
|
||
|
this.updateExpProgressBar(GameGlobalData.Instance.expCollected);
|
||
|
UmLog.log("SHOW Level Up");
|
||
|
var levelAfter = GameGlobalData.Instance.level;
|
||
|
this.levelUpLayout.setNodeActive(true);
|
||
|
this.levelUpLayout.getComponent(LevelUpLayout).showLevelUp(levelAfter - 1, levelAfter, () => {
|
||
|
this.debugSkillCollectedDebug();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public debugSkillCollectedDebug()
|
||
|
{
|
||
|
// var debug: string = "";
|
||
|
this.txtSkillCollectDebug.string = `AS => ${JSON.stringify(GameGlobalData.Instance.userDataSaver.activeSkillCollected)} | PS => ${JSON.stringify(GameGlobalData.Instance.passiveSkillCollected) }`;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|