RedBagTask.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import Util from "../../../before/util/Util";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class RedBagTask extends cc.Component{
  5. @property({displayName: '数字组', type: cc.Label})
  6. private lbl_value: cc.Label[] = [];
  7. @property({displayName: '任务描述', type: cc.RichText})
  8. private rt_task_des: cc.RichText = null;
  9. @property({displayName: '任务进度条', type: cc.Sprite})
  10. private sp_taskProgress: cc.Sprite = null;
  11. @property({displayName: '任务进度文本', type: cc.Label})
  12. private lbl_taskProgress: cc.Label = null;
  13. @property({displayName: '按钮动画', type: cc.Animation})
  14. private openBtn_ani: cc.Animation = null;
  15. @property(cc.Label)
  16. private lbl_reward_value: cc.Label = null;
  17. @property(cc.Sprite)
  18. private spr_cash_out: cc.Sprite = null;
  19. @property(cc.Label)
  20. private lbl_progress: cc.Label = null;
  21. @property(cc.Animation)
  22. private node_cash: cc.Animation = null;
  23. start(){
  24. mk.ad.showBanner();
  25. this.initTaskProgressUI();
  26. this.initCashOutStyle(gData.gameData.gameData.redMoney);
  27. this.showChangePart();
  28. }
  29. update(dt){
  30. if (gData.reward.add_redbag_value) {
  31. this.initCashOutStyle(gData.gameData.gameData.redMoney + gData.reward.add_redbag_value);
  32. }
  33. }
  34. private initTaskProgressUI()
  35. {
  36. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, {fillRange: 0.4}, {onUpdate: ()=>{
  37. let str = this.sp_taskProgress.fillRange * 100;
  38. this.lbl_taskProgress.string = str.toFixed(0) + "%";
  39. }}).start();
  40. cc.tween(this)
  41. }
  42. showChangePart() {
  43. //this.changePart.active = true
  44. let len = this.lbl_value.length;
  45. this.schedule(() => {
  46. for (var i = 0; i < len; i++) {
  47. let ran = Util.rnd(0, 9);
  48. this.lbl_value[i].string = `${ran}`;
  49. }
  50. }, 0.1)
  51. }
  52. /**
  53. * 底部提现相关样式
  54. */
  55. private initCashOutStyle(redMoney: number = 0) {
  56. const cash_bar = gData.redBagCash.cash_bar;
  57. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  58. if (!cash_data) return;
  59. const newRedMoney = redMoney > cash_data.type_value ? cash_data.type_value : redMoney;
  60. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  61. this.lbl_progress.string = newRedMoney + '/' + cash_data.type_value;
  62. const fillRange = newRedMoney / cash_data.type_value >= 1 ? 1 : newRedMoney / cash_data.type_value;
  63. // this.spr_cash_out.fillRange = fillRange;
  64. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  65. if (redMoney >= cash_data.type_value) {
  66. this.node_cash.play();
  67. } else {
  68. this.node_cash.stop();
  69. }
  70. }
  71. private clickVideoBtn()
  72. {
  73. }
  74. private clickGetRewardBtn()
  75. {
  76. }
  77. /**
  78. * 提现操作
  79. */
  80. private clickCashOut() {
  81. mk.audio.playEffect("button");
  82. gData.reward.addReward();
  83. mk.ui.closePanel(this.node.name);
  84. // let path = 'module/redBagCash/redBagCash';
  85. // mk.ui.openPanel(path);
  86. }
  87. private clickCloseBtn(){
  88. mk.audio.playEffect("closeButton");
  89. }
  90. }