import { _decorator, Component, Node, Layout, UITransform, Prefab, instantiate } from 'cc'; import { Http } from '../core/net/Http'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { WindowManager } from '../core/ui/window/WindowManager'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { ConfigData } from '../Data/ConfigData'; import { g } from '../Data/g'; import { RedBoxItem } from '../Item/RedBoxItem'; import { LoginWaitWin } from './LoginWaitWin'; const { ccclass, property } = _decorator; @ccclass('RedBox') export class RedBox extends Component { @property({ tooltip: "滚动视图", type: Node }) public listBox: Node; @property({ tooltip: "滚动视图外框", type: Node }) public listBoxGroup; @property({ tooltip: "http服务", type: Http }) public http: Http; start() { this.listBox.getComponent(Layout).spacingX = this.listBox.getComponent(Layout).paddingLeft = (this.listBoxGroup.getComponent(UITransform).width - 205 * 3) / 4; g.gameData.hasNewRedPacketUpdate = false; this.initUI(); } public async initUI() { let redList = g.gameData.myRedPacketDatas; redList.sort(function (a, b) { if (a.type != b.type) { return a.type - b.type; } else { return a.canOpenTime - b.canOpenTime; } }) for (let i = 0; i < redList.length; i++) { let prefabData = await ResourcesUtils.load("Prefabs/Item/红包", null, this.node); var itemNode = instantiate(prefabData); itemNode.parent = this.listBox; itemNode.getComponent(RedBoxItem).setData(redList[i]); } } public toPk() { let _lv = ConfigData.configMap.get("systemConfig").openBattleLv; if (g.userData.lv >= _lv) { WindowManager.open("Prefabs/Battle/BattleUIWindow", WindowOpenMode.CloseAndAdd, { tabIndex: 0 }); } else { WindowManager.showTips(_lv + '级开放'); } } /** * 关闭回调 */ public close() { g.gameData.isAddRole = true; } }