132 lines
3.4 KiB
JavaScript
132 lines
3.4 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '4ab92nZADlIlplLHVpXwh+e', 'bridge.view');
|
|
// Scripts/zbridge/base/bridge.view.js
|
|
|
|
"use strict";
|
|
|
|
/*-----------------------------------------------------+
|
|
* 桥接: 所有窗体的显示基类
|
|
+-----------------------------------------------------*/
|
|
|
|
var BridgeClass = require("bridge.class");
|
|
var _require = require("define"),
|
|
SCENE_TAG = _require.SCENE_TAG;
|
|
var BridgeView = cc.Class({
|
|
"extends": BridgeClass,
|
|
ctor: function ctor() {
|
|
this.wname = "";
|
|
this.viewTag = SCENE_TAG.panel;
|
|
this.cache = false;
|
|
this.prefabPath = "";
|
|
this.root_wnd = null;
|
|
this.is_loading = false;
|
|
this.parent = null;
|
|
},
|
|
// 设置父节点
|
|
setParent: function setParent(parent) {
|
|
this.parent = parent;
|
|
},
|
|
// 打开窗体的主入口
|
|
open: function open(params, _cb) {
|
|
var _this = this;
|
|
// 直接打开
|
|
if (this.root_wnd) {
|
|
this.openRootWndBridge(params);
|
|
nx.dt.fnInvoke(_cb, true);
|
|
return;
|
|
}
|
|
;
|
|
|
|
// 载入中
|
|
if (this.is_loading) {
|
|
nx.error("$UI:载入重复!", this.wname);
|
|
nx.dt.fnInvoke(_cb, false);
|
|
return;
|
|
}
|
|
|
|
// 加载
|
|
this.is_loading = true;
|
|
nx.res.loadPrefab(this.prefabPath, function (_err, _fab) {
|
|
_this.is_loading = false;
|
|
|
|
// 载入错误
|
|
if (_err) {
|
|
nx.error("$UI:载入失败!", nx.fmtError(_err));
|
|
nx.dt.fnInvoke(_cb, false, nx.fmtError(_err));
|
|
return;
|
|
}
|
|
|
|
// 实例化
|
|
_this.root_wnd = cc.instantiate(_fab);
|
|
_this.root_wnd.name = _this.wname;
|
|
_this.root_wnd.view = _this;
|
|
_this.root_wnd.position = cc.Vec2.ZERO;
|
|
if (_this.parent != null) {
|
|
_this.root_wnd.parent = _this.parent;
|
|
} else {
|
|
_this.bindWndBridge();
|
|
nx.bridge.ui.addToSceneNode(_this.root_wnd, _this.viewTag);
|
|
}
|
|
|
|
// 数据设置
|
|
_this.openRootWndBridge(params);
|
|
|
|
// 预制常驻
|
|
nx.assets.pushResident(_this.prefabPath, _fab);
|
|
});
|
|
},
|
|
/**
|
|
* 关闭窗体
|
|
*/
|
|
close: function close(_fromBridgeWindow) {
|
|
if (_fromBridgeWindow === void 0) {
|
|
_fromBridgeWindow = false;
|
|
}
|
|
// 如果不是通过BridgeWindow组件关闭的,那么走组件关闭的方式
|
|
if (!_fromBridgeWindow) {
|
|
this.unbindWndBridge();
|
|
return;
|
|
}
|
|
nx.debug("$UI:窗体关闭:", this.wname);
|
|
nx.bridge.Tag2PanelClose(this.wname);
|
|
// 节点销毁
|
|
if (this.root_wnd) {
|
|
this.root_wnd.destroy();
|
|
this.root_wnd = null;
|
|
}
|
|
},
|
|
// 桥接BaseView挂载
|
|
bindWndBridge: function bindWndBridge() {
|
|
var bridge = nx.bridge.getBridgeWindow(this.root_wnd, "");
|
|
if (bridge) {
|
|
bridge.bindView(this);
|
|
}
|
|
},
|
|
unbindWndBridge: function unbindWndBridge() {
|
|
var bridge = nx.bridge.getBridgeWindow(this.root_wnd, "");
|
|
if (bridge) {
|
|
bridge.close(this);
|
|
}
|
|
},
|
|
// 桥接开启参数传递
|
|
openRootWndBridge: function openRootWndBridge(_params) {
|
|
// 开启失败
|
|
var bridge = nx.bridge.getBridgeWindow(this.root_wnd, "");
|
|
if (!bridge) {
|
|
nx.error("$UI:无效窗体,开启失败!", this.wname);
|
|
return;
|
|
}
|
|
nx.debug("$UI:窗体打开:", this.wname);
|
|
|
|
// 层级提前
|
|
this.root_wnd.active = true;
|
|
this.root_wnd.parent.nxOrder = this.root_wnd.parent.nxOrder || 0;
|
|
this.root_wnd.zIndex = ++this.root_wnd.parent.nxOrder;
|
|
|
|
// 参数打开
|
|
bridge.openConfigs(_params);
|
|
}
|
|
});
|
|
module.exports = BridgeView;
|
|
|
|
cc._RF.pop(); |