SpeedUpUI.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.gameData.redMoney);
  17. }
  18. onEnable() {
  19. mk.ad.showBanner(BannerAdType.banner_click_5);
  20. }
  21. onDisable() {
  22. mk.ad.destoryBanner();
  23. }
  24. update(dt) {
  25. if (gData.reward.add_redbag_value) {
  26. this.initCashOutStyle(gData.gameData.gameData.redMoney + gData.reward.add_redbag_value);
  27. }
  28. }
  29. /**
  30. * 底部提现相关样式
  31. */
  32. private initCashOutStyle(redMoney: number = 0) {
  33. const cash_bar = gData.redBagCash.cash_bar;
  34. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  35. if (!cash_data) return;
  36. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  37. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  38. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  39. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  40. // this.spr_cash_out.fillRange = fillRange;
  41. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  42. if (redMoney >= cash_data.redMoney) {
  43. this.node_cash.play();
  44. } else {
  45. this.node_cash.stop();
  46. }
  47. }
  48. /**
  49. * 提现操作
  50. */
  51. private clickCashOut() {
  52. mk.audio.playEffect("button");
  53. gData.reward.addReward();
  54. mk.ui.closePanel(this.node.name);
  55. // let path = 'module/redBagCash/redBagCash';
  56. // mk.ui.openPanel(path);
  57. }
  58. private clickWatchVideoBtn() {
  59. mk.audio.playEffect("button");
  60. mk.ui.closePanel(this.node.name);
  61. mk.ad.videoAdType = VideoAdType.video_init_14;
  62. mk.ad.watchAd((success) => {
  63. if (success) {
  64. gData.adData.watchVideo(null);
  65. gData.gameData.setHarvest();
  66. mk.tip.pop('加速成功!');
  67. }
  68. })
  69. }
  70. private clickCloseBtn() {
  71. mk.audio.playEffect("closeButton");
  72. }
  73. }