123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import { _decorator, Button, Component, Node, PageView } from 'cc';
- const { ccclass, property } = _decorator;
- export enum UIType{
- PAGE,
- WIDGET,
- POPWIN,
- }
- @ccclass('UIBase')
- export class UIBase extends Component {
- protected _nodes: Map<string, Node> = new Map();
- protected _uiName: string = "ui";
- get UIName(){ return this._uiName;}
- set UIName(name: string){this._uiName = name;}
-
- init(){
- this._visit(this.node)
-
- this.onStart();
- }
-
- protected onStart(){
- }
- private _visit(node: Node){
-
- if(node.name.startsWith("_")){
- this._nodes.set(node.name, node);
- }
- for(const child of node.children){
- this._visit(child);
- }
- }
- show(){
- this.node.active = true;
- this.use();
- }
- showing(){
- return this.node.active;
- }
- hide(clear: Boolean = true){
- this.unUse();
- if(clear){
- this.node.destroy();
- return;
- }
- this.node.active = false;
- }
-
-
- protected use(){
- }
-
- protected unUse(){
- }
-
-
- onBtnClick(name: string, callback: Function, ...arg){
- const node = this._nodes.get(name);
- if(node){
- node.on(Button.EventType.CLICK,()=>{
-
-
- callback.apply(this, [...arg]);
- })
- }
- }
-
- onPageView(name: string, type, callback: Function){
- this._nodes.get(name).on(type, callback);
- }
- getPageView(name: string): PageView{
- return this._nodes.get(name).getComponent(PageView);
- }
- getNode(name: string): Node{
- return this._nodes.get(name);
- }
- onMsg(msg: string, callback: Function){
- }
- }
|