PigBank.ts 4.7 KB

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