NewOpenRedBag.ts 6.7 KB

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