RedBagTask.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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({ type: cc.Label, displayName: '任务描述' })
  32. private lbl_taskDes: cc.Label = null;
  33. @property(cc.Node)
  34. private node_videoIcon: cc.Node = null;
  35. private isShowNewTask = true;
  36. private num = 0;
  37. private delayTime = 0;
  38. private times = 0;
  39. private maxNum = 14;
  40. private isCanCash = false;
  41. start() {
  42. mk.console.logSingle('redBagTask=>', gData.gameData.gameData.userFarmTaskInfo);
  43. if(!gData.gameData.gameData.userFarmTaskInfo)
  44. {
  45. return;
  46. }
  47. this.maxNum = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  48. this.isShowNewTask = gData.gameData.init_redBagTask;
  49. if (this.isShowNewTask) {
  50. this.showNewTaskUI();
  51. } else {
  52. //this.node_value.active = true;
  53. //this.node_task.active = true;
  54. //this.node_cash.node.active = true;
  55. this.initTaskProgressUI();
  56. this.showChangePart();
  57. }
  58. this.initCashOutStyle(gData.gameData.gameData.redMoney);
  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.ad.destoryBanner();
  74. mk.guide.open(3);
  75. }
  76. update(dt) {
  77. if (gData.reward.add_redbag_value) {
  78. this.initCashOutStyle(gData.gameData.gameData.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. }
  120. private initTaskProgressUI() {
  121. if (gData.gameData.gameData.userFarmTaskInfo) {
  122. let com = gData.gameData.gameData.userFarmTaskInfo.completeCount;
  123. let count = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  124. let per = com / count;
  125. cc.tween(this.sp_taskProgress).delay(0.2).to(0.2, { fillRange: per }, {
  126. onUpdate: () => {
  127. let str = this.sp_taskProgress.fillRange * 100;
  128. this.lbl_taskProgress.string = str.toFixed(0) + "%";
  129. }
  130. }).start();
  131. cc.tween(this)
  132. this.lbl_taskNum.string = count.toString();
  133. this.lbl_taskDes.string = `(${com}/${count})`;
  134. let gray = this.openBtn_ani.getComponent(SetGray);
  135. if (gray && com < count) {
  136. gray.setGray(true);
  137. this.openBtn_ani.getComponent(cc.Button).interactable = false;
  138. }
  139. this.isCanCash = com >= count;
  140. if(this.isCanCash && gData.adData.checkShowVideoIcon())
  141. {
  142. this.node_videoIcon.active = true;
  143. }else{
  144. this.node_videoIcon.active = false;
  145. }
  146. }
  147. }
  148. showChangePart() {
  149. //this.changePart.active = true
  150. let len = this.lbl_value.length;
  151. this.schedule(() => {
  152. for (var i = 0; i < len; i++) {
  153. let ran = Util.rnd(0, 9);
  154. this.lbl_value[i].string = `${ran}`;
  155. }
  156. }, 0.1)
  157. }
  158. /**
  159. * 底部提现相关样式
  160. */
  161. private initCashOutStyle(redMoney: number = 0) {
  162. const cash_bar = gData.redBagCash.cash_bar;
  163. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
  164. if (!cash_data) return;
  165. const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
  166. this.lbl_reward_value.string = cash_data.money / 100 + '元';
  167. this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney;
  168. const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / cash_data.redMoney;
  169. // this.spr_cash_out.fillRange = fillRange;
  170. cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
  171. if (redMoney >= cash_data.redMoney) {
  172. this.node_cash.play();
  173. } else {
  174. this.node_cash.stop();
  175. }
  176. }
  177. private clickVideoBtn() {
  178. }
  179. private clickGetRewardBtn() {
  180. //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
  181. //mk.ui.openPanel('module/newNotice/newNotice');
  182. if (this.isCanCash) {
  183. this.httpCashOut();
  184. }
  185. }
  186. private async httpCashOut() {
  187. let data = {};
  188. let response = await mk.http.sendData('farmTask/farmTaskCash', data);
  189. mk.console.logSingle('redBagTask=>', response);
  190. if (response.errcode != 0) {
  191. return null;
  192. }
  193. gData.gameData.gameData.userFarmTaskInfo = response.data.userFarmTaskInfo;
  194. gData.gameData.init_redBagTask = true;
  195. //gData.gameData.init_task = true;
  196. this.maxNum = gData.gameData.gameData.userFarmTaskInfo.taskCount;
  197. this.num = 0;
  198. this.delayTime= 0;
  199. this.times = 0;
  200. this.showNewTaskUI();
  201. this.isShowNewTask = true;
  202. gData.receiptNotice.receip_rmb = response.data.cashMoney;
  203. mk.ui.openPanel('module/newNotice/newNotice');
  204. mk.data.sendDataEvent(DataEventId.Sundry, '任务红包提现成功');
  205. gData.adData.checkPopCashFull();
  206. }
  207. /**
  208. * 提现操作
  209. */
  210. private clickCashOut() {
  211. mk.audio.playEffect("button");
  212. gData.reward.addReward();
  213. //mk.ui.closePanel(this.node.name);
  214. let path = 'module/newCashUI/walletCashOut';
  215. mk.ui.openPanel(path);
  216. }
  217. private clickCloseBtn() {
  218. mk.audio.playEffect("closeButton");
  219. }
  220. }