import GamePlay from "../../../before/GamePlay"; import TableView from "../../component/TableView"; import { GameProp } from "../../data/GameData"; const { ccclass, property } = cc._decorator; /** * 红包提现界面 * @author 薛鸿潇 */ @ccclass export default class RedBagCash extends cc.Component { @property({ displayName: '滚动视图', type: cc.ScrollView }) private sroll_view: cc.ScrollView = null!; @property({ displayName: '条目容器', type: cc.Node }) private node_content: cc.Node = null!; @property({ displayName: 'lbl红包数量', type: cc.Label }) private lbl_redbag: cc.Label = null!; @property({ displayName: 'lbl毛币数量', type: cc.Label }) private lbl_rmb: cc.Label = null!; private tableview: TableView = null; onLoad() { // gData.gameData.gameData.redMoney = 10200;// 测试数据,数据正确后请删除 this.tableview = this.sroll_view.getComponent('TableView'); } start() { gData.redBagCash.init_list = true; gData.redBagCash.initState(); } update(dt) { if (gData.redBagCash.update_list) {//更新的时候不需要动画 this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data); this.initMoney(); return; } if (gData.redBagCash.init_list) { this.initScrollView(); this.initMoney(); } } lateUpdate() { gData.redBagCash.init_list = false; gData.redBagCash.update_list = false; } /** * 初始化滚动视图 */ private initScrollView() { this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data); // 条目动画 this.scheduleOnce(() => { this.itemAnim(); }, 0) } private itemAnim() { let arr_node = this.node_content.children; const n_count = this.node_content.childrenCount; const start_pos = new cc.Vec2(0, -this.sroll_view.node.height); for (let i = 0; i < n_count; i++) { let node_item = arr_node[i]; const end_pos = node_item.getPosition(); node_item.y = start_pos.y; this.scheduleOnce(() => { mk.tween.move(node_item, 0.6, start_pos, end_pos, null, 'backOut'); }, i * 0.1) } } /** * 初始化货币数量 */ private initMoney() { let red = gData.gameData.gameData.redMoney; red = parseFloat(red.toFixed(2)); this.lbl_redbag.string = `${red}`; let rmb = gData.gameData.gameData.redMoney / 10000; rmb = rmb > 1 ? Math.floor(rmb) : parseFloat(rmb.toFixed(2)); this.lbl_rmb.string = `${rmb}`; } onDestroy() { // 是否需要打开存钱罐 console.log('BBB gData.redBagCash.success ', gData.redBagCash.success); if (gData.redBagCash.success) { gData.redBagCash.success = false; gData.safeDepositBoxData.creatPacketAnim(2); gData.cashNormal.checkGuideBank(); let state = gData.gameData.getProp(GameProp.guideToWx); console.log('BBB gData.gameData.gameData.cashIndex ', gData.gameData.gameData.cashIndex); if (gData.gameData.gameData.cashIndex == 2 && !state) { mk.guide.open(3); return; } } const isOpenBankOnCloseCash = gData.gameData.getProp(GameProp.isOpenBankOnCloseCash); if (!isOpenBankOnCloseCash) { mk.ui.openPanel('module/pigBank/pigBank'); gData.gameData.setProp(GameProp.isOpenBankOnCloseCash, 1); } } onClickClose() { if (GamePlay.Inst && GamePlay.Inst.ifPass) { GamePlay.Inst.gameCount(); } } }