RedBagTask.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import Util from "../../../before/util/Util";
  2. import SetGray from "../../component/SetGray";
  3. import { BannerAdType, DataEventId, 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. this.maxNum = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  41. this.isShowNewTask = gData.gameData.init_redBagTask;
  42. if (this.isShowNewTask) {
  43. this.showNewTaskUI();
  44. } else {
  45. //this.node_value.active = true;
  46. //this.node_task.active = true;
  47. //this.node_cash.node.active = true;
  48. this.initTaskProgressUI();
  49. this.showChangePart();
  50. }
  51. this.initCashOutStyle(gData.gameData.gameData.redMoney);
  52. }
  53. private showNewTaskUI() {
  54. this.node_value.active = false;
  55. this.node_task.active = false;
  56. this.openBtn_ani.node.active = false;
  57. this.lbl_Ani.node.active = true;
  58. gData.gameData.init_redBagTask = false;
  59. gData.gameData.setProp(GameProp.redBagTaskRefresh, gData.gameData.init_redBagTask)
  60. }
  61. onEnable() {
  62. mk.ad.showBanner(BannerAdType.banner_click_2);
  63. }
  64. onDisable() {
  65. mk.ad.destoryBanner();
  66. mk.guide.open(3);
  67. }
  68. update(dt) {
  69. if (gData.reward.add_redbag_value) {
  70. this.initCashOutStyle(gData.gameData.gameData.redMoney + gData.reward.add_redbag_value);
  71. }
  72. if (this.isShowNewTask) {
  73. if (this.delayTime <= 0.6) {
  74. this.delayTime += dt;
  75. } else {
  76. this.times += 1;
  77. if (this.times == 2) {
  78. this.times = 0;
  79. this.num += 1;
  80. this.lbl_Ani.string = this.num.toString();
  81. if (this.num == this.maxNum) {
  82. this.isShowNewTask = false;
  83. this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
  84. let clone = cc.instantiate(this.lbl_Ani.node);
  85. clone.parent = this.lbl_Ani.node.parent;
  86. cc.tween(clone).to(0.8, { scale: 4.0, opacity: 0 }).call(() => {
  87. clone.active = false;
  88. let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
  89. let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
  90. cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
  91. cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
  92. this.lbl_Ani.node.active = false;
  93. this.node_task.active = true;
  94. cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
  95. }).start();
  96. this.node_value.active = true;
  97. this.node_value.scale = 0;
  98. cc.tween(this.node_value).to(0.76, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
  99. this.openBtn_ani.node.active = true;
  100. mk.guide.open(2);
  101. this.initTaskProgressUI();
  102. this.showChangePart();
  103. }).start();
  104. }).start();
  105. }
  106. }
  107. }
  108. }
  109. }
  110. private initTaskProgressUI() {
  111. if (gData.gameData.gameData.userFarmTaskInfo) {
  112. let com = gData.gameData.gameData.userFarmTaskInfo.completeCount;
  113. let count = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  114. let per = com / count;
  115. cc.tween(this.sp_taskProgress).delay(0.2).to(0.2, { fillRange: per }, {
  116. onUpdate: () => {
  117. let str = this.sp_taskProgress.fillRange * 100;
  118. this.lbl_taskProgress.string = str.toFixed(0) + "%";
  119. }
  120. }).start();
  121. cc.tween(this)
  122. this.lbl_taskNum.string = count.toString();
  123. this.lbl_taskDes.string = `完成 次收获,领取红包(${com}/${count})`;
  124. let gray = this.openBtn_ani.getComponent(SetGray);
  125. if (gray && com < count) {
  126. gray.setGray(true);
  127. this.openBtn_ani.getComponent(cc.Button).interactable = false;
  128. }
  129. this.isCanCash = com >= count;
  130. }
  131. }
  132. showChangePart() {
  133. //this.changePart.active = true
  134. let len = this.lbl_value.length;
  135. this.schedule(() => {
  136. for (var i = 0; i < len; i++) {
  137. let ran = Util.rnd(0, 9);
  138. this.lbl_value[i].string = `${ran}`;
  139. }
  140. }, 0.1)
  141. }
  142. /**
  143. * 底部提现相关样式
  144. */
  145. private initCashOutStyle(redMoney: number = 0) {
  146. const cash_bar = gData.redBagCash.cash_bar;
  147. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  148. if (!cash_data) return;
  149. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  150. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  151. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  152. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  153. // this.spr_cash_out.fillRange = fillRange;
  154. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  155. if (redMoney >= cash_data.redMoney) {
  156. this.node_cash.play();
  157. } else {
  158. this.node_cash.stop();
  159. }
  160. }
  161. private clickVideoBtn() {
  162. }
  163. private clickGetRewardBtn() {
  164. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  165. //mk.ui.openPanel('module/newNotice/newNotice');
  166. if (this.isCanCash) {
  167. this.httpCashOut();
  168. }
  169. }
  170. private async httpCashOut() {
  171. let data = {};
  172. let response = await mk.http.sendData('farmTask/farmTaskCash', data);
  173. mk.console.logSingle('redBagTask=>', response);
  174. if (response.errcode != 0) {
  175. return null;
  176. }
  177. gData.gameData.gameData.userFarmTaskInfo = response.data.userFarmTaskInfo;
  178. gData.gameData.init_redBagTask = true;
  179. gData.gameData.init_task = true;
  180. this.showNewTaskUI();
  181. this.isShowNewTask = true;
  182. gData.receiptNotice.receip_rmb = response.data.cashMoney;
  183. mk.ui.openPanel('module/newNotice/newNotice');
  184. mk.data.sendDataEvent(DataEventId.Sundry, '任务红包提现成功');
  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. }