2 Commit-ok fd69da96c6 ... f6fde2191d

Szerző SHA1 Üzenet Dátum
  zane f6fde2191d 1 1 hete
  zane bff98e6810 1 1 hete

+ 431 - 412
assets/core_tgx/easy_ui_framework/UIController.ts

@@ -1,68 +1,83 @@
-import { _decorator, game, Prefab, isValid, Button, find, EventHandler, Toggle, ToggleContainer, Node, SkeletalAnimation, Component, EventTouch, Slider } from "cc";
+import {
+  _decorator,
+  game,
+  Prefab,
+  isValid,
+  Button,
+  find,
+  EventHandler,
+  Toggle,
+  ToggleContainer,
+  Node,
+  SkeletalAnimation,
+  Component,
+  EventTouch,
+  Slider,
+} from "cc";
 import { DoubleList, DoubleListItem } from "../base/DoubleList";
-import BaseUI from "../../module_ball/base/BaseUI";
+
 const { ccclass, property } = _decorator;
 /***
  * @en internal class, used for handling node event.
  * @zh 内部类,用于节点事件监听
- * 
+ *
  *  */
-@ccclass('tgxNodeEventAgent')
+@ccclass("tgxNodeEventAgent")
 export class __NodeEventAgent__ extends Component {
-    /***
-     * @en recieve button click event and deliver them to the real handlers.
-     * @zh 接受按钮事件,并转发给真正的处理函数
-     * */
-    onButtonClicked(evt: EventTouch, customEventData) {
-        let btn = (evt.target as Node).getComponent(Button);
-        let clickEvents = btn.clickEvents;
-        for (let i = 0; i < clickEvents.length; ++i) {
-            let h = clickEvents[i];
-            if (h.customEventData == customEventData) {
-                let cb = h['$cb$'];
-                let target = h['$target$']
-                let args = h['$args$'];
-                cb.apply(target, [btn, args]);
-            }
-        }
+  /***
+   * @en recieve button click event and deliver them to the real handlers.
+   * @zh 接受按钮事件,并转发给真正的处理函数
+   * */
+  onButtonClicked(evt: EventTouch, customEventData) {
+    let btn = (evt.target as Node).getComponent(Button);
+    let clickEvents = btn.clickEvents;
+    for (let i = 0; i < clickEvents.length; ++i) {
+      let h = clickEvents[i];
+      if (h.customEventData == customEventData) {
+        let cb = h["$cb$"];
+        let target = h["$target$"];
+        let args = h["$args$"];
+        cb.apply(target, [btn, args]);
+      }
     }
-
-    /***
-     * @en recieve toggle event and deliver them to the real handlers.
-     * @zh 接受Toggle事件,并转发给真正的处理函数
-     * */
-    onToggleEvent(toggle: Toggle, customEventData) {
-        let checkEvents = toggle.checkEvents;
-        if (toggle['_toggleContainer']) {
-            checkEvents = toggle['_toggleContainer'].checkEvents;
-        }
-        for (let i = 0; i < checkEvents.length; ++i) {
-            let h = checkEvents[i];
-            if (h.customEventData == customEventData) {
-                let cb = h['$cb$'];
-                let target = h['$target$']
-                let args = h['$args$'];
-                cb.apply(target, [toggle, args]);
-            }
-        }
+  }
+
+  /***
+   * @en recieve toggle event and deliver them to the real handlers.
+   * @zh 接受Toggle事件,并转发给真正的处理函数
+   * */
+  onToggleEvent(toggle: Toggle, customEventData) {
+    let checkEvents = toggle.checkEvents;
+    if (toggle["_toggleContainer"]) {
+      checkEvents = toggle["_toggleContainer"].checkEvents;
     }
-
-    /***
- * @en recieve slide event and deliver them to the real handlers.
- * @zh 接受 Slide 事件,并转发给真正的处理函数
- * */
-    onSlideEvent(slider: Slider, customEventData) {
-        let slideEvents = slider.slideEvents;
-        for (let i = 0; i < slideEvents.length; ++i) {
-            let h = slideEvents[i];
-            if (h.customEventData == customEventData) {
-                let cb = h['$cb$'];
-                let target = h['$target$']
-                let args = h['$args$'];
-                cb.apply(target, [slider, args]);
-            }
-        }
+    for (let i = 0; i < checkEvents.length; ++i) {
+      let h = checkEvents[i];
+      if (h.customEventData == customEventData) {
+        let cb = h["$cb$"];
+        let target = h["$target$"];
+        let args = h["$args$"];
+        cb.apply(target, [toggle, args]);
+      }
+    }
+  }
+
+  /***
+   * @en recieve slide event and deliver them to the real handlers.
+   * @zh 接受 Slide 事件,并转发给真正的处理函数
+   * */
+  onSlideEvent(slider: Slider, customEventData) {
+    let slideEvents = slider.slideEvents;
+    for (let i = 0; i < slideEvents.length; ++i) {
+      let h = slideEvents[i];
+      if (h.customEventData == customEventData) {
+        let cb = h["$cb$"];
+        let target = h["$target$"];
+        let args = h["$args$"];
+        cb.apply(target, [slider, args]);
+      }
     }
+  }
 }
 
 /**
@@ -70,393 +85,397 @@ export class __NodeEventAgent__ extends Component {
  * @zh 各类UI面板基类
  * */
 export class UIController {
-    private static _idBase = 1000;
-
-    private static _controllers: DoubleList = new DoubleList();
-    private _listItem:DoubleListItem = null;
-    private _instId: number = 0;
-    private _prefab: string | Prefab;
-    private _layer: number;
-    protected _layout: any;
-    protected node: Node;
-    protected _destroyed: boolean = false;
-    protected _ingoreCloseAll:boolean = false;
-    constructor(prefab: string | Prefab, layer: number, layoutCls: any) {
-     
-        this._prefab = prefab;
-        this._layer = layer;
-        this._layout = layoutCls;
-        this._instId = UIController._idBase++;
-        this._listItem = UIController._controllers.addToTail(this);
+  private static _idBase = 1000;
+
+  private static _controllers: DoubleList = new DoubleList();
+  private _listItem: DoubleListItem = null;
+  private _instId: number = 0;
+  private _prefab: string | Prefab;
+  private _layer: number;
+  protected _layout: any;
+  protected node: Node;
+  protected _destroyed: boolean = false;
+  protected _ingoreCloseAll: boolean = false;
+  constructor(prefab: string | Prefab, layer: number, layoutCls: any) {
+    this._prefab = prefab;
+    this._layer = layer;
+    this._layout = layoutCls;
+    this._instId = UIController._idBase++;
+    this._listItem = UIController._controllers.addToTail(this);
+  }
+
+  /***
+   * @en the instance id to indicate an unique ui panel.
+   * @zh 实例ID,用于标记一个唯一面板实例
+   *  */
+  public get instId(): number {
+    return this._instId;
+  }
+
+  /***
+   * @en url of the prefab used by this ui panel.
+   * @zh 本UI使用prefab路径
+   *  */
+  public get prefab(): string | Prefab {
+    return this._prefab;
+  }
+
+  /***
+   * @en layer of this ui panel.
+   * @zh 本UI所在的UI层级
+   *  */
+  public get layer(): number {
+    return this._layer;
+  }
+
+  /***
+   * @en layout of this ui panel.
+   * @zh 本UI所在的UI层级
+   *  */
+  public getLayout(): any {
+    return this._layout;
+  }
+
+  /***
+   * @en hide and destroy all ui panel.
+   * @zh 隐藏并销毁所有UI面板
+   *  */
+  public static closeAll() {
+    this._controllers.forEach((v) => {
+      let c = v.data as UIController;
+      if (!c._ingoreCloseAll) {
+        c.close();
+      }
+    });
+  }
+
+  //update all ui, called by UIMgr.
+  public static updateAll(dt: number) {
+    this._controllers.forEach((v) => {
+      let c = v.data as UIController;
+      if (c.node && isValid(c.node)) {
+        c.onUpdate(dt);
+      }
+    });
+  }
+
+  //setup this ui,called by UIMgr.
+  public setup(node: Node, params: any) {
+    this.node = node;
+
+    if (this._layout) {
+      this._layout = this.node.getComponent(this._layout);
     }
+    //notify sub class to handle something.
+    //节点创建完毕,调用子类的处理函数。
+    this.onCreated(params);
 
-    /***
-     * @en the instance id to indicate an unique ui panel.
-     * @zh 实例ID,用于标记一个唯一面板实例
-     *  */
-    public get instId(): number {
-        return this._instId;
+    if (this._destroyed) {
+      this.close();
+    }
+  }
+
+  /**
+   * @en hide and destroy this ui panel.
+   * @zh 隐藏并销毁此UI面板
+   *  */
+  public close() {
+    this._destroyed = true;
+    this._listItem?.dispose();
+    this._listItem = null;
+    if (this.node) {
+      this.node.removeFromParent();
+      this.onDispose();
+      this.node.destroy();
+      this.node = null;
+    }
+  }
+
+  /**
+   * @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: string | Node | Button,
+    cb: Function,
+    target?: any,
+    args?: any
+  ) {
+    let buttonNode: Node = null;
+    if (relativeNodePath instanceof Node) {
+      buttonNode = relativeNodePath;
+    } else if (relativeNodePath instanceof Button) {
+      buttonNode = relativeNodePath.node;
+    } else {
+      buttonNode = find(relativeNodePath, this.node);
     }
 
-    /***
-     * @en url of the prefab used by this ui panel.
-     * @zh 本UI使用prefab路径
-     *  */
-    public get prefab(): string | Prefab {
-        return this._prefab;
+    if (!buttonNode) {
+      return null;
     }
 
-    /***
-     * @en layer of this ui panel.
-     * @zh 本UI所在的UI层级
-     *  */
-    public get layer(): number {
-        return this._layer;
+    //添加转发器
+    let agent = this.node.getComponent(__NodeEventAgent__);
+    if (!agent) {
+      agent = this.node.addComponent(__NodeEventAgent__);
     }
 
-    /***
-     * @en layout of this ui panel.
-     * @zh 本UI所在的UI层级
-     *  */
-    public getLayout(): any {
-        return this._layout;
+    let btn = buttonNode.getComponent(Button);
+    let clickEvents = btn.clickEvents;
+    let handler = new EventHandler();
+    handler.target = this.node;
+    handler.component = "tgxNodeEventAgent";
+    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`|`Node`|`Button` here.
+   * @param cb will be called when event emits.
+   * @param target the `this` argument of `cb`
+   *  */
+  offButtonEvent(
+    relativeNodePath: string | Node | Button,
+    cb: Function,
+    target: any
+  ) {
+    let buttonNode: Node = null;
+    if (relativeNodePath instanceof Node) {
+      buttonNode = relativeNodePath;
+    } else if (relativeNodePath instanceof Button) {
+      buttonNode = relativeNodePath.node;
+    } else {
+      buttonNode = find(relativeNodePath, this.node);
     }
 
-    /***
-     * @en hide and destroy all ui panel.
-     * @zh 隐藏并销毁所有UI面板
-     *  */
-    public static closeAll() {
-        this._controllers.forEach(v=>{
-            let c = v.data as UIController;
-            if(!c._ingoreCloseAll){
-                c.close();
-            }
-        });
+    if (!buttonNode) {
+      return;
+      ``;
     }
 
-    //update all ui, called by UIMgr.
-    public static updateAll(dt: number) {
-        this._controllers.forEach(v=>{
-            let c = v.data as UIController;
-            if(c.node && isValid(c.node)){
-                c.onUpdate(dt);
-            }
-        });
+    let agent = this.node.getComponent(__NodeEventAgent__);
+    if (!agent) {
+      return;
+    }
+    let btn = buttonNode.getComponent(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`|`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: string | Node | Toggle | ToggleContainer,
+    cb: Function,
+    target?: any,
+    args?: any
+  ) {
+    let buttonNode: Node = 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);
     }
 
-    //setup this ui,called by UIMgr.
-    public setup(node: Node,params:any) {
-        this.node = node;
-
-        let baseUI = node.getComponent(BaseUI)
-        
-        if (baseUI) {
-            baseUI.setUIController(this);
-        }
-
-        if (this._layout) {
-            this._layout = this.node.getComponent(this._layout);
-        }
-        //notify sub class to handle something.
-        //节点创建完毕,调用子类的处理函数。
-        this.onCreated(params);
-
-        if(this._destroyed){
-            this.close();
-        }
+    if (!buttonNode) {
+      return null;
     }
 
-    /**
-     * @en hide and destroy this ui panel.
-     * @zh 隐藏并销毁此UI面板
-     *  */
-    public close() {
-        this._destroyed = true;
-        this._listItem?.dispose();
-        this._listItem = null;
-        if (this.node) {
-            this.node.removeFromParent();
-            this.onDispose();
-            this.node.destroy();
-            this.node = null;
-        }
+    //添加转发器
+    let agent = this.node.getComponent(__NodeEventAgent__);
+    if (!agent) {
+      agent = this.node.addComponent(__NodeEventAgent__);
     }
 
-    /**
-     * @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: string | Node | Button, cb: Function, target?: any, args?: any) {
-
-        let buttonNode: Node = 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;
-        }
-
-        //添加转发器
-        let agent = this.node.getComponent(__NodeEventAgent__);
-        if (!agent) {
-            agent = this.node.addComponent(__NodeEventAgent__);
-        }
-
-        let btn = buttonNode.getComponent(Button);
-        let clickEvents = btn.clickEvents;
-        let handler = new EventHandler();
-        handler.target = this.node;
-        handler.component = 'tgxNodeEventAgent';
-        handler.handler = 'onButtonClicked';
-        handler.customEventData = '' + UIController._idBase++;
-
-        //附加额外信息 供事件转发使用
-        handler['$cb$'] = cb;
-        handler['$target$'] = target;
-        handler['$args$'] = args;
-
-        clickEvents.push(handler);
-        btn.clickEvents = clickEvents;
+    let btn = buttonNode.getComponent(Toggle) as any;
+    if (!btn) {
+      btn = buttonNode.getComponent(ToggleContainer) as any;
+    }
+    let checkEvents = btn.checkEvents;
+    let handler = new EventHandler();
+    handler.target = this.node;
+    handler.component = "tgxNodeEventAgent";
+    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`|`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: string | Node | Toggle | ToggleContainer,
+    cb: Function,
+    target: any
+  ) {
+    let buttonNode: Node = 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);
     }
 
-    /**
-     * @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: string | Node | Button, cb: Function, target: any) {
-        let buttonNode: Node = null;
-        if (relativeNodePath instanceof Node) {
-            buttonNode = relativeNodePath;
-
-        }
-        else if (relativeNodePath instanceof Button) {
-            buttonNode = relativeNodePath.node;
-        }
-        else {
-            buttonNode = find(relativeNodePath, this.node);
-        }
-
-        if (!buttonNode) {
-            return; ``
-        }
-
-        let agent = this.node.getComponent(__NodeEventAgent__);
-        if (!agent) {
-            return;
-        }
-        let btn = buttonNode.getComponent(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;
-            }
-        }
+    if (!buttonNode) {
+      return null;
     }
 
-    /**
-     * @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: string | Node | Toggle | ToggleContainer, cb: Function, target?: any, args?: any) {
-        let buttonNode: Node = 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;
-        }
-
-        //添加转发器
-        let agent = this.node.getComponent(__NodeEventAgent__);
-        if (!agent) {
-            agent = this.node.addComponent(__NodeEventAgent__);
-        }
-
-        let btn = buttonNode.getComponent(Toggle) as any;
-        if (!btn) {
-            btn = buttonNode.getComponent(ToggleContainer) as any;
-        }
-        let checkEvents = btn.checkEvents;
-        let handler = new EventHandler();
-        handler.target = this.node;
-        handler.component = 'tgxNodeEventAgent';
-        handler.handler = 'onToggleEvent';
-        handler.customEventData = '' + UIController._idBase++;
-
-        //附加额外信息 供事件转发使用
-        handler['$cb$'] = cb;
-        handler['$target$'] = target;
-        handler['$args$'] = args;
-
-        checkEvents.push(handler);
+    //添加转发器
+    let agent = this.node.getComponent(__NodeEventAgent__);
+    if (!agent) {
+      return;
+    }
+    let btn = buttonNode.getComponent(Toggle) as any;
+    if (!btn) {
+      btn = buttonNode.getComponent(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 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: string | Node | Toggle | ToggleContainer, cb: Function, target: any) {
-        let buttonNode: Node = 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;
-        }
-
-        //添加转发器
-        let agent = this.node.getComponent(__NodeEventAgent__);
-        if (!agent) {
-            return;
-        }
-        let btn = buttonNode.getComponent(Toggle) as any;
-        if (!btn) {
-            btn = buttonNode.getComponent(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;
-            }
-        }
+  }
+
+  onSlideEvent(
+    relativeNodePath: string | Node | Slider,
+    cb: Function,
+    target?: any,
+    args?: any
+  ) {
+    let sliderNode: Node = null;
+    if (relativeNodePath instanceof Node) {
+      sliderNode = relativeNodePath;
+    } else if (relativeNodePath instanceof Slider) {
+      sliderNode = relativeNodePath.node;
+    } else {
+      sliderNode = find(relativeNodePath, this.node);
     }
 
+    if (!sliderNode) {
+      return null;
+    }
 
-    onSlideEvent(relativeNodePath: string | Node | Slider, cb: Function, target?: any, args?: any) {
-        let sliderNode: Node = null;
-        if (relativeNodePath instanceof Node) {
-            sliderNode = relativeNodePath;
-        }
-        else if (relativeNodePath instanceof Slider) {
-            sliderNode = relativeNodePath.node;
-        }
-        else {
-            sliderNode = find(relativeNodePath, this.node);
-        }
-
-        if (!sliderNode) {
-            return null;
-        }
-
-        //添加转发器
-        let agent = this.node.getComponent(__NodeEventAgent__);
-        if (!agent) {
-            agent = this.node.addComponent(__NodeEventAgent__);
-        }
-
-        let slider = sliderNode.getComponent(Slider);
-        let slideEvents = slider.slideEvents;
-        let handler = new EventHandler();
-        handler.target = this.node;
-        handler.component = 'tgxNodeEventAgent';
-        handler.handler = 'onSlideEvent';
-        handler.customEventData = '' + UIController._idBase++;
-
-        //附加额外信息 供事件转发使用
-        handler['$cb$'] = cb;
-        handler['$target$'] = target;
-        handler['$args$'] = args;
-
-        slideEvents.push(handler);
-        slider.slideEvents = slideEvents;
+    //添加转发器
+    let agent = this.node.getComponent(__NodeEventAgent__);
+    if (!agent) {
+      agent = this.node.addComponent(__NodeEventAgent__);
     }
 
-    offSlideEvent(relativeNodePath: string | Node | Slider, cb: Function, target: any) {
-        let sliderNode: Node = null;
-        if (relativeNodePath instanceof Node) {
-            sliderNode = relativeNodePath;
-        }
-        else if (relativeNodePath instanceof Slider) {
-            sliderNode = relativeNodePath.node;
-        }
-        else {
-            sliderNode = find(relativeNodePath, this.node);
-        }
-
-        if (!sliderNode) {
-            return null;
-        }
-
-        //添加转发器
-        let agent = this.node.getComponent(__NodeEventAgent__);
-        if (!agent) {
-            return;
-        }
-        let slider = sliderNode.getComponent(Slider);
-        let slideEvents = slider.slideEvents;
-        for (let i = 0; i < slideEvents.length; ++i) {
-            let h = slideEvents[i];
-            if (h['$cb$'] == cb && h['$target$'] == target) {
-                slideEvents.splice(i, 1);
-                slider.slideEvents = slideEvents;
-                break;
-            }
-        }
+    let slider = sliderNode.getComponent(Slider);
+    let slideEvents = slider.slideEvents;
+    let handler = new EventHandler();
+    handler.target = this.node;
+    handler.component = "tgxNodeEventAgent";
+    handler.handler = "onSlideEvent";
+    handler.customEventData = "" + UIController._idBase++;
+
+    //附加额外信息 供事件转发使用
+    handler["$cb$"] = cb;
+    handler["$target$"] = target;
+    handler["$args$"] = args;
+
+    slideEvents.push(handler);
+    slider.slideEvents = slideEvents;
+  }
+
+  offSlideEvent(
+    relativeNodePath: string | Node | Slider,
+    cb: Function,
+    target: any
+  ) {
+    let sliderNode: Node = null;
+    if (relativeNodePath instanceof Node) {
+      sliderNode = relativeNodePath;
+    } else if (relativeNodePath instanceof Slider) {
+      sliderNode = relativeNodePath.node;
+    } else {
+      sliderNode = find(relativeNodePath, this.node);
     }
 
-    /***
-     * @en the extra resource needed by this ui panel.the ui will not be created until these res loaded.
-     * @zh 本UI使用的依赖资源.UI会等这些资源加载完成后才创建。
-     *  */
-    public getRes(): [] {
-        return [];
+    if (!sliderNode) {
+      return null;
     }
 
-    //子类的所有操作,需要在这个函数之后。
-    protected onCreated(params?:any) { }
-    //销毁
-    protected onDispose() { }
-    //
-    protected onUpdate(dt: number) { }
-}
+    //添加转发器
+    let agent = this.node.getComponent(__NodeEventAgent__);
+    if (!agent) {
+      return;
+    }
+    let slider = sliderNode.getComponent(Slider);
+    let slideEvents = slider.slideEvents;
+    for (let i = 0; i < slideEvents.length; ++i) {
+      let h = slideEvents[i];
+      if (h["$cb$"] == cb && h["$target$"] == target) {
+        slideEvents.splice(i, 1);
+        slider.slideEvents = slideEvents;
+        break;
+      }
+    }
+  }
+
+  /***
+   * @en the extra resource needed by this ui panel.the ui will not be created until these res loaded.
+   * @zh 本UI使用的依赖资源.UI会等这些资源加载完成后才创建。
+   *  */
+  public getRes(): [] {
+    return [];
+  }
+
+  //子类的所有操作,需要在这个函数之后。
+  protected onCreated(params?: any) {}
+  //销毁
+  protected onDispose() {}
+  //
+  protected onUpdate(dt: number) {}
+}

+ 1 - 1
assets/module_ball.meta

@@ -7,6 +7,6 @@
   "subMetas": {},
   "userData": {
     "isBundle": true,
-    "priority": 7
+    "priority": 6
   }
 }

+ 1 - 1
assets/module_ball/base.meta

@@ -2,7 +2,7 @@
   "ver": "1.2.0",
   "importer": "directory",
   "imported": true,
-  "uuid": "b7f52278-cd16-498f-b6c4-52286503cbf9",
+  "uuid": "9fcc0e7a-a23d-4de8-bd9a-1edf3395612b",
   "files": [],
   "subMetas": {},
   "userData": {}

+ 1 - 4
assets/module_ball/base/BaseUI.ts

@@ -15,10 +15,7 @@ import {
 import { UIController } from "../../core_tgx/easy_ui_framework/UIController";
 
 export default class BaseUI extends Component {
-  protected uiController: UIController;
-  setUIController(uiController: UIController) {
-    this.uiController = uiController;
-  }
+  
   public onHide() {}
   public onShow() {}
   private m_objects: Map<string, Node> = new Map<string, Node>();

+ 16 - 0
assets/module_ball/ui_game/UIGameResult.ts

@@ -8,6 +8,7 @@ import { UIGameResultPlayerItem } from "./UIGameResultPlayerItem";
 import { tween } from "cc";
 import { Vec3 } from "cc";
 import UIUtils from "../base/UIUtils";
+import { isValid } from "cc";
 const { ccclass, property } = _decorator;
 
 @ccclass("UIGameResult")
@@ -106,6 +107,9 @@ export class UIGameResult extends BaseUI {
   playTopAnim(index: number) {
     let self = this;
     setTimeout(() => {
+      if (!isValid(self.node)) {
+        return;
+      }
       let animNode = self.FindNode("no" + index);
       let moveDis = 200;
       animNode.setPosition(animNode.position.x, animNode.position.y - moveDis);
@@ -119,8 +123,14 @@ export class UIGameResult extends BaseUI {
     }, index * 200);
 
     setTimeout(() => {
+      if (!isValid(self.node)) {
+        return;
+      }
       let aaa = self.FindNode("circle_anim");
       UIUtils.AnimBezierMoveAndScale(aaa, new Vec3(0, 0, 0), 1.3, 1, () => {
+        if (!isValid(self.node)) {
+          return;
+        }
         UIUtils.AnimBezierMoveAndScale(aaa, new Vec3(0, 0, 0), 1, 0.5);
       });
     }, 0);
@@ -128,6 +138,9 @@ export class UIGameResult extends BaseUI {
   playLeftAnim(index: number) {
     let self = this;
     setTimeout(() => {
+      if (!isValid(self.node)) {
+        return;
+      }
       self.FindNode("no" + index).active = true;
       let animNode = self.FindNode("no" + index);
       let moveDis = 200;
@@ -146,6 +159,9 @@ export class UIGameResult extends BaseUI {
   playRightAnim(index: number) {
     let self = this;
     setTimeout(() => {
+      if (!isValid(self.node)) {
+        return;
+      }
       let animNode = self.FindNode("no" + index);
       let moveDis = 200;
       animNode.setPosition(animNode.position.x + moveDis, animNode.position.y);

+ 1 - 1
assets/module_ball/ui_lobby/Lobby.ts

@@ -76,7 +76,7 @@ export class Lobby extends BaseUI {
     this.setActive("connect_node", false);
     this.setActive("gem_node", true);
 
-    this.FindAs("top_layout", Layout).updateLayout();
+    // this.FindAs("top_layout", Layout).updateLayout();
     UIWaiting.hide();
   }
 }

+ 1 - 1
assets/module_ball/ui_lobby/SoloMatch.ts

@@ -9,7 +9,7 @@ export class BallUISoloMatch extends BaseUI {
   static show() {
     tgx.UIMgr.inst.show(
       ModuleDef.BALL,
-      "ui_lobby/ui_solo_match2",
+      "ui_lobby/ui_solo_match",
       GameUILayers.POPUP
     );
   }

+ 9 - 6
assets/start/Start.ts

@@ -93,18 +93,21 @@ export class Start extends Component {
       profiler.showStats();
       
       // Enable better debugging in preview mode
-      console.log("Preview mode enabled with source maps");
+      console.log("Preview mode enabled");
+      
+      // Test source map functionality
+      setTimeout(() => {
+        console.log("Testing source map - this should show the original file and line number");
+        // This will help verify if source maps are working
+        const testError = new Error("Test error for source map verification");
+        console.error("Source map test:", testError.message);
+      }, 2000);
       
       // Override error handling for better stack traces
       window.addEventListener('error', function(event) {
         console.error('Preview Error:', event.error);
         console.error('Stack:', event.error?.stack);
       });
-      
-      // Enable source map debugging
-      if (window.__PREVIEW_DEBUG__) {
-        console.log("Preview debug mode active");
-      }
     }
     tgx.ModuleContext.setDefaultModule(_defaultModule);
 

+ 35 - 19
preview-template/index.ejs

@@ -19,33 +19,49 @@
     <link rel="stylesheet" type="text/css" href="./index.css" />
     <script src="./lib/ads5.js"></script>
 
-    <!-- Source Map Support for Preview -->
+    <!-- Enhanced Source Map Support for Preview -->
     <script>
-      // Enable source maps in preview mode
+      // Enable enhanced debugging in preview mode
       window.__PREVIEW_DEBUG__ = true;
       window.__SOURCE_MAPS_ENABLED__ = true;
 
-      // Override console methods to show better stack traces
-      if (window.__PREVIEW_DEBUG__) {
-        const originalError = console.error;
-        const originalWarn = console.warn;
-        const originalLog = console.log;
+      // Override error handling for better source map support
+      window.addEventListener("error", function (event) {
+        console.error("=== ENHANCED ERROR LOGGING ===");
+        console.error("Error:", event.error);
+        console.error("Message:", event.message);
+        console.error("Filename:", event.filename);
+        console.error("Lineno:", event.lineno);
+        console.error("Colno:", event.colno);
+        console.error("Stack:", event.error?.stack);
+        console.error("==============================");
+      });
 
-        console.error = function (...args) {
-          const stack = new Error().stack;
-          originalError.apply(console, [...args, "\nStack:", stack]);
-        };
+      // Override unhandled promise rejection
+      window.addEventListener("unhandledrejection", function (event) {
+        console.error("=== UNHANDLED PROMISE REJECTION ===");
+        console.error("Reason:", event.reason);
+        console.error("Stack:", event.reason?.stack);
+        console.error("====================================");
+      });
 
-        console.warn = function (...args) {
+      // Only enhance console.error for actual errors, not regular logs
+      const originalError = console.error;
+      console.error = function (...args) {
+        // Only add stack trace for actual errors, not regular console.log calls
+        if (
+          args.length > 0 &&
+          typeof args[0] === "string" &&
+          args[0].includes("Error")
+        ) {
           const stack = new Error().stack;
-          originalWarn.apply(console, [...args, "\nStack:", stack]);
-        };
+          originalError.apply(console, [...args, "\n[Enhanced Stack]:", stack]);
+        } else {
+          originalError.apply(console, args);
+        }
+      };
 
-        console.log = function (...args) {
-          const stack = new Error().stack;
-          originalLog.apply(console, [...args, "\nStack:", stack]);
-        };
-      }
+      console.log("Preview mode with enhanced source map support enabled");
     </script>
   </head>
   <body style="overflow: hidden">

+ 9 - 3
settings/v2/packages/builder.json

@@ -75,7 +75,9 @@
             "preferredOptions": {
               "compressionType": "merge_dep",
               "isRemote": false,
-              "sourceMaps": true
+              "sourceMaps": true,
+              "debug": true,
+              "inlineSourceMap": true
             }
           }
         }
@@ -93,11 +95,15 @@
             "preferredOptions": {
               "isRemote": false,
               "compressionType": "merge_dep",
-              "sourceMaps": true
+              "sourceMaps": true,
+              "debug": true,
+              "inlineSourceMap": true
             },
             "fallbackOptions": {
               "compressionType": "merge_dep",
-              "sourceMaps": true
+              "sourceMaps": true,
+              "debug": true,
+              "inlineSourceMap": true
             }
           },
           "miniGame": {

+ 2 - 1
settings/v2/packages/device.json

@@ -1,4 +1,5 @@
 {
   "debug": true,
-  "sourceMaps": true
+  "sourceMaps": true,
+  "__version__": "1.0.1"
 }

+ 2 - 8
settings/v2/packages/preview.json

@@ -1,16 +1,10 @@
 {
-  "__version__": "1.0.0",
+  "__version__": "1.0.1",
   "debug": true,
   "sourceMaps": true,
   "inlineSourceMap": true,
   "inlineSources": true,
   "preserveSymlinks": true,
   "showStats": true,
-  "enableSourceMap": true,
-  "preview": {
-    "debug": true,
-    "sourceMaps": true,
-    "inlineSourceMap": true,
-    "inlineSources": true
-  }
+  "enableSourceMap": true
 }

+ 1 - 1
settings/v2/packages/program.json

@@ -1,5 +1,5 @@
 {
-  "__version__": "1.0.1",
+  "__version__": "1.0.4",
   "debug": true,
   "sourceMaps": true,
   "preview": {

+ 15 - 2
settings/v2/packages/project.json

@@ -46,7 +46,10 @@
   },
   "debug": {
     "sourceMaps": true,
-    "inlineSourceMap": true
+    "inlineSourceMap": true,
+    "inlineSources": true,
+    "sourceRoot": "",
+    "mapRoot": ""
   },
   "preview": {
     "debug": true,
@@ -54,6 +57,16 @@
     "inlineSourceMap": true,
     "inlineSources": true,
     "showStats": true,
-    "enableSourceMap": true
+    "enableSourceMap": true,
+    "sourceRoot": "",
+    "mapRoot": "",
+    "preserveSymlinks": true
+  },
+  "build": {
+    "debug": true,
+    "sourceMaps": true,
+    "inlineSourceMap": true,
+    "inlineSources": true,
+    "preserveSymlinks": true
   }
 }

+ 12 - 2
tsconfig.json

@@ -8,6 +8,16 @@
     "inlineSourceMap": true,
     "inlineSources": true,
     "declaration": false,
-    "removeComments": false
-  }
+    "removeComments": false,
+    "sourceRoot": "",
+    "mapRoot": "",
+    "outDir": "",
+    "rootDir": "",
+    "baseUrl": ".",
+    "paths": {
+      "db://assets/*": ["./assets/*"]
+    }
+  },
+  "include": ["assets/**/*"],
+  "exclude": ["node_modules", "temp", "library"]
 }