RedBagTask.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.Sprite })
  8. private sp_taskProgress: cc.Sprite = null;
  9. @property({ displayName: '任务进度文本', type: cc.Label })
  10. private lbl_taskProgress: cc.Label = null;
  11. @property({ displayName: '按钮动画', type: cc.Animation })
  12. private openBtn_ani: cc.Animation = null;
  13. @property(cc.Label)
  14. private lbl_reward_value: cc.Label = null;
  15. @property(cc.Sprite)
  16. private spr_cash_out: cc.Sprite = null;
  17. @property(cc.Label)
  18. private lbl_progress: cc.Label = null;
  19. @property(cc.Animation)
  20. private node_cash: cc.Animation = null;
  21. @property({ type: cc.Node, displayName: '显示金额节点' })
  22. private node_value: cc.Node = null;
  23. @property({ type: cc.Node, displayName: '任务节点' })
  24. private node_task: cc.Node = null;
  25. @property({ type: cc.Label, displayName: '动画显示文字' })
  26. private lbl_Ani: cc.Label = null;
  27. @property({ type: cc.Label, displayName: '任务数量' })
  28. private lbl_taskNum: cc.Label = null;
  29. @property({ type: cc.Label, displayName: '任务描述' })
  30. private lbl_taskDes: cc.Label = null;
  31. private isShowNewTask = true;
  32. private num = 0;
  33. private delayTime = 0;
  34. private times = 0;
  35. start() {
  36. mk.ad.showBanner();
  37. if (this.isShowNewTask) {
  38. this.node_value.active = false;
  39. this.node_task.active = false;
  40. this.openBtn_ani.node.active = false;
  41. this.lbl_Ani.node.active = true;
  42. } else {
  43. //this.node_value.active = true;
  44. //this.node_task.active = true;
  45. //this.node_cash.node.active = true;
  46. this.initTaskProgressUI();
  47. this.showChangePart();
  48. }
  49. this.initCashOutStyle(gData.gameData.gameData.redMoney);
  50. }
  51. onEnable() {
  52. mk.ad.showBanner();
  53. }
  54. onDisable() {
  55. mk.ad.destoryBanner();
  56. mk.guide.open(3);
  57. }
  58. update(dt) {
  59. if (gData.reward.add_redbag_value) {
  60. this.initCashOutStyle(gData.gameData.gameData.redMoney + gData.reward.add_redbag_value);
  61. }
  62. if (this.isShowNewTask) {
  63. if (this.delayTime <= 0.6) {
  64. this.delayTime += dt;
  65. } else {
  66. this.times += 1;
  67. if (this.times == 2) {
  68. this.times = 0;
  69. this.num += 1;
  70. this.lbl_Ani.string = this.num.toString();
  71. if (this.num == 14) {
  72. this.isShowNewTask = false;
  73. this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
  74. let clone = cc.instantiate(this.lbl_Ani.node);
  75. clone.parent = this.lbl_Ani.node.parent;
  76. cc.tween(clone).to(1.2, { scale: 4.0, opacity: 0 }).call(() => {
  77. clone.active = false;
  78. let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
  79. let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
  80. cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
  81. cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
  82. this.lbl_Ani.node.active = false;
  83. this.node_task.active = true;
  84. cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
  85. }).start();
  86. this.node_value.active = true;
  87. this.node_value.scale = 0;
  88. cc.tween(this.node_value).to(0.76, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
  89. this.openBtn_ani.node.active = true;
  90. mk.guide.open(2);
  91. }).start();
  92. }).start();
  93. }
  94. }
  95. }
  96. }
  97. }
  98. private initTaskProgressUI() {
  99. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: 0.4 }, {
  100. onUpdate: () => {
  101. let str = this.sp_taskProgress.fillRange * 100;
  102. this.lbl_taskProgress.string = str.toFixed(0) + "%";
  103. }
  104. }).start();
  105. cc.tween(this)
  106. }
  107. showChangePart() {
  108. //this.changePart.active = true
  109. let len = this.lbl_value.length;
  110. this.schedule(() => {
  111. for (var i = 0; i < len; i++) {
  112. let ran = Util.rnd(0, 9);
  113. this.lbl_value[i].string = `${ran}`;
  114. }
  115. }, 0.1)
  116. }
  117. /**
  118. * 底部提现相关样式
  119. */
  120. private initCashOutStyle(redMoney: number = 0) {
  121. const cash_bar = gData.redBagCash.cash_bar;
  122. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  123. if (!cash_data) return;
  124. const newRedMoney = redMoney > cash_data.type_value ? cash_data.type_value : redMoney;
  125. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  126. this.lbl_progress.string = newRedMoney + '/' + cash_data.type_value;
  127. const fillRange = newRedMoney / cash_data.type_value >= 1 ? 1 : newRedMoney / cash_data.type_value;
  128. // this.spr_cash_out.fillRange = fillRange;
  129. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  130. if (redMoney >= cash_data.type_value) {
  131. this.node_cash.play();
  132. } else {
  133. this.node_cash.stop();
  134. }
  135. }
  136. private clickVideoBtn() {
  137. }
  138. private clickGetRewardBtn() {
  139. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  140. //mk.ui.openPanel('module/newNotice/newNotice');
  141. gData.adData.checkPopCashFull();
  142. }
  143. /**
  144. * 提现操作
  145. */
  146. private clickCashOut() {
  147. mk.audio.playEffect("button");
  148. gData.reward.addReward();
  149. //mk.ui.closePanel(this.node.name);
  150. let path = 'module/newCashUI/walletCashOut';
  151. mk.ui.openPanel(path);
  152. }
  153. private clickCloseBtn() {
  154. mk.audio.playEffect("closeButton");
  155. }
  156. }