GamePassView.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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-16 19:01:08
  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. const { ccclass, property } = _decorator;
  21. /** 显示对象控制 */
  22. @ccclass('GamePassView')
  23. export class GamePassView extends GameComponent {
  24. //提示Node
  25. @property(Label)
  26. private lab_tips: Label = null!;
  27. @property(Node)
  28. private receiveNode: Node = null!; //十倍领取
  29. @property([Label])
  30. private lab_list: Label[] = [];
  31. private time: number = 3; //倒数时间
  32. private isAuto: boolean = true; //服务器传是否展示按钮
  33. callback: Function = null!;
  34. protected start() {
  35. this.setButton();
  36. this.isAuto = true;
  37. this.setData();
  38. this.addEventList();
  39. }
  40. addEventList() {
  41. oops.message.on(GameEvent.showCoinAnimation, this.showCoinAnimation, this);
  42. }
  43. showCoinAnimation() {
  44. if (oops.gui.has(UIID.GamePass)) {
  45. oops.gui.remove(UIID.GamePass);
  46. }
  47. }
  48. private setData() {
  49. this.isAuto = smc.game.GameModel.passViewInfo.doubleReward;
  50. this.receiveNode.active = this.isAuto;
  51. if (this.isAuto) {
  52. this.setAutoReceive();
  53. }
  54. const list = smc.game.GameModel.passViewInfo.showReward;
  55. list.forEach((item, index) => {
  56. if (this.lab_list[index]) {
  57. this.lab_list[index].string = item.propNum + "";
  58. }
  59. })
  60. }
  61. //开心收下正常领取
  62. private btn_none() {
  63. // oops.message.dispatchEvent(GameEvent.showCoinAnimation);
  64. oops.gui.remove(UIID.GamePass);
  65. //给服务器发信息--少量领取
  66. ServerHandler.inst.getPassRewards();
  67. //我要不要展示提现点,
  68. }
  69. //十倍领取
  70. private btn_more() {
  71. this.isAuto = false;
  72. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  73. smc.game.GameModel.viewType = "double_reward";
  74. console.log("十倍领取", smc.game.GameModel.viewType);
  75. ADHandler.inst.showAd(AD_TYPE.Pass_Receive);
  76. oops.gui.remove(UIID.GamePass);
  77. } else {
  78. oops.gui.remove(UIID.GamePass);
  79. }
  80. }
  81. //设置自动领取
  82. setAutoReceive() {
  83. let time = this.time;
  84. this.callback = function () {
  85. this.lab_tips.string = `${time}秒后自动领取`;
  86. time--;
  87. if (time <= 0 && this.isAuto) {
  88. this.btn_more();
  89. this.unschedule(this.callback)
  90. }
  91. }
  92. this.schedule(this.callback, 1, this.time);
  93. }
  94. }