RewardShortCutPanel.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { utils } from "./Utils";
  2. import { YZ_Reward, BannerLocation } from "./YZ_Constant";
  3. import PlatUtils from "./PlatUtils";
  4. const { ccclass, property } = cc._decorator;
  5. /**
  6. * 分享录屏面板
  7. */
  8. @ccclass
  9. export default class RewardShortCutPanel extends cc.Component {
  10. bg: cc.Node = null;
  11. btnOk: cc.Node = null;
  12. btnCancel: cc.Node = null;
  13. glodNode: cc.Node = null;
  14. glodLabel: cc.Label = null;
  15. /**
  16. * 奖励回调
  17. */
  18. rewardCallFunc: Function = null;
  19. /**
  20. * 奖励值
  21. */
  22. rewardValue: number = 0;
  23. _showBanner: boolean = false;
  24. onLoad() {
  25. utils.SendEvent("结算前广告-创建快捷桌面-展示成功!");
  26. let shortcutCreated = false;
  27. if (PlatUtils.IsOPPO) {
  28. shortcutCreated = utils.oppoTool._shortcutCreated;
  29. } else if (PlatUtils.IsVIVO) {
  30. shortcutCreated = utils.Tool_Vivo._shortcutCreated;
  31. }
  32. if (shortcutCreated) {
  33. utils.showLog("已经存在桌面快捷方式,当前窗口直接销毁!");
  34. utils.SendEvent("结算前广告-创建快捷桌面-已经存在桌面快捷方式!");
  35. this.node.destroy();
  36. return;
  37. }
  38. // cc.log(`utils.ServerConfig.auto_desktop>${utils.ServerConfig.auto_desktop === 0},${utils.ServerConfig.auto_desktop == 0}<`);
  39. if (utils.ServerConfig.auto_desktop != undefined && utils.ServerConfig.auto_desktop === 0) {
  40. utils.showLog("服务器配置直接创建桌面,不显示弹窗,当前窗口直接销毁!");
  41. utils.SendEvent("结算前广告-创建快捷桌面-服务器配置直接创建桌面,不显示弹窗!");
  42. utils.cur_tool && utils.cur_tool.createShortcut && utils.cur_tool.createShortcut((res) => {
  43. utils.SendEvent("结算前广告-直接创建快捷桌面-创建成功!");
  44. })
  45. this.node.destroy();
  46. return;
  47. }
  48. this.rewardValue = utils.rewardValue;
  49. this.rewardCallFunc = utils.rewardCallFunc;
  50. this.initUi();
  51. this.initListener();
  52. if (cc.winSize.height < cc.winSize.width) {
  53. utils.adManager.HideBanner(BannerLocation.Game);
  54. } else {
  55. this._showBanner = true;
  56. utils.adManager.ShowBanner(BannerLocation.Game);
  57. }
  58. }
  59. /**
  60. * 初始化UI
  61. */
  62. protected initUi(): void {
  63. if (utils.otherConfig && utils.otherConfig.group) {
  64. this.node.group = utils.otherConfig.group;
  65. }
  66. this.bg = this.node.getChildByName("Panel").children[0];
  67. this.btnCancel = this.bg.getChildByName("btnClose");
  68. this.btnOk = this.bg.getChildByName("btnOk");
  69. this.glodNode = this.bg.getChildByName("rewardLabel");
  70. this.glodLabel = this.glodNode.getComponent(cc.Label);
  71. this.glodLabel.string = "奖励+" + this.rewardValue;
  72. if (this.rewardValue == 0) {
  73. this.glodNode.active = false;
  74. }
  75. utils.showSkipBtn(this.btnCancel);
  76. }
  77. onDestroy() {
  78. this._showBanner && utils.adManager.HideBanner(BannerLocation.Game)
  79. if (utils.rewardShortCutPanelCloseFunc) {
  80. utils.rewardShortCutPanelCloseFunc();
  81. utils.rewardShortCutPanelCloseFunc = null;;
  82. } else {
  83. utils.rewardCloseFunc && utils.rewardCloseFunc();
  84. utils.rewardCloseFunc = null;
  85. }
  86. utils.cur_tool && utils.cur_tool.checkHasShortCut && utils.cur_tool.checkHasShortCut()
  87. }
  88. onClose() {
  89. this.bg.runAction(cc.sequence(cc.scaleTo(0.3, 0).easing(cc.easeBackIn()), cc.callFunc(() => {
  90. this.node.destroy();
  91. })));
  92. }
  93. onEnable() {
  94. this.bg.scale = 0;
  95. let ratio: number = 1;
  96. if (cc.winSize.height < cc.winSize.width) {
  97. // 横屏游戏
  98. ratio = cc.winSize.width / 1920 * 0.6;
  99. } else {
  100. ratio = cc.winSize.width / 1080;
  101. }
  102. this.bg.runAction(cc.sequence(cc.scaleTo(0.3, ratio).easing(cc.easeBackOut()), cc.callFunc(() => {
  103. this.btnOk.runAction(cc.sequence(
  104. cc.scaleTo(0.5, 1.15),
  105. cc.scaleTo(0.5, 1)
  106. ).repeatForever());
  107. })));
  108. }
  109. protected onCreateShortCut() {
  110. if (PlatUtils.IsOPPO) {
  111. utils.oppoTool.createShortcut((res) => {
  112. utils.SendEvent("结算前广告-创建快捷桌面-创建成功!");
  113. this.rewardFunc(res)
  114. })
  115. } else if (PlatUtils.IsVIVO) {
  116. utils.Tool_Vivo.createShortcut((res) => {
  117. utils.SendEvent("结算前广告-创建快捷桌面-创建成功!");
  118. this.rewardFunc(res)
  119. })
  120. }
  121. }
  122. /**
  123. * 初始化监听事件
  124. */
  125. protected initListener(): void {
  126. }
  127. /**
  128. * 分享回调
  129. * @param ret
  130. * @param msg
  131. */
  132. rewardFunc(ret) {
  133. if (ret) {
  134. let result: YZ_Reward = new YZ_Reward();
  135. result.rewardValue = this.rewardValue;
  136. utils.showMsg("添加成功!奖励:+" + this.rewardValue);
  137. if (this.rewardCallFunc) {
  138. this.rewardCallFunc(result);
  139. }
  140. this.onClose();
  141. } else {
  142. utils.showMsg("添加失败!");
  143. this.onClose();
  144. }
  145. }
  146. /**
  147. * 初始化数据
  148. */
  149. protected initData(): void {
  150. }
  151. // update (dt) {}
  152. }