RedBagTask.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
  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. mk.ad.showNative();
  76. }
  77. onDisable() {
  78. mk.event.remove('refreshCoin', this);
  79. //mk.ad.destoryBanner();
  80. mk.ad.destroyNativeAd();
  81. }
  82. update(dt) {
  83. if (gData.reward.add_redbag_value) {
  84. this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
  85. }
  86. if (this.isShowNewTask) {
  87. if (this.delayTime <= 0.6) {
  88. this.delayTime += dt;
  89. } else {
  90. this.times += 1;
  91. if (this.times == 2) {
  92. this.times = 0;
  93. this.num += 1;
  94. let randNum = mk.math.random(1, this.maxNum);
  95. this.lbl_Ani.string = randNum.toString();
  96. if (this.num == 14) {
  97. this.lbl_Ani.string = this.maxNum.toString();
  98. this.isShowNewTask = false;
  99. this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
  100. let clone = cc.instantiate(this.lbl_Ani.node);
  101. clone.parent = this.lbl_Ani.node.parent;
  102. cc.tween(clone).to(0.8, { scale: 4.0, opacity: 0 }).call(() => {
  103. clone.active = false;
  104. let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
  105. let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
  106. cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
  107. cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
  108. this.lbl_Ani.node.active = false;
  109. this.node_task.active = true;
  110. cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
  111. }).start();
  112. this.node_value.active = true;
  113. this.node_value.scale = 0;
  114. cc.tween(this.node_value).to(0.5, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
  115. this.openBtn_ani.node.active = true;
  116. // mk.guide.open(2);
  117. this.initTaskProgressUI();
  118. this.showChangePart();
  119. }).start();
  120. }).start();
  121. }
  122. }
  123. }
  124. }
  125. if (gData.gameData.init_redBagTask) {
  126. gData.gameData.init_redBagTask = false;
  127. gData.gameData.init_productTask = true;
  128. this.isRefreshTask = true;
  129. this.showNewTaskUI();
  130. this.isShowNewTask = true;
  131. }
  132. }
  133. private initTaskProgressUI() {
  134. if (gData.gameData.playerProp.userFarmTaskInfo) {
  135. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  136. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  137. let per = com / count;
  138. if (!this.isRefreshTask) {
  139. cc.tween(this.sp_taskProgress).delay(0.2).to(0.2, { fillRange: per }, {
  140. onUpdate: () => {
  141. let num = Math.round(this.sp_taskProgress.fillRange * count);
  142. this.lbl_taskProgress.string = `${num}/${count}`;
  143. }
  144. }).call(() => {
  145. this.lbl_taskProgress.string = `${com}/${count}`;
  146. }).start();
  147. } else {
  148. this.sp_taskProgress.fillRange = per;
  149. this.lbl_taskProgress.string = `${com}/${count}`;
  150. }
  151. this.lbl_taskNum.string = count.toString();
  152. let gray = this.openBtn_ani.getComponent(SetGray);
  153. if (gray && com < count) {
  154. gray.setGray(true, true);
  155. //this.openBtn_ani.getComponent(cc.Button).interactable = true;
  156. }
  157. this.isCanCash = com >= count;
  158. this.node_hand.active = this.isCanCash;
  159. if (this.isCanCash && gData.adData.checkShowVideoIcon()) {
  160. this.node_videoIcon.active = true;
  161. } else {
  162. this.node_videoIcon.active = false;
  163. }
  164. }
  165. }
  166. showChangePart() {
  167. //this.changePart.active = true
  168. let len = this.lbl_value.length;
  169. this.schedule(() => {
  170. for (var i = 0; i < len; i++) {
  171. let ran = Util.rnd(0, 9);
  172. this.lbl_value[i].string = `${ran}`;
  173. }
  174. }, 0.1)
  175. }
  176. /**
  177. * 底部提现相关样式
  178. */
  179. private initCashOutStyle(redMoney: number = 0) {
  180. if (redMoney == 0) {
  181. redMoney = gData.gameData.playerProp.redMoney;
  182. }
  183. redMoney = redMoney / 100;
  184. const cash_bar = gData.redBagCash.cash_bar;
  185. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  186. if (!cash_data) return;
  187. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  188. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  189. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
  190. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
  191. // this.spr_cash_out.fillRange = fillRange;
  192. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  193. if (redMoney >= cash_data.redMoney) {
  194. this.node_cash.play();
  195. } else {
  196. this.node_cash.stop();
  197. }
  198. }
  199. private clickVideoBtn() {
  200. }
  201. private clickGetRewardBtn() {
  202. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  203. //mk.ui.openPanel('module/newNotice/newNotice');
  204. mk.audio.playEffect("button");
  205. if (this.isCanCash) {
  206. if (cc.sys.isNative) {
  207. if (!gData.loginData.isAuth) {
  208. // JsbSystem.WxAuth();
  209. mk.ui.openPanel('module/authUI/authUI');
  210. return;
  211. }
  212. }
  213. this.httpCashOut();
  214. } else {
  215. mk.tip.pop('完成任务即可提现');
  216. }
  217. }
  218. private async httpCashOut() {
  219. // gData.cashPro.openCashPro(0);
  220. let data = {};
  221. let response = await mk.http.sendData('farmTask/farmTaskCash', data);
  222. mk.console.logSingle('redBagTask=>', response);
  223. if (response.errcode != 0) {
  224. // gData.cashPro.init_fail = true;
  225. return null;
  226. }
  227. gData.gameData.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
  228. gData.gameData.playerProp.completeFarmTaskTimes = response.data.completeFarmTaskTimes;
  229. mk.data.setTAEventUser(0, 'Cumulative_task', gData.gameData.playerProp.completeFarmTaskTimes);
  230. //gData.gameData.init_redBagTask = true;
  231. gData.gameData.checkTaskFinishUnLock();
  232. gData.gameData.init_task = true;
  233. this.maxNum = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  234. this.num = 0;
  235. this.delayTime = 0;
  236. this.times = 0;
  237. //this.showNewTaskUI();
  238. //this.isShowNewTask = true;
  239. // gData.cashPro.cashPro_money = response.data.cashMoney;
  240. // gData.cashPro.init_success = true;
  241. gData.receiptNotice.receip_rmb = response.data.cashMoney;
  242. mk.ui.openPanel('module/newNotice/newNotice');
  243. mk.data.sendDataEvent(DataEventId.Sundry, '任务红包提现成功');
  244. let value = mk.storage.getStorage('guide_harvest');
  245. if (!value) {
  246. mk.storage.setStorage('guide_harvest', 1);
  247. mk.data.sendXYEvent('guide_harvest', '首次领取任务红包');
  248. }
  249. gData.gameData.doPointToXYLogic();
  250. gData.adData.checkPopCashFull();
  251. }
  252. /**
  253. * 提现操作
  254. */
  255. private clickCashOut() {
  256. mk.audio.playEffect("button");
  257. gData.reward.addReward();
  258. //mk.ui.closePanel(this.node.name);
  259. let path = 'module/newCashUI/walletCashOut';
  260. mk.ui.openPanel(path);
  261. }
  262. private clickCloseBtn() {
  263. mk.audio.playEffect("button");
  264. }
  265. }