RedBagTask.ts 9.2 KB

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