RedBagTask.ts 11 KB

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