GamePassView.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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-23 17:32:10
  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. this.isAuto = smc.game.GameModel.passViewInfo.doubleReward;
  52. this.receiveNode.active = this.isAuto;
  53. if (this.isAuto) {
  54. this.setAutoReceive();
  55. }
  56. const list = smc.game.GameModel.passViewInfo.showReward;
  57. list.forEach((item, index) => {
  58. if (this.lab_list[index]) {
  59. this.lab_list[index].string = item.propNum + "";
  60. }
  61. })
  62. }
  63. //开心收下正常领取
  64. private btn_none() {
  65. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  66. ServerHandler.inst.getPassRewards();
  67. DCHandler.inst.reportData(3000501);
  68. }
  69. oops.gui.remove(UIID.GamePass);
  70. DCHandler.inst.reportData(3000503);
  71. }
  72. //十倍领取
  73. private btn_more() {
  74. this.isAuto = false;
  75. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  76. smc.game.GameModel.viewType = "pass_reward";
  77. ADHandler.inst.showAd(AD_TYPE.Pass_Receive);
  78. oops.gui.remove(UIID.GamePass);
  79. DCHandler.inst.reportData(3000503);
  80. } else {
  81. oops.gui.remove(UIID.GamePass);
  82. }
  83. }
  84. //设置自动领取
  85. setAutoReceive() {
  86. let time = this.time;
  87. this.lab_tips.string = `${time}秒后自动领取`;
  88. this.callback = function () {
  89. this.lab_tips.string = `${time}秒后自动领取`;
  90. time--;
  91. if (time <= 0 && this.isAuto) {
  92. this.btn_more();
  93. this.unschedule(this.callback);
  94. DCHandler.inst.reportData(3000502);
  95. }
  96. }
  97. this.schedule(this.callback, 1, this.time);
  98. }
  99. }