Turnablerule.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { BannerAdType } from "../../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class Turnablerule 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. onLoad() {
  14. }
  15. start() {
  16. mk.ad.showBanner(BannerAdType.banner_click_9);
  17. this.initCashOutStyle(gData.gameData.playerProp.redMoney);
  18. mk.ui.registerRefreshEvent(this, this.initCashOutStyle.bind(this), "refreshCoin");
  19. }
  20. update(dt) {
  21. if (gData.reward.add_redbag_value) {
  22. this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
  23. }
  24. }
  25. /**
  26. * 底部提现相关样式
  27. */
  28. private initCashOutStyle(redMoney: number = 0) {
  29. if(redMoney == 0)
  30. {
  31. redMoney = gData.gameData.playerProp.redMoney;
  32. }
  33. redMoney = redMoney/100;
  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/100;
  40. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney/100);
  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. onDisable(){
  60. mk.ui.removeRefreshEvent(this);
  61. }
  62. private onClickClose() {
  63. mk.audio.playEffect("button");
  64. mk.ad.destoryBanner();
  65. }
  66. }