PigBank.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. import { DataEventId, GameProp } from "../../data/GameData";
  3. const { ccclass, property } = cc._decorator;
  4. /**
  5. * 存钱罐界面样式
  6. * @author 薛鸿潇
  7. */
  8. @ccclass
  9. export default class PigBank extends cc.Component {
  10. @property({ type: cc.Label, displayName: '按钮描述' })
  11. private lbl_get_desc: cc.Label = null!;
  12. @property({ type: cc.Label, displayName: '存款数量' })
  13. private lbl_deposit: cc.Label = null!;
  14. @property({ type: cc.Node, displayName: '提示动画' })
  15. private node_tip_anim: cc.Node = null!;
  16. @property({ type: cc.Animation, displayName: '提现动画' })
  17. private anim_btn_cash: cc.Animation = null!;
  18. onLoad() {
  19. mk.ad.bannerOperOnlyFullScreen(0);
  20. }
  21. start() {
  22. this.initCashDesc();
  23. mk.audio.playEffect("pigBank", false);
  24. // let target_node = gData.gameData.gameStyle.icon_hb;
  25. // const end_world_pos = target_node.parent.convertToWorldSpaceAR(target_node.getPosition());
  26. // const end_node_pos = gData.gameData.gameStyle.node.parent.convertToNodeSpaceAR(end_world_pos);
  27. // let start_node_pos = new cc.Vec2(0, -300);
  28. // mk.fly.PlayCoinAnim(1, 10, start_node_pos, end_node_pos, () => {
  29. // if (!gData.gameData.init_coin) gData.gameData.gameData.redMoney = 1234
  30. // });
  31. }
  32. update(dt) {
  33. if (gData.pigbank.init_data) {
  34. this.initCashDesc();
  35. }
  36. if (gData.pigbank.adData) {
  37. cc.log('存钱罐提现', gData.pigbank.adData)
  38. }
  39. }
  40. lateUpdate() {
  41. gData.pigbank.init_data = false;
  42. gData.pigbank.adData = null;
  43. }
  44. /**
  45. * 提现描述展示
  46. */
  47. private initCashDesc() {
  48. if (gData.gameData.gameData.isWithdrawable) {
  49. this.lbl_get_desc.string = '直接提现';
  50. this.node_tip_anim.active = false;
  51. this.anim_btn_cash.play();
  52. } else {
  53. if (gData.gameData.gameData.piggyBank >= gData.pigbank.cash_min_limit) {
  54. this.lbl_get_desc.string = '明日可提现';
  55. } else {
  56. this.lbl_get_desc.string = '满' + (gData.pigbank.cash_min_limit / 100).toFixed(2) + '元可提';
  57. }
  58. this.node_tip_anim.active = true;
  59. this.anim_btn_cash.stop();
  60. this.anim_btn_cash.node.scale = 1;
  61. }
  62. this.initDeposit()
  63. }
  64. /**
  65. * 初始化存钱罐金额
  66. * - 精确到分
  67. */
  68. private initDeposit() {
  69. const new_count = gData.gameData.gameData.piggyBank / 100;
  70. this.lbl_deposit.string = new_count.toFixed(2) + '元';
  71. }
  72. /**
  73. * 提现操作
  74. */
  75. private clickCashOP() {
  76. mk.audio.playEffect("button");
  77. if (!gData.gameData.gameData.isWithdrawable) {
  78. if (gData.gameData.gameData.piggyBank < gData.pigbank.cash_min_limit) {
  79. mk.tip.pop('满' + (gData.pigbank.cash_min_limit / 100).toFixed(2) + '元可提现')
  80. }
  81. else {
  82. mk.tip.pop('明日可提现')
  83. }
  84. return;
  85. } else if (gData.gameData.gameData.piggyBank < gData.pigbank.cash_min_limit) {
  86. mk.tip.pop('满' + (gData.pigbank.cash_min_limit / 100).toFixed(2) + '元可提现')
  87. return;
  88. }
  89. if (!gData.loginData.isAuth) {
  90. JsbSystem.WxAuth();
  91. return;
  92. }
  93. mk.data.sendDataEvent(DataEventId.jarWithDrawal, "存钱罐提现成功");
  94. gData.pigbank.cashOP();
  95. mk.ui.closePanel(this.node.name);
  96. }
  97. /**
  98. * 打开帮助界面完成回调
  99. */
  100. private async clickOpenHelpCall() {
  101. let des = "1、游戏内观看任意视频,都会获得现金。\n\n2、存款达到0.3元后,次日登陆,可无门槛提现。\n\n3、提现后,存款清零,可重新开始。";
  102. gData.help.des = des;
  103. }
  104. /** 点击关闭 */
  105. onClickClose() {
  106. mk.ad.bannerOperOnlyFullScreen(1);
  107. mk.ad.checkShowInterByChance();
  108. }
  109. onDestroy() {
  110. const isAutoOpenPanel = gData.gameData.getProp(GameProp.isAutoOpenPanel);
  111. if (isAutoOpenPanel === 1) {
  112. // 必须是可签到才弹
  113. if (!gData.gameData.gameData.isSignInToday && gData.sign.haveSignDay()) {
  114. mk.ui.openPanel('module/sign/sign');
  115. }
  116. else {
  117. gData.guideToWxData.checkPop();
  118. gData.gameData.setProp(GameProp.isAutoOpenPanel, 2);
  119. }
  120. }
  121. }
  122. onDisable() {
  123. if (gData.pigbank.success) {
  124. gData.pigbank.success = false;
  125. gData.safeDepositBoxData.creatPacketAnim(2);
  126. gData.cashNormal.checkGuideBank();
  127. }
  128. }
  129. }