SpeedUpUI.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.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. const cash_bar = gData.redBagCash.cash_bar;
  35. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  36. if (!cash_data) return;
  37. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  38. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  39. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  40. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  41. // this.spr_cash_out.fillRange = fillRange;
  42. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  43. if (redMoney >= cash_data.redMoney) {
  44. this.node_cash.play();
  45. } else {
  46. this.node_cash.stop();
  47. }
  48. }
  49. /**
  50. * 提现操作
  51. */
  52. private clickCashOut() {
  53. mk.audio.playEffect("button");
  54. gData.reward.addReward();
  55. mk.ui.closePanel(this.node.name);
  56. // let path = 'module/redBagCash/redBagCash';
  57. // mk.ui.openPanel(path);
  58. }
  59. private clickWatchVideoBtn() {
  60. mk.audio.playEffect("button");
  61. if (gData.gameData.speedUpLeftTimes <= 0) {
  62. mk.tip.pop('今日加速次数已用完');
  63. return;
  64. }
  65. if (gData.gameData.checkCanSpeedUp()) {
  66. mk.ui.closePanel(this.node.name);
  67. mk.ad.videoAdType = VideoAdType.video_init_14;
  68. mk.ad.watchAd((success) => {
  69. if (success) {
  70. gData.adData.watchVideo(null);
  71. gData.gameData.setHarvest();
  72. mk.tip.pop('加速成功!');
  73. }
  74. })
  75. }
  76. else {
  77. mk.tip.pop('没有可加速的物品');
  78. }
  79. }
  80. private clickCloseBtn() {
  81. mk.audio.playEffect("closeButton");
  82. }
  83. }