SpeedUpUI.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { AdFun } from "../../data/AdData";
  2. import { BannerAdType, VideoAdType } from "../../data/GameData";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class SpeedUpUI extends cc.Component {
  6. @property(cc.Label)
  7. private lbl_reward_value: cc.Label = null;
  8. @property(cc.Sprite)
  9. private spr_cash_out: cc.Sprite = null;
  10. @property(cc.Label)
  11. private lbl_progress: cc.Label = null;
  12. @property(cc.Animation)
  13. private node_cash: cc.Animation = null;
  14. @property(cc.Label)
  15. private lbl_remainTimes: cc.Label = null;
  16. start() {
  17. this.initCashOutStyle(gData.gameData.playerProp.redMoney);
  18. this.lbl_remainTimes.string = `今日剩余次数:${gData.gameData.playerProp.speedUpLeftTimes}`;
  19. mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
  20. }
  21. onEnable() {
  22. mk.ad.showBanner(BannerAdType.banner_click_5);
  23. }
  24. onDisable() {
  25. mk.event.remove('refreshCoin', this);
  26. mk.ad.destoryBanner();
  27. }
  28. update(dt) {
  29. if (gData.reward.add_redbag_value) {
  30. this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
  31. }
  32. if (gData.gameData.init_speedup) {
  33. gData.gameData.init_speedup = false;
  34. this.lbl_remainTimes.string = `今日剩余次数:${gData.gameData.playerProp.speedUpLeftTimes}`;
  35. }
  36. }
  37. /**
  38. * 底部提现相关样式
  39. */
  40. private initCashOutStyle(redMoney: number = 0) {
  41. if (redMoney == 0) {
  42. redMoney = gData.gameData.playerProp.redMoney;
  43. }
  44. redMoney = redMoney / 100;
  45. const cash_bar = gData.redBagCash.cash_bar;
  46. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  47. if (!cash_data) return;
  48. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  49. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  50. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
  51. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
  52. // this.spr_cash_out.fillRange = fillRange;
  53. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  54. if (redMoney >= cash_data.redMoney) {
  55. this.node_cash.play();
  56. } else {
  57. this.node_cash.stop();
  58. }
  59. }
  60. /**
  61. * 提现操作
  62. */
  63. private clickCashOut() {
  64. mk.audio.playEffect("button");
  65. gData.reward.addReward();
  66. mk.ui.closePanel(this.node.name);
  67. // let path = 'module/redBagCash/redBagCash';
  68. // mk.ui.openPanel(path);
  69. }
  70. private clickWatchVideoBtn() {
  71. mk.audio.playEffect("button");
  72. if (gData.gameData.playerProp.speedUpLeftTimes <= 0) {
  73. mk.tip.pop('今日加速次数已用完');
  74. return;
  75. }
  76. if (gData.gameData.checkCanSpeedUp()) {
  77. mk.ui.closePanel(this.node.name);
  78. mk.ad.videoAdType = VideoAdType.video_init_14;
  79. mk.ad.watchAd(async (success) => {
  80. if (success) {
  81. gData.adData.watchVideo(AdFun.farmSpeedUp);
  82. let response = await mk.http.sendData('farmSpeedUp', {});
  83. if (response && response.errcode == 0) {
  84. gData.gameData.playerProp.speedUpLeftTimes = response.data.speedUpLeftTimes;
  85. gData.gameData.init_speedup = true;
  86. }
  87. gData.gameData.setHarvest();
  88. mk.tip.pop('加速成功!');
  89. //gData.gameData.popTableScreenADLogic(12);
  90. }
  91. })
  92. }
  93. else {
  94. mk.tip.pop('没有可加速的物品');
  95. }
  96. }
  97. private clickCloseBtn() {
  98. mk.audio.playEffect("button");
  99. }
  100. onDestroy(){
  101. //gData.adData.checkPopInter(InterAdType.interstitial1_click_9);
  102. gData.gameData.popTableScreenADLogic(8);
  103. }
  104. }