RedBagTask.ts 10 KB

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