GamePassView.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-27 16:24:43
  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 receiveNode: Node = null!; //十倍领取
  30. @property([Label])
  31. private lab_list: Label[] = [];
  32. private time: number = 3; //倒数时间
  33. private isAuto: boolean = true; //服务器传是否展示按钮
  34. callback: Function = null!;
  35. protected start() {
  36. DCHandler.inst.reportData(3000500);
  37. this.setButton();
  38. this.isAuto = true;
  39. this.setData();
  40. this.addEventList();
  41. }
  42. addEventList() {
  43. oops.message.on(GameEvent.showCoinAnimation, this.showCoinAnimation, this);
  44. }
  45. showCoinAnimation() {
  46. if (oops.gui.has(UIID.GamePass)) {
  47. oops.gui.remove(UIID.GamePass);
  48. }
  49. }
  50. private setData() {
  51. if (smc.game.GameModel.eventType) {
  52. const curLevel = smc.account.AccountModel.curLevel;
  53. DCHandler.inst.reportData(3000100, curLevel);
  54. }
  55. this.isAuto = smc.game.GameModel.passViewInfo.doubleReward;
  56. this.receiveNode.active = this.isAuto;
  57. if (this.isAuto) {
  58. this.setAutoReceive();
  59. }
  60. const list = smc.game.GameModel.passViewInfo.showReward;
  61. list.forEach((item, index) => {
  62. if (this.lab_list[index]) {
  63. this.lab_list[index].string = item.propNum + "";
  64. }
  65. })
  66. }
  67. //开心收下正常领取
  68. private btn_none() {
  69. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  70. ServerHandler.inst.getPassRewards();
  71. DCHandler.inst.reportData(3000501);
  72. }
  73. oops.gui.remove(UIID.GamePass);
  74. DCHandler.inst.reportData(3000503);
  75. }
  76. //十倍领取
  77. private btn_more() {
  78. this.isAuto = false;
  79. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  80. smc.game.GameModel.viewType = "pass_reward";
  81. ADHandler.inst.showAd(AD_TYPE.Pass_Receive);
  82. oops.gui.remove(UIID.GamePass);
  83. DCHandler.inst.reportData(3000503);
  84. } else {
  85. oops.gui.remove(UIID.GamePass);
  86. }
  87. }
  88. //设置自动领取
  89. setAutoReceive() {
  90. let time = this.time;
  91. this.lab_tips.string = `${time}秒后自动领取`;
  92. this.callback = function () {
  93. this.lab_tips.string = `${time}秒后自动领取`;
  94. time--;
  95. if (time <= 0 && this.isAuto) {
  96. this.btn_more();
  97. if (this.callback) {
  98. this.unschedule(this.callback);
  99. }
  100. DCHandler.inst.reportData(3000502);
  101. }
  102. }
  103. this.schedule(this.callback, 1);
  104. }
  105. }