NewOpenRedBag.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. if (this.showNativeAd) {
  64. mk.ad.showNative();
  65. } else {
  66. mk.ad.showBanner(BannerAdType.banner_click_3);
  67. }
  68. }
  69. onDisable() {
  70. mk.event.remove('refreshCoin', this);
  71. if (this.showNativeAd) {
  72. mk.ad.destroyNativeAd();
  73. } else {
  74. mk.ad.destoryBanner();
  75. }
  76. }
  77. /**
  78. * 底部提现相关样式
  79. */
  80. private initCashOutStyle(redMoney: number = 0) {
  81. if (gData.gameData.init_hideRedBag) {
  82. this.node_cashOut.active = false;
  83. gData.gameData.init_hideRedBag = false;
  84. return;
  85. }
  86. if (redMoney == 0) {
  87. redMoney = gData.gameData.playerProp.redMoney;
  88. }
  89. redMoney = redMoney / 100;
  90. const cash_bar = gData.redBagCash.cash_bar;
  91. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  92. if (!cash_data) return;
  93. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  94. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  95. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
  96. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
  97. // this.spr_cash_out.fillRange = fillRange;
  98. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  99. if (redMoney >= cash_data.redMoney) {
  100. this.node_cash.play();
  101. } else {
  102. this.node_cash.stop();
  103. }
  104. }
  105. private showWatchAdReward() {
  106. if (gData.reward.adData) {
  107. this.unschedule(this.onChangeSchedule);
  108. let v = '0.30';
  109. v = v.replace('.', '');
  110. let c = v.split('');
  111. for (let i = 0; i != this.lbl_value.length; ++i) {
  112. if (i < c.length) {
  113. this.lbl_value[i].string = c[i];
  114. } else {
  115. this.lbl_value[i].string = '0';
  116. }
  117. }
  118. }
  119. }
  120. // update() {
  121. // if (gData.harvestData.init_reward) {
  122. // gData.harvestData.init_reward = false;
  123. // //奖励弹窗
  124. // gData.reward.adData = gData.harvestData.adData;
  125. // mk.ui.openPanel('module/reward/reward');
  126. // }
  127. // }
  128. showChangePart() {
  129. //this.changePart.active = true
  130. this.schedule(this.onChangeSchedule, 0.1)
  131. }
  132. onChangeSchedule() {
  133. let len = this.lbl_value.length;
  134. for (var i = 0; i < len; i++) {
  135. let ran = Util.rnd(0, 9);
  136. this.lbl_value[i].string = `${ran}`;
  137. }
  138. }
  139. private async clickOpenBtn() {
  140. mk.audio.playEffect("button");
  141. mk.ui.closePanel(this.name);
  142. if (this.sp_icon.node.active) {
  143. this.creatorDownLoadTask();
  144. }
  145. else {
  146. mk.ad.watchAd(async (success: boolean) => {
  147. mk.console.log("watchAD:" + success);
  148. if (success) {
  149. await gData.adData.watchVideo(AdFun.harvest);
  150. //广告类型在界面打开时赋值
  151. mk.ui.closePanel(this.node.name);
  152. }
  153. });
  154. }
  155. }
  156. private clickCloseBtn() {
  157. // mk.audio.playEffect("closeButton");
  158. gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_1);
  159. }
  160. cool = false
  161. creatorDownLoadTask() {
  162. if (!CC_JSB) {
  163. gData.moreGame.popNodeGetRedBag();
  164. mk.ui.closePanel(this.node.name);
  165. return;
  166. }
  167. if (this.cool) {
  168. return
  169. }
  170. this.cool = true
  171. mk.data.sendDataEvent(DataEventId.hutuiFunction, "互推插屏下载");
  172. if (this.data.appType == 1) {
  173. if (!JsbSystem.ifCanStartGame(this.data.packageName, true)) {
  174. gData.moreGame.createNewTask(this.data)
  175. }
  176. }
  177. else if (this.data.appType == 2) {
  178. cc.sys.openURL(this.data.recommendLink);
  179. }
  180. mk.ui.closePanel(this.node.name);
  181. gData.moreGame.popNodeGetRedBag();
  182. }
  183. }