|
@@ -193,195 +193,6 @@ export class UIController extends cc.EventTarget {
|
|
|
this.node = null;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @en add button event handler
|
|
|
- * @zh 添加按钮事件
|
|
|
- * @param relativeNodePath to indicate a button node, can pass `string`|`cc.Node`|`cc.Button` here.
|
|
|
- * @param cb will be called when event emits. method format:(btn:cc.Button,args:any)=>void
|
|
|
- * @param target the `this` argument of `cb`
|
|
|
- * */
|
|
|
- onButtonEvent(relativeNodePath: string | cc.Node | cc.Button, cb: Function, target?: any, args?: any) {
|
|
|
-
|
|
|
- let buttonNode: cc.Node = null;
|
|
|
- if (relativeNodePath instanceof cc.Node) {
|
|
|
- buttonNode = relativeNodePath;
|
|
|
- }
|
|
|
- else if (relativeNodePath instanceof cc.Button) {
|
|
|
- buttonNode = relativeNodePath.node;
|
|
|
- }
|
|
|
- else {
|
|
|
- buttonNode = cc.find(relativeNodePath, this.node);
|
|
|
- }
|
|
|
-
|
|
|
- if (!buttonNode) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- //添加转发器
|
|
|
- let agent = this.node.getComponent(__NodeEventAgent__);
|
|
|
- if (!agent) {
|
|
|
- agent = this.node.addComponent(__NodeEventAgent__);
|
|
|
- }
|
|
|
-
|
|
|
- let btn = buttonNode.getComponent(cc.Button);
|
|
|
- let clickEvents = btn.clickEvents;
|
|
|
- let handler = new cc.Component.EventHandler();
|
|
|
- handler.target = this.node;
|
|
|
- handler.component = '__NodeEventAgent__';
|
|
|
- handler.handler = 'onButtonClicked';
|
|
|
- handler.customEventData = '' + UIController._idBase++;
|
|
|
-
|
|
|
- //附加额外信息 供事件转发使用
|
|
|
- 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`|`cc.Node`|`cc.Button` here.
|
|
|
- * @param cb will be called when event emits.
|
|
|
- * @param target the `this` argument of `cb`
|
|
|
- * */
|
|
|
- offButtonEvent(relativeNodePath: string | cc.Node | cc.Button, cb: Function, target: any) {
|
|
|
- let buttonNode: cc.Node = null;
|
|
|
- if (relativeNodePath instanceof cc.Node) {
|
|
|
- buttonNode = relativeNodePath;
|
|
|
-
|
|
|
- }
|
|
|
- else if (relativeNodePath instanceof cc.Button) {
|
|
|
- buttonNode = relativeNodePath.node;
|
|
|
- }
|
|
|
- else {
|
|
|
- buttonNode = cc.find(relativeNodePath, this.node);
|
|
|
- }
|
|
|
-
|
|
|
- if (!buttonNode) {
|
|
|
- return; ``
|
|
|
- }
|
|
|
-
|
|
|
- let agent = this.node.getComponent(__NodeEventAgent__);
|
|
|
- if (!agent) {
|
|
|
- return;
|
|
|
- }
|
|
|
- let btn = buttonNode.getComponent(cc.Button);
|
|
|
- if (!btn) {
|
|
|
- return;
|
|
|
- }
|
|
|
- let clickEvents = btn.clickEvents;
|
|
|
- for (let i = 0; i < clickEvents.length; ++i) {
|
|
|
- let 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`|`cc.Node`|`cc.Button` here.
|
|
|
- * @param cb will be called when event emits. method format:(btn:cc.Button,args:any)=>void
|
|
|
- * @param target the `this` argument of `cb`
|
|
|
- * */
|
|
|
-
|
|
|
- onToggleEvent(relativeNodePath: string | cc.Node | cc.Button | cc.ToggleContainer, cb: Function, target?: any, args?: any) {
|
|
|
- let buttonNode: cc.Node = null;
|
|
|
- if (relativeNodePath instanceof cc.Node) {
|
|
|
- buttonNode = relativeNodePath;
|
|
|
- }
|
|
|
- else if (relativeNodePath instanceof cc.Button) {
|
|
|
- buttonNode = relativeNodePath.node;
|
|
|
- }
|
|
|
- else if (relativeNodePath instanceof cc.ToggleContainer) {
|
|
|
- buttonNode = relativeNodePath.node;
|
|
|
- }
|
|
|
- else {
|
|
|
- buttonNode = cc.find(relativeNodePath, this.node);
|
|
|
- }
|
|
|
-
|
|
|
- if (!buttonNode) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- //添加转发器
|
|
|
- let agent = this.node.getComponent(__NodeEventAgent__);
|
|
|
- if (!agent) {
|
|
|
- agent = this.node.addComponent(__NodeEventAgent__);
|
|
|
- }
|
|
|
-
|
|
|
- let btn = buttonNode.getComponent(cc.Button) as any;
|
|
|
- if (!btn) {
|
|
|
- btn = buttonNode.getComponent(cc.ToggleContainer) as any;
|
|
|
- }
|
|
|
- let checkEvents = btn.checkEvents;
|
|
|
- let handler = new cc.Component.EventHandler();
|
|
|
- handler.target = this.node;
|
|
|
- handler.component = '__NodeEventAgent__';
|
|
|
- handler.handler = 'onToggleEvent';
|
|
|
- handler.customEventData = '' + UIController._idBase++;
|
|
|
-
|
|
|
- //附加额外信息 供事件转发使用
|
|
|
- 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`|`cc.Node`|`cc.Button` here.
|
|
|
- * @param cb will be called when event emits. method format:(btn:cc.Button,args:any)=>void
|
|
|
- * @param target the `this` argument of `cb`
|
|
|
- * */
|
|
|
- offToggleEvent(relativeNodePath: string | cc.Node | cc.Button | cc.ToggleContainer, cb: Function, target: any) {
|
|
|
- let buttonNode: cc.Node = null;
|
|
|
- if (relativeNodePath instanceof cc.Node) {
|
|
|
- buttonNode = relativeNodePath;
|
|
|
- }
|
|
|
- else if (relativeNodePath instanceof cc.Button) {
|
|
|
- buttonNode = relativeNodePath.node;
|
|
|
- }
|
|
|
- else if (relativeNodePath instanceof cc.ToggleContainer) {
|
|
|
- buttonNode = relativeNodePath.node;
|
|
|
- }
|
|
|
- else {
|
|
|
- buttonNode = cc.find(relativeNodePath, this.node);
|
|
|
- }
|
|
|
-
|
|
|
- if (!buttonNode) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- //添加转发器
|
|
|
- let agent = this.node.getComponent(__NodeEventAgent__);
|
|
|
- if (!agent) {
|
|
|
- return;
|
|
|
- }
|
|
|
- let btn = buttonNode.getComponent(cc.Button) as any;
|
|
|
- if (!btn) {
|
|
|
- btn = buttonNode.getComponent(cc.ToggleContainer) as any;
|
|
|
- }
|
|
|
- let checkEvents = btn.checkEvents;
|
|
|
- for (let i = 0; i < checkEvents.length; ++i) {
|
|
|
- let h = checkEvents[i];
|
|
|
- if (h['$cb$'] == cb && h['$target$'] == target) {
|
|
|
- checkEvents.splice(i, 1);
|
|
|
- btn.checkEvents = checkEvents;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/***
|
|
|
* @en the extra resource needed by this ui panel.the ui will not be created until these res loaded.
|
|
|
* @zh 本UI使用的依赖资源.UI会等这些资源加载完成后才创建。
|