RewardBoxPanel.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import { utils } from "./Utils";
  2. import YZ_Constant, { BannerLocation, YZ_Reward } from "./YZ_Constant";
  3. import AldUtils from "./AldUtils";
  4. import PlatUtils from "./PlatUtils";
  5. import YZ_LocalStorage from "./YZ_LocalStorage";
  6. const { ccclass, property } = cc._decorator;
  7. /**
  8. * 五倍奖励宝箱
  9. */
  10. @ccclass
  11. export default class RewardBoxPanel extends cc.Component {
  12. @property(cc.Node)
  13. checked: cc.Node = null
  14. @property(cc.Node)
  15. doubleBtn: cc.Node = null
  16. @property(cc.Node)
  17. tripleVideoBtn: cc.Node = null
  18. @property(cc.Node)
  19. tripleBtn: cc.Node = null
  20. @property(cc.Label)
  21. goldLabel: cc.Label = null
  22. @property(cc.Node)
  23. tirpNode: cc.Node = null
  24. @property(cc.Node)
  25. light: cc.Node = null
  26. @property(cc.Node)
  27. panel: cc.Node = null
  28. @property(cc.Node)
  29. closeBtn: cc.Node = null
  30. /**
  31. * 奖励回调
  32. */
  33. rewardCallFunc: Function = null;
  34. /**
  35. * 奖励值
  36. */
  37. rewardValue: number = 0;
  38. private set boxGetRewardCount(value: number) {
  39. this._boxGetRewardCount = value;
  40. YZ_LocalStorage.setItem(YZ_Constant.ST_GET_BOX_REWARD_COUNT, value + '');
  41. }
  42. _boxGetRewardCount: number = 0;
  43. private get boxGetRewardCount() {
  44. return this._boxGetRewardCount;
  45. }
  46. onLoad() {
  47. if (utils.otherConfig && utils.otherConfig.group) {
  48. this.node.group = utils.otherConfig.group;
  49. }
  50. this.rewardCallFunc = utils.rewardCallFunc;
  51. this.rewardValue = utils.rewardValue;
  52. if (cc.winSize.height < cc.winSize.width) {
  53. utils.adManager.HideBanner(BannerLocation.Game);
  54. } else {
  55. utils.adManager.ShowBanner(BannerLocation.Game);
  56. }
  57. this.panel.scale = 0;
  58. this._boxGetRewardCount = YZ_LocalStorage.getItem(YZ_Constant.ST_GET_BOX_REWARD_COUNT) || 0;
  59. // let result = utils.controView(ViewLocation.box);
  60. // this.checked.active = result.isSelect;
  61. // this.tripLabel.string = result.msg;
  62. // if (result.btnType) {
  63. // this.btnLabel.string = "领取五倍奖励"
  64. // } else {
  65. // this.btnLabel.string = "领取奖励"
  66. // }
  67. AldUtils.SendEvent("奖励宝箱显示成功!");
  68. this.goldLabel.string = "/" + this.rewardValue.toString();
  69. }
  70. onEnable() {
  71. utils.showSkipBtn(this.closeBtn, true);
  72. let ratio: number = 1;
  73. if (cc.winSize.height < cc.winSize.width) {
  74. // 横屏游戏
  75. ratio = cc.winSize.width / 1920 * 0.6;
  76. } else {
  77. ratio = cc.winSize.width / 1080;
  78. }
  79. if (PlatUtils.IsTest) {
  80. utils.ServerConfig.reward_box_change_count = 5;
  81. }
  82. this.panel.runAction(cc.sequence(cc.scaleTo(0.3, ratio).easing(cc.easeBackOut()), cc.callFunc(() => {
  83. let changeCount = utils.ServerConfig.reward_box_change_count ? parseInt(utils.ServerConfig.reward_box_change_count) : 0;
  84. if (utils.ServerConfig.reward_box_change_count != undefined && this.boxGetRewardCount >= changeCount) {
  85. this.tripleVideoBtn.active = true;
  86. this.tripleBtn.active = false
  87. utils.showScaleAction(this.tripleVideoBtn, this.doubleBtn, true, true);
  88. } else {
  89. this.tripleVideoBtn.active = false;
  90. utils.showScaleAction(this.tripleBtn, null, false, true);
  91. }
  92. this.light.runAction(cc.rotateBy(3, +360).repeatForever())
  93. })));
  94. }
  95. onDestroy() {
  96. utils.adManager.HideBanner(BannerLocation.Game)
  97. if (utils.rewardBoxPanelCloseFunc) {
  98. utils.rewardBoxPanelCloseFunc();
  99. utils.rewardBoxPanelCloseFunc = null;
  100. } else {
  101. utils.rewardCloseFunc && utils.rewardCloseFunc();
  102. utils.rewardCloseFunc = null;
  103. }
  104. }
  105. onClose() {
  106. this.panel.runAction(cc.sequence(cc.scaleTo(0.3, 0).easing(cc.easeBackIn()), cc.callFunc(() => {
  107. this.node.destroy();
  108. })));
  109. }
  110. // /**
  111. // * 初始化事件回调
  112. // * @param closeCallFunc
  113. // * @param rewardCallFunc
  114. // */
  115. // init(closeCallFunc: Function, rewardCallFunc: Function, reward: number) {
  116. // this.closeCallFunc = closeCallFunc;
  117. // this.rewardCallFunc = rewardCallFunc;
  118. // this.rewardValue = reward;
  119. // }
  120. onPlayVideo() {
  121. utils.adManager.ShowVideo((ret, msg) => {
  122. if (ret) {
  123. utils.showMsg(`获得${this._multiple}倍奖励! +${this.rewardValue * this._multiple}`);
  124. this.rewardValue = this.rewardValue * this._multiple;
  125. this.boxGetRewardCount++;
  126. let result: YZ_Reward = new YZ_Reward();
  127. result.rewardValue = this.rewardValue;
  128. if (this.rewardCallFunc) {
  129. this.rewardCallFunc(result);
  130. }
  131. this.onClose();
  132. AldUtils.SendEvent("宝箱获取奖励成功!");
  133. } else {
  134. utils.showMsg(msg ? msg : "视频广告播放失败!");
  135. AldUtils.SendEvent("宝箱视频播放失败!");
  136. }
  137. })
  138. }
  139. _multiple: number = 1;
  140. /**
  141. * 领取金币
  142. */
  143. onGetGold(event, data) {
  144. this._multiple = parseInt(data);
  145. switch (event.target.name) {
  146. case "BtnTripleVideo":
  147. AldUtils.SendEvent("点击宝箱视频获取按钮!");
  148. this.onPlayVideo();
  149. break;
  150. case "BtnDouble":
  151. case "BtnTriple":
  152. AldUtils.SendEvent("点击宝箱普通获取按钮!");
  153. utils.showMsg(`获得${this._multiple}倍奖励! +${this.rewardValue * this._multiple}`);
  154. this.boxGetRewardCount++;
  155. if (this.rewardCallFunc) {
  156. let result: YZ_Reward = new YZ_Reward();
  157. result.rewardValue = this.rewardValue * this._multiple;
  158. this.rewardCallFunc(result);
  159. }
  160. this.onClose();
  161. break;
  162. }
  163. }
  164. }