RedBagCash.ts 3.3 KB

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