RedBagTask.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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(0.8, { 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. this.initTaskProgressUI();
  92. this.showChangePart();
  93. }).start();
  94. }).start();
  95. }
  96. }
  97. }
  98. }
  99. }
  100. private initTaskProgressUI() {
  101. cc.tween(this.sp_taskProgress).delay(0.2).to(0.3, { fillRange: 0.4 }, {
  102. onUpdate: () => {
  103. let str = this.sp_taskProgress.fillRange * 100;
  104. this.lbl_taskProgress.string = str.toFixed(0) + "%";
  105. }
  106. }).start();
  107. cc.tween(this)
  108. }
  109. showChangePart() {
  110. //this.changePart.active = true
  111. let len = this.lbl_value.length;
  112. this.schedule(() => {
  113. for (var i = 0; i < len; i++) {
  114. let ran = Util.rnd(0, 9);
  115. this.lbl_value[i].string = `${ran}`;
  116. }
  117. }, 0.1)
  118. }
  119. /**
  120. * 底部提现相关样式
  121. */
  122. private initCashOutStyle(redMoney: number = 0) {
  123. const cash_bar = gData.redBagCash.cash_bar;
  124. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  125. if (!cash_data) return;
  126. const newRedMoney = redMoney > cash_data.type_value ? cash_data.type_value : redMoney;
  127. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  128. this.lbl_progress.string = newRedMoney + '/' + cash_data.type_value;
  129. const fillRange = newRedMoney / cash_data.type_value >= 1 ? 1 : newRedMoney / cash_data.type_value;
  130. // this.spr_cash_out.fillRange = fillRange;
  131. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  132. if (redMoney >= cash_data.type_value) {
  133. this.node_cash.play();
  134. } else {
  135. this.node_cash.stop();
  136. }
  137. }
  138. private clickVideoBtn() {
  139. }
  140. private clickGetRewardBtn() {
  141. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  142. //mk.ui.openPanel('module/newNotice/newNotice');
  143. gData.adData.checkPopCashFull();
  144. }
  145. /**
  146. * 提现操作
  147. */
  148. private clickCashOut() {
  149. mk.audio.playEffect("button");
  150. gData.reward.addReward();
  151. //mk.ui.closePanel(this.node.name);
  152. let path = 'module/newCashUI/walletCashOut';
  153. mk.ui.openPanel(path);
  154. }
  155. private clickCloseBtn() {
  156. mk.audio.playEffect("closeButton");
  157. }
  158. }