@cc-component/cc-core 1.2.8
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/.cc-ex-component.md +12 -0
- package/assets/core/config/CommonEnum.ts +94 -0
- package/assets/core/config/CommonEnum.ts.meta +9 -0
- package/assets/core/config/IConfig.ts +89 -0
- package/assets/core/config/IConfig.ts.meta +9 -0
- package/assets/core/config/LayerType.ts +44 -0
- package/assets/core/config/LayerType.ts.meta +9 -0
- package/assets/core/config/LayerUI.ts +113 -0
- package/assets/core/config/LayerUI.ts.meta +9 -0
- package/assets/core/config.meta +9 -0
- package/assets/core/editor/LanguageManager.ts +323 -0
- package/assets/core/editor/LanguageManager.ts.meta +9 -0
- package/assets/core/editor/SpineRunner.ts +39 -0
- package/assets/core/editor/SpineRunner.ts.meta +9 -0
- package/assets/core/editor/i18nEditorComponent.ts +137 -0
- package/assets/core/editor/i18nEditorComponent.ts.meta +9 -0
- package/assets/core/editor.meta +9 -0
- package/assets/core/home/AudioUtil.ts +164 -0
- package/assets/core/home/AudioUtil.ts.meta +9 -0
- package/assets/core/home/BaseBoxView.ts +60 -0
- package/assets/core/home/BaseBoxView.ts.meta +9 -0
- package/assets/core/home/BaseLaunchComponent.ts +9 -0
- package/assets/core/home/BaseLaunchComponent.ts.meta +9 -0
- package/assets/core/home/BaseLoading.ts +136 -0
- package/assets/core/home/BaseLoading.ts.meta +9 -0
- package/assets/core/home/BaseSkeleton.ts +39 -0
- package/assets/core/home/BaseSkeleton.ts.meta +9 -0
- package/assets/core/home/CameraAngel.ts +326 -0
- package/assets/core/home/CameraAngel.ts.meta +9 -0
- package/assets/core/home/DouYinShow.ts +27 -0
- package/assets/core/home/DouYinShow.ts.meta +9 -0
- package/assets/core/home/EventManager.ts +39 -0
- package/assets/core/home/EventManager.ts.meta +9 -0
- package/assets/core/home/ExView.ts +9 -0
- package/assets/core/home/ExView.ts.meta +9 -0
- package/assets/core/home/FollowCamera.ts +205 -0
- package/assets/core/home/FollowCamera.ts.meta +9 -0
- package/assets/core/home/InViewCenter.ts +52 -0
- package/assets/core/home/InViewCenter.ts.meta +9 -0
- package/assets/core/home/JsonUtil.ts +102 -0
- package/assets/core/home/JsonUtil.ts.meta +9 -0
- package/assets/core/home/LoadingWindow.ts +44 -0
- package/assets/core/home/LoadingWindow.ts.meta +9 -0
- package/assets/core/home/ParabolaTween.ts +110 -0
- package/assets/core/home/ParabolaTween.ts.meta +9 -0
- package/assets/core/home/ProgessView.ts +96 -0
- package/assets/core/home/ProgessView.ts.meta +9 -0
- package/assets/core/home/Quaternion.ts +237 -0
- package/assets/core/home/Quaternion.ts.meta +9 -0
- package/assets/core/home/ResUtil.ts +132 -0
- package/assets/core/home/ResUtil.ts.meta +9 -0
- package/assets/core/home/ResourceManager.ts +430 -0
- package/assets/core/home/ResourceManager.ts.meta +9 -0
- package/assets/core/home/StateMachine.ts +93 -0
- package/assets/core/home/StateMachine.ts.meta +9 -0
- package/assets/core/home/StorageManager.ts +161 -0
- package/assets/core/home/StorageManager.ts.meta +9 -0
- package/assets/core/home/ThirdFreeLookCamera.ts +201 -0
- package/assets/core/home/ThirdFreeLookCamera.ts.meta +9 -0
- package/assets/core/home/TimeManager.ts +486 -0
- package/assets/core/home/TimeManager.ts.meta +9 -0
- package/assets/core/home/Tools.ts +103 -0
- package/assets/core/home/Tools.ts.meta +9 -0
- package/assets/core/home/prefabs.meta +12 -0
- package/assets/core/home/util/EncryptUtil.ts +60 -0
- package/assets/core/home/util/EncryptUtil.ts.meta +11 -0
- package/assets/core/home/util/MathUtil.ts +22 -0
- package/assets/core/home/util/MathUtil.ts.meta +9 -0
- package/assets/core/home/util/Md5.ts +202 -0
- package/assets/core/home/util/Md5.ts.meta +11 -0
- package/assets/core/home/util/RandomUtil.ts +61 -0
- package/assets/core/home/util/RandomUtil.ts.meta +9 -0
- package/assets/core/home/util/ResUtil.ts +129 -0
- package/assets/core/home/util/ResUtil.ts.meta +9 -0
- package/assets/core/home/util/crypto-js.d.ts +30 -0
- package/assets/core/home/util/crypto-js.d.ts.meta +11 -0
- package/assets/core/home/util/crypto-js.js +6030 -0
- package/assets/core/home/util/crypto-js.js.meta +9 -0
- package/assets/core/home/util.meta +12 -0
- package/assets/core/home.meta +12 -0
- package/assets/core/interface/ISceneParam.ts +11 -0
- package/assets/core/interface/ISceneParam.ts.meta +9 -0
- package/assets/core/interface/Interface.ts +160 -0
- package/assets/core/interface/Interface.ts.meta +1 -0
- package/assets/core/interface/MainModule.ts +1019 -0
- package/assets/core/interface/MainModule.ts.meta +9 -0
- package/assets/core/interface.meta +9 -0
- package/assets/core/lib/Logger.ts +286 -0
- package/assets/core/lib/Logger.ts.meta +9 -0
- package/assets/core/lib/language/.language.md +1 -0
- package/assets/core/lib/language/Language.ts +133 -0
- package/assets/core/lib/language/Language.ts.meta +13 -0
- package/assets/core/lib/language/LanguageData.ts +114 -0
- package/assets/core/lib/language/LanguageData.ts.meta +9 -0
- package/assets/core/lib/language/LanguageLabel.ts +172 -0
- package/assets/core/lib/language/LanguageLabel.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePack.ts +126 -0
- package/assets/core/lib/language/LanguagePack.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePointLabel.ts.meta +16 -0
- package/assets/core/lib/language/LanguageSpine.ts +60 -0
- package/assets/core/lib/language/LanguageSpine.ts.meta +9 -0
- package/assets/core/lib/language/LanguageSprite.ts +138 -0
- package/assets/core/lib/language/LanguageSprite.ts.meta +13 -0
- package/assets/core/lib/language.meta +9 -0
- package/assets/core/lib/logger/ELoggerLevel.ts +16 -0
- package/assets/core/lib/logger/ELoggerLevel.ts.meta +9 -0
- package/assets/core/lib/logger/MLogger.ts +118 -0
- package/assets/core/lib/logger/MLogger.ts.meta +9 -0
- package/assets/core/lib/logger.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts +2729 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js +8 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts +102 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js +222 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto +6 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto +12 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/base.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/base.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/command.proto +31 -0
- package/assets/core/lib/net/libs/proto/source/command.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto +13 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto +26 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto +23 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto +43 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/push.meta +9 -0
- package/assets/core/lib/net/libs/proto/source.meta +12 -0
- package/assets/core/lib/net/libs/proto.meta +9 -0
- package/assets/core/lib/net/libs.meta +9 -0
- package/assets/core/lib/net/net/HttpManager.ts +307 -0
- package/assets/core/lib/net/net/HttpManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetInterface.ts +114 -0
- package/assets/core/lib/net/net/NetInterface.ts.meta +9 -0
- package/assets/core/lib/net/net/NetManager.ts +77 -0
- package/assets/core/lib/net/net/NetManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetNode.ts +471 -0
- package/assets/core/lib/net/net/NetNode.ts.meta +9 -0
- package/assets/core/lib/net/net/WebSock.ts +81 -0
- package/assets/core/lib/net/net/WebSock.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts +41 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts +11 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts +4 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts +53 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts +105 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts.meta +9 -0
- package/assets/core/lib/net/net/custom.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts +39 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts +85 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol.meta +9 -0
- package/assets/core/lib/net/net.meta +9 -0
- package/assets/core/lib/net/prompt.meta +9 -0
- package/assets/core/lib/net.meta +9 -0
- package/assets/core/lib/old/VM2.ts +619 -0
- package/assets/core/lib/old/VM2.ts.meta +9 -0
- package/assets/core/lib/old/ViewModel.ts +905 -0
- package/assets/core/lib/old/ViewModel.ts.meta +9 -0
- package/assets/core/lib/old/ViewSearch.ts +125 -0
- package/assets/core/lib/old/ViewSearch.ts.meta +9 -0
- package/assets/core/lib/old.meta +9 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts +113 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarController.ts +86 -0
- package/assets/core/lib/tabbar/TabBarController.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarItem.ts +52 -0
- package/assets/core/lib/tabbar/TabBarItem.ts.meta +9 -0
- package/assets/core/lib/tabbar.meta +9 -0
- package/assets/core/lib.meta +12 -0
- package/assets/core.meta +9 -0
- package/assets.meta +9 -0
- package/index.ts +3 -0
- package/index.ts.meta +9 -0
- package/package.json +19 -0
- package/package.json.meta +11 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
// TimeManager.ts - 多视图倒计时管理器
|
|
2
|
+
|
|
3
|
+
import { game } from "cc";
|
|
4
|
+
import { Component } from "cc";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 倒计时管理器 - 支持多个视图同时显示不同的倒计时
|
|
9
|
+
*/
|
|
10
|
+
export class TimeManager {
|
|
11
|
+
private countdowns: Map<string, CountdownInfo> = new Map();
|
|
12
|
+
timers = new Map();
|
|
13
|
+
|
|
14
|
+
/** 服务器时间 */
|
|
15
|
+
private date_s: Date = new Date();
|
|
16
|
+
/** 服务器初始时间 */
|
|
17
|
+
private date_s_start: Date = new Date();
|
|
18
|
+
/** 服务器时间后修正时间 */
|
|
19
|
+
private polymeric_s: number = 0;
|
|
20
|
+
/** 客户端时间 */
|
|
21
|
+
private date_c: Date = new Date();
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 创建或更新倒计时
|
|
30
|
+
* @param key 倒计时唯一标识符
|
|
31
|
+
* @param minutes 倒计时分钟数 (例如: 30表示30分钟, 20表示20分钟)
|
|
32
|
+
* @param onTick 倒计时更新回调
|
|
33
|
+
* @param onComplete 倒计时完成回调
|
|
34
|
+
* @param autoStart 是否自动开始,默认true
|
|
35
|
+
*/
|
|
36
|
+
start(
|
|
37
|
+
key: string,
|
|
38
|
+
minutes: number,
|
|
39
|
+
onTick?: (remaining: number, formattedTime: string) => void,
|
|
40
|
+
onComplete?: () => void,
|
|
41
|
+
autoStart: boolean = true
|
|
42
|
+
): CountdownTimer {
|
|
43
|
+
// 如果已存在相同key的倒计时,先停止它
|
|
44
|
+
if (this.countdowns.has(key)) {
|
|
45
|
+
this.removeCountdown(key);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const timer = new CountdownTimer(minutes, onTick, onComplete);
|
|
49
|
+
const countdownInfo: CountdownInfo = {
|
|
50
|
+
timer,
|
|
51
|
+
minutes,
|
|
52
|
+
onTick,
|
|
53
|
+
onComplete
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
this.countdowns.set(key, countdownInfo);
|
|
57
|
+
|
|
58
|
+
if (!autoStart) {
|
|
59
|
+
timer.pause();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return timer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 创建30分钟倒计时
|
|
67
|
+
* @param key 倒计时唯一标识符
|
|
68
|
+
* @param onTick 倒计时更新回调
|
|
69
|
+
* @param onComplete 倒计时完成回调
|
|
70
|
+
*/
|
|
71
|
+
setup30MinCountdown(
|
|
72
|
+
key: string,
|
|
73
|
+
onTick?: (remaining: number, formattedTime: string) => void,
|
|
74
|
+
onComplete?: () => void
|
|
75
|
+
): CountdownTimer {
|
|
76
|
+
return this.start(key, 30, onTick, onComplete);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 创建20分钟倒计时
|
|
81
|
+
* @param key 倒计时唯一标识符
|
|
82
|
+
* @param onTick 倒计时更新回调
|
|
83
|
+
* @param onComplete 倒计时完成回调
|
|
84
|
+
*/
|
|
85
|
+
setup20MinCountdown(
|
|
86
|
+
key: string,
|
|
87
|
+
onTick?: (remaining: number, formattedTime: string) => void,
|
|
88
|
+
onComplete?: () => void
|
|
89
|
+
): CountdownTimer {
|
|
90
|
+
return this.start(key, 20, onTick, onComplete);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 更新现有倒计时的时间
|
|
95
|
+
* @param key 倒计时唯一标识符
|
|
96
|
+
* @param minutes 新的分钟数
|
|
97
|
+
*/
|
|
98
|
+
updateCountdownTime(key: string, minutes: number): boolean {
|
|
99
|
+
const countdownInfo = this.countdowns.get(key);
|
|
100
|
+
if (!countdownInfo) {
|
|
101
|
+
console.warn(`倒计时 ${key} 不存在`);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 保存当前状态
|
|
106
|
+
const wasPaused = countdownInfo.timer.isPaused();
|
|
107
|
+
const elapsed = countdownInfo.timer.getElapsedSeconds();
|
|
108
|
+
|
|
109
|
+
// 停止当前倒计时
|
|
110
|
+
countdownInfo.timer.stop();
|
|
111
|
+
|
|
112
|
+
// 创建新的倒计时
|
|
113
|
+
const newTimer = new CountdownTimer(
|
|
114
|
+
minutes,
|
|
115
|
+
countdownInfo.onTick,
|
|
116
|
+
countdownInfo.onComplete
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// 如果之前已暂停,则新倒计时也暂停
|
|
120
|
+
if (wasPaused) {
|
|
121
|
+
newTimer.pause();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 更新存储信息
|
|
125
|
+
countdownInfo.timer = newTimer;
|
|
126
|
+
countdownInfo.minutes = minutes;
|
|
127
|
+
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 暂停倒计时
|
|
133
|
+
* @param key 倒计时唯一标识符
|
|
134
|
+
*/
|
|
135
|
+
pauseCountdown(key: string): boolean {
|
|
136
|
+
const countdownInfo = this.countdowns.get(key);
|
|
137
|
+
if (countdownInfo) {
|
|
138
|
+
countdownInfo.timer.pause();
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 恢复倒计时
|
|
146
|
+
* @param key 倒计时唯一标识符
|
|
147
|
+
*/
|
|
148
|
+
resumeCountdown(key: string): boolean {
|
|
149
|
+
const countdownInfo = this.countdowns.get(key);
|
|
150
|
+
if (countdownInfo) {
|
|
151
|
+
countdownInfo.timer.resume();
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 停止并移除倒计时
|
|
159
|
+
* @param key 倒计时唯一标识符
|
|
160
|
+
*/
|
|
161
|
+
removeCountdown(key: string): boolean {
|
|
162
|
+
const countdownInfo = this.countdowns.get(key);
|
|
163
|
+
if (countdownInfo) {
|
|
164
|
+
countdownInfo.timer.stop();
|
|
165
|
+
this.countdowns.delete(key);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 获取倒计时对象
|
|
173
|
+
* @param key 倒计时唯一标识符
|
|
174
|
+
*/
|
|
175
|
+
getCountdown(key: string): CountdownTimer | undefined {
|
|
176
|
+
const countdownInfo = this.countdowns.get(key);
|
|
177
|
+
return countdownInfo ? countdownInfo.timer : undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public formatTime(seconds: number): string {
|
|
181
|
+
const hours = Math.floor(seconds / 3600);
|
|
182
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
183
|
+
const secs = seconds % 60;
|
|
184
|
+
|
|
185
|
+
if (hours > 0) {
|
|
186
|
+
return `${padStart(hours, 2)}:${padStart(minutes, 2)}:${padStart(secs, 2)}`;
|
|
187
|
+
} else {
|
|
188
|
+
return `${padStart(minutes, 2)}:${padStart(secs, 2)}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 获取所有倒计时的键名
|
|
194
|
+
*/
|
|
195
|
+
getAllCountdownKeys(): string[] {
|
|
196
|
+
return Array.from(this.countdowns.keys());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 停止所有倒计时
|
|
201
|
+
*/
|
|
202
|
+
removeAllCountdowns(): void {
|
|
203
|
+
this.countdowns.forEach(info => info.timer.stop());
|
|
204
|
+
this.countdowns.clear();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 检查倒计时是否存在
|
|
209
|
+
* @param key 倒计时唯一标识符
|
|
210
|
+
*/
|
|
211
|
+
hasCountdown(key: string): boolean {
|
|
212
|
+
return this.countdowns.has(key);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#region 暂停和恢复计时器
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
setTimeout(callback, delay) {
|
|
220
|
+
const timerId = window.setTimeout(() => {
|
|
221
|
+
callback();
|
|
222
|
+
this.timers.delete(timerId); // 定时器执行后,从Map中删除
|
|
223
|
+
}, delay);
|
|
224
|
+
|
|
225
|
+
this.timers.set(timerId, () => window.clearTimeout(timerId));
|
|
226
|
+
return timerId;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
clearTimeout(timerId) {
|
|
230
|
+
if (this.timers.has(timerId)) {
|
|
231
|
+
this.timers.get(timerId)();
|
|
232
|
+
this.timers.delete(timerId); // 从Map中删除定时器
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
clearAllTimeouts() {
|
|
237
|
+
this.timers.forEach(clearFn => clearFn()); // 调用所有清除函数
|
|
238
|
+
this.timers.clear(); // 清空Map
|
|
239
|
+
}
|
|
240
|
+
setTimeCount(interval: number, times: number, callback: () => void): void {
|
|
241
|
+
let count = 0;
|
|
242
|
+
const timerId = window.setInterval(() => {
|
|
243
|
+
if (count < times) {
|
|
244
|
+
callback();
|
|
245
|
+
count++;
|
|
246
|
+
} else {
|
|
247
|
+
window.clearInterval(timerId);
|
|
248
|
+
this.timers.delete(timerId); // 清除定时器后,从Map中删除
|
|
249
|
+
}
|
|
250
|
+
}, interval);
|
|
251
|
+
|
|
252
|
+
this.timers.set(timerId, () => window.clearInterval(timerId));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
/**等代秒*/
|
|
258
|
+
async Await(time: number, com?: Component): Promise<void> {
|
|
259
|
+
var promise = new Promise<void>(resolve => {
|
|
260
|
+
if (com) {
|
|
261
|
+
com.scheduleOnce(resolve, time)
|
|
262
|
+
} else {
|
|
263
|
+
setTimeout(resolve, time * 1000)
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return promise;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**等代毫秒*/
|
|
270
|
+
async AwaitMS(time: number): Promise<void> {
|
|
271
|
+
var promise = new Promise<void>(resolve => {
|
|
272
|
+
setTimeout(resolve, time)
|
|
273
|
+
});
|
|
274
|
+
return promise;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
//#region 时间同步
|
|
278
|
+
/**
|
|
279
|
+
* 服务器时间与本地时间同步
|
|
280
|
+
* @param value 服务器时间刻度
|
|
281
|
+
*/
|
|
282
|
+
setServerTime(value: number): void {
|
|
283
|
+
this.polymeric_s = this.getTime();
|
|
284
|
+
this.date_s_start.setTime(value);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** 获取写服务器同步的时间刻度 */
|
|
288
|
+
getServerTime(): number {
|
|
289
|
+
return this.date_s_start.getTime() + this.getTime() - this.polymeric_s;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** 获取服务器时间对象 */
|
|
293
|
+
getServerDate(): Date {
|
|
294
|
+
this.date_s.setTime(this.getServerTime());
|
|
295
|
+
return this.date_s;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** 获取本地时间刻度 */
|
|
299
|
+
getClientTime(): number {
|
|
300
|
+
return Date.now();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** 获取本地时间对象 */
|
|
304
|
+
getClientDate(): Date {
|
|
305
|
+
this.date_c.setTime(this.getClientTime());
|
|
306
|
+
return this.date_c;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 获取游戏开始到现在逝去的时间 */
|
|
310
|
+
getTime(): number {
|
|
311
|
+
return game.totalTime;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// 倒计时信息接口
|
|
317
|
+
interface CountdownInfo {
|
|
318
|
+
timer: CountdownTimer;
|
|
319
|
+
minutes: number;
|
|
320
|
+
onTick?: (remaining: number, formattedTime: string) => void;
|
|
321
|
+
onComplete?: () => void;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 字符串补零工具函数(替代 padStart)
|
|
326
|
+
* @param str 要补零的字符串
|
|
327
|
+
* @param targetLength 目标长度
|
|
328
|
+
* @param padString 补充字符,默认为'0'
|
|
329
|
+
*/
|
|
330
|
+
function padStart(str: string | number, targetLength: number, padString: string = '0'): string {
|
|
331
|
+
let result = String(str);
|
|
332
|
+
while (result.length < targetLength) {
|
|
333
|
+
result = padString + result;
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 倒计时计时器类
|
|
340
|
+
*/
|
|
341
|
+
export class CountdownTimer {
|
|
342
|
+
private endTime: number;
|
|
343
|
+
private intervalId: any = null;
|
|
344
|
+
private paused: boolean = false;
|
|
345
|
+
private pauseTime: number = 0;
|
|
346
|
+
private remainingWhenPaused: number = 0;
|
|
347
|
+
private onTick?: (remaining: number, formattedTime: string) => void;
|
|
348
|
+
private onComplete?: () => void;
|
|
349
|
+
private totalSeconds: number;
|
|
350
|
+
private startTime: number;
|
|
351
|
+
|
|
352
|
+
constructor(
|
|
353
|
+
seconds: number,
|
|
354
|
+
onTick?: (remaining: number, formattedTime: string) => void,
|
|
355
|
+
onComplete?: () => void
|
|
356
|
+
) {
|
|
357
|
+
this.totalSeconds = seconds;
|
|
358
|
+
this.onTick = onTick;
|
|
359
|
+
this.onComplete = onComplete;
|
|
360
|
+
this.startTime = Date.now();
|
|
361
|
+
this.endTime = this.startTime + (seconds * 1000);
|
|
362
|
+
this.start();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
private start() {
|
|
366
|
+
// 立即触发一次回调
|
|
367
|
+
this.tick();
|
|
368
|
+
|
|
369
|
+
this.intervalId = setInterval(() => {
|
|
370
|
+
this.tick();
|
|
371
|
+
}, 1000);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
private tick() {
|
|
375
|
+
if (this.paused) return;
|
|
376
|
+
|
|
377
|
+
const now = Date.now();
|
|
378
|
+
const remaining = Math.max(0, Math.ceil((this.endTime - now) / 1000));
|
|
379
|
+
|
|
380
|
+
const formattedTime = this.formatTime(remaining);
|
|
381
|
+
|
|
382
|
+
if (this.onTick) {
|
|
383
|
+
this.onTick(remaining, formattedTime);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (remaining <= 0) {
|
|
387
|
+
if (this.onComplete) {
|
|
388
|
+
this.onComplete();
|
|
389
|
+
}
|
|
390
|
+
this.stop();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
public formatTime(seconds: number): string {
|
|
395
|
+
const hours = Math.floor(seconds / 3600);
|
|
396
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
397
|
+
const secs = seconds % 60;
|
|
398
|
+
|
|
399
|
+
if (hours > 0) {
|
|
400
|
+
return `${padStart(hours, 2)}:${padStart(minutes, 2)}:${padStart(secs, 2)}`;
|
|
401
|
+
} else {
|
|
402
|
+
return `${padStart(minutes, 2)}:${padStart(secs, 2)}`;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 暂停倒计时
|
|
408
|
+
*/
|
|
409
|
+
pause(): void {
|
|
410
|
+
if (!this.paused) {
|
|
411
|
+
this.paused = true;
|
|
412
|
+
this.pauseTime = Date.now();
|
|
413
|
+
this.remainingWhenPaused = Math.max(0, Math.floor((this.endTime - this.pauseTime) / 1000));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* 恢复倒计时
|
|
419
|
+
*/
|
|
420
|
+
resume(): void {
|
|
421
|
+
if (this.paused) {
|
|
422
|
+
this.paused = false;
|
|
423
|
+
const timePassed = Date.now() - this.pauseTime;
|
|
424
|
+
this.endTime += timePassed; // 调整结束时间以补偿暂停期间
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 停止并清理倒计时
|
|
430
|
+
*/
|
|
431
|
+
stop(): void {
|
|
432
|
+
if (this.intervalId) {
|
|
433
|
+
clearInterval(this.intervalId);
|
|
434
|
+
this.intervalId = null;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* 获取剩余秒数
|
|
440
|
+
*/
|
|
441
|
+
getRemainingSeconds(): number {
|
|
442
|
+
if (this.paused) {
|
|
443
|
+
return this.remainingWhenPaused;
|
|
444
|
+
}
|
|
445
|
+
return Math.max(0, Math.floor((this.endTime - Date.now()) / 1000));
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* 获取格式化的时间字符串
|
|
450
|
+
*/
|
|
451
|
+
getFormattedTime(): string {
|
|
452
|
+
const seconds = this.getRemainingSeconds();
|
|
453
|
+
return this.formatTime(seconds);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 获取总时长(秒)
|
|
458
|
+
*/
|
|
459
|
+
getTotalSeconds(): number {
|
|
460
|
+
return this.totalSeconds;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* 获取已用时间(秒)
|
|
465
|
+
*/
|
|
466
|
+
getElapsedSeconds(): number {
|
|
467
|
+
return this.totalSeconds - this.getRemainingSeconds();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 检查是否已暂停
|
|
472
|
+
*/
|
|
473
|
+
isPaused(): boolean {
|
|
474
|
+
return this.paused;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* 检查是否已完成
|
|
479
|
+
*/
|
|
480
|
+
isFinished(): boolean {
|
|
481
|
+
return this.getRemainingSeconds() <= 0;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
import { Button, Toggle, PageView, ToggleContainer, EventHandler, js } from 'cc';
|
|
3
|
+
import { _decorator, Component, Node } from 'cc';
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Predefined variables
|
|
8
|
+
* Name = Tools
|
|
9
|
+
* DateTime = Fri Mar 24 2023 14:15:55 GMT+0800 (中国标准时间)
|
|
10
|
+
* Author = yf123mb
|
|
11
|
+
* FileBasename = Tools.ts
|
|
12
|
+
* FileBasenameNoExtension = Tools
|
|
13
|
+
* URL = db://assets/tools/Tools/Tools.ts
|
|
14
|
+
* ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export enum NodeLayer {
|
|
19
|
+
bg = 1 << 0,
|
|
20
|
+
preogess = 1 << 1,
|
|
21
|
+
reconnect = 1 << 2,
|
|
22
|
+
tip = 1 << 3,
|
|
23
|
+
Player_4 = 1 << 4,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
@ccclass('Tools')
|
|
27
|
+
export class Tools {
|
|
28
|
+
|
|
29
|
+
static SetNodeLayer(node: Node, layer: number) {
|
|
30
|
+
for (var i = 0; i < node.children.length; i++) {
|
|
31
|
+
let item = node.children[i];
|
|
32
|
+
item.layer = layer
|
|
33
|
+
if (item.children.length > 0) {
|
|
34
|
+
this.SetNodeLayer(item, layer)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
declare module "cc" {
|
|
42
|
+
interface Asset {
|
|
43
|
+
/**资源路径 */
|
|
44
|
+
asset_path: string;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param eventName 绑定点击事件
|
|
50
|
+
*/
|
|
51
|
+
export function BindEventClick(target: Node, delegate: Component, func_name?: string) {
|
|
52
|
+
const node = target;
|
|
53
|
+
let comp: Button | Toggle | PageView | ToggleContainer = node.getComponent(Button);
|
|
54
|
+
if (!comp) {
|
|
55
|
+
comp = node.getComponent(Toggle)
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
if (!comp) {
|
|
59
|
+
comp = node.getComponent(ToggleContainer)
|
|
60
|
+
}
|
|
61
|
+
if (!comp) {
|
|
62
|
+
comp = node.getComponent(PageView)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!comp) {
|
|
66
|
+
console.error(`没有找到按钮组件,需要手动添加组件到节点 ${target.name}`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// const call_name = "bindClick_"+target.name;
|
|
70
|
+
//(delegate as any)[call_name] = call;
|
|
71
|
+
const clickEventHandler = new EventHandler();
|
|
72
|
+
clickEventHandler.target = delegate.node; // 这个 node 节点是你的事件处理代码组件所属的节点
|
|
73
|
+
|
|
74
|
+
clickEventHandler.component = js.getClassName(delegate)//delegate.constructor.name;// 这个是脚本类名
|
|
75
|
+
clickEventHandler.handler = (func_name ?? node.name)
|
|
76
|
+
//console.error("按钮",delegate.constructor.name,node.name)
|
|
77
|
+
//clickEventHandler.customEventData = 'foobar';
|
|
78
|
+
|
|
79
|
+
// 绑定播放点击按钮音效事件
|
|
80
|
+
// const clickEventHandler_sound = new EventHandler();
|
|
81
|
+
// clickEventHandler_sound.target = delegate.node; // 这个 node 节点是你的事件处理代码组件所属的节点
|
|
82
|
+
// clickEventHandler_sound.component = js.getClassName(delegate)//delegate.constructor.name;// 这个是脚本类名
|
|
83
|
+
// clickEventHandler_sound.handler = "playClickSound"
|
|
84
|
+
|
|
85
|
+
if (comp instanceof Toggle) {
|
|
86
|
+
comp.checkEvents = [];
|
|
87
|
+
comp.checkEvents.push(clickEventHandler);
|
|
88
|
+
//comp.checkEvents.push(clickEventHandler_sound);
|
|
89
|
+
} else if (comp instanceof PageView) {
|
|
90
|
+
comp.pageEvents = [];
|
|
91
|
+
comp.pageEvents.push(clickEventHandler);
|
|
92
|
+
// (comp as PageView).pageEvents.push(clickEventHandler_sound);
|
|
93
|
+
}
|
|
94
|
+
else if (comp instanceof ToggleContainer) {
|
|
95
|
+
comp.checkEvents = [];
|
|
96
|
+
comp.checkEvents.push(clickEventHandler);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
comp.clickEvents = [];
|
|
100
|
+
comp.clickEvents.push(clickEventHandler);
|
|
101
|
+
//comp.clickEvents.push(clickEventHandler_sound);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @file EncryptUtil.ts
|
|
4
|
+
* @author yangfan
|
|
5
|
+
* @description 一些加密解密方法
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export module EncryptUtil {
|
|
10
|
+
|
|
11
|
+
export const KEY = "abc1236f7f8fcbcb";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* AES 加密
|
|
15
|
+
* @param msg
|
|
16
|
+
* @param key
|
|
17
|
+
* @param iv
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export function aesEncrypt(msg: string, key?: string, iv?: string): string {
|
|
21
|
+
|
|
22
|
+
let _iv = "";
|
|
23
|
+
let _key = "";
|
|
24
|
+
|
|
25
|
+
// let encrypt = CryptoJS.AES.encrypt(msg, utf8Parse(KEY), {
|
|
26
|
+
// iv: utf8Parse(_iv),
|
|
27
|
+
// mode: CryptoJS.mode.ECB,
|
|
28
|
+
// padding: CryptoJS.pad.Pkcs7
|
|
29
|
+
// });
|
|
30
|
+
let encrypt = CryptoJS.AES.encrypt(msg, utf8Parse(KEY), {
|
|
31
|
+
iv: utf8Parse(_iv),
|
|
32
|
+
mode: CryptoJS.mode.ECB,
|
|
33
|
+
padding: CryptoJS.pad.Pkcs7
|
|
34
|
+
});
|
|
35
|
+
return encrypt.toString();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* AES 解密
|
|
40
|
+
* @param str
|
|
41
|
+
* @param key
|
|
42
|
+
* @param iv
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export function aesDecrypt(str: string, key?: string, iv?: string): string {
|
|
46
|
+
let _iv = "";
|
|
47
|
+
let _key = "";
|
|
48
|
+
let decrypt = CryptoJS.AES.decrypt(str, utf8Parse(KEY), {
|
|
49
|
+
iv: utf8Parse(_iv),
|
|
50
|
+
mode: CryptoJS.mode.CBC,
|
|
51
|
+
padding: CryptoJS.pad.Pkcs7
|
|
52
|
+
});
|
|
53
|
+
return CryptoJS.enc.Utf8.stringify(decrypt);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function utf8Parse(utf8Str: string): string {
|
|
57
|
+
return CryptoJS.enc.Utf8.parse(utf8Str);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|