123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import { Asset, Node, Prefab } from "cc";
- import { EventMgr } from "../event/EventManager";
- import { LoadQueue } from "../res/LoadQueue";
- import { StringUtil } from "../util/StringUtil";
- import { BaseLayer } from "./BaseLayer";
- import { BaseView } from "./BaseView";
- import { LayerConf, LayerType } from "../config/LayerConf";
- export interface LayerInfo {
- id: number;
- view: BaseView;
- args: any[];
- res: Asset;
- callback: Function;
- active: Boolean;
-
- bLoading: Boolean;
- }
- export class LayerManager {
- private _game_layer: BaseLayer = null;
- private _ui_layer: BaseLayer = null;
- private _notice_layer: BaseLayer = null;
- private _guide_layer: BaseLayer = null;
- private _layer_conf: { [key: number]: LayerConf } = {};
- private _class_uuid = StringUtil.getUUID(32);
- constructor(root: Node, conf: any) {
- this._layer_conf = conf;
-
- for (let id in this._layer_conf) {
- let conf = this._layer_conf[id];
- (conf.preload) && LoadQueue.pushPreload(1, conf.bundle, conf.url, Prefab);
-
- }
- this._game_layer = new BaseLayer("Game_Layer", this._layer_conf);
- root.addChild(this._game_layer);
- this._ui_layer = new BaseLayer("UI_Layer", this._layer_conf, true);
- root.addChild(this._ui_layer);
- this._notice_layer = new BaseLayer("Notice_Layer", this._layer_conf);
- root.addChild(this._notice_layer);
- this._guide_layer = new BaseLayer("Guide_Layer", this._layer_conf);
- root.addChild(this._guide_layer);
- EventMgr.addEvent("_Framewrok_Show_GameLayer", (value: boolean) => {
-
- }, this, this._class_uuid);
- }
-
- open(id: number, callback: Function = null, ...args: any[]) {
-
-
-
-
-
- let conf = this._layer_conf[id];
-
- if (conf) {
-
- let mCallback = () => {
-
- if (callback) {
- callback();
- }
- };
- console.log('conf.type', conf.type)
- if (conf.type === LayerType.Game) {
- this._game_layer.open(id, mCallback, args);
- } else if (conf.type === LayerType.UI) {
- this._ui_layer.open(id, mCallback, args);
- } else if (conf.type === LayerType.Notice) {
- this._notice_layer.open(id, mCallback, args);
- } else if (conf.type === LayerType.Guide) {
- this._guide_layer.open(id, mCallback, args);
- }
- return true;
- }
- console.error("未找到对应UI:" + id);
- return false;
- }
-
- close(ui: number | BaseView) {
- if (ui) {
- let id = (typeof ui != "number") ? ui.view_id : ui;
- let conf = this._layer_conf[id];
- if (conf) {
- if (conf.type === LayerType.Game) {
- this._game_layer.close(ui);
- } else if (conf.type === LayerType.UI) {
- this._ui_layer.close(ui);
- } else if (conf.type === LayerType.Notice) {
- this._notice_layer.close(ui);
- } else if (conf.type === LayerType.Guide) {
- this._guide_layer.close(ui);
- }
- return true;
- }
- }
- return false;
- }
- ShowUI(ui, state, callback: Function = null, ...args: any[]) {
- this._ui_layer.ShowUI(ui, state, callback, args);
- }
-
- getUIView(id: number) {
- let conf = this._layer_conf[id];
- if (conf) {
- if (conf.type === LayerType.Game) {
- return this._game_layer.getUIView(id);
- } else if (conf.type === LayerType.UI) {
- return this._ui_layer.getUIView(id);
- } else if (conf.type === LayerType.Notice) {
- return this._notice_layer.getUIView(id);
- } else if (conf.type === LayerType.Guide) {
- return this._guide_layer.getUIView(id);
- }
- }
- console.error("未找到对应UI:" + id);
- return null;
- }
-
- closeAllUI(withoutID: number = -1) {
- EventMgr.fireEvent("_Framewrok_Show_GameLayer", true);
- this._ui_layer.closeAll(withoutID);
- }
- closeAllGame(withoutID: number = -1) {
- this._game_layer.closeAll(withoutID);
- }
- }
|