@gongxh/bit-ui 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var e,t,i=require("@gongxh/bit-core"),s=require("fairygui-cc"),o=require("cc");exports.WindowType=void 0,(e=exports.WindowType||(exports.WindowType={}))[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne",exports.AdapterType=void 0,(t=exports.AdapterType||(exports.AdapterType={}))[t.Full=0]="Full",t[t.Bang=1]="Bang",t[t.Fixed=2]="Fixed";class n extends s.GComponent{constructor(){super(...arguments),this.adapterType=exports.AdapterType.Full,this._refCount=0}onHide(){}onAdapted(){}_init(){this.onInit()}_adapted(){switch(this.setPosition(.5*i.Screen.ScreenWidth,.5*i.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(i.Screen.ScreenWidth,i.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(i.Screen.SafeWidth,i.Screen.SafeHeight,!0)}this.onAdapted()}_show(e){var t;this.visible=!0,this.onShow(e,null===(t=e.getHeaderInfo())||void 0===t?void 0:t.userdata)}_hide(){this.visible=!1,this.onHide()}_close(){this.onClose(),this.dispose()}_addRef(){this._refCount++}_decRef(){return--this._refCount}_screenResize(){this._adapted()}}class r{static setConfig(e){this._config=e}static serializeProps(e,t,i){if(!this._config)return;const s=this._config[t];if(!s)return;const o=s[i=i||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const r=o.callbacks;this.serializationCallbacksNode(e,r);const a=o.controls;this.serializationControlsNode(e,a);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})属性(${i})赋值,请检查节点配置是否正确`);break}e[i]=n==e?null:n}}static serializationCallbacksNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})的(${i})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[i],e)}}static serializationControlsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置控制器,请检查配置是否正确`);break}e[i]=n,s+=2}}static serializationTransitionsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置动画,请检查配置是否正确`);break}e[i]=n,s+=2}}}r._config={};class a{static register(){for(const{ctor:e,res:t}of exports._uidecorator.getComponentMaps().values()){const i=`${t.pkg}/${t.name}`;this._registeredComponents.has(i)?console.debug(`自定义组件已注册,跳过 组件名:${t.name} 包名:${t.pkg}`):(console.debug(`自定义组件注册 组件名:${t.name} 包名:${t.pkg}`),this.registerComponent(e,t.pkg,t.name),this._registeredComponents.add(i))}}static dynamicRegister(e,t,s){const o=`${t}/${s}`;this._registeredComponents.has(o)?console.debug(`自定义组件已注册,跳过 组件名:${s} 包名:${t}`):(i.debug(`自定义组件注册 组件名:${s} 包名:${t}`),this.registerComponent(e,t,s),this._registeredComponents.add(o))}static registerComponent(e,t,i){e.prototype.onConstruct=function(){r.serializeProps(this,t,i),this.onInit&&this.onInit()},s.UIObjectFactory.setExtension(`ui://${t}/${i}`,e)}}a._registeredComponents=new Set;class h{static initPackageConfig(e){this._resPool.initPackageConfig(e)}static showWindow(e,t){return new Promise((i,s)=>{this._resPool.loadWindowRes(e,{complete:()=>{this.showWindowIm(e,t),i()},fail:e=>{s(e)}})})}static showWindowIm(e,t){const i=this._resPool.get(e),s=this.getWindowGroup(i.group);this._resPool.addResRef(e),s.showWindow(i,t)}static closeWindow(e){if(!this._windows.has(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);let t=this._resPool.get(e);const i=this.getWindowGroup(t.group);if(i._removeWindow(e),0==i.size){let e=this._queryGroupNames.indexOf(i.name);if(e>0&&i.name==this.getTopGroupName())do{const t=this._queryGroupNames[--e];let i=this.getWindowGroup(t);if(i.size>0){this.getWindow(i.getTopWindowName())._recover();break}}while(e>=0)}}static closeAllWindow(e=[]){let t=e.length>0;this._windows.forEach((i,s)=>{t&&e.includes(s)||this.closeWindow(s)}),t||this._windows.clear()}static getTopWindow(){for(let e=this._queryGroupNames.length;e>0;){let t=this.getWindowGroup(this._queryGroupNames[--e]);if(t.size>0)return this.getWindow(t.getTopWindowName())}return null}static getWindow(e){return this._windows.get(e)}static hasWindow(e){return this._windows.has(e)}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`UIManager.getWindowGroup: window group 【${e}】 not found`)}static getTopGroupName(){for(let e=this._queryGroupNames.length-1;e>=0;e--){let t=this._queryGroupNames[e];if(this._groups.get(t).size>0)return t}return""}static _init(e){this._resPool=e}static _addWindow(e,t){this._windows.set(e,t)}static _removeWindow(e){this.hasWindow(e)&&(this._windows.get(e)._close(),this._windows.delete(e),this._resPool.releaseWindowRes(e))}static registerUI(){for(const{ctor:e,res:t}of exports._uidecorator.getWindowMaps().values())i.debug(`窗口注册 窗口名:${t.name} 包名:${t.pkg} 组名:${t.group}`),this._resPool.add(e,t.group,t.pkg,t.name,t.bundle);for(const{ctor:e,res:t}of exports._uidecorator.getHeaderMaps().values())i.debug(`header注册 header名:${t.name} 包名:${t.pkg}`),this._resPool.addHeader(e,t.pkg,t.name,t.bundle);a.register()}static dynamicRegisterWindow(e,t,s,o,n){i.debug(`窗口注册 窗口名:${o} 包名:${s} 组名:${t}`),this._resPool.add(e,t,s,o,n)}static dynamicRegisterHeader(e,t,s,o){i.debug(`header注册 header名:${s} 包名:${t}`),this._resPool.addHeader(e,t,s,o)}static _addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`UIManager._addWindowGroup: window group 【${e.name}】 already exists`);this._groups.set(e.name,e),!e.isIgnore&&this._queryGroupNames.push(e.name)}static _screenResize(){this._windows.forEach(e=>{e.screenResize()}),this._groups.forEach(e=>{e._screenResize()})}static _getResPool(){return this._resPool}}h._groups=new Map,h._queryGroupNames=[],h._windows=new Map,exports._uidecorator=void 0,function(e){const t="__uipropmeta__",i="__uicbmeta__",s="__uicontrolmeta__",o="__uitransitionmeta__",n=new Map;function r(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}e.getWindowMaps=function(){return n},e.uiclass=function(e,r,a,d){return function(l){const p=l;return n.set(p,{ctor:l,props:l[t]||null,callbacks:l[i]||null,controls:l[s]||null,transitions:l[o]||null,res:{group:e,pkg:r,name:a,bundle:d||""}}),c&&h.dynamicRegisterWindow(l,e,r,a,d||""),l}};let d=new Map;e.getComponentMaps=function(){return d},e.uicom=function(e,n){return function(r){const h=r;return d.set(h,{ctor:r,props:r[t]||null,callbacks:r[i]||null,controls:r[s]||null,transitions:r[o]||null,res:{pkg:e,name:n}}),c&&a.dynamicRegister(r,e,n),r}};let l=new Map;e.getHeaderMaps=function(){return l},e.uiheader=function(e,n,r){return function(a){const d=a;return l.set(d,{ctor:a,props:a[t]||null,callbacks:a[i]||null,controls:a[s]||null,transitions:a[o]||null,res:{pkg:e,name:n,bundle:r||""}}),c&&h.dynamicRegisterHeader(a,e,n,r||""),a}},e.uiprop=function(e,i){r(e.constructor,t)[i]=1},e.uicontrol=function(e,t){r(e.constructor,s)[t]=1},e.uitransition=function(e,t){r(e.constructor,o)[t]=1},e.uiclick=function(e,t,s){r(e.constructor,i)[t]=s.value};let c=!1;e.setRegisterFinish=function(){c=!0}}(exports._uidecorator||(exports._uidecorator={}));const d=globalThis||window||global;d.getKunpoRegisterWindowMaps=function(){return exports._uidecorator.getWindowMaps()},d.getKunpoRegisterComponentMaps=function(){return exports._uidecorator.getComponentMaps()},d.getKunpoRegisterHeaderMaps=function(){return exports._uidecorator.getHeaderMaps()};class l extends s.GComponent{constructor(){super(...arguments),this.type=exports.WindowType.Normal,this.adapterType=exports.AdapterType.Full,this._header=null,this._isCover=!1,this._swallowComponent=null}_init(e,t){if(e){let t=new s.GComponent;t.name="swallow",t.setSize(i.Screen.ScreenWidth,i.Screen.ScreenHeight,!0),t.setPivot(.5,.5,!0),t.setPosition(.5*this.width,.5*this.height),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowComponent=t}this.opaque=e,this.bgAlpha=t,this.onInit()}_adapted(){var e,t;switch(this.setPosition(.5*i.Screen.ScreenWidth,.5*i.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(i.Screen.ScreenWidth,i.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(i.Screen.SafeWidth,i.Screen.SafeHeight,!0)}null===(e=this._swallowComponent)||void 0===e||e.setSize(i.Screen.ScreenWidth,i.Screen.ScreenHeight,!0),null===(t=this._swallowComponent)||void 0===t||t.setPosition(.5*this.width,.5*+this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_cover(){this._isCover=!0,this.onCover()}_recover(){this._isCover=!1,this.onRecover()}_setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isCover(){return this._isCover}screenResize(){this._adapted()}getHeaderInfo(){return null}getHeader(){return this._header}_setHeader(e){this._header=e}}class c{get name(){return this._name}get size(){return this._windowNames.length}get isIgnore(){return this._ignoreQuery}constructor(e,t,i,n,r){this._name="",this._ignoreQuery=!1,this._swallowTouch=!1,this._windowNames=[],this._headers=new Map,this._bgAlpha=0,this._color=new o.Color(0,0,0,255),this._name=e,this._root=t,this._ignoreQuery=i,this._swallowTouch=n,this._bgAlpha=r;const a=new s.GGraph;a.touchable=!1,a.name="bgAlpha",a.setPosition(.5*t.width,.5*t.height),a.setSize(t.width,t.height,!0),a.setPivot(.5,.5,!0),t.addChild(a),this._alphaGraph=a}_createWindow(e,t){let i=s.UIPackage.createObject(e,t);return i.name=t,r.serializeProps(i,e),i._init(this._swallowTouch,this._bgAlpha),i._adapted(),this._createHeader(i),this._addWindow(i),i}_addWindow(e){this._root.addChild(e),h._addWindow(e.name,e)}showWindow(e,t){let i=e.name,s=h.getWindow(i);s||(s=this._createWindow(e.pkg,i),this._processWindowCloseStatus(s),this._windowNames.push(i)),s._show(t),this._moveWindowToTop(i),this._processHeaderStatus(),this._root.visible=!0}_removeWindow(e){let t=this._windowNames.lastIndexOf(e),i=this.size-1;if(t<0)return void console.warn(`窗口组${this._name}中未找到窗口${e} 删除失败`);let s=h.getWindow(e).getHeader();if(s&&this._removeHeader(s),this._windowNames.splice(t,1),h._removeWindow(e),this._processWindowHideStatus(this.size-1,!0),0==this.size)this._root.visible=!1;else if(i==t&&t>0){let e=this.getTopWindowName(),t=h.getWindow(e);this._adjustAlphaGraph(t),t._setDepth(this._root.numChildren-1)}this._processHeaderStatus()}_moveWindowToTop(e){let t=!1;if(0==this.size)return console.warn(`WindowGroup.moveWindowToTop: window group 【${this._name}】 is empty`),!1;if(this._windowNames[this.size-1]==e);else{const i=this._windowNames.indexOf(e);if(-1==i)return console.warn(`WindowGroup.moveWindowToTop: window 【${e}】 not found in window group 【${this._name}】`),!1;i<this._windowNames.length-1&&(this._windowNames.splice(i,1),this._windowNames.push(e),t=!0)}let i=h.getWindow(e);return this._adjustAlphaGraph(i),i._setDepth(this._root.numChildren-1),this._processWindowHideStatus(this.size-1,t),!0}_processWindowHideStatus(e,t=!0){if(e<0)return;let i=this._windowNames[e],s=h.getWindow(i);if(e!=this.size-1||s.isShowing()||s._showFromHide(),0==e)return;let o=s.type;if(o!=exports.WindowType.HideAll){if(o==exports.WindowType.HideOne){let t=this._windowNames[e-1],i=h.getWindow(t);i.isShowing()&&i._hide()}else{let t=this._windowNames[e-1],i=h.getWindow(t);!i.isShowing()&&i._showFromHide()}t&&this._processWindowHideStatus(e-1,t)}else for(let t=e-1;t>=0;--t){let e=this._windowNames[t];const i=h.getWindow(e);i.isShowing()&&i._hide()}}_processWindowCloseStatus(e){if(e.type==exports.WindowType.CloseOne){let e=this.size;for(;e>0;){let e=this._windowNames.pop(),t=h.getWindow(e).getHeader();t&&this._removeHeader(t),h._removeWindow(e);break}}else if(e.type==exports.WindowType.CloseAll){for(let e=this.size;e>0;){let t=this._windowNames[--e],i=h.getWindow(t).getHeader();i&&this._removeHeader(i),h._removeWindow(t)}this._windowNames.length=0}}_processHeaderStatus(){let e=null,t=null,i=this.size-1;for(let s=this.size-1;s>=0;--s){let o=this._windowNames[s],n=h.getWindow(o);if(n.isShowing()&&n.getHeader()){t=n,e=n.getHeader(),i=s;break}}this._headers.forEach((i,s)=>{this._root.setChildIndex(i,0),!e&&i.visible?i._hide():e&&(e.name!=s||i.visible?e.name!=s&&i.visible&&i._hide():i._show(t))}),e&&(i==this.size-1?this._root.setChildIndex(e,this._root.numChildren-1):this._root.setChildIndex(e,this._root.numChildren-this.size+i-1))}_adjustAlphaGraph(e){this._root.setChildIndex(this._alphaGraph,this._root.numChildren-1),this._color.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._color,this._color)}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindowName(){return this.size>0?this._windowNames[this.size-1]:(console.warn(`WindowGroup.getTopWindowName: window group 【${this._name}】 is empty`),"")}_createHeader(e){let t=e.getHeaderInfo();if(!t)return;let i=t.name,o=this._getHeader(i);if(o)e._setHeader(o),o._addRef();else{let{pkg:t}=h._getResPool().getHeader(i),o=s.UIPackage.createObject(t,i);o.name=i,o.opaque=!1,e._setHeader(o),o.visible=!1,r.serializeProps(o,t),o._init(),o._adapted(),this._root.addChild(o),o._addRef(),this._headers.set(o.name,o)}}_removeHeader(e){if(this._headers.has(e.name)){e._decRef()<=0&&(this._headers.delete(e.name),e._close())}}_getHeader(e){return this._headers.get(e)}_screenResize(){this._headers.forEach(e=>{e._screenResize()}),this._alphaGraph.setPosition(.5*i.Screen.ScreenWidth,.5*i.Screen.ScreenHeight),this._alphaGraph.setSize(i.Screen.ScreenWidth,i.Screen.ScreenHeight,!0),this._alphaGraph.setPivot(.5,.5,!0)}closeAllWindow(){for(;this.size>0;){let e=this.getTopWindowName();h.closeWindow(e)}}}class p{static create(e,t){const i=new p;return i.name=e,i.userdata=t,i}}function u(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,i,r):o(t,i))||r);return n>3&&r&&Object.defineProperty(t,i,r),r}"function"==typeof SuppressedError&&SuppressedError;class w{constructor(){this._windowInfos=new Map,this._headerInfos=new Map,this._pkgBundles=new Map,this._isInit=!1,this._windowPkgs=new Map,this._pkgRefs={},this._uiPaths={},this._manualPackages=new Set,this._imReleasePackages=new Set,this._showWaitWindow=null,this._hideWaitWindow=null,this._fail=null,this._waitRef=0}add(e,t,i,o,n){this.has(o)||(this._windowInfos.set(o,{ctor:e,group:t,pkg:i,name:o,bundle:n}),this._pkgBundles.set(i,n||"resources"),this.addWindowPkg(o,i),s.UIObjectFactory.setExtension(`ui://${i}/${o}`,e))}has(e){return this._windowInfos.has(e)}get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}addHeader(e,t,i,o){this.hasHeader(i)||(this._headerInfos.set(i,{ctor:e,pkg:t,bundle:o}),this._pkgBundles.set(t,o||"resources"),s.UIObjectFactory.setExtension(`ui://${t}/${i}`,e))}hasHeader(e){return this._headerInfos.has(e)}getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}initPackageConfig(e){var t,i;if(!e||!e.config)return;if(this._isInit)throw new Error("资源配置已初始化,请勿重复设置");this._isInit=!0,this._showWaitWindow=null==e?void 0:e.showWaitWindow,this._hideWaitWindow=null==e?void 0:e.hideWaitWindow,this._fail=null==e?void 0:e.fail,this._uiPaths=(null===(t=e.config)||void 0===t?void 0:t.bundlePaths)||{},this._uiPaths.resources=(null===(i=e.config)||void 0===i?void 0:i.uiPath)||"";for(const e in this._uiPaths)""==this._uiPaths[e]||this._uiPaths[e].endsWith("/")||(this._uiPaths[e]+="/");this._manualPackages=new Set(e.config.manualPackages||[]),this._imReleasePackages=new Set(e.config.imReleasePackages||[]);let s=e.config.linkPackages||{};for(const e in s){let t=s[e];for(const i of t||[])this.addWindowPkg(e,i)}this._windowPkgs.forEach((e,t)=>{for(let t=e.length-1;t>=0;t--)this._manualPackages.has(e[t])&&e.splice(t,1);e.length<=0&&this._windowPkgs.delete(t)})}addWindowPkg(e,t){this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}loadWindowRes(e,t){var i;if(!this._isInit)return console.warn("UI包信息未配置 将手动管理所有UI包资源的加载,如果需要配置,请使用 【UIManager.initPackageConfig】接口"),void t.complete();this.hasWindowPkg(e)?(this._waitRef++<=0&&(null===(i=this._showWaitWindow)||void 0===i||i.call(this)),this.loadPackages({pkgs:this.getWindowPkgs(e),complete:()=>{var e;--this._waitRef<=0&&(t.complete(),null===(e=this._hideWaitWindow)||void 0===e||e.call(this))},fail:i=>{var s,o;console.warn(`界面${e}打开失败`),t.fail(i),null===(s=this._fail)||void 0===s||s.call(this,e,"UI包加载失败",i),--this._waitRef<=0&&(null===(o=this._hideWaitWindow)||void 0===o||o.call(this))}})):t.complete()}addResRef(e){if(!this._isInit)return;if(!this.hasWindowPkg(e))return;let t=this.getWindowPkgs(e);for(const e of t)this.addRef(e)}releaseWindowRes(e){if(!this._isInit||!this.hasWindowPkg(e))return;let t=this.getWindowPkgs(e);for(const e of t)this.decRef(e)}loadPackages(e){let t=e.pkgs.filter(e=>this.getRef(e)<=0),i=[],n=[],r=t.length;if(r<=0)e.complete();else for(const a of t){let t=this.getPkgBundle(a),h="resources"===t?o.resources:o.assetManager.getBundle(t);if(!h)throw new Error(`UI包【${a}】所在的bundle【${t}】未加载`);s.UIPackage.loadPackage(h,this.getPkgPath(a),t=>{r--,t?n.push(a):i.push(a),r>0||(n.length>0?e.fail(n):e.complete())})}}getPkgBundle(e){return this._pkgBundles.get(e)||"resources"}getPkgPath(e){let t=this._pkgBundles.get(e);return this._uiPaths[t]+e}getWindowPkgs(e){return this._windowPkgs.has(e)?this._windowPkgs.get(e):[]}hasWindowPkg(e){return this._windowPkgs.has(e)}getRef(e){return this._pkgRefs[e]?this._pkgRefs[e]:0}addRef(e){this._pkgRefs[e]=this.getRef(e)+1}decRef(e){this._pkgRefs[e]=this.getRef(e)-1,this.getRef(e)<=0&&(delete this._pkgRefs[e],this._imReleasePackages.has(e)&&s.UIPackage.removePackage(e))}}const{ccclass:_,property:g,menu:f}=o._decorator;let m=class extends o.Component{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1,this.bgAlpha=.75}init(){let e=this.node.name;i.debug(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new s.GComponent;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(i.Screen.ScreenWidth,i.Screen.ScreenHeight,!0),s.GRoot.inst.addChild(t),h._addWindowGroup(new c(e,t,this.ignoreQuery,this.swallowTouch,this.bgAlpha))}};u([g({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],m.prototype,"ignoreQuery",void 0),u([g({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],m.prototype,"swallowTouch",void 0),u([g({displayName:"底部遮罩透明度",tooltip:"底部半透明遮罩的默认透明度",min:0,max:1,step:.01})],m.prototype,"bgAlpha",void 0),m=u([_("CocosWindowContainer"),f("kunpo/UI/UIContainer")],m);const{ccclass:W,menu:k,property:P}=o._decorator;exports.UIModule=class extends o.Component{constructor(){super(...arguments),this.moduleName="UI模块"}init(){h._init(new w),s.GRoot.create(),i.debug("初始化 WindowContainers");for(const e of this.node.children){const t=e.getComponent(m);null==t||t.init()}this.node.destroyAllChildren(),h.registerUI(),exports._uidecorator.setRegisterFinish(),this.onInit()}onInit(){i.debug("UIModule init complete")}},exports.UIModule=u([W("UIModule"),k("kunpo/UIModule")],exports.UIModule),exports.UIHeader=n,exports.UIManager=h,exports.Window=class extends l{onAdapted(){}onClose(){}onShow(e){}onHide(){}onShowFromHide(){}onCover(){}onRecover(){}onEmptyAreaClick(){}},exports.WindowGroup=c,exports.WindowHeaderInfo=p;
1
+ "use strict";var e,t,s,i=require("fairygui-cc"),o=require("@gongxh/bit-core"),n=require("cc");exports.WindowType=void 0,(e=exports.WindowType||(exports.WindowType={}))[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne",exports.AdapterType=void 0,(t=exports.AdapterType||(exports.AdapterType={}))[t.Full=0]="Full",t[t.Bang=1]="Bang",t[t.Fixed=2]="Fixed",function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(s||(s={}));class a{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const d=o.transitions;this.serializationTransitionsNode(e,d)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}a._config={};class r{static add(e,t,s,n,a){if(this.has(n))console.warn(`窗口【${n}】已注册,跳过,请检查是否重复注册`);else if(o.debug(`窗口注册 窗口名:${n} 包名:${s} 组名:${t}`),this._windowInfos.set(n,{ctor:e,group:t,pkgName:s,name:n}),i.UIObjectFactory.setExtension(`ui://${s}/${n}`,e),this.addWindowPkg(n,s),a.length>0)for(const e of a)this.addWindowPkg(n,e)}static addHeader(e,t,s){this.hasHeader(s)?console.warn(`header【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`header注册 header名:${s} 包名:${t}`),this._headerInfos.set(s,{ctor:e,pkgName:t}),i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(o.debug(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(e,t,s){e.prototype.onConstruct=function(){a.serializeProps(this,t,s),this.onInit&&this.onInit()},i.UIObjectFactory.setExtension(`ui://${t}/${s}`,e)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}r._windowInfos=new Map,r._headerInfos=new Map,r._customComponents=new Set,r._customPackageBundle=new Map,r._customPackagePath=new Map,r._windowPkgs=new Map,r._manualPackages=new Set,r._dirty=!0;class d{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=r.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=r.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){let s=e.filter(e=>this.getRef(e)<=0);if(s.length<=0)return e.forEach(e=>this.addRef(e)),Promise.resolve();this.addWaitRef();let i=s.map(e=>r.getBundleName(e));return this.loadBundles(i,t).then(()=>this.loadUIPackagesSequentially(s,t)).then(()=>{this.decWaitRef(),e.forEach(e=>this.addRef(e))}).catch(e=>{throw this.decWaitRef(),e})}static loadBundles(e,t){let s=e.filter(e=>"resources"!==e&&!n.assetManager.getBundle(e));if(s.length<=0)return Promise.resolve();const i=e=>{if(e>=s.length)return Promise.resolve();const o=s[e];return new Promise((e,s)=>{n.assetManager.loadBundle(o,(i,n)=>{i?(this._onLoadFail&&this._onLoadFail(t,1,o),s(new Error(`bundle【${o}】加载失败`))):e(null)})}).then(()=>i(e+1))};return i(0)}static loadUIPackagesSequentially(e,t){const s=i=>{if(i>=e.length)return Promise.resolve();const o=e[i];return this.loadSingleUIPackage(o,t).then(()=>s(i+1))};return s(0)}static loadSingleUIPackage(e,t){return new Promise((s,o)=>{let a=r.getBundleName(e),d="resources"===a?n.resources:n.assetManager.getBundle(a);i.UIPackage.loadPackage(d,r.getPackagePath(e),i=>{i?(t&&this._onLoadFail&&this._onLoadFail(t,2,e),o(new Error(`UI包【${e}】加载失败`))):s()})})}static unloadUIPackages(e){for(const t of e)0===this.subRef(t)&&this.autoRelease&&i.UIPackage.removePackage(t)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const t of e)this.getRef(t)<=0&&(i.UIPackage.removePackage(t),this.pkgRefs.delete(t))}}d.waitRef=0,d.pkgRefs=new Map,d.autoRelease=!0,d._showWaitWindow=null,d._hideWaitWindow=null,d._onLoadFail=null;class h{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this._alphaGraph.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),l.onScreenResize()}static addManualPackage(e){r.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&r.addBundleName(e,t),"ui"!==s&&r.addPackagePath(e,s)}static setUIConfig(e){a.setConfig(e)}static setPackageCallbacks(e){d.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const i=e[s.originalName];if(!i)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(i,t)}static showWindowByName(e,t){const s=r.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[s.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=r.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=h.getWindow(i);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){d.releaseUnusedRes()}}h._bgAlpha=.75,h._bgColor=new n.Color(0,0,0,0),h._alphaGraph=null,h._groups=new Map,h._groupNames=[],h._windows=new Map;class l{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,this._refCounts.get(s)+1),this._headerWindowsMap.get(s).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const i=this.getHeader(t);if(0===s)i._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),i._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),i.isShowing()&&i._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const t=r.getHeader(e.name),s=i.UIPackage.createObject(t.pkgName,e.name);return s.name=e.name,a.serializeProps(s,t.pkgName),s._init(),s._adapted(),s}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!1;const s=r.get(e),i=r.get(t),o=h.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const d=h.getWindowGroup(s.group);return d.windowNames.indexOf(e)>d.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=h.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=h.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=h.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=h.getWindow(t),o=r.get(t),n=h.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let d=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=h.getWindow(n.windowNames[e]);t&&t.isShowing()&&(d=Math.max(d,a.getChildIndex(t)))}a.setChildIndex(s,d+1)}}l._headers=new Map,l._refCounts=new Map,l._headerWindowsMap=new Map,l._headerInfos=new Map,l._cacheHeaderTopWindow=new Map;class c{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return new Promise((s,i)=>{let o=h.getTopWindow();if(h.hasWindow(e.name)){const i=h.getWindow(e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),i._toTop(),s(i)}else d.loadWindowRes(e.name).then(()=>{const i=this.createWindow(e.pkgName,e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),s(i)}).catch(t=>{i(new Error(`窗口【${e.name}】打开失败: ${t.message}`))})})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),l.showHeader(e.name),h.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,t){let s=i.UIPackage.createObject(e,t);return s.name=t,a.serializeProps(s,e),s._init(this._swallowTouch),s._adapted(),this._root.addChild(s),0===this.size&&(this._root.visible=!0),this._windowNames.push(t),h.addWindow(t,s),l.requestHeader(t,s.getHeaderInfo()),s}processWindowHideStatus(e){let t=h.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),l.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=h.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===exports.WindowType.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=h.getWindow(t);s&&s.isShowing()&&(s._hide(),l.hideHeader(t))}break}if(e.type===exports.WindowType.HideOne){let e=this._windowNames[t-1],s=h.getWindow(e);s&&s.isShowing()&&(s._hide(),l.hideHeader(e))}else{let e=this._windowNames[t-1],s=h.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),l.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===exports.WindowType.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=h.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);l.releaseHeader(e),t._close(),h.removeWindow(e)}else if(e.type===exports.WindowType.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=h.getWindow(t);if(!s)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);l.releaseHeader(t),s._close(),h.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=h.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);l.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),h.removeWindow(e),d.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?h.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=h.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);l.releaseHeader(s),i._close(),h.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function p(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}exports._uidecorator=void 0,function(e){const t=new Map,i=new Map,o=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return i},e.getHeaderMaps=function(){return o},e.uiclass=function(e,i,o,n){return function(a){const d=a;a[s.originalName]=o,t.set(d,{ctor:a,props:a[s.prop]||null,callbacks:a[s.callback]||null,controls:a[s.control]||null,transitions:a[s.transition]||null,res:{group:e,pkg:i,name:o}});let h=[];return Array.isArray(n)?h=n:"string"==typeof n&&(h=[n]),r.add(a,e,i,o,h),a}},e.uicom=function(e,t){return function(o){const n=o;return o[s.originalName]=t,i.set(n,{ctor:o,props:o[s.prop]||null,callbacks:o[s.callback]||null,controls:o[s.control]||null,transitions:o[s.transition]||null,res:{pkg:e,name:t}}),r.addComponent(o,e,t),o}},e.uiheader=function(e,t){return function(i){const n=i;return i[s.originalName]=t,o.set(n,{ctor:i,props:i[s.prop]||null,callbacks:i[s.callback]||null,controls:i[s.control]||null,transitions:i[s.transition]||null,res:{pkg:e,name:t}}),r.addHeader(i,e,t),i}},e.uiprop=function(e,t){p(e.constructor,s.prop)[t]=1},e.uicontrol=function(e,t){p(e.constructor,s.control)[t]=1},e.uitransition=function(e,t){p(e.constructor,s.transition)[t]=1},e.uiclick=function(e,t,i){p(e.constructor,s.callback)[t]=i.value}}(exports._uidecorator||(exports._uidecorator={}));const u=globalThis||window||global;u.getKunpoRegisterWindowMaps=function(){return exports._uidecorator.getWindowMaps()},u.getKunpoRegisterComponentMaps=function(){return exports._uidecorator.getComponentMaps()},u.getKunpoRegisterHeaderMaps=function(){return exports._uidecorator.getHeaderMaps()};class w extends i.GComponent{constructor(){super(...arguments),this.adapterType=exports.AdapterType.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class g{static create(e,t){const i=e[s.originalName];if(!i)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const o=new g;return o.name=i,o.userdata=t,o}}class _ extends i.GComponent{constructor(){super(...arguments),this.type=exports.WindowType.Normal,this.adapterType=exports.AdapterType.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new i.GComponent;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=h.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case exports.AdapterType.Full:this.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0);break;case exports.AdapterType.Bang:this.setSize(o.Screen.SafeWidth,o.Screen.SafeHeight,!0)}this._swallowNode.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){l.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){h.closeWindowByName(this.name)}}function m(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}"function"==typeof SuppressedError&&SuppressedError;const{ccclass:f,property:W,menu:H}=n._decorator;let N=class extends n.Component{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;o.debug(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new i.GComponent;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),i.GRoot.inst.addChild(t),h.addWindowGroup(new c(e,t,this.ignoreQuery,this.swallowTouch))}};m([W({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],N.prototype,"ignoreQuery",void 0),m([W({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],N.prototype,"swallowTouch",void 0),N=m([f("CocosWindowContainer"),H("bit/UIContainer")],N);const{ccclass:S,menu:k,property:P}=n._decorator;exports.UIModule=class extends o.Module{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&a.setConfig(this.ui_config.json),d.setAutoRelease(this.autoReleaseUIRes),h.bgAlpha=this.bgAlpha,i.GRoot.create(),o.debug("初始化 WindowContainers");const e=new i.GGraph;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*o.Screen.ScreenWidth,.5*o.Screen.ScreenHeight),e.setSize(o.Screen.ScreenWidth,o.Screen.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.GRoot.inst.addChild(e),h.setAlphaGraph(e);for(const e of this.getComponentsInChildren(N))e.init();this.node.destroyAllChildren(),o.Adapter.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){h.onScreenResize()}},m([P({type:n.JsonAsset,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],exports.UIModule.prototype,"ui_config",void 0),m([P({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],exports.UIModule.prototype,"bgAlpha",void 0),m([P({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],exports.UIModule.prototype,"autoReleaseUIRes",void 0),exports.UIModule=m([S("UIModule"),k("bit/UIModule")],exports.UIModule),exports.Header=w,exports.HeaderInfo=g,exports.Window=class extends _{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}},exports.WindowGroup=c,exports.WindowManager=h;
@@ -1 +1 @@
1
- import{Screen as e,debug as t}from"@gongxh/bit-core";import{GComponent as i,UIObjectFactory as s,GGraph as o,UIPackage as n,GRoot as r}from"fairygui-cc";import{Color as a,resources as h,assetManager as d,_decorator as l,Component as c}from"cc";var u,w,_;!function(e){e[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne"}(u||(u={})),function(e){e[e.Full=0]="Full",e[e.Bang=1]="Bang",e[e.Fixed=2]="Fixed"}(w||(w={}));class g extends i{constructor(){super(...arguments),this.adapterType=w.Full,this._refCount=0}onHide(){}onAdapted(){}_init(){this.onInit()}_adapted(){switch(this.setPosition(.5*e.ScreenWidth,.5*e.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case w.Full:this.setSize(e.ScreenWidth,e.ScreenHeight,!0);break;case w.Bang:this.setSize(e.SafeWidth,e.SafeHeight,!0)}this.onAdapted()}_show(e){var t;this.visible=!0,this.onShow(e,null===(t=e.getHeaderInfo())||void 0===t?void 0:t.userdata)}_hide(){this.visible=!1,this.onHide()}_close(){this.onClose(),this.dispose()}_addRef(){this._refCount++}_decRef(){return--this._refCount}_screenResize(){this._adapted()}}class p{static setConfig(e){this._config=e}static serializeProps(e,t,i){if(!this._config)return;const s=this._config[t];if(!s)return;const o=s[i=i||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const r=o.callbacks;this.serializationCallbacksNode(e,r);const a=o.controls;this.serializationControlsNode(e,a);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})属性(${i})赋值,请检查节点配置是否正确`);break}e[i]=n==e?null:n}}static serializationCallbacksNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s++],o=s+t[s];let n=e;for(;++s<=o;)if(n=n.getChildAt(t[s]),!n){console.warn(`无法对UI类(${e.name})的(${i})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[i],e)}}static serializationControlsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置控制器,请检查配置是否正确`);break}e[i]=n,s+=2}}static serializationTransitionsNode(e,t){const i=t.length;let s=0;for(;s<i;){const i=t[s],o=t[s+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${i})设置动画,请检查配置是否正确`);break}e[i]=n,s+=2}}}p._config={};class f{static register(){for(const{ctor:e,res:t}of _.getComponentMaps().values()){const i=`${t.pkg}/${t.name}`;this._registeredComponents.has(i)?console.debug(`自定义组件已注册,跳过 组件名:${t.name} 包名:${t.pkg}`):(console.debug(`自定义组件注册 组件名:${t.name} 包名:${t.pkg}`),this.registerComponent(e,t.pkg,t.name),this._registeredComponents.add(i))}}static dynamicRegister(e,i,s){const o=`${i}/${s}`;this._registeredComponents.has(o)?console.debug(`自定义组件已注册,跳过 组件名:${s} 包名:${i}`):(t(`自定义组件注册 组件名:${s} 包名:${i}`),this.registerComponent(e,i,s),this._registeredComponents.add(o))}static registerComponent(e,t,i){e.prototype.onConstruct=function(){p.serializeProps(this,t,i),this.onInit&&this.onInit()},s.setExtension(`ui://${t}/${i}`,e)}}f._registeredComponents=new Set;class m{static initPackageConfig(e){this._resPool.initPackageConfig(e)}static showWindow(e,t){return new Promise((i,s)=>{this._resPool.loadWindowRes(e,{complete:()=>{this.showWindowIm(e,t),i()},fail:e=>{s(e)}})})}static showWindowIm(e,t){const i=this._resPool.get(e),s=this.getWindowGroup(i.group);this._resPool.addResRef(e),s.showWindow(i,t)}static closeWindow(e){if(!this._windows.has(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);let t=this._resPool.get(e);const i=this.getWindowGroup(t.group);if(i._removeWindow(e),0==i.size){let e=this._queryGroupNames.indexOf(i.name);if(e>0&&i.name==this.getTopGroupName())do{const t=this._queryGroupNames[--e];let i=this.getWindowGroup(t);if(i.size>0){this.getWindow(i.getTopWindowName())._recover();break}}while(e>=0)}}static closeAllWindow(e=[]){let t=e.length>0;this._windows.forEach((i,s)=>{t&&e.includes(s)||this.closeWindow(s)}),t||this._windows.clear()}static getTopWindow(){for(let e=this._queryGroupNames.length;e>0;){let t=this.getWindowGroup(this._queryGroupNames[--e]);if(t.size>0)return this.getWindow(t.getTopWindowName())}return null}static getWindow(e){return this._windows.get(e)}static hasWindow(e){return this._windows.has(e)}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`UIManager.getWindowGroup: window group 【${e}】 not found`)}static getTopGroupName(){for(let e=this._queryGroupNames.length-1;e>=0;e--){let t=this._queryGroupNames[e];if(this._groups.get(t).size>0)return t}return""}static _init(e){this._resPool=e}static _addWindow(e,t){this._windows.set(e,t)}static _removeWindow(e){this.hasWindow(e)&&(this._windows.get(e)._close(),this._windows.delete(e),this._resPool.releaseWindowRes(e))}static registerUI(){for(const{ctor:e,res:i}of _.getWindowMaps().values())t(`窗口注册 窗口名:${i.name} 包名:${i.pkg} 组名:${i.group}`),this._resPool.add(e,i.group,i.pkg,i.name,i.bundle);for(const{ctor:e,res:i}of _.getHeaderMaps().values())t(`header注册 header名:${i.name} 包名:${i.pkg}`),this._resPool.addHeader(e,i.pkg,i.name,i.bundle);f.register()}static dynamicRegisterWindow(e,i,s,o,n){t(`窗口注册 窗口名:${o} 包名:${s} 组名:${i}`),this._resPool.add(e,i,s,o,n)}static dynamicRegisterHeader(e,i,s,o){t(`header注册 header名:${s} 包名:${i}`),this._resPool.addHeader(e,i,s,o)}static _addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`UIManager._addWindowGroup: window group 【${e.name}】 already exists`);this._groups.set(e.name,e),!e.isIgnore&&this._queryGroupNames.push(e.name)}static _screenResize(){this._windows.forEach(e=>{e.screenResize()}),this._groups.forEach(e=>{e._screenResize()})}static _getResPool(){return this._resPool}}m._groups=new Map,m._queryGroupNames=[],m._windows=new Map,function(e){const t="__uipropmeta__",i="__uicbmeta__",s="__uicontrolmeta__",o="__uitransitionmeta__",n=new Map;function r(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}e.getWindowMaps=function(){return n},e.uiclass=function(e,r,a,h){return function(l){const c=l;return n.set(c,{ctor:l,props:l[t]||null,callbacks:l[i]||null,controls:l[s]||null,transitions:l[o]||null,res:{group:e,pkg:r,name:a,bundle:h||""}}),d&&m.dynamicRegisterWindow(l,e,r,a,h||""),l}};let a=new Map;e.getComponentMaps=function(){return a},e.uicom=function(e,n){return function(r){const h=r;return a.set(h,{ctor:r,props:r[t]||null,callbacks:r[i]||null,controls:r[s]||null,transitions:r[o]||null,res:{pkg:e,name:n}}),d&&f.dynamicRegister(r,e,n),r}};let h=new Map;e.getHeaderMaps=function(){return h},e.uiheader=function(e,n,r){return function(a){const l=a;return h.set(l,{ctor:a,props:a[t]||null,callbacks:a[i]||null,controls:a[s]||null,transitions:a[o]||null,res:{pkg:e,name:n,bundle:r||""}}),d&&m.dynamicRegisterHeader(a,e,n,r||""),a}},e.uiprop=function(e,i){r(e.constructor,t)[i]=1},e.uicontrol=function(e,t){r(e.constructor,s)[t]=1},e.uitransition=function(e,t){r(e.constructor,o)[t]=1},e.uiclick=function(e,t,s){r(e.constructor,i)[t]=s.value};let d=!1;e.setRegisterFinish=function(){d=!0}}(_||(_={}));const W=globalThis||window||global;W.getKunpoRegisterWindowMaps=function(){return _.getWindowMaps()},W.getKunpoRegisterComponentMaps=function(){return _.getComponentMaps()},W.getKunpoRegisterHeaderMaps=function(){return _.getHeaderMaps()};class k extends i{constructor(){super(...arguments),this.type=u.Normal,this.adapterType=w.Full,this._header=null,this._isCover=!1,this._swallowComponent=null}_init(t,s){if(t){let s=new i;s.name="swallow",s.setSize(e.ScreenWidth,e.ScreenHeight,!0),s.setPivot(.5,.5,!0),s.setPosition(.5*this.width,.5*this.height),this.addChild(s),s.parent.setChildIndex(s,0),s.onClick(this.onEmptyAreaClick,this),s.opaque=t,this._swallowComponent=s}this.opaque=t,this.bgAlpha=s,this.onInit()}_adapted(){var t,i;switch(this.setPosition(.5*e.ScreenWidth,.5*e.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case w.Full:this.setSize(e.ScreenWidth,e.ScreenHeight,!0);break;case w.Bang:this.setSize(e.SafeWidth,e.SafeHeight,!0)}null===(t=this._swallowComponent)||void 0===t||t.setSize(e.ScreenWidth,e.ScreenHeight,!0),null===(i=this._swallowComponent)||void 0===i||i.setPosition(.5*this.width,.5*+this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_cover(){this._isCover=!0,this.onCover()}_recover(){this._isCover=!1,this.onRecover()}_setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isCover(){return this._isCover}screenResize(){this._adapted()}getHeaderInfo(){return null}getHeader(){return this._header}_setHeader(e){this._header=e}}class P extends k{onAdapted(){}onClose(){}onShow(e){}onHide(){}onShowFromHide(){}onCover(){}onRecover(){}onEmptyAreaClick(){}}class v{get name(){return this._name}get size(){return this._windowNames.length}get isIgnore(){return this._ignoreQuery}constructor(e,t,i,s,n){this._name="",this._ignoreQuery=!1,this._swallowTouch=!1,this._windowNames=[],this._headers=new Map,this._bgAlpha=0,this._color=new a(0,0,0,255),this._name=e,this._root=t,this._ignoreQuery=i,this._swallowTouch=s,this._bgAlpha=n;const r=new o;r.touchable=!1,r.name="bgAlpha",r.setPosition(.5*t.width,.5*t.height),r.setSize(t.width,t.height,!0),r.setPivot(.5,.5,!0),t.addChild(r),this._alphaGraph=r}_createWindow(e,t){let i=n.createObject(e,t);return i.name=t,p.serializeProps(i,e),i._init(this._swallowTouch,this._bgAlpha),i._adapted(),this._createHeader(i),this._addWindow(i),i}_addWindow(e){this._root.addChild(e),m._addWindow(e.name,e)}showWindow(e,t){let i=e.name,s=m.getWindow(i);s||(s=this._createWindow(e.pkg,i),this._processWindowCloseStatus(s),this._windowNames.push(i)),s._show(t),this._moveWindowToTop(i),this._processHeaderStatus(),this._root.visible=!0}_removeWindow(e){let t=this._windowNames.lastIndexOf(e),i=this.size-1;if(t<0)return void console.warn(`窗口组${this._name}中未找到窗口${e} 删除失败`);let s=m.getWindow(e).getHeader();if(s&&this._removeHeader(s),this._windowNames.splice(t,1),m._removeWindow(e),this._processWindowHideStatus(this.size-1,!0),0==this.size)this._root.visible=!1;else if(i==t&&t>0){let e=this.getTopWindowName(),t=m.getWindow(e);this._adjustAlphaGraph(t),t._setDepth(this._root.numChildren-1)}this._processHeaderStatus()}_moveWindowToTop(e){let t=!1;if(0==this.size)return console.warn(`WindowGroup.moveWindowToTop: window group 【${this._name}】 is empty`),!1;if(this._windowNames[this.size-1]==e);else{const i=this._windowNames.indexOf(e);if(-1==i)return console.warn(`WindowGroup.moveWindowToTop: window 【${e}】 not found in window group 【${this._name}】`),!1;i<this._windowNames.length-1&&(this._windowNames.splice(i,1),this._windowNames.push(e),t=!0)}let i=m.getWindow(e);return this._adjustAlphaGraph(i),i._setDepth(this._root.numChildren-1),this._processWindowHideStatus(this.size-1,t),!0}_processWindowHideStatus(e,t=!0){if(e<0)return;let i=this._windowNames[e],s=m.getWindow(i);if(e!=this.size-1||s.isShowing()||s._showFromHide(),0==e)return;let o=s.type;if(o!=u.HideAll){if(o==u.HideOne){let t=this._windowNames[e-1],i=m.getWindow(t);i.isShowing()&&i._hide()}else{let t=this._windowNames[e-1],i=m.getWindow(t);!i.isShowing()&&i._showFromHide()}t&&this._processWindowHideStatus(e-1,t)}else for(let t=e-1;t>=0;--t){let e=this._windowNames[t];const i=m.getWindow(e);i.isShowing()&&i._hide()}}_processWindowCloseStatus(e){if(e.type==u.CloseOne){let e=this.size;for(;e>0;){let e=this._windowNames.pop(),t=m.getWindow(e).getHeader();t&&this._removeHeader(t),m._removeWindow(e);break}}else if(e.type==u.CloseAll){for(let e=this.size;e>0;){let t=this._windowNames[--e],i=m.getWindow(t).getHeader();i&&this._removeHeader(i),m._removeWindow(t)}this._windowNames.length=0}}_processHeaderStatus(){let e=null,t=null,i=this.size-1;for(let s=this.size-1;s>=0;--s){let o=this._windowNames[s],n=m.getWindow(o);if(n.isShowing()&&n.getHeader()){t=n,e=n.getHeader(),i=s;break}}this._headers.forEach((i,s)=>{this._root.setChildIndex(i,0),!e&&i.visible?i._hide():e&&(e.name!=s||i.visible?e.name!=s&&i.visible&&i._hide():i._show(t))}),e&&(i==this.size-1?this._root.setChildIndex(e,this._root.numChildren-1):this._root.setChildIndex(e,this._root.numChildren-this.size+i-1))}_adjustAlphaGraph(e){this._root.setChildIndex(this._alphaGraph,this._root.numChildren-1),this._color.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._color,this._color)}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindowName(){return this.size>0?this._windowNames[this.size-1]:(console.warn(`WindowGroup.getTopWindowName: window group 【${this._name}】 is empty`),"")}_createHeader(e){let t=e.getHeaderInfo();if(!t)return;let i=t.name,s=this._getHeader(i);if(s)e._setHeader(s),s._addRef();else{let{pkg:t}=m._getResPool().getHeader(i),s=n.createObject(t,i);s.name=i,s.opaque=!1,e._setHeader(s),s.visible=!1,p.serializeProps(s,t),s._init(),s._adapted(),this._root.addChild(s),s._addRef(),this._headers.set(s.name,s)}}_removeHeader(e){if(this._headers.has(e.name)){e._decRef()<=0&&(this._headers.delete(e.name),e._close())}}_getHeader(e){return this._headers.get(e)}_screenResize(){this._headers.forEach(e=>{e._screenResize()}),this._alphaGraph.setPosition(.5*e.ScreenWidth,.5*e.ScreenHeight),this._alphaGraph.setSize(e.ScreenWidth,e.ScreenHeight,!0),this._alphaGraph.setPivot(.5,.5,!0)}closeAllWindow(){for(;this.size>0;){let e=this.getTopWindowName();m.closeWindow(e)}}}class C{static create(e,t){const i=new C;return i.name=e,i.userdata=t,i}}function H(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,i,r):o(t,i))||r);return n>3&&r&&Object.defineProperty(t,i,r),r}"function"==typeof SuppressedError&&SuppressedError;class R{constructor(){this._windowInfos=new Map,this._headerInfos=new Map,this._pkgBundles=new Map,this._isInit=!1,this._windowPkgs=new Map,this._pkgRefs={},this._uiPaths={},this._manualPackages=new Set,this._imReleasePackages=new Set,this._showWaitWindow=null,this._hideWaitWindow=null,this._fail=null,this._waitRef=0}add(e,t,i,o,n){this.has(o)||(this._windowInfos.set(o,{ctor:e,group:t,pkg:i,name:o,bundle:n}),this._pkgBundles.set(i,n||"resources"),this.addWindowPkg(o,i),s.setExtension(`ui://${i}/${o}`,e))}has(e){return this._windowInfos.has(e)}get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}addHeader(e,t,i,o){this.hasHeader(i)||(this._headerInfos.set(i,{ctor:e,pkg:t,bundle:o}),this._pkgBundles.set(t,o||"resources"),s.setExtension(`ui://${t}/${i}`,e))}hasHeader(e){return this._headerInfos.has(e)}getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}initPackageConfig(e){var t,i;if(!e||!e.config)return;if(this._isInit)throw new Error("资源配置已初始化,请勿重复设置");this._isInit=!0,this._showWaitWindow=null==e?void 0:e.showWaitWindow,this._hideWaitWindow=null==e?void 0:e.hideWaitWindow,this._fail=null==e?void 0:e.fail,this._uiPaths=(null===(t=e.config)||void 0===t?void 0:t.bundlePaths)||{},this._uiPaths.resources=(null===(i=e.config)||void 0===i?void 0:i.uiPath)||"";for(const e in this._uiPaths)""==this._uiPaths[e]||this._uiPaths[e].endsWith("/")||(this._uiPaths[e]+="/");this._manualPackages=new Set(e.config.manualPackages||[]),this._imReleasePackages=new Set(e.config.imReleasePackages||[]);let s=e.config.linkPackages||{};for(const e in s){let t=s[e];for(const i of t||[])this.addWindowPkg(e,i)}this._windowPkgs.forEach((e,t)=>{for(let t=e.length-1;t>=0;t--)this._manualPackages.has(e[t])&&e.splice(t,1);e.length<=0&&this._windowPkgs.delete(t)})}addWindowPkg(e,t){this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}loadWindowRes(e,t){var i;if(!this._isInit)return console.warn("UI包信息未配置 将手动管理所有UI包资源的加载,如果需要配置,请使用 【UIManager.initPackageConfig】接口"),void t.complete();this.hasWindowPkg(e)?(this._waitRef++<=0&&(null===(i=this._showWaitWindow)||void 0===i||i.call(this)),this.loadPackages({pkgs:this.getWindowPkgs(e),complete:()=>{var e;--this._waitRef<=0&&(t.complete(),null===(e=this._hideWaitWindow)||void 0===e||e.call(this))},fail:i=>{var s,o;console.warn(`界面${e}打开失败`),t.fail(i),null===(s=this._fail)||void 0===s||s.call(this,e,"UI包加载失败",i),--this._waitRef<=0&&(null===(o=this._hideWaitWindow)||void 0===o||o.call(this))}})):t.complete()}addResRef(e){if(!this._isInit)return;if(!this.hasWindowPkg(e))return;let t=this.getWindowPkgs(e);for(const e of t)this.addRef(e)}releaseWindowRes(e){if(!this._isInit||!this.hasWindowPkg(e))return;let t=this.getWindowPkgs(e);for(const e of t)this.decRef(e)}loadPackages(e){let t=e.pkgs.filter(e=>this.getRef(e)<=0),i=[],s=[],o=t.length;if(o<=0)e.complete();else for(const r of t){let t=this.getPkgBundle(r),a="resources"===t?h:d.getBundle(t);if(!a)throw new Error(`UI包【${r}】所在的bundle【${t}】未加载`);n.loadPackage(a,this.getPkgPath(r),t=>{o--,t?s.push(r):i.push(r),o>0||(s.length>0?e.fail(s):e.complete())})}}getPkgBundle(e){return this._pkgBundles.get(e)||"resources"}getPkgPath(e){let t=this._pkgBundles.get(e);return this._uiPaths[t]+e}getWindowPkgs(e){return this._windowPkgs.has(e)?this._windowPkgs.get(e):[]}hasWindowPkg(e){return this._windowPkgs.has(e)}getRef(e){return this._pkgRefs[e]?this._pkgRefs[e]:0}addRef(e){this._pkgRefs[e]=this.getRef(e)+1}decRef(e){this._pkgRefs[e]=this.getRef(e)-1,this.getRef(e)<=0&&(delete this._pkgRefs[e],this._imReleasePackages.has(e)&&n.removePackage(e))}}const{ccclass:b,property:S,menu:I}=l;let $=class extends c{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1,this.bgAlpha=.75}init(){let s=this.node.name;t(`\tUIContainer name:${s} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const o=new i;o.name=s,o.node.name=s,o.visible=!1,o.opaque=this.swallowTouch,o.setSize(e.ScreenWidth,e.ScreenHeight,!0),r.inst.addChild(o),m._addWindowGroup(new v(s,o,this.ignoreQuery,this.swallowTouch,this.bgAlpha))}};H([S({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],$.prototype,"ignoreQuery",void 0),H([S({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],$.prototype,"swallowTouch",void 0),H([S({displayName:"底部遮罩透明度",tooltip:"底部半透明遮罩的默认透明度",min:0,max:1,step:.01})],$.prototype,"bgAlpha",void 0),$=H([b("CocosWindowContainer"),I("kunpo/UI/UIContainer")],$);const{ccclass:y,menu:N,property:z}=l;let G=class extends c{constructor(){super(...arguments),this.moduleName="UI模块"}init(){m._init(new R),r.create(),t("初始化 WindowContainers");for(const e of this.node.children){const t=e.getComponent($);null==t||t.init()}this.node.destroyAllChildren(),m.registerUI(),_.setRegisterFinish(),this.onInit()}onInit(){t("UIModule init complete")}};G=H([y("UIModule"),N("kunpo/UIModule")],G);export{w as AdapterType,g as UIHeader,m as UIManager,G as UIModule,P as Window,v as WindowGroup,C as WindowHeaderInfo,u as WindowType,_ as _uidecorator};
1
+ import{UIObjectFactory as e,UIPackage as t,GComponent as s,GRoot as i,GGraph as o}from"fairygui-cc";import{debug as n,Screen as a,Module as r,Adapter as h}from"@gongxh/bit-core";import{assetManager as d,resources as l,Color as c,_decorator as u,Component as w,JsonAsset as p}from"cc";var g,_,m,f;!function(e){e[e.Normal=0]="Normal",e[e.CloseAll=1]="CloseAll",e[e.CloseOne=2]="CloseOne",e[e.HideAll=4]="HideAll",e[e.HideOne=8]="HideOne"}(g||(g={})),function(e){e[e.Full=0]="Full",e[e.Bang=1]="Bang",e[e.Fixed=2]="Fixed"}(_||(_={})),function(e){e.prop="__uipropmeta__",e.callback="__uicbmeta__",e.control="__uicontrolmeta__",e.transition="__uitransitionmeta__",e.originalName="__UI_ORIGINAL_NAME__"}(m||(m={}));class W{static setConfig(e){this._config=e}static serializeProps(e,t,s){if(!this._config)return;const i=this._config[t];if(!i)return;const o=i[s=s||e.name];if(!o)return;const n=o.props;this.serializationPropsNode(e,n);const a=o.callbacks;this.serializationCallbacksNode(e,a);const r=o.controls;this.serializationControlsNode(e,r);const h=o.transitions;this.serializationTransitionsNode(e,h)}static serializationPropsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})属性(${s})赋值,请检查节点配置是否正确`);break}e[s]=n==e?null:n}}static serializationCallbacksNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i++],o=i+t[i];let n=e;for(;++i<=o;)if(n=n.getChildAt(t[i]),!n){console.warn(`无法对UI类(${e.name})的(${s})设置回调,请检查节点配置是否正确`);break}n!=e&&n.onClick(e[s],e)}}static serializationControlsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getController(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置控制器,请检查配置是否正确`);break}e[s]=n,i+=2}}static serializationTransitionsNode(e,t){const s=t.length;let i=0;for(;i<s;){const s=t[i],o=t[i+1],n=e.getTransition(o);if(!n){console.warn(`无法对UI类(${e.name})的(${s})设置动画,请检查配置是否正确`);break}e[s]=n,i+=2}}}W._config={};class H{static add(t,s,i,o,a){if(this.has(o))console.warn(`窗口【${o}】已注册,跳过,请检查是否重复注册`);else if(n(`窗口注册 窗口名:${o} 包名:${i} 组名:${s}`),this._windowInfos.set(o,{ctor:t,group:s,pkgName:i,name:o}),e.setExtension(`ui://${i}/${o}`,t),this.addWindowPkg(o,i),a.length>0)for(const e of a)this.addWindowPkg(o,e)}static addHeader(t,s,i){this.hasHeader(i)?console.warn(`header【${i}】已注册,跳过,请检查是否重复注册`):(n(`header注册 header名:${i} 包名:${s}`),this._headerInfos.set(i,{ctor:t,pkgName:s}),e.setExtension(`ui://${s}/${i}`,t))}static addComponent(e,t,s){const i=`${t}/${s}`;this._customComponents.has(i)?console.debug(`自定义组件【${s}】已注册,跳过,请检查是否重复注册`):(n(`自定义组件注册 组件名:${s} 包名:${t}`),this._customComponents.add(i),this.registerComponent(e,t,s))}static has(e){return this._windowInfos.has(e)}static get(e){if(!this.has(e))throw new Error(`窗口【${e}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this._windowInfos.get(e)}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){if(!this.hasHeader(e))throw new Error(`窗口header【${e}】未注册,请使用 _uidecorator.uiheader 注册窗口header`);return this._headerInfos.get(e)}static addBundleName(e,t){this._customPackageBundle.has(e)?console.warn(`UI包【${e}】已设置过包名`):this._customPackageBundle.set(e,t)}static getBundleName(e){return this._customPackageBundle.get(e)||"resources"}static addPackagePath(e,t){this._customPackagePath.has(e)?console.warn(`UI包【${e}】已设置过自定义路径`):this._customPackagePath.set(e,t)}static getPackagePath(e){return`${this._customPackagePath.get(e)||"ui"}/${e}`}static addWindowPkg(e,t){this._dirty=!0,this._windowPkgs.has(e)?this._windowPkgs.get(e).push(t):this._windowPkgs.set(e,[t])}static getWindowPkg(e){return this._dirty&&(this.refreshWindowPackages(),this._dirty=!1),this._windowPkgs.get(e)||[]}static addManualPackage(e){this._dirty=!0,this._manualPackages.add(e)}static registerComponent(t,s,i){t.prototype.onConstruct=function(){W.serializeProps(this,s,i),this.onInit&&this.onInit()},e.setExtension(`ui://${s}/${i}`,t)}static refreshWindowPackages(){for(const e of this._windowPkgs.values()){for(let t=e.length-1;t>=0;t--){const s=e[t];this._manualPackages.has(s)&&e.splice(t,1)}}}}H._windowInfos=new Map,H._headerInfos=new Map,H._customComponents=new Set,H._customPackageBundle=new Map,H._customPackagePath=new Map,H._windowPkgs=new Map,H._manualPackages=new Set,H._dirty=!0;class N{static setCallbacks(e){this._showWaitWindow=e.showWaitWindow,this._hideWaitWindow=e.hideWaitWindow,this._onLoadFail=e.fail}static setAutoRelease(e){this.autoRelease=e}static addWaitRef(){var e;0===this.waitRef++&&(null===(e=this._showWaitWindow)||void 0===e||e.call(this))}static decWaitRef(){var e;0===--this.waitRef&&(null===(e=this._hideWaitWindow)||void 0===e||e.call(this))}static getRef(e){return this.pkgRefs.get(e)||0}static addRef(e){this.pkgRefs.set(e,this.getRef(e)+1)}static subRef(e){let t=this.getRef(e)-1;return this.pkgRefs.set(e,t),t}static loadWindowRes(e){let t=H.getWindowPkg(e);return t.length<=0?Promise.resolve():this.loadUIPackages(t,e)}static unloadWindowRes(e){let t=H.getWindowPkg(e);t.length<=0||this.unloadUIPackages(t)}static loadUIPackages(e,t){let s=e.filter(e=>this.getRef(e)<=0);if(s.length<=0)return e.forEach(e=>this.addRef(e)),Promise.resolve();this.addWaitRef();let i=s.map(e=>H.getBundleName(e));return this.loadBundles(i,t).then(()=>this.loadUIPackagesSequentially(s,t)).then(()=>{this.decWaitRef(),e.forEach(e=>this.addRef(e))}).catch(e=>{throw this.decWaitRef(),e})}static loadBundles(e,t){let s=e.filter(e=>"resources"!==e&&!d.getBundle(e));if(s.length<=0)return Promise.resolve();const i=e=>{if(e>=s.length)return Promise.resolve();const o=s[e];return new Promise((e,s)=>{d.loadBundle(o,(i,n)=>{i?(this._onLoadFail&&this._onLoadFail(t,1,o),s(new Error(`bundle【${o}】加载失败`))):e(null)})}).then(()=>i(e+1))};return i(0)}static loadUIPackagesSequentially(e,t){const s=i=>{if(i>=e.length)return Promise.resolve();const o=e[i];return this.loadSingleUIPackage(o,t).then(()=>s(i+1))};return s(0)}static loadSingleUIPackage(e,s){return new Promise((i,o)=>{let n=H.getBundleName(e),a="resources"===n?l:d.getBundle(n);t.loadPackage(a,H.getPackagePath(e),t=>{t?(s&&this._onLoadFail&&this._onLoadFail(s,2,e),o(new Error(`UI包【${e}】加载失败`))):i()})})}static unloadUIPackages(e){for(const s of e)0===this.subRef(s)&&this.autoRelease&&t.removePackage(s)}static releaseUnusedRes(){let e=Array.from(this.pkgRefs.keys());for(const s of e)this.getRef(s)<=0&&(t.removePackage(s),this.pkgRefs.delete(s))}}N.waitRef=0,N.pkgRefs=new Map,N.autoRelease=!0,N._showWaitWindow=null,N._hideWaitWindow=null,N._onLoadFail=null;class k{static get bgAlpha(){return this._bgAlpha}static set bgAlpha(e){this._bgAlpha=e}static onScreenResize(){this._alphaGraph&&(this._alphaGraph.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this._alphaGraph.setSize(a.ScreenWidth,a.ScreenHeight,!0)),this._windows.forEach(e=>{e._adapted()}),P.onScreenResize()}static addManualPackage(e){H.addManualPackage(e)}static setPackageInfo(e,t="resources",s="ui"){"resources"!==t&&H.addBundleName(e,t),"ui"!==s&&H.addPackagePath(e,s)}static setUIConfig(e){W.setConfig(e)}static setPackageCallbacks(e){N.setCallbacks(e)}static addWindowGroup(e){if(this._groups.has(e.name))throw new Error(`窗口组【${e.name}】已存在`);this._groups.set(e.name,e),this._groupNames.push(e.name)}static setAlphaGraph(e){this._alphaGraph=e}static showWindow(e,t){const s=e[m.originalName];if(!s)throw new Error(`窗口【${e.name}】未注册,请使用 _uidecorator.uiclass 注册窗口`);return this.showWindowByName(s,t)}static showWindowByName(e,t){const s=H.get(e);return this.getWindowGroup(s.group).showWindow(s,t)}static closeWindow(e){const t=e[m.originalName];this.closeWindowByName(t)}static closeWindowByName(e){if(!this.hasWindow(e))return void console.warn(`窗口不存在 ${e} 不需要关闭`);const t=H.get(e);this.getWindowGroup(t.group).removeWindow(e),this.adjustAlphaGraph();let s=this.getTopWindow();s&&!s.isTop()&&s._toTop()}static hasWindow(e){return this._windows.has(e)}static addWindow(e,t){this._windows.set(e,t)}static removeWindow(e){this._windows.delete(e)}static getWindow(e){return this._windows.get(e)}static getTopWindow(e=!0){const t=this._groupNames;for(let s=t.length-1;s>=0;s--){const i=this.getWindowGroup(t[s]);if((!i.isIgnore||e)&&0!==i.size)return i.getTopWindow()}return null}static getGroupNames(){return this._groupNames}static getWindowGroup(e){if(this._groups.has(e))return this._groups.get(e);throw new Error(`窗口组【${e}】不存在`)}static closeAllWindow(e=[]){for(let t=this._groupNames.length-1;t>=0;t--){this.getWindowGroup(this._groupNames[t]).closeAllWindow(e)}let t=this.getTopWindow();t&&!t.isTop()&&t._toTop()}static adjustAlphaGraph(){let e=null;for(let t=this._groupNames.length-1;t>=0;t--){const s=this._groups.get(this._groupNames[t]);if(0!==s.size){for(let t=s.windowNames.length-1;t>=0;t--){const i=s.windowNames[t],o=k.getWindow(i);if(o.bgAlpha>0){e=o;break}}if(e)break}}if(e){const t=e.parent,s=t.getChildIndex(e);let i=0;this._alphaGraph.parent!==t?(this._alphaGraph.removeFromParent(),t.addChild(this._alphaGraph),i=t.numChildren-1):i=t.getChildIndex(this._alphaGraph);let o=i>=s?s:s-1;t.setChildIndex(this._alphaGraph,o),this._alphaGraph.visible=!0,this._bgColor.a=255*e.bgAlpha,this._alphaGraph.clearGraphics(),this._alphaGraph.drawRect(0,this._bgColor,this._bgColor)}else this._alphaGraph.visible=!1}static releaseUnusedRes(){N.releaseUnusedRes()}}k._bgAlpha=.75,k._bgColor=new c(0,0,0,0),k._alphaGraph=null,k._groups=new Map,k._groupNames=[],k._windows=new Map;class P{static onScreenResize(){for(const e of this._headers.values())e._adapted()}static requestHeader(e,t){if(!t)return;this._headerInfos.set(e,t);const s=t.name;if(!this._headers.has(s)){const e=this.createHeader(t);this._headers.set(s,e),this._refCounts.set(s,0),this._headerWindowsMap.set(s,new Set)}this._refCounts.set(s,this._refCounts.get(s)+1),this._headerWindowsMap.get(s).add(e)}static showHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);this.updateTopWindow(t,e,!0);this._cacheHeaderTopWindow.get(t)===e&&s._show(this.getHeaderUserData(e))}static hideHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this.getHeader(t);if(this.updateTopWindow(t,e,!1),this._cacheHeaderTopWindow.has(t)){const e=this._cacheHeaderTopWindow.get(t);s._show(this.getHeaderUserData(e))}else s.isShowing()&&s._hide()}static releaseHeader(e){if(!this.hasHeader(e))return;const t=this.getHeaderName(e),s=this._refCounts.get(t)-1;this._headerWindowsMap.get(t).delete(e),this._headerInfos.delete(e);const i=this.getHeader(t);if(0===s)i._close(),this._headers.delete(t),this._refCounts.delete(t),this._headerWindowsMap.delete(t),this._cacheHeaderTopWindow.delete(t);else{this._refCounts.set(t,s);const o=this.findTopWindowForHeader(t,e);o?(this._cacheHeaderTopWindow.set(t,o),this.adjustHeaderPosition(t,o),i._show(this.getHeaderUserData(o))):(this._cacheHeaderTopWindow.delete(t),i.isShowing()&&i._hide())}}static getHeaderByWindow(e){if(!this.hasHeader(e))return null;const t=this.getHeaderName(e);return this._headers.get(t)||null}static refreshWindowHeader(e,t){const s=this.getHeaderName(e),i=null==t?void 0:t.name;if(s!==i)s&&this.releaseHeader(e),t&&(this.requestHeader(e,t),this.showHeader(e));else if(t){this._headerInfos.set(e,t);if(this._cacheHeaderTopWindow.get(i)===e){this.getHeader(i)._show(t.userdata)}}}static createHeader(e){const s=H.getHeader(e.name),i=t.createObject(s.pkgName,e.name);return i.name=e.name,W.serializeProps(i,s.pkgName),i._init(),i._adapted(),i}static getHeaderUserData(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.userdata}static getHeaderName(e){var t;return null===(t=this._headerInfos.get(e))||void 0===t?void 0:t.name}static hasHeader(e){return this._headerInfos.has(e)}static getHeader(e){return this._headers.get(e)}static updateTopWindow(e,t,s){const i=this._cacheHeaderTopWindow.get(e);if(s){if(!i||this.isWindowAbove(t,i))return this._cacheHeaderTopWindow.set(e,t),void this.adjustHeaderPosition(e,t)}else if(i===t){const s=this.findTopWindowForHeader(e,t);if(s)this._cacheHeaderTopWindow.set(e,s),this.adjustHeaderPosition(e,s);else{this._cacheHeaderTopWindow.delete(e);const t=this.getHeader(e);t&&t.isShowing()&&t._hide()}}}static isWindowAbove(e,t){if(e===t)return!1;const s=H.get(e),i=H.get(t),o=k.getGroupNames(),n=o.indexOf(s.group),a=o.indexOf(i.group);if(n!==a)return n>a;const r=k.getWindowGroup(s.group);return r.windowNames.indexOf(e)>r.windowNames.indexOf(t)}static findTopWindowForHeader(e,t){const s=this._headerWindowsMap.get(e);if(!s||0===s.size)return null;const i=k.getGroupNames();for(let e=i.length-1;e>=0;e--){const o=k.getWindowGroup(i[e]);for(let e=o.windowNames.length-1;e>=0;e--){const i=o.windowNames[e];if(i===t)continue;if(!s.has(i))continue;const n=k.getWindow(i);if(n&&n.isShowing())return i}}return null}static adjustHeaderPosition(e,t){const s=this._headers.get(e),i=k.getWindow(t),o=H.get(t),n=k.getWindowGroup(o.group),a=n.root;s.parent!==a&&(s.removeFromParent(),a.addChild(s));let r=a.getChildIndex(i);for(let e=n.windowNames.length-1;e>=0;e--){const t=k.getWindow(n.windowNames[e]);t&&t.isShowing()&&(r=Math.max(r,a.getChildIndex(t)))}a.setChildIndex(s,r+1)}}P._headers=new Map,P._refCounts=new Map,P._headerWindowsMap=new Map,P._headerInfos=new Map,P._cacheHeaderTopWindow=new Map;class b{get name(){return this._name}get root(){return this._root}get size(){return this._windowNames.length}get windowNames(){return this._windowNames}get isIgnore(){return this._ignore}constructor(e,t,s,i){this._name="",this._ignore=!1,this._swallowTouch=!1,this._windowNames=[],this._name=e,this._root=t,this._ignore=s,this._swallowTouch=i,this._windowNames=[]}showWindow(e,t){return new Promise((s,i)=>{let o=k.getTopWindow();if(k.hasWindow(e.name)){const i=k.getWindow(e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),i._toTop(),s(i)}else N.loadWindowRes(e.name).then(()=>{const i=this.createWindow(e.pkgName,e.name);this.showAdjustment(i,t),o&&o.name!==i.name&&o._toBottom(),s(i)}).catch(t=>{i(new Error(`窗口【${e.name}】打开失败: ${t.message}`))})})}showAdjustment(e,t){this.moveWindowToTop(e),e._show(t),P.showHeader(e.name),k.adjustAlphaGraph()}moveWindowToTop(e){if(e.name!==this._windowNames[this.size-1]){const t=this._windowNames.indexOf(e.name);if(t<0)return void console.error(`[BUG] 窗口【${e.name}】不在数组中,数据结构已损坏`);this._windowNames.splice(t,1),this._windowNames.push(e.name)}this._processWindowCloseStatus(e),e.setDepth(this._root.numChildren-1),this.processWindowHideStatus(this.size-1)}createWindow(e,s){let i=t.createObject(e,s);return i.name=s,W.serializeProps(i,e),i._init(this._swallowTouch),i._adapted(),this._root.addChild(i),0===this.size&&(this._root.visible=!0),this._windowNames.push(s),k.addWindow(s,i),P.requestHeader(s,i.getHeaderInfo()),i}processWindowHideStatus(e){let t=k.getWindow(this._windowNames[e]);if(t&&e==this.size-1&&!t.isShowing()&&(t._showFromHide(),P.showHeader(t.name)),!(e<=0))for(let t=e;t>0;t--){let e=k.getWindow(this._windowNames[t]);if(!e)return void console.error(`[BUG] 窗口【${this._windowNames[t]}】不存在,数据结构已损坏`);if(e.type===g.HideAll){for(let e=t-1;e>=0;e--){let t=this._windowNames[e];const s=k.getWindow(t);s&&s.isShowing()&&(s._hide(),P.hideHeader(t))}break}if(e.type===g.HideOne){let e=this._windowNames[t-1],s=k.getWindow(e);s&&s.isShowing()&&(s._hide(),P.hideHeader(e))}else{let e=this._windowNames[t-1],s=k.getWindow(e);s&&!s.isShowing()&&(s._showFromHide(),P.showHeader(e))}}}_processWindowCloseStatus(e){if(e.type===g.CloseOne){if(this.size<=1)return;const e=this._windowNames[this.size-2];this._windowNames.splice(this.size-2,1);const t=k.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);P.releaseHeader(e),t._close(),k.removeWindow(e)}else if(e.type===g.CloseAll){for(let e=this.size-2;e>=0;e--){const t=this._windowNames[e],s=k.getWindow(t);if(!s)return void console.error(`[BUG] 窗口【${t}】不存在,数据结构已损坏`);P.releaseHeader(t),s._close(),k.removeWindow(t)}this._windowNames.splice(0,this.size-1)}}removeWindow(e){let t=k.getWindow(e);if(!t)return void console.error(`[BUG] 窗口【${e}】不存在,数据结构已损坏`);P.releaseHeader(e),t._close();let s=this._windowNames.lastIndexOf(e);s<0?console.error(`[BUG] 窗口【${e}】不在数组中,数据结构已损坏`):(this._windowNames.splice(s,1),k.removeWindow(e),N.unloadWindowRes(e),0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1))}hasWindow(e){return this._windowNames.indexOf(e)>=0}getTopWindow(){return this.size>0?k.getWindow(this._windowNames[this.size-1]):(console.warn(`窗口组【${this._name}】中不存在窗口`),null)}closeAllWindow(e=[]){for(let t=this.size-1;t>=0;t--){let s=this._windowNames[t];if(e.some(e=>e.name===s))continue;const i=k.getWindow(s);if(!i)return void console.error(`[BUG] 窗口【${s}】不存在,数据结构已损坏`);P.releaseHeader(s),i._close(),k.removeWindow(s),this._windowNames.splice(t,1)}0==this.size?this._root.visible=!1:this.processWindowHideStatus(this.size-1)}}function C(e,t){return e.hasOwnProperty(t)?e[t]:e[t]=Object.assign({},e[t])}!function(e){const t=new Map,s=new Map,i=new Map;e.getWindowMaps=function(){return t},e.getComponentMaps=function(){return s},e.getHeaderMaps=function(){return i},e.uiclass=function(e,s,i,o){return function(n){const a=n;n[m.originalName]=i,t.set(a,{ctor:n,props:n[m.prop]||null,callbacks:n[m.callback]||null,controls:n[m.control]||null,transitions:n[m.transition]||null,res:{group:e,pkg:s,name:i}});let r=[];return Array.isArray(o)?r=o:"string"==typeof o&&(r=[o]),H.add(n,e,s,i,r),n}},e.uicom=function(e,t){return function(i){const o=i;return i[m.originalName]=t,s.set(o,{ctor:i,props:i[m.prop]||null,callbacks:i[m.callback]||null,controls:i[m.control]||null,transitions:i[m.transition]||null,res:{pkg:e,name:t}}),H.addComponent(i,e,t),i}},e.uiheader=function(e,t){return function(s){const o=s;return s[m.originalName]=t,i.set(o,{ctor:s,props:s[m.prop]||null,callbacks:s[m.callback]||null,controls:s[m.control]||null,transitions:s[m.transition]||null,res:{pkg:e,name:t}}),H.addHeader(s,e,t),s}},e.uiprop=function(e,t){C(e.constructor,m.prop)[t]=1},e.uicontrol=function(e,t){C(e.constructor,m.control)[t]=1},e.uitransition=function(e,t){C(e.constructor,m.transition)[t]=1},e.uiclick=function(e,t,s){C(e.constructor,m.callback)[t]=s.value}}(f||(f={}));const S=globalThis||window||global;S.getKunpoRegisterWindowMaps=function(){return f.getWindowMaps()},S.getKunpoRegisterComponentMaps=function(){return f.getComponentMaps()},S.getKunpoRegisterHeaderMaps=function(){return f.getHeaderMaps()};class v extends s{constructor(){super(...arguments),this.adapterType=_.Full}onAdapted(){}onClose(){}onHide(){}onShowFromHide(){}isShowing(){return this.visible}_init(){this.opaque=!1,this.onInit()}_close(){this.onClose(),this.dispose()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case _.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case _.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this.onAdapted()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}}class I{static create(e,t){const s=e[m.originalName];if(!s)throw new Error(`header【${e.name}】未注册,请使用 _uidecorator.uiheader 注册header`);const i=new I;return i.name=s,i.userdata=t,i}}class T extends s{constructor(){super(...arguments),this.type=g.Normal,this.adapterType=_.Full,this._swallowNode=null,this._isTop=!0}_init(e){let t=new s;t.name="swallow",t.setPivot(.5,.5,!0),this.addChild(t),t.parent.setChildIndex(t,0),t.onClick(this.onEmptyAreaClick,this),t.opaque=e,this._swallowNode=t,this.opaque=e,this._isTop=!0,this.bgAlpha=k.bgAlpha,this.onInit()}_adapted(){switch(this.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),this.setPivot(.5,.5,!0),this.adapterType){case _.Full:this.setSize(a.ScreenWidth,a.ScreenHeight,!0);break;case _.Bang:this.setSize(a.SafeWidth,a.SafeHeight,!0)}this._swallowNode.setSize(a.ScreenWidth,a.ScreenHeight,!0),this._swallowNode.setPosition(.5*this.width,.5*this.height),this.onAdapted()}_close(){this.onClose(),this.dispose()}_show(e){this.visible=!0,this.onShow(e)}_hide(){this.visible=!1,this.onHide()}_showFromHide(){this.visible=!0,this.onShowFromHide()}_toTop(){this._isTop=!0,this.onToTop()}_toBottom(){this._isTop=!1,this.onToBottom()}setDepth(e){this.parent.setChildIndex(this,e)}isShowing(){return this.visible}isTop(){return this._isTop}screenResize(){this._adapted()}refreshHeader(){P.refreshWindowHeader(this.name,this.getHeaderInfo())}removeSelf(){k.closeWindowByName(this.name)}}class R extends T{onAdapted(){}onHide(){}onShowFromHide(){}onToTop(){}onToBottom(){}onEmptyAreaClick(){}getHeaderInfo(){return null}}function y(e,t,s,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,i);else for(var r=e.length-1;r>=0;r--)(o=e[r])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}"function"==typeof SuppressedError&&SuppressedError;const{ccclass:$,property:A,menu:z}=u;let G=class extends w{constructor(){super(...arguments),this.ignoreQuery=!1,this.swallowTouch=!1}init(){let e=this.node.name;n(`\tUIContainer name:${e} 忽略顶部窗口查询:${this.ignoreQuery} 吞噬触摸事件:${this.swallowTouch}`);const t=new s;t.name=e,t.node.name=e,t.visible=!1,t.opaque=this.swallowTouch,t.setSize(a.ScreenWidth,a.ScreenHeight,!0),i.inst.addChild(t),k.addWindowGroup(new b(e,t,this.ignoreQuery,this.swallowTouch))}};y([A({displayName:"忽略顶部窗口查询",tooltip:"当通过窗口管理器获取顶部窗口时,是否忽略查询"})],G.prototype,"ignoreQuery",void 0),y([A({displayName:"吞噬触摸事件",tooltip:"窗口组是否会吞噬触摸事件,防止层级下的窗口接收触摸事件"})],G.prototype,"swallowTouch",void 0),G=y([$("CocosWindowContainer"),z("bit/UIContainer")],G);const{ccclass:U,menu:M,property:B}=u;let x=class extends r{constructor(){super(...arguments),this.ui_config=null,this.bgAlpha=.75,this.autoReleaseUIRes=!0,this.moduleName="UI模块"}onInit(){this.ui_config&&W.setConfig(this.ui_config.json),N.setAutoRelease(this.autoReleaseUIRes),k.bgAlpha=this.bgAlpha,i.create(),n("初始化 WindowContainers");const e=new o;e.touchable=!1,e.name="bgAlpha",e.setPosition(.5*a.ScreenWidth,.5*a.ScreenHeight),e.setSize(a.ScreenWidth,a.ScreenHeight,!0),e.setPivot(.5,.5,!0),e.visible=!1,i.inst.addChild(e),k.setAlphaGraph(e);for(const e of this.getComponentsInChildren(G))e.init();this.node.destroyAllChildren(),h.instance.addResizeListener(this.onScreenResize.bind(this))}onScreenResize(...e){k.onScreenResize()}};y([B({type:p,displayName:"配置文件",tooltip:"编辑器:https://store.cocos.com/app/detail/7213 导出的配置文件"})],x.prototype,"ui_config",void 0),y([B({displayName:"底部遮罩透明度",tooltip:"半透明遮罩的默认透明度",min:0,max:1,step:.01})],x.prototype,"bgAlpha",void 0),y([B({displayName:"自动释放UI资源",tooltip:"界面关闭时自动释放加载的资源"})],x.prototype,"autoReleaseUIRes",void 0),x=y([U("UIModule"),M("bit/UIModule")],x);export{_ as AdapterType,v as Header,I as HeaderInfo,x as UIModule,R as Window,b as WindowGroup,k as WindowManager,g as WindowType,f as _uidecorator};