RedBagCash.ts 2.7 KB

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