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