RedBagTask.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import Util from "../../../before/util/Util";
  2. import SetGray from "../../component/SetGray";
  3. import { GameProp } from "../../data/GameData";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class RedBagTask extends cc.Component {
  7. @property({ displayName: '数字组', type: cc.Label })
  8. private lbl_value: cc.Label[] = [];
  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. @property({ type: cc.Node, displayName: '显示金额节点' })
  24. private node_value: cc.Node = null;
  25. @property({ type: cc.Node, displayName: '任务节点' })
  26. private node_task: cc.Node = null;
  27. @property({ type: cc.Label, displayName: '动画显示文字' })
  28. private lbl_Ani: cc.Label = null;
  29. @property({ type: cc.Label, displayName: '任务数量' })
  30. private lbl_taskNum: cc.Label = null;
  31. @property({ type: cc.Label, displayName: '任务描述' })
  32. private lbl_taskDes: cc.Label = null;
  33. private isShowNewTask = true;
  34. private num = 0;
  35. private delayTime = 0;
  36. private times = 0;
  37. private maxNum = 14;
  38. private isCanCash = false;
  39. start() {
  40. mk.ad.showBanner();
  41. this.maxNum = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  42. this.isShowNewTask = gData.gameData.init_redBagTask;
  43. if (this.isShowNewTask) {
  44. this.showNewTaskUI();
  45. } else {
  46. //this.node_value.active = true;
  47. //this.node_task.active = true;
  48. //this.node_cash.node.active = true;
  49. this.initTaskProgressUI();
  50. this.showChangePart();
  51. }
  52. this.initCashOutStyle(gData.gameData.gameData.redMoney);
  53. }
  54. private showNewTaskUI() {
  55. this.node_value.active = false;
  56. this.node_task.active = false;
  57. this.openBtn_ani.node.active = false;
  58. this.lbl_Ani.node.active = true;
  59. gData.gameData.init_redBagTask = false;
  60. gData.gameData.setProp(GameProp.redBagTaskRefresh, gData.gameData.init_redBagTask)
  61. }
  62. onEnable() {
  63. mk.ad.showBanner();
  64. }
  65. onDisable() {
  66. mk.ad.destoryBanner();
  67. mk.guide.open(3);
  68. }
  69. update(dt) {
  70. if (gData.reward.add_redbag_value) {
  71. this.initCashOutStyle(gData.gameData.gameData.redMoney + gData.reward.add_redbag_value);
  72. }
  73. if (this.isShowNewTask) {
  74. if (this.delayTime <= 0.6) {
  75. this.delayTime += dt;
  76. } else {
  77. this.times += 1;
  78. if (this.times == 2) {
  79. this.times = 0;
  80. this.num += 1;
  81. this.lbl_Ani.string = this.num.toString();
  82. if (this.num == this.maxNum) {
  83. this.isShowNewTask = false;
  84. this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
  85. let clone = cc.instantiate(this.lbl_Ani.node);
  86. clone.parent = this.lbl_Ani.node.parent;
  87. cc.tween(clone).to(0.8, { scale: 4.0, opacity: 0 }).call(() => {
  88. clone.active = false;
  89. let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
  90. let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
  91. cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
  92. cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
  93. this.lbl_Ani.node.active = false;
  94. this.node_task.active = true;
  95. cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
  96. }).start();
  97. this.node_value.active = true;
  98. this.node_value.scale = 0;
  99. cc.tween(this.node_value).to(0.76, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
  100. this.openBtn_ani.node.active = true;
  101. mk.guide.open(2);
  102. this.initTaskProgressUI();
  103. this.showChangePart();
  104. }).start();
  105. }).start();
  106. }
  107. }
  108. }
  109. }
  110. }
  111. private initTaskProgressUI() {
  112. if (gData.gameData.gameData.userFarmTaskInfo) {
  113. let com = gData.gameData.gameData.userFarmTaskInfo.completeCount;
  114. let count = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  115. let per = com / count;
  116. cc.tween(this.sp_taskProgress).delay(0.2).to(0.2, { fillRange: per }, {
  117. onUpdate: () => {
  118. let str = this.sp_taskProgress.fillRange * 100;
  119. this.lbl_taskProgress.string = str.toFixed(0) + "%";
  120. }
  121. }).start();
  122. cc.tween(this)
  123. this.lbl_taskNum.string = count.toString();
  124. this.lbl_taskDes.string = `完成 次收获,领取红包(${com}/${count})`;
  125. let gray = this.openBtn_ani.getComponent(SetGray);
  126. if (gray && com < count) {
  127. gray.setGray(true);
  128. this.openBtn_ani.getComponent(cc.Button).interactable = false;
  129. }
  130. this.isCanCash = com >= count;
  131. }
  132. }
  133. showChangePart() {
  134. //this.changePart.active = true
  135. let len = this.lbl_value.length;
  136. this.schedule(() => {
  137. for (var i = 0; i < len; i++) {
  138. let ran = Util.rnd(0, 9);
  139. this.lbl_value[i].string = `${ran}`;
  140. }
  141. }, 0.1)
  142. }
  143. /**
  144. * 底部提现相关样式
  145. */
  146. private initCashOutStyle(redMoney: number = 0) {
  147. const cash_bar = gData.redBagCash.cash_bar;
  148. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  149. if (!cash_data) return;
  150. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  151. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  152. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  153. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  154. // this.spr_cash_out.fillRange = fillRange;
  155. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  156. if (redMoney >= cash_data.redMoney) {
  157. this.node_cash.play();
  158. } else {
  159. this.node_cash.stop();
  160. }
  161. }
  162. private clickVideoBtn() {
  163. }
  164. private clickGetRewardBtn() {
  165. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  166. //mk.ui.openPanel('module/newNotice/newNotice');
  167. if (this.isCanCash) {
  168. this.httpCashOut();
  169. }
  170. }
  171. private async httpCashOut() {
  172. let data = {};
  173. let response = await mk.http.sendData('farmTask/farmTaskCash', data);
  174. mk.console.logSingle('redBagTask=>', response);
  175. if (response.errcode != 0) {
  176. return null;
  177. }
  178. gData.gameData.gameData.userFarmTaskInfo = response.data.userFarmTaskInfo;
  179. gData.gameData.init_redBagTask = true;
  180. gData.gameData.init_task = true;
  181. this.showNewTaskUI();
  182. this.isShowNewTask = true;
  183. gData.receiptNotice.receip_rmb = response.data.cashMoney;
  184. mk.ui.openPanel('module/newNotice/newNotice');
  185. gData.adData.checkPopCashFull();
  186. }
  187. /**
  188. * 提现操作
  189. */
  190. private clickCashOut() {
  191. mk.audio.playEffect("button");
  192. gData.reward.addReward();
  193. //mk.ui.closePanel(this.node.name);
  194. let path = 'module/newCashUI/walletCashOut';
  195. mk.ui.openPanel(path);
  196. }
  197. private clickCloseBtn() {
  198. mk.audio.playEffect("closeButton");
  199. }
  200. }