|
@@ -3,6 +3,8 @@ import { UserManager } from './Manager/UserMgr';
|
|
|
import { GameUtil } from './GameUtil';
|
|
|
import { tgxUIMgr } from '../../core_tgx/tgx';
|
|
|
import { UI_BattleGambit } from '../../scripts/UIDef';
|
|
|
+import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
|
|
|
+import { GameEvent } from './Enum/GameEvent';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('HomeUI')
|
|
@@ -23,6 +25,14 @@ export class HomeUI extends Component {
|
|
|
//剩余恢复时间
|
|
|
private remainingTime: number = 0;
|
|
|
|
|
|
+ protected onLoad(): void {
|
|
|
+ this.registerListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onDestroy(): void {
|
|
|
+ this.unregisterListener();
|
|
|
+ }
|
|
|
+
|
|
|
start() {
|
|
|
const {powerRecoverTime,powerMax,powerCurrent} = UserManager.instance.userModel;
|
|
|
this.powerRecoverTime = powerRecoverTime;
|
|
@@ -56,6 +66,10 @@ export class HomeUI extends Component {
|
|
|
this.updatePowerUI();
|
|
|
}
|
|
|
|
|
|
+ private registerListener() {
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updatePowerUI,this);
|
|
|
+ }
|
|
|
+
|
|
|
update(deltaTime: number) {
|
|
|
if(!this.lbTimeCount || !this.lbPower) return;
|
|
|
if (this.powerCurrent >= this.powerMax) {
|
|
@@ -80,4 +94,8 @@ export class HomeUI extends Component {
|
|
|
this.lbTimeCount.string = 'Max';
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private unregisterListener() {
|
|
|
+ EventDispatcher.instance.off(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updatePowerUI,this);
|
|
|
+ }
|
|
|
}
|