SpeedUpUI.ts 4.1 KB

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