RedBagCash.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. mk.ad.showBanner();
  28. }
  29. update(dt) {
  30. if (gData.redBagCash.update_list) {//更新的时候不需要动画
  31. this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data);
  32. this.initMoney();
  33. return;
  34. }
  35. if (gData.redBagCash.init_list) {
  36. this.initScrollView();
  37. this.initMoney();
  38. }
  39. }
  40. lateUpdate() {
  41. gData.redBagCash.init_list = false;
  42. gData.redBagCash.update_list = false;
  43. }
  44. /**
  45. * 初始化滚动视图
  46. */
  47. private initScrollView() {
  48. this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data);
  49. // 条目动画
  50. this.scheduleOnce(() => {
  51. this.itemAnim();
  52. }, 0)
  53. }
  54. private itemAnim() {
  55. let arr_node = this.node_content.children;
  56. const n_count = this.node_content.childrenCount;
  57. const start_pos = new cc.Vec2(0, -this.sroll_view.node.height);
  58. for (let i = 0; i < n_count; i++) {
  59. let node_item = arr_node[i];
  60. const end_pos = node_item.getPosition();
  61. node_item.y = start_pos.y;
  62. this.scheduleOnce(() => {
  63. mk.tween.move(node_item, 0.6, start_pos, end_pos, null, 'backOut');
  64. }, i * 0.1)
  65. }
  66. }
  67. /**
  68. * 初始化货币数量
  69. */
  70. private initMoney() {
  71. // let red = gData.gameData.gameData.redMoney;
  72. // red = parseFloat(red.toFixed(2));
  73. // rmb = rmb > 1 ? Math.floor(rmb) : parseFloat(rmb.toFixed(2));
  74. let rmb = gData.gameData.gameData.redMoney / 10000;
  75. this.lbl_redbag.string = `${rmb.toFixed(2)}元`;
  76. // this.lbl_rmb.string = `${rmb}`;
  77. }
  78. onDestroy() {
  79. // 是否需要打开存钱罐
  80. // console.log('BBB gData.redBagCash.success ', gData.redBagCash.success);
  81. // if (gData.redBagCash.success) {
  82. // gData.redBagCash.success = false;
  83. // gData.safeDepositBoxData.creatPacketAnim(2);
  84. // gData.cashNormal.checkGuideBank();
  85. // let state = gData.gameData.getProp(GameProp.guideToWx);
  86. // console.log('BBB gData.gameData.gameData.cashIndex ', gData.gameData.gameData.cashIndex);
  87. // if (gData.gameData.gameData.cashIndex == 2 && !state) {
  88. // mk.guide.open(3);
  89. // return;
  90. // }
  91. // }
  92. // const isOpenBankOnCloseCash = gData.gameData.getProp(GameProp.isOpenBankOnCloseCash);
  93. // if (!isOpenBankOnCloseCash) {
  94. // mk.ui.openPanel('module/pigBank/pigBank');
  95. // gData.gameData.setProp(GameProp.isOpenBankOnCloseCash, 1);
  96. // }
  97. }
  98. onClickClose() {
  99. if (GamePlay.Inst && GamePlay.Inst.ifPass) {
  100. GamePlay.Inst.gameCount();
  101. }
  102. mk.ad.destoryBanner();
  103. }
  104. }