BlessingBagItem.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * @description 福袋item
  3. * @author kaka
  4. */
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class BlessingBagItem extends cc.Component {
  8. @property(cc.Label)
  9. txtNum: cc.Label = null;
  10. @property(cc.RichText)
  11. txtTip: cc.RichText = null;
  12. @property(cc.Label)
  13. txtSlider: cc.Label = null;
  14. @property(cc.Sprite)
  15. slider: cc.Sprite = null;
  16. @property(cc.Node)
  17. btnCashed: cc.Node = null;
  18. @property(cc.Node)
  19. btnCanCash: cc.Node = null;
  20. @property(cc.Node)
  21. btnNoFinish: cc.Node = null;
  22. @property(cc.Node)
  23. ani_fadeUp: cc.Node = null;
  24. data: any = null;
  25. lastNum: number = 0;
  26. totalTime: number = 0;
  27. deltaTime: number = 0;
  28. delta: number = 0;
  29. curValue: number = 0;
  30. curTime: number = 0;
  31. isPlayAni: boolean = false;
  32. isInit: boolean = true;
  33. /**
  34. * list_data
  35. * @param data item数据
  36. */
  37. public async setItemData(bData) {
  38. this.ani_fadeUp.opacity = 0;
  39. this.Init(bData.data, bData.isPlayAniUpdate, bData.isPlayInitAni);
  40. }
  41. Init(data: any, isPlayAni: boolean = false, isPlayInitAni: boolean = false) {
  42. this.data = data;
  43. this.txtNum.string = data.redMoney / 100 + "元";
  44. this.txtTip.string = "<b><color=#F89800>" + data.redMoney / 100 + "元</c><color = #BB6738>提现进度</c></b>";
  45. this.btnCashed.active = data.status == 2;
  46. this.btnCanCash.active = data.status == 1;
  47. this.btnNoFinish.active = data.status == 0;
  48. if (isPlayAni) {
  49. this.scheduleOnce(() => {
  50. this.PlayNumAni(0.3);
  51. cc.tween(this.txtSlider.node).to(0.15, { scale: 1.4 })
  52. .to(0.15, { scale: 1 })
  53. .start();
  54. }, 0.3);
  55. }
  56. else if (isPlayInitAni) {
  57. this.scheduleOnce(() => {
  58. this.PlayInitNumAni(0.2);
  59. cc.tween(this.txtSlider.node).to(0.1, { scale: 1.4 })
  60. .to(0.1, { scale: 1 })
  61. .start();
  62. }, 0.3);
  63. } else {
  64. this.txtSlider.string = (data.progressRate * 100).toFixed(2) + "%";
  65. this.slider.fillRange = data.progressRate;
  66. this.lastNum = data.progressRate * 100;
  67. }
  68. }
  69. update(dt) {
  70. this.UpdateAniFrame(dt);
  71. }
  72. PlayNumAni(time: number) {
  73. this.totalTime = time;
  74. this.delta = (this.data.progressRate * 100 - this.lastNum) / time;
  75. this.deltaTime = time / (this.data.progressRate * 100 - this.lastNum);
  76. this.curValue = this.lastNum;
  77. this.curTime = 0;
  78. this.isPlayAni = true;
  79. }
  80. PlayInitNumAni(time: number) {
  81. this.totalTime = time;
  82. this.delta = (this.data.progressRate * 100 - 0) / time;
  83. this.deltaTime = time / (this.data.progressRate * 100 - 0);
  84. this.curValue = 0;
  85. this.curTime = 0;
  86. this.isPlayAni = true;
  87. }
  88. UpdateAni() {
  89. if (this.curTime < this.totalTime) {
  90. this.curTime += this.deltaTime;
  91. this.curValue += this.delta * this.deltaTime;
  92. if (this.curValue >= this.data.progressRate * 100) {
  93. this.curValue = this.data.progressRate * 100;
  94. }
  95. } else {
  96. this.curTime = this.totalTime;
  97. this.unschedule(this.UpdateAni);
  98. this.curValue = this.data.progressRate * 100;
  99. this.lastNum = this.data.progressRate * 100;
  100. }
  101. this.txtSlider.string = this.curValue.toFixed(2) + "%";
  102. this.slider.fillRange = this.curValue * 0.01;
  103. }
  104. UpdateAniFrame(dt) {
  105. if (this.isPlayAni) {
  106. if (this.curTime < this.totalTime) {
  107. this.curTime += dt;
  108. this.curValue += this.delta * dt;
  109. if (this.curValue >= this.data.progressRate * 100) {
  110. this.isPlayAni = false;
  111. //this.doAni();
  112. this.curValue = this.data.progressRate * 100;
  113. this.lastNum = this.data.progressRate * 100;
  114. }
  115. //if (this.data.redMoneyId == 1) {
  116. //console.log("-->CurValue:" + this.curValue);
  117. //}
  118. } else {
  119. this.isPlayAni = false;
  120. //this.doAni();
  121. this.curTime = this.totalTime;
  122. //this.unschedule(this.UpdateAni);
  123. this.curValue = this.data.progressRate * 100;
  124. this.lastNum = this.data.progressRate * 100;
  125. }
  126. this.txtSlider.string = this.curValue.toFixed(2) + "%";
  127. this.slider.fillRange = this.curValue * 0.01;
  128. }
  129. }
  130. doAni() {
  131. if(this.isInit)
  132. {
  133. this.isInit = false;
  134. return;
  135. }
  136. let add = this.data.progressRate*100 - this.lastNum;
  137. if(add > 0)
  138. {
  139. this.ani_fadeUp.scale = 0;
  140. this.ani_fadeUp.opacity = 255;
  141. cc.tween(this.ani_fadeUp).to(0.2, {scale: 1}).delay(0.6).to(0.2, {opacity: 0}).start();
  142. this.ani_fadeUp.getComponent(cc.Label).string = '+' + add.toFixed(1);
  143. }
  144. }
  145. OnExit() {
  146. this.txtSlider.string = "0.00%";
  147. this.slider.fillRange = 0;
  148. }
  149. Click_CashedBtn() {
  150. mk.audio.playEffect("button");
  151. console.log("clicked cashed");
  152. mk.tip.pop('该红包已提现');
  153. }
  154. Click_CanCashBtn() {
  155. mk.audio.playEffect("button");
  156. console.log("clicked canCash");
  157. gData.blessingBag.OpenTaskRbPanel(this.data.Id, this.data.redMoney);
  158. }
  159. Click_NoFinishBtn() {
  160. mk.audio.playEffect("button");
  161. console.log("clicked noFinish");
  162. mk.tip.pop('提现进度不足');
  163. }
  164. }