76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import SKLocalUtil from "../util/SKLocalUtil";
|
|
import SKLogger from "../util/SKLogger";
|
|
|
|
let EFFECT = {
|
|
NORMAL: 0,
|
|
SCALE: 1
|
|
};
|
|
class PopupManager {
|
|
|
|
private static instance: PopupManager;
|
|
|
|
public static getInstance(): PopupManager {
|
|
if(!this.instance)
|
|
this.instance = new PopupManager();
|
|
return this.instance;
|
|
}
|
|
private current: cc.Node = null;
|
|
private dicts: any[];
|
|
|
|
|
|
constructor() {
|
|
this.dicts = [];
|
|
}
|
|
|
|
showView(prefab: cc.Prefab, effcet: number = EFFECT.NORMAL,callBack:Function=null) {
|
|
let node = cc.instantiate(prefab);
|
|
let parent = cc.find("Canvas");
|
|
node.parent = parent;
|
|
(callBack)&&(callBack(node))
|
|
this.current = node;
|
|
let dict = {
|
|
name: node.name,
|
|
node: node,
|
|
};
|
|
this.dicts.push(dict);
|
|
}
|
|
|
|
closeView(name: string, effcet: number = EFFECT.NORMAL) {
|
|
let node = null;
|
|
for(let i=0; i<this.dicts.length; i++){
|
|
if(this.dicts[i] && this.dicts[i].name == name){
|
|
node = this.dicts[i].node;
|
|
this.dicts.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
if(!node){
|
|
node = cc.find("Canvas").getChildByName(name);
|
|
}
|
|
if(node){
|
|
if(effcet == EFFECT.NORMAL){
|
|
node.destroy();
|
|
}
|
|
}
|
|
}
|
|
|
|
closeAll() {
|
|
for(let i=0; i<this.dicts.length; i++){
|
|
if(this.dicts[i] && this.dicts[i].name == name){
|
|
this.dicts[i].node.destroy();
|
|
}
|
|
}
|
|
this.dicts = [];
|
|
}
|
|
|
|
isExist(name: string) {
|
|
for(let i=0; i<this.dicts.length; i++){
|
|
if(this.dicts[i] && this.dicts[i].name == name){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export default PopupManager.getInstance(); |