@gongxh/bit-ui 0.0.1 → 0.0.6

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 bit老宫
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,243 +1,161 @@
1
- ## UI模块
2
-
3
- ### 特点
4
-
5
- * 基于FairyGUI, 查看[FairyGUI官方文档](https://www.fairygui.com/docs/editor)
6
-
7
- * 灵活的 UI 装饰器(配合插件 `kunpo-fgui` 使用,一键导出界面配置,省时省力省代码)
8
-
9
- * 控制窗口之间的相互关系(eg: 打开界面时,是隐藏/关闭前一个界面,还是隐藏/关闭所有界面)
10
-
11
- * 多窗口组管理
12
-
13
- * 顶部显示金币钻石的资源栏(header),一次实现,多界面复用,
14
-
15
- * 支持不同界面使用不同 header
16
-
17
- ### 插件链接
18
- * **kunpo-fgui**: [https://store.cocos.com/app/detail/7213](https://store.cocos.com/app/detail/7213)
19
-
20
- ### 使用
21
-
22
- #### *一、FairyGUI界面*
23
- > ![image-fgui-project](../image/image-fgui-project.png#pic_left)
24
-
25
- #### *二、UI 装饰器使用*
26
-
27
- > 注:只有使用了装饰器的内容才能在 `kunpo-fgui` 插件中识别,`kunpo-fgui`插件操作界面如下图
28
-
29
- > ![image-fgui-editor](../image/image-fgui-editor.png#pic_left)
30
-
31
-
32
- 1. 窗口装饰器
33
-
34
- ```typescript
35
- import { Window, _uidecorator } from 'bit-ui';
36
- const { uiclass, uiprop, uiclick } = _uidecorator;
37
-
38
- /**
39
- * 窗口装饰器
40
- * @param 参数1: 窗口容器节点名字
41
- * @param 参数2: FairyGUI中的UI包名
42
- * @param 参数3: FairyGUI中的组件名 必须和 class 类同名 这里是 MyWindow
43
- */
44
- @uiclass("Window", "UI包名", "MyWindow")
45
- export class MyWindow extends Window {
46
- // ... 窗口实现
47
- }
48
- ```
49
-
50
- 2. Header 装饰器
51
-
52
- ```typescript
53
- import { WindowHeader, _uidecorator } from 'bit-ui';
54
- const { uiheader } = _uidecorator;
55
-
56
- /**
57
- * 窗口顶部资源栏装饰器
58
- * @param 参数1: FairyGUI中的UI包名
59
- * @param 参数2: FairyGUI中的组件名 必须和 class 类同名 这里是 MyWindowHeader
60
- */
61
- @uiheader("UI包名", "WindowHeader")
62
- export class MyWindowHeader extends WindowHeader {
63
- // ... Header 实现
64
- }
65
- ```
66
-
67
- 3. UI组件装饰器
68
-
69
- ```typescript
70
- import { _uidecorator } from 'bit-ui';
71
- const { uicom, uiprop, uiclick } = _uidecorator;
72
-
73
- /**
74
- * UI组件类装饰器
75
- * @param 参数1: FairyGUI中的UI包名
76
- * @param 参数2: FairyGUI中的组件名 必须和 class 类同名 这里是 MyComponent
77
- */
78
- @uicom("Home", "MyComponent")
79
- export class MyComponent {
80
- // ... 组件实现
81
- }
82
- ```
83
-
84
- 4. UI属性装饰器
85
-
86
- ```typescript
87
- import { Window, _uidecorator } from 'bit-ui';
88
- const { uiclass, uiprop, uiclick } = _uidecorator;
89
-
90
- @uiclass("Window", "Home", "MyWindow")
91
- export class MyWindow extends Window {
92
- // FairyGUI 组件属性装饰器
93
- @uiprop private btnConfirm: GButton; // 按钮组件
94
- @uiprop private txtTitle: GTextField; // 文本组件
95
- @uiprop private listItems: GList; // 列表组件
96
- }
97
- ```
98
-
99
- 5. 点击事件装饰器
100
-
101
- ```typescript
102
- import { Window, _uidecorator } from 'bit-ui';
103
- const { uiclass, uiprop, uiclick } = _uidecorator;
104
-
105
- @uiclass("Window", "Home", "MyWindow")
106
- export class MyWindow extends Window {
107
- // 点击事件装饰器
108
- @uiclick
109
- private onTouchEvent(event: cc.Event): void {
110
- console.log('确认按钮被点击');
111
- }
112
- }
113
- ```
114
-
115
- 6. 控制器和动画装饰器
116
-
117
- ```typescript
118
- import { Window, _uidecorator } from 'bit-ui';
119
- const { uiclass, uiprop, uiclick, uicontrol, uitransition } = _uidecorator;
120
-
121
- @uiclass("Window", "Home", "MyWindow")
122
- export class MyWindow extends Window {
123
- // FairyGUI 组件属性装饰器
124
- @uicontrol private control: Controller;
125
- @uitransition private transition: Transition;
126
- }
127
- ```
128
-
129
-
130
- #### *三、创建窗口*
131
-
132
- 1. 新建窗口类
133
-
134
- ```typescript
135
- /**
136
- * 窗口名必须和FairyGUI中的组件同名
137
- */
138
- import { Window, _uidecorator } from 'bit-ui';
139
- const { uiclass, uiprop, uiclick } = _uidecorator;
140
-
141
- @uiclass("Window", "UI包名", "MyWindow")
142
- export class MyWindow extends Window {
143
- protected onInit(): void {
144
- // 初始化窗口
145
- }
146
-
147
- protected onShow(userdata?: any): void {
148
- // 窗口显示时的逻辑
149
- }
150
-
151
- protected onClose(): void {
152
- // 窗口关闭时的逻辑
153
- }
154
- }
155
- ```
156
-
157
- 2. 窗口生命周期
158
- - `onInit`: 窗口初始化时调用
159
- - `onShow`: 窗口显示时调用
160
- - `onClose`: 窗口关闭时调用
161
- - `onHide`: 窗口隐藏时调用
162
- - `onShowFromHide`: 窗口从隐藏状态恢复时调用
163
- - `onCover`: 窗口被覆盖时调用
164
- - `onRecover`: 窗口恢复时调用
165
- - `onEmptyAreaClick`: 点击窗口空白区域时调用
166
-
167
- #### *四、窗口资源加载配置*
168
- ```typescript
169
- interface IPackageConfig {
170
- /** UI所在resources中的路径 */
171
- uiPath: string;
172
- /**
173
- * 手动管理资源的包
174
- * 1. 用于基础UI包, 提供一些最基础的组件,所有其他包都可能引用其中的内容
175
- * 2. 资源header所在的包
176
- * 3. 用于一些特殊场景, 比如需要和其他资源一起加载, 并且显示进度条的包
177
- */
178
- manualPackages: string[];
179
- /**
180
- * 不推荐配置 只是提供一种特殊需求的实现方式
181
- * 窗口引用到其他包中的资源 需要的配置信息
182
- */
183
- linkPackages: { [windowName: string]: string[] };
184
-
185
- /**
186
- * 关闭界面后,需要立即释放资源的包名(建议尽量少)
187
- * 一般不建议包进行频繁装载卸载,因为每次装载卸载必然是要消耗CPU时间(意味着耗电)和产生大量GC的。UI系统占用的内存是可以精确估算的,你可以按照包的使用频率设定哪些包是需要立即释放的。
188
- * 不包括手动管理的包
189
- */
190
- imReleasePackages: string[];
191
- }
192
-
193
- export interface IPackageConfigRes {
194
- /** 配置信息 */
195
- config: IPackageConfig;
196
- /** 显示加载等待窗 */
197
- showWaitWindow: () => void;
198
- /** 隐藏加载等待窗 */
199
- hideWaitWindow: () => void;
200
- /** 打开窗口时UI包加载失败 */
201
- fail: (windowName: string, errmsg: string, pkgs: string[]) => void;
202
- }
1
+ # bit-ui
2
+
3
+ 基于 FairyGUI 的 UI 管理系统,提供灵活的窗口管理和装饰器支持。
4
+
5
+ ## 简介
6
+
7
+ `bit-ui` 是基于 FairyGUI 的 UI 管理库,提供窗口生命周期管理、资源自动加载、多窗口组管理等功能。支持配套的可视化编辑器一键导出界面配置。
8
+
9
+ **核心特性**:
10
+ - 🎨 灵活的 UI 装饰器
11
+ - 🪟 完整的窗口生命周期管理
12
+ - 📦 自动资源加载和卸载
13
+ - 🎯 窗口间关系控制(隐藏/关闭前一个界面)
14
+ - 🎪 多窗口组管理
15
+ - 📊 Header 资源栏复用
16
+ - 🖥️ 配套可视化编辑器(付费插件)
17
+
18
+ **依赖**:
19
+ - FairyGUI - [官方文档](https://www.fairygui.com/docs/editor)
20
+
21
+ ## 安装
22
+
23
+ ```bash
24
+ npm install @gongxh/bit-ui
203
25
  ```
204
26
 
205
- #### *五、窗口管理接口*
206
- ```typescript
207
- export class WindowManager {
208
- /**
209
- * 配置UI包的一些信息 (可以不配置 完全手动管理资源)
210
- */
211
- public static initPackageConfig(res: IPackageConfigRes): void;
212
-
213
- /**
214
- * 异步打开一个窗口 (如果UI包的资源未加载, 会自动加载 配合 WindowManager.initPackageConfig一起使用)
215
- */
216
- public static showWindow(windowName: string, userdata?: any): Promise<void>
217
-
218
- /**
219
- * 打开一个窗口 (用于已加载过资源的窗口)
220
- */
221
- public static showWindowIm(windowName: string, userdata?: any): void;
222
-
223
- /**
224
- * 关闭窗口
225
- */
226
- public static closeWindow(windowName: string);
227
-
228
- /*
229
- * 获取窗口实例
230
- */
231
- public static getWindow<T extends Window>(windowName: string): T;
232
-
233
- /**
234
- * 获取当前最顶层窗口
235
- */
236
- public static getTopWindow(): Window;
237
-
238
- /**
239
- * 检查窗口是否存在
240
- */
241
- public static hasWindow(windowName: string): boolean;
242
- }
243
- ```
27
+ ## 可视化编辑器
28
+
29
+ 提供专业的 FairyGUI 配置编辑器,支持快速配置和导出。
30
+
31
+ **下载地址**:[Cocos Store - kunpo-fgui](https://store.cocos.com/app/detail/7213)
32
+
33
+ ## 使用说明
34
+
35
+ ### UI 装饰器
36
+
37
+ 使用装饰器简化 UI 组件定义和配置。
38
+
39
+ **窗口装饰器**:
40
+ - `@uiclass(groupName, pkgName, name, inlinePkgs?)` - 注册窗口类
41
+ - `groupName` - 窗口组名称
42
+ - `pkgName` - FairyGUI 包名
43
+ - `name` - 组件名(必须和类名相同)
44
+ - `inlinePkgs` - 内联的包名(可选,当前界面引用其他包资源时使用)
45
+
46
+ **Header 装饰器**:
47
+ - `@uiheader(pkgName, name)` - 注册 Header 类
48
+ - 用于定义窗口顶部资源栏
49
+
50
+ **UI 组件装饰器**:
51
+ - `@uicom(pkgName, name)` - 注册自定义 UI 组件类
52
+
53
+ **属性装饰器**:
54
+ - `@uiprop` - 标记 FairyGUI 组件属性(按钮、文本、列表等)
55
+ - `@uicontrol` - 标记 FairyGUI 控制器
56
+ - `@uitransition` - 标记 FairyGUI 动画
57
+
58
+ **事件装饰器**:
59
+ - `@uiclick` - 标记点击事件处理函数
60
+
61
+ ### 窗口基类 (Window)
62
+
63
+ 所有窗口的基类,提供完整的生命周期。
64
+
65
+ **生命周期方法**:
66
+ - `onInit()` - 窗口初始化
67
+ - `onShow(userdata?)` - 窗口显示
68
+ - `onHide()` - 窗口隐藏
69
+ - `onClose()` - 窗口关闭
70
+ - `onShowFromHide()` - 从隐藏状态恢复
71
+ - `onToTop()` - 窗口到顶层
72
+ - `onToBottom()` - 窗口到底层
73
+ - `onEmptyAreaClick()` - 点击空白区域
74
+ - `onAdapted()` - 窗口适配完成
75
+
76
+ ### Header 基类 (Header)
77
+
78
+ 窗口顶部资源栏基类,支持多窗口复用。
79
+
80
+ **生命周期方法**:
81
+ - `onInit()` - Header 初始化
82
+ - `onShow(userdata?)` - Header 显示
83
+ - `onHide()` - Header 隐藏
84
+ - `onClose()` - Header 关闭
85
+ - `onShowFromHide()` - 从隐藏状态恢复
86
+ - `onAdapted()` - 适配完成
87
+
88
+ ### 窗口管理器 (WindowManager)
89
+
90
+ 全局窗口管理器,负责窗口的创建、显示、关闭等。
91
+
92
+ **配置方法**:
93
+ - `setPackageCallbacks(callbacks)` - 设置 UI 包加载回调
94
+ - `callbacks.showWaitWindow` - 显示加载等待窗口
95
+ - `callbacks.hideWaitWindow` - 隐藏加载等待窗口
96
+ - `callbacks.fail` - 加载失败回调
97
+ - `addManualPackage(pkgName)` - 添加手动管理资源的包
98
+ - `setPackageInfo(pkgName, bundleName?, path?)` - 设置包所在的 bundle 和路径
99
+ - `setUIConfig(config)` - 设置 UI 导出数据
100
+
101
+ **窗口操作**:
102
+ - `showWindow<T>(windowClass, userdata?)` - 异步打开窗口(自动加载资源)
103
+ - 参数是窗口类(构造函数),非窗口名称
104
+ - `closeWindow<T>(windowClass)` - 关闭窗口(通过窗口类)
105
+ - `closeWindowByName(name)` - 关闭窗口(通过窗口名称)
106
+ - `getWindow<T>(name)` - 获取窗口实例
107
+ - `getTopWindow<T>(isAll?)` - 获取最顶层窗口
108
+ - `hasWindow(name)` - 检查窗口是否存在
109
+
110
+ **其他方法**:
111
+ - `getGroupNames()` - 获取所有窗口组名称
112
+ - `getWindowGroup(name)` - 获取指定窗口组
113
+ - `closeAllWindow(ignores?)` - 关闭所有窗口
114
+ - `releaseUnusedRes()` - 释放不再使用的 UI 资源
115
+
116
+ ### 窗口类型 (WindowType)
117
+
118
+ 定义窗口显示时对其他窗口的处理方式:
119
+
120
+ - `Normal` - 不做任何处理
121
+ - `CloseAll` - 关闭所有窗口
122
+ - `CloseOne` - 关闭上一个窗口
123
+ - `HideAll` - 隐藏所有窗口
124
+ - `HideOne` - 隐藏上一个窗口
125
+
126
+ ### 适配类型 (AdapterType)
127
+
128
+ 窗口适配类型:
129
+
130
+ - `Full` - 全屏适配(默认)
131
+ - `Bang` - 空出刘海区域
132
+ - `Fixed` - 固定尺寸,不适配
133
+
134
+ ### 典型使用流程
135
+
136
+ 1. **FairyGUI 设计** - 使用 FairyGUI 编辑器设计界面
137
+ 2. **定义窗口类** - 继承 Window 并使用 @uiclass 装饰器注册
138
+ 3. **配置属性和事件** - 使用 @uiprop 和 @uiclick 标记
139
+ 4. **配置加载回调** - 调用 `WindowManager.setPackageCallbacks()`(可选)
140
+ 5. **打开窗口** - 调用 `WindowManager.showWindow(MyWindow, userdata)`
141
+ 6. **管理生命周期** - 实现窗口生命周期方法
142
+
143
+ 详细 API 请查看 `bit-ui.d.ts` 类型定义文件和 FairyGUI 官方文档。
144
+
145
+ ## 依赖
146
+
147
+ - [FairyGUI](https://www.fairygui.com/) - UI 编辑器和运行时库
148
+
149
+ ## 许可证
150
+
151
+ MIT License
152
+
153
+ ## 作者
154
+
155
+ **bit老宫** (gongxh)
156
+ **邮箱**: gong.xinhai@163.com
157
+
158
+ ## 源码仓库
159
+
160
+ - [GitHub](https://github.com/Gongxh0901/bit-framework)
161
+ - [npm](https://www.npmjs.com/package/@gongxh/bit-ui)