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
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { RedDotNode } from './RedDotNode.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 红点管理器,管理整个游戏的红点系统
|
|
5
|
+
*/
|
|
6
|
+
class RedDotManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._root = null;
|
|
9
|
+
this._nodeCache = new Map();
|
|
10
|
+
}
|
|
11
|
+
initialize() {
|
|
12
|
+
this._root = new RedDotNode('root');
|
|
13
|
+
this._nodeCache.set('root', this._root);
|
|
14
|
+
console.log('RedDotManager 初始化完成');
|
|
15
|
+
}
|
|
16
|
+
dispose() {
|
|
17
|
+
this._root.destroy();
|
|
18
|
+
this._nodeCache.clear();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取或创建红点节点
|
|
22
|
+
* @param path 节点路径,如 'main/bag/weapon'
|
|
23
|
+
*/
|
|
24
|
+
_getOrCreateNode(path) {
|
|
25
|
+
// 标准化路径
|
|
26
|
+
path = this._normalizePath(path);
|
|
27
|
+
// 检查缓存
|
|
28
|
+
if (this._nodeCache.has(path)) {
|
|
29
|
+
return this._nodeCache.get(path);
|
|
30
|
+
}
|
|
31
|
+
// 分割路径
|
|
32
|
+
const parts = path.split('/');
|
|
33
|
+
let currentNode = this._root;
|
|
34
|
+
let currentPath = 'root';
|
|
35
|
+
// 逐级创建节点
|
|
36
|
+
for (const part of parts) {
|
|
37
|
+
if (!part)
|
|
38
|
+
continue;
|
|
39
|
+
currentPath = currentPath === 'root' ? part : `${currentPath}/${part}`;
|
|
40
|
+
let childNode = currentNode.getChild(part);
|
|
41
|
+
if (!childNode) {
|
|
42
|
+
childNode = new RedDotNode(currentPath);
|
|
43
|
+
currentNode.addChild(childNode);
|
|
44
|
+
this._nodeCache.set(currentPath, childNode);
|
|
45
|
+
}
|
|
46
|
+
currentNode = childNode;
|
|
47
|
+
}
|
|
48
|
+
return currentNode;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 设置红点数量
|
|
52
|
+
* @param path 节点路径
|
|
53
|
+
* @param count 红点数量
|
|
54
|
+
*/
|
|
55
|
+
setCount(path, count) {
|
|
56
|
+
const node = this._getOrCreateNode(path);
|
|
57
|
+
node.setCount(count);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 增加红点数量
|
|
61
|
+
* @param path 节点路径
|
|
62
|
+
* @param delta 增量(可以为负数)
|
|
63
|
+
*/
|
|
64
|
+
addCount(path, delta = 1) {
|
|
65
|
+
const node = this._getOrCreateNode(path);
|
|
66
|
+
node.addCount(delta);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 获取红点数量(包含子节点)
|
|
70
|
+
* @param path 节点路径
|
|
71
|
+
*/
|
|
72
|
+
getCount(path) {
|
|
73
|
+
const node = this._nodeCache.get(this._normalizePath(path));
|
|
74
|
+
return node ? node.getTotalCount() : 0;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 是否有红点
|
|
78
|
+
* @param path 节点路径
|
|
79
|
+
*/
|
|
80
|
+
hasRedDot(path) {
|
|
81
|
+
return this.getCount(path) > 0;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 清空红点
|
|
85
|
+
* @param path 节点路径
|
|
86
|
+
*/
|
|
87
|
+
clearRedDot(path) {
|
|
88
|
+
const node = this._nodeCache.get(this._normalizePath(path));
|
|
89
|
+
if (node) {
|
|
90
|
+
node.clear();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 添加监听器
|
|
95
|
+
* @param path 节点路径
|
|
96
|
+
* @param listener 监听函数 (totalCount, selfCount) => void
|
|
97
|
+
*/
|
|
98
|
+
on(path, listener) {
|
|
99
|
+
const node = this._getOrCreateNode(path);
|
|
100
|
+
node.addListener(listener);
|
|
101
|
+
// 立即触发一次,让监听者知道当前状态
|
|
102
|
+
listener(node.getTotalCount(), node.getCount());
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 移除监听器
|
|
106
|
+
* @param path 节点路径
|
|
107
|
+
* @param listener 监听函数
|
|
108
|
+
*/
|
|
109
|
+
off(path, listener) {
|
|
110
|
+
const node = this._nodeCache.get(this._normalizePath(path));
|
|
111
|
+
if (node) {
|
|
112
|
+
node.removeListener(listener);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 标准化路径
|
|
117
|
+
*/
|
|
118
|
+
_normalizePath(path) {
|
|
119
|
+
// 移除开头和结尾的斜杠
|
|
120
|
+
return path.replace(/^\/+|\/+$/g, '');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { RedDotManager };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 红点节点
|
|
3
|
+
* 采用树形结构,支持父子关系和自动向上传递
|
|
4
|
+
*/
|
|
5
|
+
export declare class RedDotNode {
|
|
6
|
+
private path;
|
|
7
|
+
private count;
|
|
8
|
+
private totalCount;
|
|
9
|
+
private parent;
|
|
10
|
+
private children;
|
|
11
|
+
private listeners;
|
|
12
|
+
constructor(path: string);
|
|
13
|
+
/**
|
|
14
|
+
* 获取路径
|
|
15
|
+
*/
|
|
16
|
+
getPath(): string;
|
|
17
|
+
/**
|
|
18
|
+
* 设置红点数量(只影响当前节点)
|
|
19
|
+
*/
|
|
20
|
+
setCount(count: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* 增加红点数量
|
|
23
|
+
*/
|
|
24
|
+
addCount(delta: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* 获取红点数量(只包含自身)
|
|
27
|
+
*/
|
|
28
|
+
getCount(): number;
|
|
29
|
+
/**
|
|
30
|
+
* 获取总红点数量(包含所有子节点)
|
|
31
|
+
*/
|
|
32
|
+
getTotalCount(): number;
|
|
33
|
+
/**
|
|
34
|
+
* 是否有红点(包含子节点)
|
|
35
|
+
*/
|
|
36
|
+
hasRedDot(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* 添加子节点
|
|
39
|
+
*/
|
|
40
|
+
addChild(child: RedDotNode): void;
|
|
41
|
+
/**
|
|
42
|
+
* 获取子节点
|
|
43
|
+
*/
|
|
44
|
+
getChild(name: string): RedDotNode | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* 添加监听器
|
|
47
|
+
*/
|
|
48
|
+
addListener(listener: Function): void;
|
|
49
|
+
/**
|
|
50
|
+
* 移除监听器
|
|
51
|
+
*/
|
|
52
|
+
removeListener(listener: Function): void;
|
|
53
|
+
/**
|
|
54
|
+
* 更新总数(包含所有子节点)
|
|
55
|
+
*/
|
|
56
|
+
private updateTotalCount;
|
|
57
|
+
/**
|
|
58
|
+
* 通知所有监听器
|
|
59
|
+
*/
|
|
60
|
+
private notifyListeners;
|
|
61
|
+
/**
|
|
62
|
+
* 清空红点(包含所有子节点)
|
|
63
|
+
*/
|
|
64
|
+
clear(): void;
|
|
65
|
+
/**
|
|
66
|
+
* 销毁节点
|
|
67
|
+
*/
|
|
68
|
+
destroy(): void;
|
|
69
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 红点节点
|
|
3
|
+
* 采用树形结构,支持父子关系和自动向上传递
|
|
4
|
+
*/
|
|
5
|
+
class RedDotNode {
|
|
6
|
+
constructor(path) {
|
|
7
|
+
this.count = 0; // 红点数量(自身)
|
|
8
|
+
this.totalCount = 0; // 红点数量(包含子节点)
|
|
9
|
+
this.parent = null; // 父节点
|
|
10
|
+
this.children = new Map(); // 子节点
|
|
11
|
+
this.listeners = new Set(); // 监听器
|
|
12
|
+
this.path = path;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 获取路径
|
|
16
|
+
*/
|
|
17
|
+
getPath() {
|
|
18
|
+
return this.path;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 设置红点数量(只影响当前节点)
|
|
22
|
+
*/
|
|
23
|
+
setCount(count) {
|
|
24
|
+
if (this.count === count)
|
|
25
|
+
return;
|
|
26
|
+
this.count;
|
|
27
|
+
this.count = Math.max(0, count);
|
|
28
|
+
// 重新计算总数
|
|
29
|
+
this.updateTotalCount();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 增加红点数量
|
|
33
|
+
*/
|
|
34
|
+
addCount(delta) {
|
|
35
|
+
this.setCount(this.count + delta);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 获取红点数量(只包含自身)
|
|
39
|
+
*/
|
|
40
|
+
getCount() {
|
|
41
|
+
return this.count;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 获取总红点数量(包含所有子节点)
|
|
45
|
+
*/
|
|
46
|
+
getTotalCount() {
|
|
47
|
+
return this.totalCount;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 是否有红点(包含子节点)
|
|
51
|
+
*/
|
|
52
|
+
hasRedDot() {
|
|
53
|
+
return this.totalCount > 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 添加子节点
|
|
57
|
+
*/
|
|
58
|
+
addChild(child) {
|
|
59
|
+
const childName = child.getPath().split('/').pop();
|
|
60
|
+
this.children.set(childName, child);
|
|
61
|
+
child.parent = this;
|
|
62
|
+
// 子节点变化时,更新自己的总数
|
|
63
|
+
this.updateTotalCount();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 获取子节点
|
|
67
|
+
*/
|
|
68
|
+
getChild(name) {
|
|
69
|
+
return this.children.get(name);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 添加监听器
|
|
73
|
+
*/
|
|
74
|
+
addListener(listener) {
|
|
75
|
+
this.listeners.add(listener);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 移除监听器
|
|
79
|
+
*/
|
|
80
|
+
removeListener(listener) {
|
|
81
|
+
this.listeners.delete(listener);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 更新总数(包含所有子节点)
|
|
85
|
+
*/
|
|
86
|
+
updateTotalCount() {
|
|
87
|
+
const oldTotalCount = this.totalCount;
|
|
88
|
+
// 计算新的总数:自身数量 + 所有子节点的总数
|
|
89
|
+
let newTotalCount = this.count;
|
|
90
|
+
this.children.forEach(child => {
|
|
91
|
+
newTotalCount += child.getTotalCount();
|
|
92
|
+
});
|
|
93
|
+
this.totalCount = newTotalCount;
|
|
94
|
+
// 如果总数发生变化
|
|
95
|
+
if (oldTotalCount !== newTotalCount) {
|
|
96
|
+
// 通知监听器
|
|
97
|
+
this.notifyListeners();
|
|
98
|
+
// 向上传递给父节点
|
|
99
|
+
if (this.parent) {
|
|
100
|
+
this.parent.updateTotalCount();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 通知所有监听器
|
|
106
|
+
*/
|
|
107
|
+
notifyListeners() {
|
|
108
|
+
this.listeners.forEach(listener => {
|
|
109
|
+
try {
|
|
110
|
+
listener(this.totalCount, this.count);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error(`红点监听器执行错误 [${this.path}]:`, error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 清空红点(包含所有子节点)
|
|
119
|
+
*/
|
|
120
|
+
clear() {
|
|
121
|
+
this.setCount(0);
|
|
122
|
+
this.children.forEach(child => child.clear());
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 销毁节点
|
|
126
|
+
*/
|
|
127
|
+
destroy() {
|
|
128
|
+
this.listeners.clear();
|
|
129
|
+
this.children.forEach(child => child.destroy());
|
|
130
|
+
this.children.clear();
|
|
131
|
+
this.parent = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { RedDotNode };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component, Node, Label } from 'cc';
|
|
2
|
+
/**
|
|
3
|
+
* 红点显示组件
|
|
4
|
+
* 挂载到需要显示红点的 UI 节点上
|
|
5
|
+
*/
|
|
6
|
+
export declare class UIRedDot extends Component {
|
|
7
|
+
redDotNode: Node;
|
|
8
|
+
showCount: boolean;
|
|
9
|
+
countLabel: Label | null;
|
|
10
|
+
maxCount: number;
|
|
11
|
+
redDotPath: string;
|
|
12
|
+
private _listener;
|
|
13
|
+
onLoad(): void;
|
|
14
|
+
start(): void;
|
|
15
|
+
onDestroy(): void;
|
|
16
|
+
/**
|
|
17
|
+
* 绑定红点路径
|
|
18
|
+
*/
|
|
19
|
+
bindPath(path: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* 解绑
|
|
22
|
+
*/
|
|
23
|
+
unbind(): void;
|
|
24
|
+
/**
|
|
25
|
+
* 更新显示
|
|
26
|
+
*/
|
|
27
|
+
private _updateDisplay;
|
|
28
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { __decorate, __metadata } from '../../_virtual/_tslib.js';
|
|
2
|
+
import { _decorator, Node, Label, Component } from 'cc';
|
|
3
|
+
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
/**
|
|
6
|
+
* 红点显示组件
|
|
7
|
+
* 挂载到需要显示红点的 UI 节点上
|
|
8
|
+
*/
|
|
9
|
+
let UIRedDot = class UIRedDot extends Component {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.redDotNode = null; // 红点节点(圆点或图标)
|
|
13
|
+
this.showCount = true;
|
|
14
|
+
this.countLabel = null; // 数字标签(可选)
|
|
15
|
+
this.maxCount = 99;
|
|
16
|
+
this.redDotPath = '';
|
|
17
|
+
this._listener = null;
|
|
18
|
+
}
|
|
19
|
+
onLoad() {
|
|
20
|
+
if (!this.redDotNode) {
|
|
21
|
+
console.error('RedDotComponent: redDotNode 未设置');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// 初始时隐藏红点
|
|
25
|
+
this.redDotNode.active = false;
|
|
26
|
+
}
|
|
27
|
+
start() {
|
|
28
|
+
if (this.redDotPath) {
|
|
29
|
+
this.bindPath(this.redDotPath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
onDestroy() {
|
|
33
|
+
this.unbind();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 绑定红点路径
|
|
37
|
+
*/
|
|
38
|
+
bindPath(path) {
|
|
39
|
+
this.unbind();
|
|
40
|
+
this.redDotPath = path;
|
|
41
|
+
// 创建监听器
|
|
42
|
+
this._listener = (totalCount, selfCount) => {
|
|
43
|
+
this._updateDisplay(totalCount);
|
|
44
|
+
};
|
|
45
|
+
// 添加监听
|
|
46
|
+
mf.reddot.on(path, this._listener);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 解绑
|
|
50
|
+
*/
|
|
51
|
+
unbind() {
|
|
52
|
+
if (this._listener && this.redDotPath) {
|
|
53
|
+
mf.reddot.off(this.redDotPath, this._listener);
|
|
54
|
+
this._listener = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 更新显示
|
|
59
|
+
*/
|
|
60
|
+
_updateDisplay(count) {
|
|
61
|
+
if (!this.redDotNode)
|
|
62
|
+
return;
|
|
63
|
+
// 显示/隐藏红点
|
|
64
|
+
this.redDotNode.active = count > 0;
|
|
65
|
+
// 更新数字
|
|
66
|
+
if (this.countLabel && this.showCount) {
|
|
67
|
+
if (count > this.maxCount) {
|
|
68
|
+
this.countLabel.string = `${this.maxCount}+`;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.countLabel.string = count.toString();
|
|
72
|
+
}
|
|
73
|
+
this.countLabel.node.active = count > 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__decorate([
|
|
78
|
+
property(Node),
|
|
79
|
+
__metadata("design:type", Node)
|
|
80
|
+
], UIRedDot.prototype, "redDotNode", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
property({ tooltip: '是否显示数字' }),
|
|
83
|
+
__metadata("design:type", Boolean)
|
|
84
|
+
], UIRedDot.prototype, "showCount", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
property(Label),
|
|
87
|
+
__metadata("design:type", Object)
|
|
88
|
+
], UIRedDot.prototype, "countLabel", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
property({ tooltip: '最大显示数字,超过显示 99+' }),
|
|
91
|
+
__metadata("design:type", Number)
|
|
92
|
+
], UIRedDot.prototype, "maxCount", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
property({ tooltip: '红点路径,如 main/bag/weapon' }),
|
|
95
|
+
__metadata("design:type", String)
|
|
96
|
+
], UIRedDot.prototype, "redDotPath", void 0);
|
|
97
|
+
UIRedDot = __decorate([
|
|
98
|
+
ccclass('UIRedDot')
|
|
99
|
+
], UIRedDot);
|
|
100
|
+
|
|
101
|
+
export { UIRedDot };
|
package/dist/mflow-tools.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED