RedBagCash.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import GamePlay from "../../../before/GamePlay";
  2. import TableView from "../../component/TableView";
  3. import { GameProp } from "../../data/GameData";
  4. const { ccclass, property } = cc._decorator;
  5. /**
  6. * 红包提现界面
  7. * @author 薛鸿潇
  8. */
  9. @ccclass
  10. export default class RedBagCash extends cc.Component {
  11. @property({ displayName: '滚动视图', type: cc.ScrollView })
  12. private sroll_view: cc.ScrollView = null!;
  13. @property({ displayName: '条目容器', type: cc.Node })
  14. private node_content: cc.Node = null!;
  15. @property({ displayName: 'lbl红包数量', type: cc.Label })
  16. private lbl_redbag: cc.Label = null!;
  17. @property({ displayName: 'lbl毛币数量', type: cc.Label })
  18. private lbl_rmb: cc.Label = null!;
  19. private tableview: TableView = null;
  20. onLoad() {
  21. // gData.gameData.gameData.redMoney = 10200;// 测试数据,数据正确后请删除
  22. this.tableview = this.sroll_view.getComponent('TableView');
  23. }
  24. start() {
  25. gData.redBagCash.init_list = true;
  26. gData.redBagCash.initState();
  27. }
  28. update(dt) {
  29. if (gData.redBagCash.update_list) {//更新的时候不需要动画
  30. this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data);
  31. this.initMoney();
  32. return;
  33. }
  34. if (gData.redBagCash.init_list) {
  35. this.initScrollView();
  36. this.initMoney();
  37. }
  38. }
  39. lateUpdate() {
  40. gData.redBagCash.init_list = false;
  41. gData.redBagCash.update_list = false;
  42. }
  43. /**
  44. * 初始化滚动视图
  45. */
  46. private initScrollView() {
  47. this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data);
  48. // 条目动画
  49. this.scheduleOnce(() => {
  50. this.itemAnim();
  51. }, 0)
  52. }
  53. private itemAnim() {
  54. let arr_node = this.node_content.children;
  55. const n_count = this.node_content.childrenCount;
  56. const start_pos = new cc.Vec2(0, -this.sroll_view.node.height);
  57. for (let i = 0; i < n_count; i++) {
  58. let node_item = arr_node[i];
  59. const end_pos = node_item.getPosition();
  60. node_item.y = start_pos.y;
  61. this.scheduleOnce(() => {
  62. mk.tween.move(node_item, 0.6, start_pos, end_pos, null, 'backOut');
  63. }, i * 0.1)
  64. }
  65. }
  66. /**
  67. * 初始化货币数量
  68. */
  69. private initMoney() {
  70. let red = gData.gameData.gameData.redMoney;
  71. red = parseFloat(red.toFixed(2));
  72. this.lbl_redbag.string = `${red}`;
  73. let rmb = gData.gameData.gameData.redMoney / 10000;
  74. rmb = rmb > 1 ? Math.floor(rmb) : parseFloat(rmb.toFixed(2));
  75. this.lbl_rmb.string = `${rmb}`;
  76. }
  77. onDestroy() {
  78. // 是否需要打开存钱罐
  79. console.log('BBB gData.redBagCash.success ', gData.redBagCash.success);
  80. if (gData.redBagCash.success) {
  81. gData.redBagCash.success = false;
  82. gData.safeDepositBoxData.creatPacketAnim(2);
  83. gData.cashNormal.checkGuideBank();
  84. let state = gData.gameData.getProp(GameProp.guideToWx);
  85. console.log('BBB gData.gameData.gameData.cashIndex ', gData.gameData.gameData.cashIndex);
  86. if (gData.gameData.gameData.cashIndex == 2 && !state) {
  87. mk.guide.open(3);
  88. return;
  89. }
  90. }
  91. const isOpenBankOnCloseCash = gData.gameData.getProp(GameProp.isOpenBankOnCloseCash);
  92. if (!isOpenBankOnCloseCash) {
  93. mk.ui.openPanel('module/pigBank/pigBank');
  94. gData.gameData.setProp(GameProp.isOpenBankOnCloseCash, 1);
  95. }
  96. }
  97. onClickClose() {
  98. if (GamePlay.Inst && GamePlay.Inst.ifPass) {
  99. GamePlay.Inst.gameCount();
  100. }
  101. }
  102. }