GamePassView.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-21 14:43:24
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-28 20:41:55
  6. * @Description: 游戏通关弹窗
  7. */
  8. import { Label, Node } from 'cc';
  9. import { _decorator } from 'cc';
  10. import { oops } from 'db://oops-framework/core/Oops';
  11. import { DeviceUtil } from 'db://oops-framework/core/utils/DeviceUtil';
  12. import { GameComponent } from "db://oops-framework/module/common/GameComponent";
  13. import { AD_TYPE } from '../common/config/GameDefine';
  14. import { UIID } from '../common/config/GameUIConfig';
  15. import { CocosHandler } from '../common/manager/CocosHandler';
  16. import { smc } from '../common/SingletonModuleComp';
  17. import { ADHandler } from '../common/manager/ADHandler';
  18. import { GameEvent } from '../common/config/GameEvent';
  19. import { ServerHandler } from '../common/manager/ServerHandler';
  20. import { DCHandler } from '../common/manager/DCHandler';
  21. const { ccclass, property } = _decorator;
  22. /** 显示对象控制 */
  23. @ccclass('GamePassView')
  24. export class GamePassView extends GameComponent {
  25. //提示Node
  26. @property(Label)
  27. private lab_tips: Label = null!;
  28. @property(Node)
  29. private showBtn1: Node = null!;
  30. @property(Node)
  31. private showBtn2: Node = null!;
  32. @property([Label])
  33. private lab_list: Label[] = [];
  34. private time: number = 3; //倒数时间
  35. private isAuto: boolean = true; //服务器传是否展示按钮
  36. callback: Function = null!;
  37. protected start() {
  38. DCHandler.inst.reportData(3000500);
  39. this.setButton();
  40. this.isAuto = true;
  41. this.setData();
  42. this.addEventList();
  43. }
  44. addEventList() {
  45. oops.message.on(GameEvent.showCoinAnimation, this.showCoinAnimation, this);
  46. }
  47. showCoinAnimation() {
  48. if (oops.gui.has(UIID.GamePass)) {
  49. oops.gui.remove(UIID.GamePass);
  50. }
  51. }
  52. private setData() {
  53. if (smc.game.GameModel.eventType) {
  54. const curLevel = smc.account.AccountModel.curLevel;
  55. DCHandler.inst.reportData(3000100, curLevel);
  56. }
  57. this.isAuto = smc.game.GameModel.passViewInfo.doubleReward;
  58. this.showBtn1.active = this.isAuto;
  59. this.showBtn2.active = !this.isAuto;
  60. if (this.isAuto) {
  61. this.setAutoReceive();
  62. }
  63. const list = smc.game.GameModel.passViewInfo.showReward;
  64. list.forEach((item, index) => {
  65. if (this.lab_list[index]) {
  66. this.lab_list[index].string = item.propNum + "";
  67. }
  68. })
  69. }
  70. //开心收下正常领取
  71. private btn_none() {
  72. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  73. ServerHandler.inst.getPassRewards();
  74. DCHandler.inst.reportData(3000501);
  75. }
  76. oops.gui.remove(UIID.GamePass);
  77. DCHandler.inst.reportData(3000503);
  78. }
  79. //十倍领取
  80. private btn_more() {
  81. this.isAuto = false;
  82. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  83. smc.game.GameModel.viewType = "pass_reward";
  84. ADHandler.inst.showAd(AD_TYPE.Pass_Receive);
  85. oops.gui.remove(UIID.GamePass);
  86. DCHandler.inst.reportData(3000503);
  87. } else {
  88. oops.gui.remove(UIID.GamePass);
  89. }
  90. }
  91. //设置自动领取
  92. setAutoReceive() {
  93. let time = this.time;
  94. this.lab_tips.string = `${time}秒后自动领取`;
  95. this.callback = function () {
  96. this.lab_tips.string = `${time}秒后自动领取`;
  97. time--;
  98. if (time <= 0 && this.isAuto) {
  99. this.btn_more();
  100. if (this.callback) {
  101. this.unschedule(this.callback);
  102. }
  103. DCHandler.inst.reportData(3000502);
  104. }
  105. }
  106. this.schedule(this.callback, 1);
  107. }
  108. }