260 lines
7.2 KiB
JavaScript
260 lines
7.2 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '7cdbbzOjHVM7JwR149+ikie', 'bridge.window.manager');
|
|
// Scripts/zbridge/cmps/bridge.window.manager.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 窗体管理器
|
|
*
|
|
* 对scenes/wins二层进行自动置顶显示,其他界面透明度归零,减少DC次数
|
|
******************************************************************************/
|
|
|
|
var _require = require("define"),
|
|
SCENE_TAG = _require.SCENE_TAG;
|
|
var _require2 = require("bridge.panels"),
|
|
PANELS = _require2.PANELS,
|
|
TPanel = _require2.TPanel;
|
|
var DELAY_SECS = 0.01;
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {
|
|
root: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
// 开启
|
|
onEnable: function onEnable() {
|
|
nx.bridge.ui = this;
|
|
this.root = this.root || this.node;
|
|
|
|
// 重建层级
|
|
this.node_list = [];
|
|
this.addSceneNode(SCENE_TAG.scene, nx.gui.find(this.root, "scenes"));
|
|
this.addSceneNode(SCENE_TAG.win, nx.gui.find(this.root, "wins"));
|
|
this.addSceneNode(SCENE_TAG.panel, nx.gui.find(this.root, "panels"));
|
|
this.addSceneNode(SCENE_TAG.chat, nx.gui.find(this.root, "chat_tag"));
|
|
this.addSceneNode(SCENE_TAG.popup, nx.gui.find(this.root, "popups"));
|
|
this.addSceneNode(SCENE_TAG.plot, nx.gui.find(this.root, "plots"));
|
|
this.addSceneNode(SCENE_TAG.msg, nx.gui.find(this.root, "msg_tag"));
|
|
this.addSceneNode(SCENE_TAG.summon, nx.gui.find(this.root, "summon"));
|
|
|
|
// 界面层优化
|
|
this.scenes = this.getSceneNode(SCENE_TAG.scene);
|
|
this.wins = this.getSceneNode(SCENE_TAG.win);
|
|
|
|
// UI互斥层优化
|
|
this.open(true);
|
|
},
|
|
// 关闭
|
|
onDisable: function onDisable() {
|
|
// UI互斥层优化
|
|
this.open(false);
|
|
nx.bridge.ui = null;
|
|
},
|
|
// 储存节点
|
|
addSceneNode: function addSceneNode(tag, node) {
|
|
this.node_list[tag] = node;
|
|
},
|
|
// 将节点add到指定的层
|
|
addToSceneNode: function addToSceneNode(node, tag) {
|
|
if (!node) {
|
|
return;
|
|
}
|
|
var scene_node = this.node_list[tag];
|
|
if (!scene_node) {
|
|
return;
|
|
}
|
|
scene_node.active = true;
|
|
scene_node.addChild(node);
|
|
|
|
// 置顶
|
|
scene_node.nxOrder = scene_node.nxOrder || 0;
|
|
node.zIndex = ++scene_node.nxOrder;
|
|
},
|
|
// 专门hide UI层
|
|
hideOnUITag: function hideOnUITag(tag) {
|
|
var scene_node = this.node_list[SCENE_TAG.win];
|
|
if (tag != null) {
|
|
scene_node = this.node_list[tag];
|
|
}
|
|
if (scene_node) {
|
|
scene_node.active = false;
|
|
}
|
|
},
|
|
showOnUITag: function showOnUITag(tag) {
|
|
var scene_node = this.node_list[SCENE_TAG.win];
|
|
if (tag != null) {
|
|
scene_node = this.node_list[tag];
|
|
}
|
|
if (scene_node) {
|
|
scene_node.active = true;
|
|
}
|
|
},
|
|
// 获取指定节点
|
|
getSceneNode: function getSceneNode(tag) {
|
|
if (tag == null) {
|
|
tag = SCENE_TAG.panel;
|
|
}
|
|
var node = this.node_list[tag];
|
|
return node;
|
|
},
|
|
// 开关
|
|
open: function open(_open) {
|
|
if (_open) {
|
|
// 关注全屏界面层
|
|
this.wins.on("child-added", this.delayFresh.bind(this));
|
|
this.wins.on("child-removed", this.doFresh.bind(this));
|
|
this.wins.on("child-reorder", this.doFresh.bind(this));
|
|
} else {
|
|
// 关注全屏界面层
|
|
this.wins.off("child-added", this.delayFresh.bind(this));
|
|
this.wins.off("child-removed", this.doFresh.bind(this));
|
|
this.wins.off("child-reorder", this.doFresh.bind(this));
|
|
}
|
|
},
|
|
// 刷新
|
|
doFresh: function doFresh() {
|
|
// 全屏界面层检测
|
|
var chds = this.wins.children;
|
|
if (chds.length > 0) {
|
|
var find = false;
|
|
for (var i = chds.length - 1; i >= 0; --i) {
|
|
var node = chds[i];
|
|
if (!find && node.active) {
|
|
find = true;
|
|
node.opacity = 255;
|
|
} else {
|
|
node.opacity = 0;
|
|
}
|
|
}
|
|
if (find) {
|
|
this.scenes.opacity = 0;
|
|
if (nx.bridge.mainui) {
|
|
nx.bridge.mainui.show(false);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 主场景
|
|
this.scenes.opacity = 255;
|
|
if (nx.bridge.mainui) {
|
|
nx.bridge.mainui.show(true);
|
|
}
|
|
},
|
|
// 延迟刷新
|
|
delayFresh: function delayFresh() {
|
|
var _this = this;
|
|
this.unscheduleAllCallbacks();
|
|
this.scheduleOnce(function () {
|
|
_this.doFresh();
|
|
}, DELAY_SECS);
|
|
},
|
|
// ==================================================
|
|
// 窗口操作
|
|
// ==================================================
|
|
|
|
// 打开窗口
|
|
openWindow: function openWindow(_wname, _params, _cb, _directly) {
|
|
if (_directly === void 0) {
|
|
_directly = false;
|
|
}
|
|
// 配置查找
|
|
var info = PANELS[_wname];
|
|
if (nx.dt.objEmpty(info)) {
|
|
nx.error("$UI:无效窗口,打开失败!", _wname);
|
|
nx.dt.fnInvoke(_cb, false, "ErrOpenWindow");
|
|
return;
|
|
}
|
|
|
|
// 非直接创建
|
|
if (!_directly && nx.bridge.popups && info.tag == SCENE_TAG.popup) {
|
|
nx.bridge.popups.push(_wname, _params, info);
|
|
if (nx.dt.fnGood(_cb)) {
|
|
nx.error("WindowManager:\u961F\u5217\u5F39\u7A97\u68C0\u67E5,\u6682\u4E0D\u652F\u6301\u56DE\u8C03!");
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 所属层级
|
|
var root = this.getSceneNode(info.tag);
|
|
if (!root || !root.children) {
|
|
nx.error("$UI:无效标记,打开失败!", _wname, info.tag);
|
|
nx.dt.fnInvoke(_cb, false, "ErrOpenWindow");
|
|
return;
|
|
}
|
|
nx.bridge.setTag2PanelInfos(_wname, _params, info.tag);
|
|
// 查找&&新建
|
|
var wnd = root.getChildByName(_wname);
|
|
var panel = wnd ? wnd.view : null;
|
|
if (!panel) {
|
|
panel = new TPanel();
|
|
panel.init(_wname, _params ? _params.__keys : null);
|
|
}
|
|
|
|
// 打开
|
|
panel.open(_params || {}, _cb);
|
|
},
|
|
// 关闭窗口
|
|
closeWindow: function closeWindow(_wname) {
|
|
// 配置查找
|
|
var info = PANELS[_wname];
|
|
if (nx.dt.objEmpty(info)) {
|
|
nx.error("$UI:无效窗口,关闭失败!", _wname);
|
|
return;
|
|
}
|
|
|
|
// 所属层级
|
|
var root = this.getSceneNode(info.tag);
|
|
if (!root || !root.children) {
|
|
nx.error("$UI:无效标记,关闭失败!", _wname, info.tag);
|
|
return;
|
|
}
|
|
|
|
// 查找&&关闭
|
|
var wnd = root.getChildByName(_wname);
|
|
var panel = wnd ? wnd.view : null;
|
|
if (panel) {
|
|
panel.close();
|
|
}
|
|
},
|
|
// 彻底关闭非场景层所有窗口
|
|
cleanWindows: function cleanWindows() {
|
|
var cleanLayer = function cleanLayer(_layer) {
|
|
if (!_layer || !_layer.parent) {
|
|
return;
|
|
}
|
|
_layer.children.forEach(function (_cd) {
|
|
if (_cd.view) {
|
|
// if( _cd.view && _cd.name != "WndBattleScene" ) {
|
|
_cd.view.close();
|
|
}
|
|
});
|
|
};
|
|
cleanLayer(this.getSceneNode(SCENE_TAG.chat));
|
|
cleanLayer(this.getSceneNode(SCENE_TAG.popup));
|
|
cleanLayer(this.getSceneNode(SCENE_TAG.panel));
|
|
cleanLayer(this.getSceneNode(SCENE_TAG.battleUI));
|
|
cleanLayer(this.getSceneNode(SCENE_TAG.win));
|
|
},
|
|
// 彻底关闭非场景层所有窗口
|
|
cleanWindowsByTag: function cleanWindowsByTag(_tag) {
|
|
var cleanLayer = function cleanLayer(_layer) {
|
|
if (!_layer || !_layer.parent) {
|
|
return;
|
|
}
|
|
_layer.children.forEach(function (_cd) {
|
|
if (_cd.view) {
|
|
// if( _cd.view && _cd.name != "WndBattleScene" ) {
|
|
_cd.view.close();
|
|
}
|
|
});
|
|
};
|
|
cleanLayer(this.getSceneNode(_tag));
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |