dzkcc-mflow 0.0.38 → 0.0.40
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/README.md +46 -27
- package/dist/core/Api.d.ts +8 -2
- package/dist/libs/BaseView.d.ts +36 -0
- package/dist/libs/BaseView.js +74 -1
- package/dist/libs/ResLoader.d.ts +14 -0
- package/dist/libs/ResLoader.js +67 -17
- package/dist/libs/UIManager.d.ts +167 -18
- package/dist/libs/UIManager.js +499 -132
- package/dist/mflow-tools.zip +0 -0
- package/dist/utils/ImageUtil.d.ts +5 -1
- package/dist/utils/ImageUtil.js +25 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
## 核心特性
|
|
8
8
|
|
|
9
9
|
✨ **模块化设计** - 通过 Manager 和 Model 模式实现业务逻辑的模块化管理
|
|
10
|
-
✨ **依赖注入** -
|
|
10
|
+
✨ **依赖注入** - 基于装饰器的自动依赖注入和字符串标识
|
|
11
11
|
✨ **服务定位器** - 统一的服务管理机制,实现服务解耦
|
|
12
12
|
✨ **UI 管理系统** - 完整的 UI 界面管理方案,支持视图栈和分组
|
|
13
13
|
✨ **事件系统** - 强大的事件广播和监听机制,支持粘性事件
|
|
@@ -62,7 +62,7 @@ export class GameCore extends CocosCore {
|
|
|
62
62
|
|
|
63
63
|
### 1. 核心概念
|
|
64
64
|
|
|
65
|
-
了解框架的基础架构、Core 容器、ServiceLocator、Manager、Model、View
|
|
65
|
+
了解框架的基础架构、Core 容器、ServiceLocator、Manager、Model、View 和字符串标识系统。
|
|
66
66
|
|
|
67
67
|
📖 **查看文档**: [核心概念](./docs/CORE_CONCEPTS.md)
|
|
68
68
|
|
|
@@ -171,12 +171,13 @@ mf.reddot.on('main/bag', (totalCount) => {
|
|
|
171
171
|
// types/api-type-hints.d.ts
|
|
172
172
|
declare module 'dzkcc-mflow/core' {
|
|
173
173
|
interface ModelTypeMap {
|
|
174
|
-
|
|
174
|
+
UserModel: UserModel;
|
|
175
|
+
GameModel: GameModel;
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
// 使用时自动推断类型
|
|
179
|
-
const userModel = mf.core.getModel(
|
|
180
|
+
const userModel = mf.core.getModel('UserModel');
|
|
180
181
|
userModel.name; // ✅ 有完整的代码补全
|
|
181
182
|
```
|
|
182
183
|
|
|
@@ -187,7 +188,7 @@ userModel.name; // ✅ 有完整的代码补全
|
|
|
187
188
|
**编辑器菜单**:**mflow-tools -> Generate API type hints/生成API类型提示**
|
|
188
189
|
|
|
189
190
|
> ⚠️ **如果 getManager/getModel 没有类型提示**?
|
|
190
|
-
>
|
|
191
|
+
>
|
|
191
192
|
> 需要创建类型映射文件,使用编辑器的 **mflow-tools -> Generate API type hints/生成API类型提示** 自动生成,
|
|
192
193
|
> 或查看 [类型提示问题解决方案](./docs/TYPE_INFERENCE_FIX.md)
|
|
193
194
|
|
|
@@ -219,40 +220,58 @@ Cocos Creator 编辑器插件,自动生成 UI 脚本,自动设置组件引
|
|
|
219
220
|
## 架构图
|
|
220
221
|
|
|
221
222
|
```
|
|
222
|
-
|
|
223
|
-
│
|
|
224
|
-
│
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
│
|
|
229
|
-
▼
|
|
230
|
-
┌─────────┐
|
|
231
|
-
│ Core │ │
|
|
232
|
-
│(核心容器)│ │(
|
|
233
|
-
└─────────┘
|
|
234
|
-
│
|
|
235
|
-
├─ Manager ─┐
|
|
236
|
-
│ │
|
|
237
|
-
├─ Model ───┤
|
|
238
|
-
│ │
|
|
239
|
-
└─
|
|
240
|
-
|
|
223
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
224
|
+
│ 全局对象 mf │
|
|
225
|
+
│ (统一访问入口,暴露所有框架能力) │
|
|
226
|
+
└─────────────────────────┬───────────────────────────────────────┘
|
|
227
|
+
│
|
|
228
|
+
┌─────────────────────┼─────────────────────┐
|
|
229
|
+
│ │ │
|
|
230
|
+
▼ ▼ ▼
|
|
231
|
+
┌─────────┐ ┌─────────────────────────────────────────┐ ┌──────────┐
|
|
232
|
+
│ Core │ │ ServiceLocator │ │ Views │
|
|
233
|
+
│(核心容器)│ │ (服务定位器) │ │ (UI界面) │
|
|
234
|
+
└─────────┘ └─────────────────────────────────────────┘ └──────────┘
|
|
235
|
+
│ │ │
|
|
236
|
+
├─ Manager ─┐ ├─ Broadcaster(EventMgr) ├─ BaseView
|
|
237
|
+
│ │ ├─ UIManager └─ 自动资源管理
|
|
238
|
+
├─ Model ───┤ ├─ ResLoader └─ 自动事件清理
|
|
239
|
+
│ │ ├─ HttpManager
|
|
240
|
+
└─ 字符串 ───┘ ├─ WebSocketManager
|
|
241
|
+
标识系统 └─ RedDotManager
|
|
241
242
|
```
|
|
242
243
|
|
|
244
|
+
### 架构说明
|
|
245
|
+
|
|
246
|
+
1. **全局对象 `mf`** - 提供统一访问入口,通过 `mf.core`、`mf.gui`、`mf.event` 等访问各模块功能
|
|
247
|
+
|
|
248
|
+
2. **Core (核心容器)** - 管理业务层的 Model 和 Manager,支持依赖注入和类型推断
|
|
249
|
+
|
|
250
|
+
3. **ServiceLocator (服务定位器)** - 统一管理框架的基础服务,包括:
|
|
251
|
+
- **Broadcaster** - 事件广播系统,支持粘性事件
|
|
252
|
+
- **UIManager** - UI界面管理系统,支持视图栈和生命周期管理
|
|
253
|
+
- **ResLoader** - 资源加载器,支持自动释放和缓存管理
|
|
254
|
+
- **HttpManager** - HTTP网络客户端,支持RESTful API
|
|
255
|
+
- **WebSocketManager** - WebSocket实时通信,支持自动重连和心跳
|
|
256
|
+
- **RedDotManager** - 树形结构的红点提示管理系统
|
|
257
|
+
|
|
258
|
+
4. **Views (UI界面)** - 基于 BaseView 的界面组件,支持完整的生命周期管理和自动资源清理
|
|
259
|
+
|
|
260
|
+
5. **依赖注入系统** - 通过装饰器(@manager、@model、@view)和字符串标识实现自动依赖注入
|
|
261
|
+
|
|
243
262
|
## 使用全局对象
|
|
244
263
|
|
|
245
264
|
框架提供了全局对象 `mf` 用于访问所有功能:
|
|
246
265
|
|
|
247
266
|
```typescript
|
|
248
267
|
// 访问 Manager
|
|
249
|
-
mf.core.getManager(
|
|
268
|
+
mf.core.getManager('GameManager');
|
|
250
269
|
|
|
251
270
|
// 访问 Model
|
|
252
|
-
mf.core.getModel(
|
|
271
|
+
mf.core.getModel('UserModel');
|
|
253
272
|
|
|
254
273
|
// UI 管理
|
|
255
|
-
mf.gui.open(
|
|
274
|
+
mf.gui.open('HomeView');
|
|
256
275
|
|
|
257
276
|
// 事件系统
|
|
258
277
|
mf.event.dispatch('gameStart');
|
package/dist/core/Api.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ export interface IView {
|
|
|
65
65
|
onPause(): void;
|
|
66
66
|
/** 恢复视图(从暂停状态恢复) */
|
|
67
67
|
onResume(): void;
|
|
68
|
+
/** 进入动画(可选) */
|
|
69
|
+
onEnterAnimation?(): Promise<void>;
|
|
70
|
+
/** 退出动画(可选) */
|
|
71
|
+
onExitAnimation?(): Promise<void>;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
70
74
|
* UI 管理器接口 - 管理视图的打开、关闭和栈操作
|
|
@@ -75,15 +79,17 @@ export interface IUIManager {
|
|
|
75
79
|
/** 打开视图 */
|
|
76
80
|
open<T extends keyof UIRegistry>(viewClass: T, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
77
81
|
/** 关闭视图 */
|
|
78
|
-
close<T extends keyof UIRegistry>(viewClass: T): void
|
|
82
|
+
close<T extends keyof UIRegistry>(viewClass: T): Promise<void>;
|
|
79
83
|
/** 打开视图并入栈 */
|
|
80
84
|
openAndPush<T extends keyof UIRegistry>(viewClass: T, group: string, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
81
85
|
/** 关闭栈顶视图并弹出 */
|
|
82
|
-
closeAndPop(group: string, destroy?: boolean): void
|
|
86
|
+
closeAndPop(group: string, destroy?: boolean): Promise<void>;
|
|
83
87
|
/** 获取栈顶视图 */
|
|
84
88
|
getTopView(): IView | undefined;
|
|
85
89
|
/** 清空视图栈 */
|
|
86
90
|
clearStack(group: string, destroy?: boolean): void;
|
|
91
|
+
/** 关闭所有视图 */
|
|
92
|
+
closeAll(destroy?: boolean): void;
|
|
87
93
|
}
|
|
88
94
|
/**
|
|
89
95
|
* 资源管理器接口
|
package/dist/libs/BaseView.d.ts
CHANGED
|
@@ -36,4 +36,40 @@ export declare abstract class BaseView extends Component implements IView {
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
protected getManager<T extends keyof ManagerRegistry>(managerClass: T): InstanceType<ManagerRegistry[T]>;
|
|
39
|
+
/**
|
|
40
|
+
* 进入动画(可被子类覆盖以实现自定义动画)
|
|
41
|
+
* 默认实现:缩放+淡入效果
|
|
42
|
+
* @returns 返回 Promise 以支持异步动画
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* async onEnterAnimation(): Promise<void> {
|
|
46
|
+
* // 自定义动画实现
|
|
47
|
+
* return new Promise<void>((resolve) => {
|
|
48
|
+
* tween(this.node)
|
|
49
|
+
* .to(0.5, { scale: new Vec3(1, 1, 1) })
|
|
50
|
+
* .call(() => resolve())
|
|
51
|
+
* .start();
|
|
52
|
+
* });
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
onEnterAnimation(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* 退出动画(可被子类覆盖以实现自定义动画)
|
|
59
|
+
* 默认实现:缩放+淡出效果
|
|
60
|
+
* @returns 返回 Promise 以支持异步动画
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* async onExitAnimation(): Promise<void> {
|
|
64
|
+
* // 自定义动画实现
|
|
65
|
+
* return new Promise<void>((resolve) => {
|
|
66
|
+
* tween(this.node)
|
|
67
|
+
* .to(0.3, { scale: new Vec3(0, 0, 1) })
|
|
68
|
+
* .call(() => resolve())
|
|
69
|
+
* .start();
|
|
70
|
+
* });
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
onExitAnimation(): Promise<void>;
|
|
39
75
|
}
|
package/dist/libs/BaseView.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { _decorator, Component, UIOpacity, tween, Vec3 } from 'cc';
|
|
2
3
|
|
|
3
4
|
const { ccclass, property } = _decorator;
|
|
4
5
|
class BaseView extends Component {
|
|
@@ -93,6 +94,78 @@ class BaseView extends Component {
|
|
|
93
94
|
getManager(managerClass) {
|
|
94
95
|
return mf.core.getManager(managerClass);
|
|
95
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* 进入动画(可被子类覆盖以实现自定义动画)
|
|
99
|
+
* 默认实现:缩放+淡入效果
|
|
100
|
+
* @returns 返回 Promise 以支持异步动画
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* async onEnterAnimation(): Promise<void> {
|
|
104
|
+
* // 自定义动画实现
|
|
105
|
+
* return new Promise<void>((resolve) => {
|
|
106
|
+
* tween(this.node)
|
|
107
|
+
* .to(0.5, { scale: new Vec3(1, 1, 1) })
|
|
108
|
+
* .call(() => resolve())
|
|
109
|
+
* .start();
|
|
110
|
+
* });
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
onEnterAnimation() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const node = this.node;
|
|
117
|
+
node.setScale(0.8, 0.8, 1);
|
|
118
|
+
let uiOpacity = node.getComponent(UIOpacity);
|
|
119
|
+
if (uiOpacity) {
|
|
120
|
+
uiOpacity.opacity = 0;
|
|
121
|
+
}
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
const tweenNode = tween(node).to(0.3, { scale: new Vec3(1, 1, 1) }, { easing: 'backOut' });
|
|
124
|
+
if (uiOpacity) {
|
|
125
|
+
tween(uiOpacity)
|
|
126
|
+
.to(0.3, { opacity: 255 })
|
|
127
|
+
.start();
|
|
128
|
+
}
|
|
129
|
+
tweenNode
|
|
130
|
+
.call(() => resolve())
|
|
131
|
+
.start();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 退出动画(可被子类覆盖以实现自定义动画)
|
|
137
|
+
* 默认实现:缩放+淡出效果
|
|
138
|
+
* @returns 返回 Promise 以支持异步动画
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* async onExitAnimation(): Promise<void> {
|
|
142
|
+
* // 自定义动画实现
|
|
143
|
+
* return new Promise<void>((resolve) => {
|
|
144
|
+
* tween(this.node)
|
|
145
|
+
* .to(0.3, { scale: new Vec3(0, 0, 1) })
|
|
146
|
+
* .call(() => resolve())
|
|
147
|
+
* .start();
|
|
148
|
+
* });
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
onExitAnimation() {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const node = this.node;
|
|
155
|
+
const uiOpacity = node.getComponent(UIOpacity);
|
|
156
|
+
return new Promise((resolve) => {
|
|
157
|
+
const tweenNode = tween(node).to(0.2, { scale: new Vec3(0.8, 0.8, 1) }, { easing: 'backIn' });
|
|
158
|
+
if (uiOpacity) {
|
|
159
|
+
tween(uiOpacity)
|
|
160
|
+
.to(0.2, { opacity: 0 })
|
|
161
|
+
.start();
|
|
162
|
+
}
|
|
163
|
+
tweenNode
|
|
164
|
+
.call(() => resolve())
|
|
165
|
+
.start();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
96
169
|
}
|
|
97
170
|
|
|
98
171
|
export { BaseView };
|
package/dist/libs/ResLoader.d.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { Asset, Prefab, SpriteFrame, Sprite, sp } from "cc";
|
|
2
2
|
import { ICocosResManager, AssetType } from "../core";
|
|
3
3
|
export declare class ResLoader implements ICocosResManager {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param nameOrUrl 资源包名称或路径
|
|
7
|
+
* @returns Promise<AssetManager.Bundle>
|
|
8
|
+
*/
|
|
9
|
+
private _loadBundle;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param path
|
|
13
|
+
* @param type
|
|
14
|
+
* @param nameOrUrl
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
4
17
|
loadAsset<T extends Asset>(path: string, type: AssetType<T>, nameOrUrl?: string): Promise<T>;
|
|
5
18
|
loadPrefab(path: string, nameOrUrl?: string): Promise<Prefab>;
|
|
6
19
|
loadSpriteFrame(ref: Sprite, path: string, nameOrUrl?: string): Promise<SpriteFrame>;
|
|
7
20
|
loadSpine(ref: sp.Skeleton, path: string, nameOrUrl?: string): Promise<sp.SkeletonData>;
|
|
21
|
+
preloadAsset(paths: string | string[], type: AssetType<Asset>, nameOrUrl?: string): Promise<void>;
|
|
8
22
|
release(asset: Asset, force?: boolean): void;
|
|
9
23
|
release(path: string, type?: AssetType<Asset>, nameOrUrl?: string, force?: boolean): void;
|
|
10
24
|
}
|
package/dist/libs/ResLoader.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
-
import { assetManager, Prefab,
|
|
2
|
+
import { path, assetManager, Prefab, SpriteFrame, sp, Asset } from 'cc';
|
|
3
3
|
|
|
4
4
|
const DefaultBundle = "resources";
|
|
5
5
|
class ResLoader {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param nameOrUrl 资源包名称或路径
|
|
9
|
+
* @returns Promise<AssetManager.Bundle>
|
|
10
|
+
*/
|
|
11
|
+
_loadBundle(nameOrUrl = DefaultBundle) {
|
|
12
|
+
const bundleName = path.basename(nameOrUrl);
|
|
13
|
+
const bundle = assetManager.getBundle(bundleName);
|
|
14
|
+
if (bundle) {
|
|
15
|
+
return Promise.resolve(bundle);
|
|
11
16
|
}
|
|
12
17
|
return new Promise((resolve, reject) => {
|
|
13
18
|
assetManager.loadBundle(nameOrUrl, (err, bundle) => {
|
|
@@ -15,22 +20,52 @@ class ResLoader {
|
|
|
15
20
|
reject(err);
|
|
16
21
|
}
|
|
17
22
|
else {
|
|
18
|
-
bundle
|
|
19
|
-
if (err) {
|
|
20
|
-
reject(err);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
data.addRef();
|
|
24
|
-
resolve(data);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
23
|
+
resolve(bundle);
|
|
27
24
|
}
|
|
28
25
|
});
|
|
29
26
|
});
|
|
30
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param path
|
|
31
|
+
* @param type
|
|
32
|
+
* @param nameOrUrl
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
loadAsset(path, type, nameOrUrl = DefaultBundle) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
// 如果是在resources路径下,则截取resources之后的路径,否则直接使用路径
|
|
38
|
+
const _path = (nameOrUrl == DefaultBundle && path.includes('resources')) ? path.split('resources/')[1] : path;
|
|
39
|
+
// 加载资源的通用逻辑
|
|
40
|
+
const loadFromBundle = (bundle) => {
|
|
41
|
+
const cachedAsset = bundle.get(_path, type);
|
|
42
|
+
if (cachedAsset) {
|
|
43
|
+
cachedAsset.addRef();
|
|
44
|
+
return Promise.resolve(cachedAsset);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
bundle.load(_path, type, (err, data) => {
|
|
49
|
+
if (err) {
|
|
50
|
+
reject(err);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
data.addRef();
|
|
54
|
+
resolve(data);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const bundle = yield this._loadBundle(nameOrUrl);
|
|
61
|
+
return loadFromBundle(bundle);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
31
64
|
loadPrefab(path, nameOrUrl = DefaultBundle) {
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
//refCount 记录的是持有者数量,不是资源份数,所以prefab也需要addRef
|
|
67
|
+
return yield this.loadAsset(path, Prefab, nameOrUrl);
|
|
68
|
+
});
|
|
34
69
|
}
|
|
35
70
|
loadSpriteFrame(ref, path, nameOrUrl = DefaultBundle) {
|
|
36
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -60,6 +95,21 @@ class ResLoader {
|
|
|
60
95
|
}
|
|
61
96
|
});
|
|
62
97
|
}
|
|
98
|
+
preloadAsset(paths, type, nameOrUrl = DefaultBundle) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const bundle = yield this._loadBundle(nameOrUrl);
|
|
101
|
+
new Promise((resolve, reject) => {
|
|
102
|
+
bundle.preload(paths, type, (err, data) => {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolve(data);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
63
113
|
release(pathOrAsset, typeOrForce, nameOrUrl = DefaultBundle, forceParam = false) {
|
|
64
114
|
var _a;
|
|
65
115
|
let asset;
|
package/dist/libs/UIManager.d.ts
CHANGED
|
@@ -1,34 +1,183 @@
|
|
|
1
|
-
import { Component } from "cc";
|
|
1
|
+
import { Component, Node, Color } from "cc";
|
|
2
2
|
import { IUIManager, IView } from "../core";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* UI遮罩配置选项
|
|
5
|
+
*/
|
|
6
|
+
export interface UIMaskOptions {
|
|
7
|
+
/** 遮罩颜色 */
|
|
8
|
+
color?: Color;
|
|
9
|
+
/** 是否可点击关闭顶层UI */
|
|
10
|
+
clickToClose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* UI打开选项
|
|
14
|
+
*/
|
|
15
|
+
export interface UIOpenOptions {
|
|
16
|
+
/** 是否显示等待视图 */
|
|
17
|
+
showLoading?: boolean;
|
|
18
|
+
/** 是否可点击遮罩关闭 */
|
|
19
|
+
clickToClose?: boolean;
|
|
20
|
+
/** 自定义参数 */
|
|
21
|
+
args?: any;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 等待视图配置
|
|
25
|
+
*/
|
|
26
|
+
export interface UILoadingConfig {
|
|
27
|
+
/** 是否全局启用等待视图 */
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/** 等待视图预制体路径 */
|
|
30
|
+
prefabPath?: string;
|
|
31
|
+
/** 等待视图显示延迟(毫秒) */
|
|
32
|
+
delay?: number;
|
|
33
|
+
/** 最小显示时间(毫秒) */
|
|
34
|
+
minShowTime?: number;
|
|
35
|
+
/** 自定义创建函数(高级用法) */
|
|
36
|
+
createCustomLoading?: () => Node | Promise<Node>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* LRU缓存配置
|
|
40
|
+
*/
|
|
41
|
+
export interface UICacheConfig {
|
|
42
|
+
/** 最大缓存数量 */
|
|
43
|
+
maxSize?: number;
|
|
44
|
+
/** 是否启用LRU策略 */
|
|
45
|
+
enableLRU?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 预加载配置
|
|
49
|
+
*/
|
|
50
|
+
export interface UIPreloadConfig {
|
|
51
|
+
/** 预加载的视图列表 */
|
|
52
|
+
views?: (keyof UIRegistry)[];
|
|
53
|
+
/** 预加载延迟(毫秒) */
|
|
54
|
+
delay?: number;
|
|
55
|
+
}
|
|
56
|
+
interface IInternalView extends IView {
|
|
57
|
+
__group__: string | undefined;
|
|
58
|
+
__isIView__: boolean;
|
|
59
|
+
}
|
|
60
|
+
type ICocosView = IInternalView & Component;
|
|
4
61
|
declare abstract class CcocosUIManager implements IUIManager {
|
|
5
62
|
getTopView(): IView | undefined;
|
|
6
|
-
open<T extends keyof UIRegistry>(viewClass: T, args?:
|
|
7
|
-
close<T extends keyof UIRegistry>(viewClass: T): void
|
|
8
|
-
openAndPush<T extends keyof UIRegistry>(viewClass: T, group: string, args?:
|
|
9
|
-
closeAndPop(group: string, destroy?: boolean): void
|
|
63
|
+
open<T extends keyof UIRegistry>(viewClass: T, args?: UIOpenOptions): Promise<InstanceType<UIRegistry[T]>>;
|
|
64
|
+
close<T extends keyof UIRegistry>(viewClass: T): Promise<void>;
|
|
65
|
+
openAndPush<T extends keyof UIRegistry>(viewClass: T, group: string, args?: UIOpenOptions): Promise<InstanceType<UIRegistry[T]>>;
|
|
66
|
+
closeAndPop(group: string, destroy?: boolean): Promise<void>;
|
|
10
67
|
clearStack(group: string, destroy?: boolean): void;
|
|
11
|
-
|
|
12
|
-
protected abstract
|
|
13
|
-
protected abstract
|
|
14
|
-
protected abstract
|
|
15
|
-
protected abstract
|
|
16
|
-
protected abstract
|
|
68
|
+
closeAll(destroy?: boolean): void;
|
|
69
|
+
protected abstract _internalOpen(viewKey: string, args?: UIOpenOptions): Promise<ICocosView>;
|
|
70
|
+
protected abstract _internalClose(viewKey: string | IView, destory?: boolean): Promise<void>;
|
|
71
|
+
protected abstract _internalOpenAndPush(viewKey: string, group: string, args?: UIOpenOptions): Promise<ICocosView>;
|
|
72
|
+
protected abstract _internalCloseAndPop(group: string, destroy?: boolean): Promise<void>;
|
|
73
|
+
protected abstract _internalClearStack(group: string, destroy?: boolean): void;
|
|
74
|
+
protected abstract _internalGetTopView(): ICocosView | undefined;
|
|
75
|
+
protected abstract _internalCloseAll(destroy?: boolean): void;
|
|
17
76
|
}
|
|
18
77
|
export declare class UIManager extends CcocosUIManager {
|
|
19
78
|
private _cache;
|
|
20
79
|
private _groupStacks;
|
|
80
|
+
private _inputBlocker;
|
|
81
|
+
private _loadingView;
|
|
82
|
+
private _loadingPromises;
|
|
83
|
+
private _lruOrder;
|
|
84
|
+
private _preloadedViews;
|
|
85
|
+
private _maskOptions;
|
|
86
|
+
private _loadingConfig;
|
|
87
|
+
private _cacheConfig;
|
|
88
|
+
private _preloadConfig;
|
|
89
|
+
private _openOptions;
|
|
21
90
|
constructor();
|
|
91
|
+
/**
|
|
92
|
+
* 设置遮罩配置
|
|
93
|
+
*/
|
|
94
|
+
setMaskConfig(options: UIMaskOptions): void;
|
|
95
|
+
/**
|
|
96
|
+
* 设置等待视图配置
|
|
97
|
+
*/
|
|
98
|
+
setLoadingConfig(config: UILoadingConfig): void;
|
|
99
|
+
/**
|
|
100
|
+
* 设置缓存配置
|
|
101
|
+
*/
|
|
102
|
+
setCacheConfig(config: UICacheConfig): void;
|
|
103
|
+
/**
|
|
104
|
+
* 设置预加载配置
|
|
105
|
+
*/
|
|
106
|
+
setPreloadConfig(config: UIPreloadConfig): void;
|
|
107
|
+
/**
|
|
108
|
+
* 检查指定视图是否已打开
|
|
109
|
+
*/
|
|
110
|
+
contains<T extends keyof UIRegistry>(viewKey: T): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* 检查视图是否正在加载
|
|
113
|
+
*/
|
|
114
|
+
isLoading<T extends keyof UIRegistry>(viewKey: T): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* 预加载视图(支持单个或多个)
|
|
117
|
+
*/
|
|
118
|
+
preload<T extends keyof UIRegistry>(viewKeyOrKeys: T | T[]): Promise<void>;
|
|
22
119
|
private _getPrefabPath;
|
|
120
|
+
/**
|
|
121
|
+
* 获取所有活跃的视图节点(排除遮罩节点)
|
|
122
|
+
*/
|
|
123
|
+
private _getActiveViews;
|
|
124
|
+
/**
|
|
125
|
+
* 通过prefab创建Node对象
|
|
126
|
+
* @param args
|
|
127
|
+
* @returns Node对象
|
|
128
|
+
*/
|
|
129
|
+
private _generateNode;
|
|
130
|
+
/**
|
|
131
|
+
* 调整遮罩层级:始终保持在最顶层UI的下一层
|
|
132
|
+
*/
|
|
23
133
|
private _adjustMaskLayer;
|
|
134
|
+
/**
|
|
135
|
+
* 更新LRU顺序
|
|
136
|
+
*/
|
|
137
|
+
private _updateLRUOrder;
|
|
138
|
+
/**
|
|
139
|
+
* 阻塞/解除输入事件
|
|
140
|
+
*/
|
|
24
141
|
private _blockInput;
|
|
142
|
+
/**
|
|
143
|
+
* 设置遮罩点击处理器
|
|
144
|
+
*/
|
|
145
|
+
private _setupMaskClickHandler;
|
|
146
|
+
/**
|
|
147
|
+
* 显示等待视图
|
|
148
|
+
*/
|
|
149
|
+
private _showLoading;
|
|
150
|
+
/**
|
|
151
|
+
* 隐藏等待视图
|
|
152
|
+
*/
|
|
153
|
+
private _hideLoading;
|
|
154
|
+
/**
|
|
155
|
+
* 预加载视图
|
|
156
|
+
*/
|
|
157
|
+
private _startPreload;
|
|
158
|
+
/**
|
|
159
|
+
* 预加载单个视图
|
|
160
|
+
*/
|
|
161
|
+
private _preloadView;
|
|
162
|
+
/**
|
|
163
|
+
* 获取当前最顶层的视图
|
|
164
|
+
*/
|
|
165
|
+
protected _internalGetTopView(): ICocosView | undefined;
|
|
25
166
|
private _load;
|
|
167
|
+
private _loadInternal;
|
|
168
|
+
protected _internalOpen(viewKey: string, options?: UIOpenOptions): Promise<ICocosView>;
|
|
169
|
+
protected _internalClose(viewKeyOrInstance: string | IView, destroy?: boolean): Promise<void>;
|
|
170
|
+
protected _internalOpenAndPush(viewKey: string, group: string, options?: UIOpenOptions): Promise<ICocosView>;
|
|
171
|
+
protected _internalCloseAndPop(group: string, destroy?: boolean): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* 移除视图
|
|
174
|
+
*/
|
|
26
175
|
private _remove;
|
|
27
|
-
|
|
28
|
-
protected
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
protected
|
|
176
|
+
private _releasePrefab;
|
|
177
|
+
protected _internalClearStack(group: string, destroy?: boolean): void;
|
|
178
|
+
/**
|
|
179
|
+
* 关闭所有视图,不播放动画
|
|
180
|
+
*/
|
|
181
|
+
protected _internalCloseAll(destroy?: boolean): void;
|
|
33
182
|
}
|
|
34
183
|
export {};
|