123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- // UI
- class UIMgr{
- constructor() {
- console.log('UIMgr初始化');
- this.recordList = {};
- this.popupList = [];
- }
- openUI(path, callBack){
- let arr = path.split('/');
- let key = arr[arr.length - 1];
- if(key != 'TipsLayer')
- this.showWait();
- cc.resources.load(path, function(err, prefab){
- if(err){
- console.log('加载界面出错: ', path);
- return;
- }
- this.hideWait();
- if(cc.isValid(this.recordList[key])){
- console.log("弹框已加载: ", key);
- if (callBack)
- callBack(this.recordList[key]);
- return;
- }
- let pf = cc.instantiate(prefab);
- let layer = cc.director.getScene();
- pf.parent = layer;
- pf.name = key;
- this.setLayerIndex(pf);
- this.recordList[key] = pf;
- this.popupList.push({name: key, node: pf});
- if(callBack)
- callBack(pf);
- }.bind(this));
- }
- setLayerIndex(target){
- let tName = target.name;
- if(tName == 'TipsLayer'){
- target.zIndex = 100 + this.popupList.length;
- }else{
- // target.zIndex = 200 + this.popupList.length;
- }
- }
- clearPopupList(){
- this.popupList = [];
- }
- getPopupNums() {
- console.log('getPopupNums: ', this.popupList);
- return this.popupList.length;
- }
- closeUI(key, bDestroy=true){
- for(let i=0; i < this.popupList.length; i++){
- let item = this.popupList[i];
- if(item.name == key){
- if(bDestroy){
- if(cc.isValid(item.node)){
- item.node.destroy();
- }
- }
- this.popupList.splice(i, 1);
- break;
- }
- }
- delete this.recordList[key];
- }
- closeAllUI(){
- for(let i=0; i < this.popupList.length; i++){
- let item = this.popupList[i];
- if (cc.isValid(item.node)) {
- item.node.destroy();
- }
- }
- this.popupList = [];
- this.recordList = {};
- }
- // -------- wait --------
- showWait(callBack = null){
- let waitNode = cc.find('WaitNodeLayer');
- if(waitNode)
- waitNode.getComponent('WaitNodeLayer').showWait(callBack);
- }
- hideWait(){
- let waitNode = cc.find('WaitNodeLayer');
- if(waitNode)
- waitNode.getComponent('WaitNodeLayer').hideWait();
- }
- }
- let instance = null;
- UIMgr.getInstance = function(){
- if(!instance){
- instance = new UIMgr();
- }
- return instance;
- }
- export default UIMgr.getInstance();
|