import { Button, director } from 'cc'; import { _decorator, Component, Node } from 'cc'; import { GameGlobalData } from '../global/GameGlobalData'; import { Label } from 'cc'; import { UmLog } from '../../../cc-common/cc-util/UmLog'; const { ccclass, property } = _decorator; @ccclass('GameWinLayout') export class GameWinLayout extends Component { @property(Button) btnPlay: Button = null!; @property(Label) txtLevel: Label = null!; @property(Label) txtExp: Label = null!; @property(Label) txtCoin: Label = null!; @property(Label) txtReward: Label = null!; public onGameWinClose: (() => void) | undefined; protected onLoad(): void { this.btnPlay?.node.on(Button.EventType.CLICK, this.onBtnReplayClicked, this); } onBtnReplayClicked() { this.onGameWinClose?.(); } showWin(rewardData, callback = null) { UmLog.log("Show Game Win => ", JSON.stringify(rewardData)); this.onGameWinClose = callback; this.txtLevel.string = `Reward Level ${GameGlobalData.Instance.level}`; var exp = rewardData.exp || 0; this.txtExp.string = `Exp: ${exp}`; var gold = rewardData.gold || 0; this.txtCoin.string = `Gold: ${gold}`; this.txtReward.string = `Reward: ${rewardData.reward || ""}`; var userDataSaver = GameGlobalData.Instance.userDataSaver; userDataSaver.expInLevel += exp; userDataSaver.expAllTime += exp; userDataSaver.gold += gold; userDataSaver.saveData(); } }