BlessingBagItem.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. data: any = null;
  23. lastNum: number = 0;
  24. totalTime: number = 0;
  25. deltaTime: number = 0;
  26. delta: number = 0;
  27. curValue: number = 0;
  28. curTime: number = 0;
  29. isPlayAni: boolean = false;
  30. /**
  31. * list_data
  32. * @param data item数据
  33. */
  34. public async setItemData(bData) {
  35. this.Init(bData.data, bData.isPlayAniUpdate, bData.isPlayInitAni);
  36. }
  37. Init(data: any, isPlayAni: boolean = false, isPlayInitAni: boolean = false) {
  38. this.data = data;
  39. this.txtNum.string = data.redMoney + "元";
  40. this.txtTip.string = "<outline color=#8C1010 width=4><color=#FFE00C>" + data.redMoney + "元</c>提现进度</outline>";
  41. this.btnCashed.active = data.status == 2;
  42. this.btnCanCash.active = data.status == 1;
  43. this.btnNoFinish.active = data.status == 0;
  44. if (isPlayAni) {
  45. this.scheduleOnce(() => {
  46. this.PlayNumAni(0.3);
  47. cc.tween(this.txtSlider.node).to(0.15, { scale: 1.2 })
  48. .to(0.15, { scale: 1 })
  49. .start();
  50. }, 0.3);
  51. }
  52. else if (isPlayInitAni) {
  53. this.scheduleOnce(() => {
  54. this.PlayInitNumAni(0.2);
  55. cc.tween(this.txtSlider.node).to(0.1, { scale: 1.2 })
  56. .to(0.1, { scale: 1 })
  57. .start();
  58. }, 0.3);
  59. } else {
  60. this.txtSlider.string = data.progressRate + "%";
  61. this.slider.fillRange = data.progressRate * 0.01;
  62. this.lastNum = data.progressRate;
  63. }
  64. }
  65. update(dt) {
  66. this.UpdateAniFrame(dt);
  67. }
  68. PlayNumAni(time: number) {
  69. this.totalTime = time;
  70. this.delta = (this.data.progressRate - this.lastNum) / time;
  71. this.deltaTime = time / (this.data.progressRate - this.lastNum);
  72. this.curValue = this.lastNum;
  73. this.curTime = 0;
  74. this.isPlayAni = true;
  75. }
  76. PlayInitNumAni(time: number) {
  77. this.totalTime = time;
  78. this.delta = (this.data.progressRate - 0) / time;
  79. this.deltaTime = time / (this.data.progressRate - 0);
  80. this.curValue = 0;
  81. this.curTime = 0;
  82. this.isPlayAni = true;
  83. }
  84. UpdateAni() {
  85. if (this.curTime < this.totalTime) {
  86. this.curTime += this.deltaTime;
  87. this.curValue += this.delta * this.deltaTime;
  88. if (this.curValue >= this.data.progressRate) {
  89. this.curValue = this.data.progressRate;
  90. }
  91. } else {
  92. this.curTime = this.totalTime;
  93. this.unschedule(this.UpdateAni);
  94. this.curValue = this.data.progressRate;
  95. this.lastNum = this.data.progressRate;
  96. }
  97. this.txtSlider.string = this.curValue.toFixed(2) + "%";
  98. this.slider.fillRange = this.curValue * 0.01;
  99. }
  100. UpdateAniFrame(dt) {
  101. if (this.isPlayAni) {
  102. if (this.curTime < this.totalTime) {
  103. this.curTime += dt;
  104. this.curValue += this.delta * dt;
  105. if (this.curValue >= this.data.progressRate) {
  106. this.isPlayAni = false;
  107. this.curValue = this.data.progressRate;
  108. this.lastNum = this.data.progressRate;
  109. }
  110. //if (this.data.redMoneyId == 1) {
  111. //console.log("-->CurValue:" + this.curValue);
  112. //}
  113. } else {
  114. this.isPlayAni = false;
  115. this.curTime = this.totalTime;
  116. //this.unschedule(this.UpdateAni);
  117. this.curValue = this.data.progressRate;
  118. this.lastNum = this.data.progressRate;
  119. }
  120. this.txtSlider.string = this.curValue.toFixed(2) + "%";
  121. this.slider.fillRange = this.curValue * 0.01;
  122. }
  123. }
  124. OnExit() {
  125. this.txtSlider.string = "0.00%";
  126. this.slider.fillRange = 0;
  127. }
  128. Click_CashedBtn() {
  129. mk.audio.playEffect("button");
  130. console.log("clicked cashed");
  131. mk.tip.pop('该红包已提现');
  132. }
  133. Click_CanCashBtn() {
  134. mk.audio.playEffect("button");
  135. console.log("clicked canCash");
  136. gData.blessingBag.OpenTaskRbPanel(this.data.redMoney, this.data.redMoneyId, 2, this.data.redMoney);
  137. }
  138. Click_NoFinishBtn() {
  139. mk.audio.playEffect("button");
  140. console.log("clicked noFinish");
  141. mk.tip.pop('提现进度不足');
  142. }
  143. }