BattleUI.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { UserManager } from './Manager/UserMgr';
  3. import { GameUtil } from './GameUtil';
  4. import { tgxUIMgr } from '../../core_tgx/tgx';
  5. import { UI_BattleGambit } from '../../scripts/UIDef';
  6. import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
  7. import { GameEvent } from './Enum/GameEvent';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('BattleUI')
  10. export class BattleUI extends Component {
  11. @property(Node)
  12. public renderAd: Node = null;
  13. @property(Label)
  14. public lbRenderFreeCount: Label = null;
  15. @property(Node)
  16. public radarAd: Node = null;
  17. @property(Label)
  18. public lbRadarFreeCount: Label = null;
  19. protected onLoad(): void {
  20. this.registerListener();
  21. }
  22. protected onDestroy(): void {
  23. this.unregisterListener();
  24. }
  25. start() {
  26. this.updateBtnsCountUI();
  27. }
  28. private registerListener() {
  29. EventDispatcher.instance.on(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this);
  30. }
  31. private updateBtnsCountUI(){
  32. const {radarFreeCount,freeScreenShotCount} = UserManager.instance.userModel;
  33. this.lbRenderFreeCount.string = `${freeScreenShotCount}`;
  34. this.lbRadarFreeCount.string = `${radarFreeCount}`;
  35. this.renderAd.active = false; //默认隐藏
  36. this.radarAd.active = false; //默认隐藏
  37. if(radarFreeCount <= 0){
  38. this.lbRadarFreeCount.string = '';
  39. this.radarAd.active = true;
  40. }
  41. if(freeScreenShotCount <= 0){
  42. this.lbRenderFreeCount.string = '';
  43. this.renderAd.active = true;
  44. }
  45. }
  46. private unregisterListener() {
  47. EventDispatcher.instance.off(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this);
  48. }
  49. }