| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- import PrefabManager from "../manager/PrefabManager";
- import { Dictionary } from "../tools/General";
- import BasePanel from "./BasePanel";
- export default class UIMng {
- private static _ins: UIMng;
- public static get Ins(): UIMng {
- if (this._ins == null) {
- console.log("---------------------------------------------------UIMng");
- this._ins = new UIMng();
- }
- return this._ins;
- }
- private canvasNode: cc.Node;
- private get CanvasNode(): cc.Node {
- if (this.canvasNode == null) {
- this.canvasNode = cc.find("Canvas/Panel");
- }
- return this.canvasNode;
- }
- private canvasNode0: cc.Node;
- private get CanvasNode0(): cc.Node {
- if (this.canvasNode0 == null) {
- this.canvasNode0 = cc.find("Canvas/Panel0");
- }
- return this.canvasNode0;
- }
- private canvasNodeA: cc.Node;
- private get CanvasNodeA(): cc.Node {
- if (this.canvasNodeA == null) {
- this.canvasNodeA = cc.find("Canvas/PanelA");
- }
- return this.canvasNodeA;
- }
- private panelDic: Dictionary<PanelType, BasePanel>;
- private panelPath: Dictionary<PanelType, string>;
- private id: number = 1;
- Destroy() {
- this.canvasNode = null;
- this.canvasNode0 = null;
- this.canvasNodeA = null;
- //if (this.panelDic)
- // this.panelDic.Clear();
- this.panelDic = null;
- this.panelPath = null;
- console.log("UIMng Destroy::", this.panelDic + " ID:" + this.id);
- UIMng._ins = null;
- }
- constructor() {
- //return;
- this.id = (new Date).getSeconds();
- this.panelPath = new Dictionary();
- let index: number = 0;
- for (var item in PanelType) {
- let isValueProperty = parseInt(item, 10) >= 0;
- if (isValueProperty) {
- index++;
- this.panelPath.Add(PanelType[item.toString()], "ui/" + PanelType[item]);
- }
- }
- this.CanvasNode;
- console.log("Keys:" + this.panelPath.GetKey());
- }
- /**是否存在页面*/
- IsExistPanel(panelType: PanelType) {
- if (this.panelDic == null)
- return false;
- return this.panelDic.ContainKey(panelType);
- }
- /**
- * 获取UI页面
- * @param panelType 页面类型
- * @param layer 层级 1 Panel层 0 Panel0层(更内一层) 2 PanelA 最高级层
- */
- GetPanel(panelType: PanelType, layer: number = 1): BasePanel {
- if (this.panelDic == null) {
- this.panelDic = new Dictionary<PanelType, BasePanel>();
- }
- let basePanel = this.panelDic.TryGetValue(panelType);
- if (basePanel == null) {
- let panel = PrefabManager.LoadPanel(this.panelPath.Item(PanelType[panelType.toString()]));
- if (layer == 1)
- this.CanvasNode.addChild(panel);
- else if (layer == 0)
- this.CanvasNode0.addChild(panel);
- else if (layer == 2)
- this.CanvasNodeA.addChild(panel);
- basePanel = panel.getComponent(BasePanel);
- this.panelDic.Add(panelType, basePanel);
- }
- return basePanel;
- }
- /**动态获取界面
- * @param panelType 页面类型
- * @param layer 层级 1 Panel层 0 Panel0层(更内一层) 2 PanelA 最高级层
- * @param cb 加载完成回调
- */
- AsyncGetPanel(panelType: PanelType, cb: (panel) => void, layer: number = 1) {
- if (this.panelDic == null) {
- this.panelDic = new Dictionary<PanelType, BasePanel>();
- }
- let basePanel = this.panelDic.TryGetValue(panelType);
- //console.log("UIMng Destroy::", this.panelDic + " ID:" + this.id);
- if (basePanel == null) {
- PrefabManager.LoadPanelAsync(this.panelPath.Item(PanelType[panelType.toString()])
- , (panel) => {
- if (layer == 1)
- this.CanvasNode.addChild(panel);
- else if (layer == 0)
- this.CanvasNode0.addChild(panel);
- else if (layer == 2)
- this.CanvasNodeA.addChild(panel);
- //panel.setParent(this.CanvasNode);
- console.log("ui : "+PanelType[panelType.toString()]);
- basePanel = panel.getComponent(BasePanel);
- this.panelDic.Add(panelType, basePanel);
- cb(basePanel);
- })
- } else {
- cb(basePanel);
- }
- }
- OnEnter(panelType, param?) {
- this.GetPanel(panelType).OnEnter(param);
- }
- OnExit(panelType, param?) {
- this.GetPanel(panelType).OnExit(param);
- }
- }
- export enum PanelType {
- TestPanel,
- FightRolePanel,
- FightRoleBPanel,
- FightPanel,
- FightResultPanel,
- MateUnlockPanel,
- MatePanel,
- FightUpPanel,
- WealthPanel,
- RichPanel,
- RichPropPanel,
- RichBookPanel,
- RichHelpPanel,
- RichCollectPanel,
- RichRewardPanel,
- AdRbPanel,
- CashProPanel,
- RedCodePanel,
- RedCodeListPanel,
- }
|