NewOpenRedBag.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. data = null
  25. start() {
  26. mk.audio.playEffect("openRedBag");
  27. if (gData.moreGame.init_newOpenRedBag) {
  28. gData.moreGame.init_newOpenRedBag = false;
  29. this.showElectUI();
  30. }
  31. this.showChangePart();
  32. this.initCashOutStyle(gData.gameData.playerProp.redMoney);
  33. mk.ui.registerRefreshEvent(this.node, this.initCashOutStyle.bind(this), "refreshCoin");
  34. }
  35. showElectUI() {
  36. this.sendRecommendList();
  37. }
  38. async sendRecommendList() {
  39. if( this.sp_icon)
  40. {
  41. this.sp_icon.node.active = true;
  42. this.data = gData.moreGame.getRandomNormal();
  43. if (this.data && cc.sys.os != cc.sys.OS_WINDOWS) {
  44. cc.loader.load(this.data.icon, (err, res) => {
  45. if (err) {
  46. console.log('err:', err);
  47. return;
  48. }
  49. let tex: cc.Texture2D = res as cc.Texture2D;
  50. this.sp_icon.spriteFrame = new cc.SpriteFrame(tex);
  51. })
  52. }
  53. }
  54. this.node_openBtn.active = false;
  55. this.node_getBtn.active = true;
  56. }
  57. onEnable() {
  58. gData.adData.checkPopInter(InterAdType.interstitial1_click_1);
  59. mk.ad.showBanner(BannerAdType.banner_click_3);
  60. }
  61. onDisable() {
  62. mk.ui.removeRefreshEvent(this.node);
  63. mk.ad.destoryBanner();
  64. }
  65. /**
  66. * 底部提现相关样式
  67. */
  68. private initCashOutStyle(redMoney: number = 0) {
  69. if(redMoney == 0)
  70. {
  71. redMoney = gData.gameData.playerProp.redMoney;
  72. }
  73. redMoney = redMoney/100;
  74. const cash_bar = gData.redBagCash.cash_bar;
  75. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  76. if (!cash_data) return;
  77. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  78. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  79. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney/100;
  80. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  81. // this.spr_cash_out.fillRange = fillRange;
  82. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  83. if (redMoney >= cash_data.redMoney) {
  84. this.node_cash.play();
  85. } else {
  86. this.node_cash.stop();
  87. }
  88. }
  89. private showWatchAdReward() {
  90. if (gData.reward.adData) {
  91. this.unschedule(this.onChangeSchedule);
  92. let v = '0.30';
  93. v = v.replace('.', '');
  94. let c = v.split('');
  95. for (let i = 0; i != this.lbl_value.length; ++i) {
  96. if (i < c.length) {
  97. this.lbl_value[i].string = c[i];
  98. } else {
  99. this.lbl_value[i].string = '0';
  100. }
  101. }
  102. }
  103. }
  104. // update() {
  105. // if (gData.harvestData.init_reward) {
  106. // gData.harvestData.init_reward = false;
  107. // //奖励弹窗
  108. // gData.reward.adData = gData.harvestData.adData;
  109. // mk.ui.openPanel('module/reward/reward');
  110. // }
  111. // }
  112. showChangePart() {
  113. //this.changePart.active = true
  114. this.schedule(this.onChangeSchedule, 0.1)
  115. }
  116. onChangeSchedule() {
  117. let len = this.lbl_value.length;
  118. for (var i = 0; i < len; i++) {
  119. let ran = Util.rnd(0, 9);
  120. this.lbl_value[i].string = `${ran}`;
  121. }
  122. }
  123. private async clickOpenBtn() {
  124. mk.audio.playEffect("button");
  125. mk.ui.closePanel(this.name);
  126. if (this.sp_icon.node.active) {
  127. this.creatorDownLoadTask();
  128. }
  129. else {
  130. mk.ad.watchAd(async (success: boolean) => {
  131. mk.console.log("watchAD:" + success);
  132. if (success) {
  133. await gData.adData.watchVideo(AdFun.harvest);
  134. //广告类型在界面打开时赋值
  135. mk.ui.closePanel(this.node.name);
  136. }
  137. });
  138. }
  139. }
  140. private clickCloseBtn() {
  141. // mk.audio.playEffect("closeButton");
  142. gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_1);
  143. }
  144. cool = false
  145. creatorDownLoadTask() {
  146. if (!CC_JSB) {
  147. gData.moreGame.popNodeGetRedBag();
  148. mk.ui.closePanel(this.node.name);
  149. return;
  150. }
  151. if (this.cool) {
  152. return
  153. }
  154. this.cool = true
  155. mk.data.sendDataEvent(DataEventId.hutuiFunction, "互推插屏下载");
  156. if (this.data.appType == 1) {
  157. if (!JsbSystem.ifCanStartGame(this.data.packageName, true)) {
  158. gData.moreGame.createNewTask(this.data)
  159. }
  160. }
  161. else if (this.data.appType == 2) {
  162. cc.sys.openURL(this.data.recommendLink);
  163. }
  164. mk.ui.closePanel(this.node.name);
  165. gData.moreGame.popNodeGetRedBag();
  166. }
  167. }