NewOpenRedBag.ts 9.8 KB

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