dzkcc-mflow 0.0.21 → 0.0.23
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 +1583 -575
- package/dist/App.d.ts +2 -1
- package/dist/App.js +3 -0
- package/dist/_virtual/_tslib.js +12 -1
- package/dist/core/Api.d.ts +145 -27
- package/dist/core/Core.d.ts +7 -11
- package/dist/core/Core.js +20 -54
- package/dist/core/Decorators.d.ts +115 -5
- package/dist/core/Decorators.js +197 -89
- package/dist/core/index.js +1 -1
- package/dist/libs/BaseView.d.ts +2 -2
- package/dist/libs/BaseView.js +4 -4
- package/dist/libs/CocosCore.js +2 -0
- package/dist/libs/UIManager.d.ts +9 -9
- package/dist/libs/UIManager.js +37 -29
- package/dist/libs/index.d.ts +3 -0
- package/dist/libs/index.js +3 -0
- package/dist/libs/indicator/RedDotManager.d.ts +58 -0
- package/dist/libs/indicator/RedDotManager.js +124 -0
- package/dist/libs/indicator/RedDotNode.d.ts +69 -0
- package/dist/libs/indicator/RedDotNode.js +135 -0
- package/dist/libs/indicator/UIRedDot.d.ts +28 -0
- package/dist/libs/indicator/UIRedDot.js +101 -0
- package/dist/mflow-tools.zip +0 -0
- package/package.json +1 -1
package/dist/core/Decorators.js
CHANGED
|
@@ -1,105 +1,213 @@
|
|
|
1
|
-
import { ServiceLocator } from './ServiceLocator.js';
|
|
2
1
|
import 'reflect-metadata';
|
|
3
2
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// Symbol 注册系统 - Names 对象(提供代码补全)
|
|
5
|
+
// ============================================================================
|
|
6
|
+
/** Model 名称到 Symbol 的映射,用于代码补全 */
|
|
7
|
+
const ModelNames = {};
|
|
8
|
+
/** Manager 名称到 Symbol 的映射,用于代码补全 */
|
|
9
|
+
const ManagerNames = {};
|
|
10
|
+
/** View 名称到 Symbol 的映射,用于代码补全 */
|
|
11
|
+
const ViewNames = {};
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// 内部注册表
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Model 注册表
|
|
16
|
+
const modelSymbolRegistry = new Map(); // Symbol → 类
|
|
17
|
+
const ctorToModelSymbol = new Map(); // 类 → Symbol
|
|
18
|
+
// Manager 注册表
|
|
19
|
+
const managerSymbolRegistry = new Map(); // Symbol → 类
|
|
20
|
+
const ctorToManagerSymbol = new Map(); // 类 → Symbol
|
|
21
|
+
// View 注册表
|
|
22
|
+
const viewRegistry = new Map(); // Symbol → 类
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Model 装饰器
|
|
25
|
+
// ============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Model 装饰器,用于注册 Model 到全局注册表
|
|
28
|
+
* @param name 可选的 Model 名称,如果不提供则使用类名
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* @model('User')
|
|
32
|
+
* export class UserModel implements IModel {
|
|
33
|
+
* initialize(): void { }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* // 使用
|
|
37
|
+
* const user = mf.core.getModel(ModelNames.User);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function model(name) {
|
|
41
|
+
return function (ctor) {
|
|
42
|
+
const modelName = name || ctor.name;
|
|
43
|
+
const modelSymbol = Symbol(modelName);
|
|
44
|
+
// 注册到映射表
|
|
45
|
+
modelSymbolRegistry.set(modelSymbol, ctor);
|
|
46
|
+
ctorToModelSymbol.set(ctor, modelSymbol);
|
|
47
|
+
ModelNames[modelName] = modelSymbol;
|
|
48
|
+
console.log(`Model registered: ${modelName}`);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 获取所有已注册的 Model 名称
|
|
53
|
+
* @returns Model 名称数组
|
|
54
|
+
*/
|
|
55
|
+
function getRegisteredModelNames() {
|
|
56
|
+
return Object.keys(ModelNames);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 通过 Symbol 获取 Model 类构造函数
|
|
60
|
+
* @param modelSymbol Model 的 Symbol 标识
|
|
61
|
+
* @returns Model 类构造函数
|
|
62
|
+
* @throws 如果 Model 未注册则抛出错误
|
|
63
|
+
*/
|
|
64
|
+
function getModelClass(modelSymbol) {
|
|
65
|
+
const modelClass = modelSymbolRegistry.get(modelSymbol);
|
|
66
|
+
if (!modelClass) {
|
|
67
|
+
throw new Error(`Model not registered! Symbol: ${modelSymbol.toString()}`);
|
|
68
|
+
}
|
|
69
|
+
return modelClass;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 通过类构造函数获取 Model 的 Symbol
|
|
73
|
+
* @param ctor Model 类构造函数
|
|
74
|
+
* @returns Model 的 Symbol
|
|
75
|
+
* @internal 内部使用
|
|
76
|
+
*/
|
|
77
|
+
function getModelSymbol(ctor) {
|
|
78
|
+
return ctorToModelSymbol.get(ctor);
|
|
14
79
|
}
|
|
15
|
-
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Manager 装饰器
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Manager 装饰器,用于注册 Manager 到全局注册表
|
|
85
|
+
* @param name 可选的 Manager 名称,如果不提供则使用类名
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* @manager('Game')
|
|
89
|
+
* export class GameManager extends AbstractManager {
|
|
90
|
+
* initialize(): void { }
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
function manager(name) {
|
|
16
95
|
return function (ctor) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
96
|
+
const managerName = name || ctor.name;
|
|
97
|
+
const managerSymbol = Symbol(managerName);
|
|
98
|
+
// 注册到映射表
|
|
99
|
+
managerSymbolRegistry.set(managerSymbol, ctor);
|
|
100
|
+
ctorToManagerSymbol.set(ctor, managerSymbol);
|
|
101
|
+
ManagerNames[managerName] = managerSymbol;
|
|
102
|
+
console.log(`Manager registered: ${managerName}`);
|
|
22
103
|
};
|
|
23
104
|
}
|
|
24
|
-
|
|
105
|
+
/**
|
|
106
|
+
* 获取所有已注册的 Manager 名称
|
|
107
|
+
* @returns Manager 名称数组
|
|
108
|
+
*/
|
|
109
|
+
function getRegisteredManagerNames() {
|
|
110
|
+
return Object.keys(ManagerNames);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 通过 Symbol 获取 Manager 类构造函数
|
|
114
|
+
* @param managerSymbol Manager 的 Symbol 标识
|
|
115
|
+
* @returns Manager 类构造函数
|
|
116
|
+
* @throws 如果 Manager 未注册则抛出错误
|
|
117
|
+
*/
|
|
118
|
+
function getManagerClass(managerSymbol) {
|
|
119
|
+
const managerClass = managerSymbolRegistry.get(managerSymbol);
|
|
120
|
+
if (!managerClass) {
|
|
121
|
+
throw new Error(`Manager not registered! Symbol: ${managerSymbol.toString()}`);
|
|
122
|
+
}
|
|
123
|
+
return managerClass;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 通过类构造函数获取 Manager 的 Symbol
|
|
127
|
+
* @param ctor Manager 类构造函数
|
|
128
|
+
* @returns Manager 的 Symbol
|
|
129
|
+
* @internal 内部使用
|
|
130
|
+
*/
|
|
131
|
+
function getManagerSymbol(ctor) {
|
|
132
|
+
return ctorToManagerSymbol.get(ctor);
|
|
133
|
+
}
|
|
134
|
+
// ============================================================================
|
|
135
|
+
// View 装饰器
|
|
136
|
+
// ============================================================================
|
|
137
|
+
/**
|
|
138
|
+
* View 装饰器,用于注册 View 到全局注册表
|
|
139
|
+
* @param name 可选的 View 名称,如果不提供则使用类名
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* @view('Home')
|
|
143
|
+
* @ccclass('HomeView')
|
|
144
|
+
* export class HomeView extends BaseView {
|
|
145
|
+
* onEnter(): void { }
|
|
146
|
+
* onPause(): void { }
|
|
147
|
+
* onResume(): void { }
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* // 使用
|
|
151
|
+
* await mf.ui.open(ViewNames.Home);
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function view(name) {
|
|
25
155
|
return function (ctor) {
|
|
26
|
-
|
|
156
|
+
const viewName = name || ctor.name;
|
|
157
|
+
const viewSymbol = Symbol(viewName);
|
|
158
|
+
// 注册到映射表
|
|
159
|
+
viewRegistry.set(viewSymbol, ctor);
|
|
160
|
+
ViewNames[viewName] = viewSymbol;
|
|
161
|
+
console.log(`View registered: ${viewName}`);
|
|
27
162
|
};
|
|
28
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* 获取所有已注册的 View 名称
|
|
166
|
+
* @returns View 名称数组
|
|
167
|
+
*/
|
|
168
|
+
function getRegisteredViewNames() {
|
|
169
|
+
return Object.keys(ViewNames);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 通过 Symbol 获取 View 类构造函数
|
|
173
|
+
* @param viewSymbol View 的 Symbol 标识
|
|
174
|
+
* @returns View 类构造函数
|
|
175
|
+
* @throws 如果 View 未注册则抛出错误
|
|
176
|
+
*/
|
|
177
|
+
function getViewClass(viewSymbol) {
|
|
178
|
+
const viewClass = viewRegistry.get(viewSymbol);
|
|
179
|
+
if (!viewClass) {
|
|
180
|
+
throw new Error(`View not registered! Symbol: ${viewSymbol.toString()}`);
|
|
181
|
+
}
|
|
182
|
+
return viewClass;
|
|
183
|
+
}
|
|
184
|
+
// ============================================================================
|
|
185
|
+
// 自动注册
|
|
186
|
+
// ============================================================================
|
|
187
|
+
/**
|
|
188
|
+
* 自动注册所有使用装饰器标记的 Model 和 Manager
|
|
189
|
+
* @param core Core 实例
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // 导入所有 Model 和 Manager
|
|
193
|
+
* import '@/models/UserModel';
|
|
194
|
+
* import '@/managers/GameManager';
|
|
195
|
+
*
|
|
196
|
+
* // 自动注册
|
|
197
|
+
* autoRegister(mf.core);
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
29
200
|
function autoRegister(core) {
|
|
30
|
-
|
|
201
|
+
// 注册所有 Model
|
|
202
|
+
ctorToModelSymbol.forEach((modelSymbol, ctor) => {
|
|
31
203
|
console.log(`${ctor.name} initialize`);
|
|
32
|
-
core.regModel(
|
|
204
|
+
core.regModel(modelSymbol);
|
|
33
205
|
});
|
|
34
|
-
|
|
206
|
+
// 注册所有 Manager
|
|
207
|
+
ctorToManagerSymbol.forEach((managerSymbol, ctor) => {
|
|
35
208
|
console.log(`${ctor.name} initialize`);
|
|
36
|
-
core.regManager(
|
|
209
|
+
core.regManager(managerSymbol);
|
|
37
210
|
});
|
|
38
|
-
}
|
|
39
|
-
// 依赖注入
|
|
40
|
-
// ------------------------------------------------------------------------------------
|
|
41
|
-
const INJECTED_PROPERTIES_KEY = 'injectedProperties';
|
|
42
|
-
// 因为明文定义的属性会覆盖injectManager(通过defineProperty定义)注入的属性,所以需要在编译时删除明文定义的属性
|
|
43
|
-
function CleanInjectedProperties(constructor) {
|
|
44
|
-
return class extends constructor {
|
|
45
|
-
constructor(...args) {
|
|
46
|
-
super(...args);
|
|
47
|
-
// 递归收集当前类及其所有父类的注入属性
|
|
48
|
-
const collectInjectedProperties = (klass) => {
|
|
49
|
-
if (klass === null || klass === Object)
|
|
50
|
-
return [];
|
|
51
|
-
const parentProperties = collectInjectedProperties(Object.getPrototypeOf(klass));
|
|
52
|
-
const currentProperties = Reflect.getMetadata(INJECTED_PROPERTIES_KEY, klass) || [];
|
|
53
|
-
// const currentProperties :any[] = []
|
|
54
|
-
return [...parentProperties, ...currentProperties];
|
|
55
|
-
};
|
|
56
|
-
// 合并并去重属性名
|
|
57
|
-
const injectedProperties = [
|
|
58
|
-
...new Set(collectInjectedProperties(constructor))
|
|
59
|
-
];
|
|
60
|
-
// 删除实例上的所有注入属性
|
|
61
|
-
injectedProperties.forEach(prop => {
|
|
62
|
-
if (this.hasOwnProperty(prop)) {
|
|
63
|
-
delete this[prop];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function managedWithClean() {
|
|
70
|
-
return function (ctor) {
|
|
71
|
-
// 先执行清理逻辑
|
|
72
|
-
const decoratedCtor = CleanInjectedProperties(ctor);
|
|
73
|
-
// 后执行注册逻辑
|
|
74
|
-
manager()(decoratedCtor);
|
|
75
|
-
return decoratedCtor;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
// 懒加载依赖注入manager
|
|
79
|
-
function injectManager(sym) {
|
|
80
|
-
return function (target, prop) {
|
|
81
|
-
const injectionKey = Symbol.for(prop);
|
|
82
|
-
Object.defineProperty(target, prop, {
|
|
83
|
-
get: function () {
|
|
84
|
-
console.log(`[属性访问] 触发getter:${injectionKey.toString()}`);
|
|
85
|
-
if (!this[injectionKey]) {
|
|
86
|
-
this[injectionKey] = ServiceLocator.getService('core').getManager(sym);
|
|
87
|
-
}
|
|
88
|
-
return this[injectionKey];
|
|
89
|
-
},
|
|
90
|
-
set: function (val) {
|
|
91
|
-
throw new Error('InjectManager property is read-only');
|
|
92
|
-
},
|
|
93
|
-
enumerable: true,
|
|
94
|
-
configurable: false // 禁止修改属性描述符
|
|
95
|
-
});
|
|
96
|
-
// 2. 将属性名记录到元数据
|
|
97
|
-
const injectedProperties = Reflect.getMetadata(INJECTED_PROPERTIES_KEY, target.constructor) || [];
|
|
98
|
-
if (!injectedProperties.includes(prop)) {
|
|
99
|
-
injectedProperties.push(prop);
|
|
100
|
-
}
|
|
101
|
-
Reflect.defineMetadata(INJECTED_PROPERTIES_KEY, injectedProperties, target.constructor);
|
|
102
|
-
};
|
|
103
211
|
}
|
|
104
212
|
|
|
105
|
-
export { autoRegister,
|
|
213
|
+
export { ManagerNames, ModelNames, ViewNames, autoRegister, getManagerClass, getManagerSymbol, getModelClass, getModelSymbol, getRegisteredManagerNames, getRegisteredModelNames, getRegisteredViewNames, getViewClass, manager, model, view };
|
package/dist/core/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AbstractCore, AbstractManager } from './Core.js';
|
|
2
|
-
export { autoRegister,
|
|
2
|
+
export { ManagerNames, ModelNames, ViewNames, autoRegister, getManagerClass, getManagerSymbol, getModelClass, getModelSymbol, getRegisteredManagerNames, getRegisteredModelNames, getRegisteredViewNames, getViewClass, manager, model, view } from './Decorators.js';
|
|
3
3
|
export { ServiceLocator } from './ServiceLocator.js';
|
package/dist/libs/BaseView.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ export declare abstract class BaseView extends Component implements IView {
|
|
|
16
16
|
abstract onEnter(args?: any): void;
|
|
17
17
|
onExit(): void;
|
|
18
18
|
protected onDestroy(): void;
|
|
19
|
-
protected getManager<T extends IManager>(
|
|
20
|
-
protected getModel<T extends IModel>(
|
|
19
|
+
protected getManager<T extends IManager>(managerSymbol: symbol): T;
|
|
20
|
+
protected getModel<T extends IModel>(modelSymbol: symbol): T;
|
|
21
21
|
}
|
package/dist/libs/BaseView.js
CHANGED
|
@@ -69,13 +69,13 @@ class BaseView extends Component {
|
|
|
69
69
|
});
|
|
70
70
|
this._loaderHandlers = [];
|
|
71
71
|
}
|
|
72
|
-
getManager(
|
|
72
|
+
getManager(managerSymbol) {
|
|
73
73
|
// 业务组件避免直接依赖底层服务定位器,所以使用app.core统一对外接口,方便后续架构演进
|
|
74
|
-
return mf.core.getManager(
|
|
74
|
+
return mf.core.getManager(managerSymbol);
|
|
75
75
|
}
|
|
76
|
-
getModel(
|
|
76
|
+
getModel(modelSymbol) {
|
|
77
77
|
// 业务组件避免直接依赖底层服务定位器,所以使用app.core统一对外接口,方便后续架构演进
|
|
78
|
-
return mf.core.getModel(
|
|
78
|
+
return mf.core.getModel(modelSymbol);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
package/dist/libs/CocosCore.js
CHANGED
|
@@ -7,6 +7,7 @@ import { ResLoader } from './ResLoader.js';
|
|
|
7
7
|
import { Broadcaster } from './Broadcaster.js';
|
|
8
8
|
import { HttpManager } from './HttpManager.js';
|
|
9
9
|
import { WebSocketManager } from './WebSocketManager.js';
|
|
10
|
+
import { RedDotManager } from './indicator/RedDotManager.js';
|
|
10
11
|
import '../App.js';
|
|
11
12
|
|
|
12
13
|
class Core extends AbstractCore {
|
|
@@ -18,6 +19,7 @@ class Core extends AbstractCore {
|
|
|
18
19
|
ServiceLocator.regService('UIManager', new UIManager());
|
|
19
20
|
ServiceLocator.regService('HttpManager', new HttpManager());
|
|
20
21
|
ServiceLocator.regService('WebSocketManager', new WebSocketManager());
|
|
22
|
+
ServiceLocator.regService('RedDotManager', new RedDotManager());
|
|
21
23
|
// 注册业务模块(通过装饰器自动注册)
|
|
22
24
|
// 推迟到构造函数执行完毕
|
|
23
25
|
queueMicrotask(() => autoRegister(this));
|
package/dist/libs/UIManager.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { IUIManager, IView } from "../core";
|
|
|
3
3
|
type ICocosView = IView & Component;
|
|
4
4
|
declare abstract class CcocosUIManager implements IUIManager {
|
|
5
5
|
getTopView(): IView | undefined;
|
|
6
|
-
open<T extends IView>(
|
|
7
|
-
close
|
|
8
|
-
openAndPush<T extends IView>(
|
|
6
|
+
open<T extends IView>(viewSymbol: symbol, args?: any): Promise<T>;
|
|
7
|
+
close(viewSymbol: symbol | IView, destory?: boolean): void;
|
|
8
|
+
openAndPush<T extends IView>(viewSymbol: symbol, group: string, args?: any): Promise<T>;
|
|
9
9
|
closeAndPop(group: string, destroy?: boolean): void;
|
|
10
10
|
clearStack(group: string, destroy?: boolean): void;
|
|
11
|
-
protected abstract internalOpen<T extends ICocosView>(
|
|
12
|
-
protected abstract internalClose
|
|
13
|
-
protected abstract internalOpenAndPush<T extends ICocosView>(
|
|
11
|
+
protected abstract internalOpen<T extends ICocosView>(viewSymbol: symbol, args?: any): Promise<T>;
|
|
12
|
+
protected abstract internalClose(viewSymbol: symbol | IView, destory?: boolean): void;
|
|
13
|
+
protected abstract internalOpenAndPush<T extends ICocosView>(viewSymbol: symbol, group: string, args?: any): Promise<T>;
|
|
14
14
|
protected abstract internalCloseAndPop(group: string, destroy?: boolean): void;
|
|
15
15
|
protected abstract internalClearStack(group: string, destroy?: boolean): void;
|
|
16
16
|
protected abstract internalGetTopView(): ICocosView | undefined;
|
|
@@ -25,9 +25,9 @@ export declare class UIManager extends CcocosUIManager {
|
|
|
25
25
|
private _load;
|
|
26
26
|
private _remove;
|
|
27
27
|
protected internalGetTopView(): ICocosView | undefined;
|
|
28
|
-
protected internalOpen<T extends ICocosView>(
|
|
29
|
-
protected internalClose
|
|
30
|
-
protected internalOpenAndPush<T extends ICocosView>(
|
|
28
|
+
protected internalOpen<T extends ICocosView>(viewSymbol: symbol, args?: any): Promise<T>;
|
|
29
|
+
protected internalClose(viewSymbol: symbol | IView, destroy?: boolean): void;
|
|
30
|
+
protected internalOpenAndPush<T extends ICocosView>(viewSymbol: symbol, group: string, args?: any): Promise<T>;
|
|
31
31
|
protected internalCloseAndPop(group: string, destroy?: boolean): void;
|
|
32
32
|
protected internalClearStack(group: string, destroy?: boolean): void;
|
|
33
33
|
}
|
package/dist/libs/UIManager.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
2
|
import { director, Node, Sprite, Widget, Input, input, Prefab, instantiate } from 'cc';
|
|
3
3
|
import { ServiceLocator } from '../core/ServiceLocator.js';
|
|
4
|
-
import '
|
|
4
|
+
import { getViewClass } from '../core/Decorators.js';
|
|
5
5
|
|
|
6
6
|
function addWidget(node) {
|
|
7
7
|
const widget = node.getComponent(Widget) || node.addComponent(Widget);
|
|
@@ -60,16 +60,14 @@ class CcocosUIManager {
|
|
|
60
60
|
getTopView() {
|
|
61
61
|
return this.internalGetTopView();
|
|
62
62
|
}
|
|
63
|
-
open(
|
|
64
|
-
|
|
65
|
-
return this.internalOpen(vt, args);
|
|
63
|
+
open(viewSymbol, args) {
|
|
64
|
+
return this.internalOpen(viewSymbol, args);
|
|
66
65
|
}
|
|
67
|
-
close(
|
|
68
|
-
this.internalClose(
|
|
66
|
+
close(viewSymbol, destory) {
|
|
67
|
+
this.internalClose(viewSymbol, destory);
|
|
69
68
|
}
|
|
70
|
-
openAndPush(
|
|
71
|
-
|
|
72
|
-
return this.internalOpenAndPush(vt, group, args);
|
|
69
|
+
openAndPush(viewSymbol, group, args) {
|
|
70
|
+
return this.internalOpenAndPush(viewSymbol, group, args);
|
|
73
71
|
}
|
|
74
72
|
closeAndPop(group, destroy) {
|
|
75
73
|
this.internalCloseAndPop(group, destroy);
|
|
@@ -104,7 +102,7 @@ class UIManager extends CcocosUIManager {
|
|
|
104
102
|
}
|
|
105
103
|
prototype = Object.getPrototypeOf(prototype);
|
|
106
104
|
}
|
|
107
|
-
throw new Error(`Prefab path not found for ${viewType.
|
|
105
|
+
throw new Error(`Prefab path not found for ${viewType.name}`);
|
|
108
106
|
}
|
|
109
107
|
// 调整Mask层级
|
|
110
108
|
_adjustMaskLayer() {
|
|
@@ -131,8 +129,9 @@ class UIManager extends CcocosUIManager {
|
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
|
-
_load(
|
|
132
|
+
_load(viewSymbol, args) {
|
|
135
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const viewType = getViewClass(viewSymbol);
|
|
136
135
|
let target;
|
|
137
136
|
if (this._cache.has(viewType.name)) {
|
|
138
137
|
target = this._cache.get(viewType.name);
|
|
@@ -148,30 +147,39 @@ class UIManager extends CcocosUIManager {
|
|
|
148
147
|
return target.getComponent(viewType);
|
|
149
148
|
});
|
|
150
149
|
}
|
|
151
|
-
_remove(
|
|
150
|
+
_remove(viewSymbolOrInstance, destroy) {
|
|
152
151
|
var _a;
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
// 如果是 symbol,从缓存中获取视图实例
|
|
153
|
+
if (typeof viewSymbolOrInstance === 'symbol') {
|
|
154
|
+
const viewType = getViewClass(viewSymbolOrInstance);
|
|
155
|
+
const cached = this._cache.get(viewType.name);
|
|
155
156
|
if (!cached) {
|
|
156
|
-
console.warn(`No cached view found for ${
|
|
157
|
+
console.warn(`No cached view found for ${viewType.name}`);
|
|
157
158
|
return;
|
|
158
159
|
}
|
|
159
|
-
|
|
160
|
+
const viewInstance = cached.getComponent(viewType);
|
|
161
|
+
if (!viewInstance) {
|
|
162
|
+
console.warn(`No view component found on node ${cached.name}`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this._remove(viewInstance, destroy);
|
|
160
166
|
return;
|
|
161
167
|
}
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
// 处理视图实例
|
|
169
|
+
const viewInstance = viewSymbolOrInstance;
|
|
170
|
+
if ('__group__' in viewInstance) {
|
|
171
|
+
viewInstance.__group__ = undefined;
|
|
164
172
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
viewInstance.onExit();
|
|
174
|
+
viewInstance.node.removeFromParent();
|
|
175
|
+
viewInstance.node.active = false;
|
|
168
176
|
if (destroy) {
|
|
169
|
-
let cacheKey =
|
|
177
|
+
let cacheKey = viewInstance.constructor.name;
|
|
170
178
|
(_a = this._cache.get(cacheKey)) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
171
179
|
this._cache.delete(cacheKey);
|
|
172
180
|
// 销毁被克隆出的UI后Node后,尝试释放 Prefab 资源
|
|
173
181
|
try {
|
|
174
|
-
const viewType =
|
|
182
|
+
const viewType = viewInstance.constructor;
|
|
175
183
|
const prefabPath = this._getPrefabPath(viewType);
|
|
176
184
|
const ResMgr = ServiceLocator.getService('ResLoader');
|
|
177
185
|
ResMgr.release(prefabPath, Prefab);
|
|
@@ -198,10 +206,10 @@ class UIManager extends CcocosUIManager {
|
|
|
198
206
|
console.warn(`No view found in ${target.name}`);
|
|
199
207
|
return undefined;
|
|
200
208
|
}
|
|
201
|
-
internalOpen(
|
|
209
|
+
internalOpen(viewSymbol, args) {
|
|
202
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
211
|
this._blockInput(true);
|
|
204
|
-
let view = yield this._load(
|
|
212
|
+
let view = yield this._load(viewSymbol, args);
|
|
205
213
|
addChild(view.node);
|
|
206
214
|
this._adjustMaskLayer();
|
|
207
215
|
view.onEnter(args);
|
|
@@ -209,14 +217,14 @@ class UIManager extends CcocosUIManager {
|
|
|
209
217
|
return view;
|
|
210
218
|
});
|
|
211
219
|
}
|
|
212
|
-
internalClose(
|
|
213
|
-
this._remove(
|
|
220
|
+
internalClose(viewSymbol, destroy) {
|
|
221
|
+
this._remove(viewSymbol, destroy);
|
|
214
222
|
this._adjustMaskLayer();
|
|
215
223
|
}
|
|
216
|
-
internalOpenAndPush(
|
|
224
|
+
internalOpenAndPush(viewSymbol, group, args) {
|
|
217
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
226
|
this._blockInput(true);
|
|
219
|
-
let view = yield this._load(
|
|
227
|
+
let view = yield this._load(viewSymbol, args);
|
|
220
228
|
let stack = this._groupStacks.get(group) || [];
|
|
221
229
|
this._groupStacks.set(group, stack);
|
|
222
230
|
let top = stack[stack.length - 1];
|
package/dist/libs/index.d.ts
CHANGED
package/dist/libs/index.js
CHANGED
|
@@ -6,3 +6,6 @@ export { UIManager } from './UIManager.js';
|
|
|
6
6
|
export { UIRoot } from './UIRoot.js';
|
|
7
7
|
export { HttpManager } from './HttpManager.js';
|
|
8
8
|
export { WebSocketManager } from './WebSocketManager.js';
|
|
9
|
+
export { RedDotManager } from './indicator/RedDotManager.js';
|
|
10
|
+
export { UIRedDot } from './indicator/UIRedDot.js';
|
|
11
|
+
export { RedDotNode } from './indicator/RedDotNode.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { IRedDotManager } from "../../core";
|
|
2
|
+
/**
|
|
3
|
+
* 红点管理器,管理整个游戏的红点系统
|
|
4
|
+
*/
|
|
5
|
+
export declare class RedDotManager implements IRedDotManager {
|
|
6
|
+
private _root;
|
|
7
|
+
private _nodeCache;
|
|
8
|
+
initialize(): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
/**
|
|
11
|
+
* 获取或创建红点节点
|
|
12
|
+
* @param path 节点路径,如 'main/bag/weapon'
|
|
13
|
+
*/
|
|
14
|
+
private _getOrCreateNode;
|
|
15
|
+
/**
|
|
16
|
+
* 设置红点数量
|
|
17
|
+
* @param path 节点路径
|
|
18
|
+
* @param count 红点数量
|
|
19
|
+
*/
|
|
20
|
+
setCount(path: string, count: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* 增加红点数量
|
|
23
|
+
* @param path 节点路径
|
|
24
|
+
* @param delta 增量(可以为负数)
|
|
25
|
+
*/
|
|
26
|
+
addCount(path: string, delta?: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* 获取红点数量(包含子节点)
|
|
29
|
+
* @param path 节点路径
|
|
30
|
+
*/
|
|
31
|
+
getCount(path: string): number;
|
|
32
|
+
/**
|
|
33
|
+
* 是否有红点
|
|
34
|
+
* @param path 节点路径
|
|
35
|
+
*/
|
|
36
|
+
hasRedDot(path: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* 清空红点
|
|
39
|
+
* @param path 节点路径
|
|
40
|
+
*/
|
|
41
|
+
clearRedDot(path: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* 添加监听器
|
|
44
|
+
* @param path 节点路径
|
|
45
|
+
* @param listener 监听函数 (totalCount, selfCount) => void
|
|
46
|
+
*/
|
|
47
|
+
on(path: string, listener: Function): void;
|
|
48
|
+
/**
|
|
49
|
+
* 移除监听器
|
|
50
|
+
* @param path 节点路径
|
|
51
|
+
* @param listener 监听函数
|
|
52
|
+
*/
|
|
53
|
+
off(path: string, listener: Function): void;
|
|
54
|
+
/**
|
|
55
|
+
* 标准化路径
|
|
56
|
+
*/
|
|
57
|
+
private _normalizePath;
|
|
58
|
+
}
|