RedBagTask.ts 11 KB

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