RedBagTask.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. }
  59. private showNewTaskUI() {
  60. this.node_value.active = false;
  61. this.node_task.active = false;
  62. this.openBtn_ani.node.active = false;
  63. this.lbl_Ani.node.active = true;
  64. //gData.gameData.init_redBagTask = false;
  65. gData.gameData.init_task = true;
  66. //gData.gameData.setProp(GameProp.redBagTaskRefresh, gData.gameData.init_redBagTask)
  67. }
  68. onEnable() {
  69. mk.ad.showBanner(BannerAdType.banner_click_2);
  70. }
  71. onDisable() {
  72. mk.ad.destoryBanner();
  73. mk.guide.open(3);
  74. }
  75. update(dt) {
  76. if (gData.reward.add_redbag_value) {
  77. this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
  78. }
  79. if (this.isShowNewTask) {
  80. if (this.delayTime <= 0.6) {
  81. this.delayTime += dt;
  82. } else {
  83. this.times += 1;
  84. if (this.times == 2) {
  85. this.times = 0;
  86. this.num += 1;
  87. let randNum = mk.math.random(1, this.maxNum);
  88. this.lbl_Ani.string = randNum.toString();
  89. if (this.num == 14) {
  90. this.lbl_Ani.string = this.maxNum.toString();
  91. this.isShowNewTask = false;
  92. this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
  93. let clone = cc.instantiate(this.lbl_Ani.node);
  94. clone.parent = this.lbl_Ani.node.parent;
  95. cc.tween(clone).to(0.8, { scale: 4.0, opacity: 0 }).call(() => {
  96. clone.active = false;
  97. let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
  98. let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
  99. cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
  100. cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
  101. this.lbl_Ani.node.active = false;
  102. this.node_task.active = true;
  103. cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
  104. }).start();
  105. this.node_value.active = true;
  106. this.node_value.scale = 0;
  107. cc.tween(this.node_value).to(0.5, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
  108. this.openBtn_ani.node.active = true;
  109. mk.guide.open(2);
  110. this.initTaskProgressUI();
  111. this.showChangePart();
  112. }).start();
  113. }).start();
  114. }
  115. }
  116. }
  117. }
  118. if (gData.gameData.init_redBagTask) {
  119. gData.gameData.init_redBagTask = false;
  120. gData.gameData.init_productTask = true;
  121. this.isRefreshTask = true;
  122. this.showNewTaskUI();
  123. this.isShowNewTask = true;
  124. }
  125. }
  126. private initTaskProgressUI() {
  127. if (gData.gameData.playerProp.userFarmTaskInfo) {
  128. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  129. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  130. let per = com / count;
  131. if(!this.isRefreshTask)
  132. {
  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. redMoney = redMoney/100;
  174. const cash_bar = gData.redBagCash.cash_bar;
  175. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  176. if (!cash_data) return;
  177. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  178. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  179. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  180. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  181. // this.spr_cash_out.fillRange = fillRange;
  182. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  183. if (redMoney >= cash_data.redMoney) {
  184. this.node_cash.play();
  185. } else {
  186. this.node_cash.stop();
  187. }
  188. }
  189. private clickVideoBtn() {
  190. }
  191. private clickGetRewardBtn() {
  192. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  193. //mk.ui.openPanel('module/newNotice/newNotice');
  194. mk.audio.playEffect("button");
  195. if (this.isCanCash) {
  196. this.httpCashOut();
  197. }
  198. }
  199. private async httpCashOut() {
  200. let data = {};
  201. let response = await mk.http.sendData('farmTask/farmTaskCash', data);
  202. mk.console.logSingle('redBagTask=>', response);
  203. if (response.errcode != 0) {
  204. return null;
  205. }
  206. gData.gameData.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
  207. //gData.gameData.init_redBagTask = true;
  208. gData.gameData.init_task = true;
  209. this.maxNum = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  210. this.num = 0;
  211. this.delayTime = 0;
  212. this.times = 0;
  213. //this.showNewTaskUI();
  214. //this.isShowNewTask = true;
  215. gData.receiptNotice.receip_rmb = response.data.cashMoney;
  216. mk.ui.openPanel('module/newNotice/newNotice');
  217. mk.data.sendDataEvent(DataEventId.Sundry, '任务红包提现成功');
  218. gData.adData.checkPopCashFull();
  219. }
  220. /**
  221. * 提现操作
  222. */
  223. private clickCashOut() {
  224. mk.audio.playEffect("button");
  225. gData.reward.addReward();
  226. //mk.ui.closePanel(this.node.name);
  227. let path = 'module/newCashUI/walletCashOut';
  228. mk.ui.openPanel(path);
  229. }
  230. private clickCloseBtn() {
  231. mk.audio.playEffect("closeButton");
  232. }
  233. }