BattleUI.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { _decorator, Component, find, Label, Node, NodeEventType } 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. import { GlobalConfig } from '../../start/Config/GlobalConfig';
  9. import { AdvertMgr } from '../../core_tgx/base/ad/AdvertMgr';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('BattleUI')
  12. export class BattleUI extends Component {
  13. @property(Node)
  14. public renderAd: Node = null;
  15. @property(Label)
  16. public lbRenderFreeCount: Label = null;
  17. @property(Node)
  18. public radarAd: Node = null;
  19. @property(Label)
  20. public lbRadarFreeCount: Label = null;
  21. protected onLoad(): void {
  22. this.registerListener();
  23. }
  24. protected onDestroy(): void {
  25. this.unregisterListener();
  26. }
  27. start() {
  28. this.updateBtnsCountUI();
  29. }
  30. private registerListener() {
  31. EventDispatcher.instance.on(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this);
  32. EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SPLIT,this.startCamerSplit,this);
  33. const btnRender = find('Canvas/GameUI/BattleUI/BottomBtns/BtnRender')!;
  34. const btnProbe = find('Canvas/GameUI/BattleUI/BottomBtns/BtnProbe')!;
  35. btnRender.on(NodeEventType.TOUCH_END, () => this.onScreenShot(), this);
  36. btnProbe.on(NodeEventType.TOUCH_END, () => this.onRadar(), this);
  37. }
  38. private updateBtnsCountUI(){
  39. const {radarFreeCount,freeScreenShotCount} = UserManager.instance.userModel;
  40. this.lbRenderFreeCount.string = `${freeScreenShotCount}`;
  41. this.lbRadarFreeCount.string = `${radarFreeCount}`;
  42. this.renderAd.active = false; //默认隐藏
  43. this.radarAd.active = false; //默认隐藏
  44. if(radarFreeCount <= 0){
  45. this.lbRadarFreeCount.string = '';
  46. this.radarAd.active = true;
  47. }
  48. if(freeScreenShotCount <= 0){
  49. this.lbRenderFreeCount.string = '';
  50. this.renderAd.active = true;
  51. }
  52. }
  53. private onScreenShot(){
  54. this.useAbility(
  55. UserManager.instance.userModel.freeScreenShotCount,
  56. (count) => UserManager.instance.reduceFreeScreenShotCount(count),
  57. GameEvent.EVENT_CAMERA_SCREENSHOT
  58. );
  59. }
  60. private onRadar(){
  61. this.useAbility(
  62. UserManager.instance.userModel.radarFreeCount,
  63. (count) => UserManager.instance.reduceRadarFreeCount(count),
  64. GameEvent.EVENT_CAMERA_SCREENSHOT_RADAR
  65. );
  66. }
  67. private useAbility(freeCount: number,reduceFn: (count: number) => void,eventName: string) {
  68. if(freeCount <= 0) {
  69. if (!GlobalConfig.isDebug) {
  70. AdvertMgr.instance.showReawardVideo(() => {
  71. EventDispatcher.instance.emit(eventName);
  72. });
  73. } else {
  74. EventDispatcher.instance.emit(eventName);
  75. }
  76. } else {
  77. reduceFn(1);
  78. EventDispatcher.instance.emit(eventName);
  79. }
  80. }
  81. private startCamerSplit() {
  82. this.node.active = false;
  83. }
  84. private unregisterListener() {
  85. EventDispatcher.instance.off(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this);
  86. }
  87. }