RedBagTask.ts 11 KB

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