SpeedUpUI.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { BannerAdType, 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. }
  19. onEnable() {
  20. mk.ad.showBanner(BannerAdType.banner_click_5);
  21. }
  22. onDisable() {
  23. mk.ad.destoryBanner();
  24. }
  25. update(dt) {
  26. if (gData.reward.add_redbag_value) {
  27. this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
  28. }
  29. }
  30. /**
  31. * 底部提现相关样式
  32. */
  33. private initCashOutStyle(redMoney: number = 0) {
  34. redMoney = redMoney/100;
  35. const cash_bar = gData.redBagCash.cash_bar;
  36. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  37. if (!cash_data) return;
  38. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  39. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  40. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  41. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  42. // this.spr_cash_out.fillRange = fillRange;
  43. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  44. if (redMoney >= cash_data.redMoney) {
  45. this.node_cash.play();
  46. } else {
  47. this.node_cash.stop();
  48. }
  49. }
  50. /**
  51. * 提现操作
  52. */
  53. private clickCashOut() {
  54. mk.audio.playEffect("button");
  55. gData.reward.addReward();
  56. mk.ui.closePanel(this.node.name);
  57. // let path = 'module/redBagCash/redBagCash';
  58. // mk.ui.openPanel(path);
  59. }
  60. private clickWatchVideoBtn() {
  61. mk.audio.playEffect("button");
  62. if (gData.gameData.playerProp.speedUpLeftTimes <= 0) {
  63. mk.tip.pop('今日加速次数已用完');
  64. return;
  65. }
  66. if (gData.gameData.checkCanSpeedUp()) {
  67. mk.ui.closePanel(this.node.name);
  68. mk.ad.videoAdType = VideoAdType.video_init_14;
  69. let self = this;
  70. mk.ad.watchAd(async (success) => {
  71. if (success) {
  72. gData.adData.watchVideo(null);
  73. let response = await mk.http.sendData('farmSpeedUp', {});
  74. if (response && response.errcode == 0) {
  75. gData.gameData.playerProp.speedUpLeftTimes = response.data.speedUpLeftTimes;
  76. self.lbl_remainTimes.string = `今日剩余次数:${gData.gameData.playerProp.speedUpLeftTimes}`;
  77. }
  78. gData.gameData.setHarvest();
  79. mk.tip.pop('加速成功!');
  80. }
  81. })
  82. }
  83. else {
  84. mk.tip.pop('没有可加速的物品');
  85. }
  86. }
  87. private clickCloseBtn() {
  88. mk.audio.playEffect("closeButton");
  89. }
  90. }