BattleUI.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. const btnRender = find('Canvas/GameUI/BattleUI/BottomBtns/BtnRender')!;
  33. const btnProbe = find('Canvas/GameUI/BattleUI/BottomBtns/BtnProbe')!;
  34. btnRender.on(NodeEventType.TOUCH_END, () => this.onScreenShot(), this);
  35. btnProbe.on(NodeEventType.TOUCH_END, () => this.onRadar(), this);
  36. }
  37. private updateBtnsCountUI(){
  38. const {radarFreeCount,freeScreenShotCount} = UserManager.instance.userModel;
  39. this.lbRenderFreeCount.string = `${freeScreenShotCount}`;
  40. this.lbRadarFreeCount.string = `${radarFreeCount}`;
  41. this.renderAd.active = false; //默认隐藏
  42. this.radarAd.active = false; //默认隐藏
  43. if(radarFreeCount <= 0){
  44. this.lbRadarFreeCount.string = '';
  45. this.radarAd.active = true;
  46. }
  47. if(freeScreenShotCount <= 0){
  48. this.lbRenderFreeCount.string = '';
  49. this.renderAd.active = true;
  50. }
  51. }
  52. private onScreenShot(){
  53. this.useAbility(
  54. UserManager.instance.userModel.freeScreenShotCount,
  55. (count) => UserManager.instance.reduceFreeScreenShotCount(count),
  56. GameEvent.EVENT_CAMERA_SCREENSHOT
  57. );
  58. }
  59. private onRadar(){
  60. this.useAbility(
  61. UserManager.instance.userModel.radarFreeCount,
  62. (count) => UserManager.instance.reduceRadarFreeCount(count),
  63. GameEvent.EVENT_CAMERA_SCREENSHOT_RADAR
  64. );
  65. }
  66. private useAbility(freeCount: number,reduceFn: (count: number) => void,eventName: string) {
  67. if(freeCount <= 0) {
  68. if (!GlobalConfig.isDebug) {
  69. AdvertMgr.instance.showReawardVideo(() => {
  70. EventDispatcher.instance.emit(eventName);
  71. });
  72. } else {
  73. EventDispatcher.instance.emit(eventName);
  74. }
  75. } else {
  76. reduceFn(1);
  77. EventDispatcher.instance.emit(eventName);
  78. }
  79. }
  80. private unregisterListener() {
  81. EventDispatcher.instance.off(GameEvent.EVENT_REFRESH_PLAYER_INFO,this.updateBtnsCountUI,this);
  82. }
  83. }