System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, assetManager, Button, Component, EventHandler, find, isValid, Node, Toggle, ToggleContainer, ui_base, _dec, _class, _crd, ccclass, property, __NodeEventAgent__, _id; _export("default", void 0); return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; __checkObsolete__ = _cc.__checkObsolete__; __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__; _decorator = _cc._decorator; assetManager = _cc.assetManager; Button = _cc.Button; Component = _cc.Component; EventHandler = _cc.EventHandler; find = _cc.find; isValid = _cc.isValid; Node = _cc.Node; Toggle = _cc.Toggle; ToggleContainer = _cc.ToggleContainer; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "a34ebvwnv5E2LG2J8RHwXU2", "ui_base", undefined); __checkObsolete__(['_decorator', 'assetManager', 'Button', 'Component', 'EventHandler', 'EventTouch', 'find', 'isValid', 'Node', 'Prefab', 'Toggle', 'ToggleContainer']); ({ ccclass, property } = _decorator); /*** * @en internal class, used for handling node event. * @zh 内部类,用于节点事件监听 * * */ __NodeEventAgent__ = (_dec = ccclass('tgxNodeEventAgent'), _dec(_class = class __NodeEventAgent__ extends Component { /*** * @en recieve button click event and deliver them to the real handlers. * @zh 接受按钮事件,并转发给真正的处理函数 * */ onButtonClicked(evt, customEventData) { var btn = evt.target.getComponent(Button); var clickEvents = btn.clickEvents; for (var i = 0; i < clickEvents.length; ++i) { var h = clickEvents[i]; if (h.customEventData == customEventData) { var cb = h['$cb$']; var target = h['$target$']; var args = h['$args$']; cb.apply(target, [btn, args]); } } } /*** * @en recieve toggle event and deliver them to the real handlers. * @zh 接受Toggle事件,并转发给真正的处理函数 * */ onToggleEvent(toggle, customEventData) { var checkEvents = toggle.checkEvents; //if (toggle['_toggleContainer']) { // checkEvents = toggle['_toggleContainer'].checkEvents; //} for (var i = 0; i < checkEvents.length; ++i) { var h = checkEvents[i]; if (h.customEventData == customEventData) { var cb = h['$cb$']; var target = h['$target$']; var args = h['$args$']; cb.apply(target, [toggle, args]); } } } }) || _class); _id = 0; _export("default", ui_base = class ui_base { /*** * @en hide and destroy all ui panel. * @zh 隐藏并销毁所有UI面板 * */ static closeAll() { while (this._uis.length) { this._uis[0].close(); } this._clss.clear(); } // static closeAndReleaseAll() { while (this._uis.length) { this._uis[0].closeAndRelease(); } this._clss.clear(); } //update all ui, called by UI. static updateAll(dt) { for (var i = 0; i < this._uis.length; ++i) { var ctrl = this._uis[i]; if (ctrl.node && isValid(ctrl.node)) { this._uis[i].onUpdate(dt); } } } static _addCls(cls) { if (!cls) return; this._clss.add(cls); } static _removeCls(cls) { if (!cls) return; this._clss.delete(cls); } static _hasCls(cls) { return this._clss.has(cls); } /*** * @en the instance id to indicate an unique ui panel. * @zh 实例ID,用于标记一个唯一面板实例 * */ get id() { return this._id; } /*** * @en url of the prefab used by this ui panel. * @zh 本UI使用prefab路径 * */ get prefab() { return this._prefab; } get bundle() { return this._bundle; } /*** * @en layer of this ui panel. * @zh 本UI所在的UI层级 * */ get layer() { return this._layer; } /*** * @en layout of this ui panel. * @zh 本UI组件 * */ get layout() { return this._layout; } getLayout() { return this._layout; } constructor(bundle, prefab, layer, layoutCls) { this._id = 0; this._bundle = void 0; this._prefab = void 0; this._layer = void 0; this._layout = void 0; this._cls = void 0; this.node = void 0; this._destroyed = false; this._resolve_close = null; this._cls = null; this._bundle = bundle; this._prefab = prefab; this._layer = layer; this._layout = layoutCls; this._id = _id++; } //setup this ui,called by UIMgr. _setup(cls, node) { ui_base._uis.push(this); this._cls = cls; ui_base._addCls(this._cls); this.node = node; if (this._layout) this._layout = this.node.getComponent(this._layout); //notify sub class to handle something. //节点创建完毕,调用子类的处理函数。 for (var _len = arguments.length, data = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { data[_key - 2] = arguments[_key]; } this.onCreated(...data); //check whether it has been destroyed, if has, hide it. //检查是否为已销毁,如果已销毁,则走销毁流程 if (this._destroyed) this.close(); } /** * @en hide and destroy this ui panel. * @zh 隐藏并销毁此UI面板 * */ close() { var _this$_resolve_close; (_this$_resolve_close = this._resolve_close) == null || _this$_resolve_close.call(this); this._resolve_close = null; this._destroyed = true; if (!this.node) return; this.node.removeFromParent(); for (var i = 0; i < ui_base._uis.length; ++i) { if (ui_base._uis[i] == this) { ui_base._uis.splice(i, 1); break; } } this.onDispose(); this.node.destroy(); this.node = null; ui_base._removeCls(this._cls); this._cls = null; } closeAndRelease() { var _assetManager$getBund; this.close(); (_assetManager$getBund = assetManager.getBundle(this._bundle)) == null || _assetManager$getBund.release(this._prefab); } /**等待此ui关闭*/ wait_close() { if (this._resolve_close) return; return new Promise(resolve => { this._resolve_close = resolve; }); } /** * @en add button event handler * @zh 添加按钮事件 * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here. * @param cb will be called when event emits. method format:(btn:Button,args:any)=>void * @param target the `this` argument of `cb` * */ onButtonEvent(relativeNodePath, cb, target, args) { var buttonNode = null; if (relativeNodePath instanceof Node) { buttonNode = relativeNodePath; } else if (relativeNodePath instanceof Button) { buttonNode = relativeNodePath.node; } else { buttonNode = find(relativeNodePath, this.node); } if (!buttonNode) { return null; } //添加转发器 var agent = this.node.getComponent(__NodeEventAgent__); if (!agent) { agent = this.node.addComponent(__NodeEventAgent__); } var btn = buttonNode.getComponent(Button); var clickEvents = btn.clickEvents; var handler = new EventHandler(); handler.target = this.node; handler.component = 'tgxNodeEventAgent'; handler.handler = 'onButtonClicked'; handler.customEventData = '' + _id++; //附加额外信息 供事件转发使用 handler['$cb$'] = cb; handler['$target$'] = target; handler['$args$'] = args; clickEvents.push(handler); btn.clickEvents = clickEvents; } /** * @en remove button event handler * @zh 移除按钮事件 * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here. * @param cb will be called when event emits. * @param target the `this` argument of `cb` * */ offButtonEvent(relativeNodePath, cb, target) { var buttonNode = null; if (relativeNodePath instanceof Node) { buttonNode = relativeNodePath; } else if (relativeNodePath instanceof Button) { buttonNode = relativeNodePath.node; } else { buttonNode = find(relativeNodePath, this.node); } if (!buttonNode) { return; ""; } var agent = this.node.getComponent(__NodeEventAgent__); if (!agent) { return; } var btn = buttonNode.getComponent(Button); if (!btn) { return; } var clickEvents = btn.clickEvents; for (var i = 0; i < clickEvents.length; ++i) { var h = clickEvents[i]; if (h['$cb$'] == cb && h['$target$'] == target) { clickEvents.splice(i, 1); btn.clickEvents = clickEvents; break; } } } /** * @en add toggle event handler * @zh 添加Toggle事件 * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here. * @param cb will be called when event emits. method format:(btn:Toggle,args:any)=>void * @param target the `this` argument of `cb` */ onToggleEvent(relativeNodePath, cb, target, args) { var buttonNode = null; if (relativeNodePath instanceof Node) { buttonNode = relativeNodePath; } else if (relativeNodePath instanceof Toggle) { buttonNode = relativeNodePath.node; } else if (relativeNodePath instanceof ToggleContainer) { buttonNode = relativeNodePath.node; } else { buttonNode = find(relativeNodePath, this.node); } if (!buttonNode) { return null; } //添加转发器 var agent = this.node.getComponent(__NodeEventAgent__); if (!agent) agent = this.node.addComponent(__NodeEventAgent__); var btn = buttonNode.getComponent(Toggle); if (!btn) btn = buttonNode.getComponent(ToggleContainer); var checkEvents = btn.checkEvents; var handler = new EventHandler(); handler.target = this.node; handler.component = 'tgxNodeEventAgent'; handler.handler = 'onToggleEvent'; handler.customEventData = '' + _id++; //附加额外信息 供事件转发使用 handler['$cb$'] = cb; handler['$target$'] = target; handler['$args$'] = args; checkEvents.push(handler); btn.checkEvents = checkEvents; } /** * @en remove toggle event handler * @zh 移除Toggle事件 * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here. * @param cb will be called when event emits. method format:(btn:Toggle,args:any)=>void * @param target the `this` argument of `cb` * */ offToggleEvent(relativeNodePath, cb, target) { var buttonNode = null; if (relativeNodePath instanceof Node) { buttonNode = relativeNodePath; } else if (relativeNodePath instanceof Toggle) { buttonNode = relativeNodePath.node; } else if (relativeNodePath instanceof ToggleContainer) { buttonNode = relativeNodePath.node; } else { buttonNode = find(relativeNodePath, this.node); } if (!buttonNode) { return null; } //添加转发器 var agent = this.node.getComponent(__NodeEventAgent__); if (!agent) { return; } var btn = buttonNode.getComponent(Toggle); if (!btn) { btn = buttonNode.getComponent(ToggleContainer); } var checkEvents = btn.checkEvents; for (var i = 0; i < checkEvents.length; ++i) { var h = checkEvents[i]; if (h['$cb$'] == cb && h['$target$'] == target) { checkEvents.splice(i, 1); btn.checkEvents = checkEvents; break; } } } //子类的所有操作,需要在这个函数之后。 onCreated() {} //当界面销毁时调用 onDispose() {} // onUpdate(dt) {} }); ui_base._clss = new Set(); ui_base._uis = []; _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=1c6623815813aae756c57cca6f89a3182c222719.js.map