keepDoubleSpeedView.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-04-15 20:16:16
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-28 20:44:31
  6. * @Description: 继续二倍速
  7. */
  8. import { _decorator, Component, Node } from 'cc';
  9. import { oops } from 'db://oops-framework/core/Oops';
  10. import { GameComponent } from 'db://oops-framework/module/common/GameComponent';
  11. import { AD_TYPE } from '../common/config/GameDefine';
  12. import { UIID } from '../common/config/GameUIConfig';
  13. import { ADHandler } from '../common/manager/ADHandler';
  14. import { smc } from '../common/SingletonModuleComp';
  15. import { Label } from 'cc';
  16. import { DCHandler } from '../common/manager/DCHandler';
  17. import { GameEvent } from '../common/config/GameEvent';
  18. const { ccclass, property } = _decorator;
  19. @ccclass('keepDoubleSpeedView')
  20. export class keepDoubleSpeedView extends GameComponent {
  21. private isAuto: boolean = false;
  22. @property(Label)
  23. private lab_time: Label = null!;
  24. private time: number = 3;
  25. private autoFunction: Function | null = null;
  26. start() {
  27. this.setButton();
  28. //设置3秒自启动
  29. this.isAuto = true;
  30. this.time = 3;
  31. this.lab_time.string = `${this.time}秒后自启动`;
  32. this.autoFunction = () => {
  33. this.time--
  34. this.lab_time.string = `${this.time}秒后自启动`;
  35. if (this.isAuto && this.time <= 0) {
  36. if (this.autoFunction) {
  37. this.unschedule(this.autoFunction);
  38. this.isAuto = false;
  39. this.openAd();
  40. oops.gui.remove(UIID.KeepSpeed);
  41. DCHandler.inst.reportData(3000304);
  42. }
  43. }
  44. }
  45. this.schedule(this.autoFunction, 1);
  46. }
  47. private btn_open() {
  48. this.isAuto = false;
  49. this.openAd();
  50. oops.gui.remove(UIID.KeepSpeed);
  51. DCHandler.inst.reportData(3000303);
  52. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  53. }
  54. //打开广告
  55. private openAd() {
  56. smc.game.GameModel.viewType = "speed_reward";
  57. ADHandler.inst.showAd(AD_TYPE.Double_Speed_Receive);
  58. smc.game.GameModel.doubleSpeedAdCount++;
  59. }
  60. private btn_no() {
  61. this.isAuto = false;
  62. oops.gui.remove(UIID.KeepSpeed);
  63. ADHandler.inst.showAd("107");
  64. oops.message.dispatchEvent(GameEvent.updateGameState, "paused");
  65. }
  66. private btn_close() {
  67. this.isAuto = false;
  68. oops.gui.remove(UIID.KeepSpeed);
  69. //播放插屏广告
  70. ADHandler.inst.showAd("107");
  71. DCHandler.inst.reportData(3000305);
  72. oops.message.dispatchEvent(GameEvent.updateGameState, "paused");
  73. }
  74. protected onDestroy(): void {
  75. this.isAuto = false;
  76. if (this.autoFunction) {
  77. this.unschedule(this.autoFunction);
  78. }
  79. }
  80. }