12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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){
- }
- }
|