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 '../joy_stick/JoyStick'; import { BUILD_MODE, UmConfig } from '../../../cc-common/cc-util/UmConfig'; import { UmUtil } from '../../../cc-common/cc-util/UmUtil'; 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) levelTxt: Label = null!; @property(Label) txtSkillCollectDebug: Label = null!; @property(Label) txtCoin: 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(); 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; } setLevelTxt(level: number) { this.levelTxt.string = `Level ${level}`; } setCoinValue(value: number) { this.txtCoin.string = value.formatMoney(); } 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.setLevelTxt(level); this.getExpbar().setHPValue(GameGlobalData.Instance.userDataSaver.expInLevel, expLevel); this.debugSkillCollectedDebug(); this.setCoinValue(GameGlobalData.Instance.getGold()); } 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 async showGameLose() { GameGlobalData.Instance.changeState(EGAME_STATE.FINISH); JoyStick.Instance.hideJoySitck(); await UmUtil.asyncDelay(5); 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) }`; } }