NewOpenRedBag.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import Util from "../../../before/util/Util";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { AdFun } from "../../data/AdData";
  4. import { BannerAdType, DataEventId, InterAdType, InterFullAdType, VideoAdType } from "../../data/GameData";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class NewOpenRedBag extends cc.Component {
  8. @property({ displayName: '数字组', type: cc.Label })
  9. private lbl_value: cc.Label[] = [];
  10. @property(cc.Label)
  11. private lbl_reward_value: cc.Label = null;
  12. @property(cc.Sprite)
  13. private spr_cash_out: cc.Sprite = null;
  14. @property(cc.Label)
  15. private lbl_progress: cc.Label = null;
  16. @property(cc.Animation)
  17. private node_cash: cc.Animation = null;
  18. @property(cc.Sprite)
  19. private sp_icon: cc.Sprite = null;
  20. @property(cc.Node)
  21. private node_openBtn: cc.Node = null;
  22. @property(cc.Node)
  23. private node_getBtn: cc.Node = null;
  24. @property(cc.Node)
  25. private node_cashOut: cc.Node = null;
  26. data = null
  27. private showNativeAd = false;
  28. onLoad() {
  29. this.showNativeAd = gData.gameData.init_hideRedBag;
  30. }
  31. start() {
  32. if (gData.moreGame.init_newOpenRedBag) {
  33. gData.moreGame.init_newOpenRedBag = false;
  34. this.showElectUI();
  35. }
  36. this.showChangePart();
  37. this.initCashOutStyle(gData.gameData.playerProp.redMoney);
  38. mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
  39. }
  40. showElectUI() {
  41. this.sendRecommendList();
  42. }
  43. async sendRecommendList() {
  44. if (this.sp_icon) {
  45. this.sp_icon.node.active = true;
  46. this.data = gData.moreGame.getRandomNormal();
  47. if (this.data && cc.sys.os != cc.sys.OS_WINDOWS) {
  48. cc.loader.load(this.data.icon, (err, res) => {
  49. if (err) {
  50. console.log('err:', err);
  51. return;
  52. }
  53. let tex: cc.Texture2D = res as cc.Texture2D;
  54. this.sp_icon.spriteFrame = new cc.SpriteFrame(tex);
  55. })
  56. }
  57. }
  58. this.node_openBtn.active = false;
  59. this.node_getBtn.active = true;
  60. }
  61. onEnable() {
  62. //gData.adData.checkPopInter(InterAdType.interstitial1_click_1);
  63. gData.gameData.popTableScreenADLogic(0);
  64. if (this.showNativeAd) {
  65. mk.ad.showNative();
  66. } else {
  67. mk.ad.showBanner(BannerAdType.banner_click_3);
  68. }
  69. }
  70. onDisable() {
  71. mk.event.remove('refreshCoin', this);
  72. if (this.showNativeAd) {
  73. mk.ad.destroyNativeAd();
  74. } else {
  75. mk.ad.destoryBanner();
  76. }
  77. }
  78. /**
  79. * 底部提现相关样式
  80. */
  81. private initCashOutStyle(redMoney: number = 0) {
  82. if (gData.gameData.init_hideRedBag) {
  83. this.node_cashOut.active = false;
  84. gData.gameData.init_hideRedBag = false;
  85. return;
  86. }
  87. if (redMoney == 0) {
  88. redMoney = gData.gameData.playerProp.redMoney;
  89. }
  90. redMoney = redMoney / 100;
  91. const cash_bar = gData.redBagCash.cash_bar;
  92. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  93. if (!cash_data) return;
  94. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  95. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  96. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
  97. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
  98. // this.spr_cash_out.fillRange = fillRange;
  99. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  100. if (redMoney >= cash_data.redMoney) {
  101. this.node_cash.play();
  102. } else {
  103. this.node_cash.stop();
  104. }
  105. }
  106. private showWatchAdReward() {
  107. if (gData.reward.adData) {
  108. this.unschedule(this.onChangeSchedule);
  109. let v = '0.30';
  110. v = v.replace('.', '');
  111. let c = v.split('');
  112. for (let i = 0; i != this.lbl_value.length; ++i) {
  113. if (i < c.length) {
  114. this.lbl_value[i].string = c[i];
  115. } else {
  116. this.lbl_value[i].string = '0';
  117. }
  118. }
  119. }
  120. }
  121. // update() {
  122. // if (gData.harvestData.init_reward) {
  123. // gData.harvestData.init_reward = false;
  124. // //奖励弹窗
  125. // gData.reward.adData = gData.harvestData.adData;
  126. // mk.ui.openPanel('module/reward/reward');
  127. // }
  128. // }
  129. showChangePart() {
  130. //this.changePart.active = true
  131. this.schedule(this.onChangeSchedule, 0.1)
  132. }
  133. onChangeSchedule() {
  134. let len = this.lbl_value.length;
  135. for (var i = 0; i < len; i++) {
  136. let ran = Util.rnd(0, 9);
  137. this.lbl_value[i].string = `${ran}`;
  138. }
  139. }
  140. private async clickOpenBtn() {
  141. mk.audio.playEffect("button");
  142. mk.ui.closePanel(this.name);
  143. if (this.sp_icon.node.active) {
  144. this.creatorDownLoadTask();
  145. switch (gData.moreGame.openType) {
  146. case 0:
  147. mk.data.sendDataEvent(DataEventId.htRedBag_eject, "点击可收获-领取");
  148. break;
  149. case 1:
  150. mk.data.sendDataEvent(DataEventId.htRedBag_eject, "关闭提现界面-领取");
  151. break;
  152. case 2:
  153. mk.data.sendDataEvent(DataEventId.htRedBag_eject, "关闭福利界面-领取");
  154. break;
  155. case 3:
  156. mk.data.sendDataEvent(DataEventId.htRedBag_eject, "关闭农场等级奖励界面-领取");
  157. break;
  158. }
  159. gData.moreGame.openType = -1;
  160. }
  161. else {
  162. mk.ad.watchAd(async (success: boolean) => {
  163. mk.console.log("watchAD:" + success);
  164. if (success) {
  165. await gData.adData.watchVideo(AdFun.harvest);
  166. //广告类型在界面打开时赋值
  167. mk.ui.closePanel(this.node.name);
  168. }
  169. });
  170. }
  171. }
  172. private clickCloseBtn() {
  173. // mk.audio.playEffect("closeButton");
  174. gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_1);
  175. }
  176. cool = false
  177. creatorDownLoadTask() {
  178. if (!CC_JSB) {
  179. gData.moreGame.popNodeGetRedBag();
  180. mk.ui.closePanel(this.node.name);
  181. return;
  182. }
  183. if (this.cool) {
  184. return
  185. }
  186. this.cool = true
  187. mk.data.sendDataEvent(DataEventId.hutuiFunction, "互推插屏下载");
  188. if (this.data.appType == 1) {
  189. if (!JsbSystem.ifCanStartGame(this.data.packageName, true)) {
  190. gData.moreGame.createNewTask(this.data, 1)
  191. }
  192. }
  193. else if (this.data.appType == 2) {
  194. cc.sys.openURL(this.data.recommendLink);
  195. }
  196. mk.ui.closePanel(this.node.name);
  197. gData.moreGame.popNodeGetRedBag();
  198. }
  199. }