@chiyou/minigame-framework 1.0.0 → 1.0.2
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/assets/AssetsPackage/GUI/Images/Block.png +0 -0
- package/assets/AssetsPackage/GUI/Images/Block.png.meta +134 -0
- package/assets/AssetsPackage/GUI/Images.meta +9 -0
- package/assets/AssetsPackage/GUI/UIPrefabs/ChessBoard_Card.prefab +509 -0
- package/assets/AssetsPackage/GUI/UIPrefabs/ChessBoard_Card.prefab.meta +13 -0
- package/assets/AssetsPackage/GUI/UIPrefabs.meta +9 -0
- package/assets/AssetsPackage/GUI.meta +11 -0
- package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.plist +1106 -0
- package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.plist.meta +3329 -0
- package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.png +0 -0
- package/assets/AssetsPackage/SpriteAtlas/Card_Pattern.png.meta +134 -0
- package/assets/AssetsPackage/SpriteAtlas/SA_Card.plist +1196 -0
- package/assets/AssetsPackage/SpriteAtlas/SA_Card.plist.meta +3605 -0
- package/assets/AssetsPackage/SpriteAtlas/SA_Card.png +0 -0
- package/assets/AssetsPackage/SpriteAtlas/SA_Card.png.meta +134 -0
- package/assets/AssetsPackage/SpriteAtlas.meta +11 -0
- package/assets/AssetsPackage/SpriteFrame/Card_PatternType_Back.png +0 -0
- package/assets/AssetsPackage/SpriteFrame/Card_PatternType_Back.png.meta +134 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_BG.png +0 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_BG.png.meta +134 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_FG.png +0 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Back_FG.png.meta +134 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_BG.png +0 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_BG.png.meta +134 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_FG.png +0 -0
- package/assets/AssetsPackage/SpriteFrame/Card_TowardType_Front_FG.png.meta +134 -0
- package/assets/AssetsPackage/SpriteFrame.meta +11 -0
- package/assets/AssetsPackage.meta +9 -0
- package/assets/Scenes/Game.scene +831 -0
- package/assets/Scenes/Game.scene.meta +11 -0
- package/assets/Scenes.meta +9 -0
- package/assets/Scripts/Biz.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AbsAdAdapter.ts +312 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AbsAdAdapter.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterBilibili.ts +294 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterBilibili.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterDouYin.ts +650 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterDouYin.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHonor.ts +782 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHonor.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHuaWei.ts +582 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterHuaWei.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterJingDong.ts +298 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterJingDong.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.ts +575 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterOppo.ts +946 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterOppo.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterTapTap.ts +643 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterTapTap.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterVivo.ts +616 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterVivo.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterWeiXin.ts +847 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterWeiXin.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.ts +747 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.ts +579 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/AdAdapter.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.ts +102 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts +660 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts +224 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts +827 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts +378 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts +363 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.ts +368 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts +498 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts +323 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts +617 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts +377 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts +1136 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts +377 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts +483 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts.meta +9 -0
- package/assets/Scripts/Framework/Adapter/PlatformAdapter.meta +9 -0
- package/assets/Scripts/Framework/Adapter.meta +9 -0
- package/assets/Scripts/Framework/Definition/AdDefinition.ts +284 -0
- package/assets/Scripts/Framework/Definition/AdDefinition.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition/FrameworkBase.ts +15 -0
- package/assets/Scripts/Framework/Definition/FrameworkBase.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition/PrivacyDefinition.ts +95 -0
- package/assets/Scripts/Framework/Definition/PrivacyDefinition.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition/SocialDefinition.ts +21 -0
- package/assets/Scripts/Framework/Definition/SocialDefinition.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition/SystemDefinition.ts +58 -0
- package/assets/Scripts/Framework/Definition/SystemDefinition.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition/UIDefinition.ts +10 -0
- package/assets/Scripts/Framework/Definition/UIDefinition.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition/UserDefinition.ts +17 -0
- package/assets/Scripts/Framework/Definition/UserDefinition.ts.meta +9 -0
- package/assets/Scripts/Framework/Definition.meta +9 -0
- package/assets/Scripts/Framework/Manager/AdMgr.ts +812 -0
- package/assets/Scripts/Framework/Manager/AdMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/AudioMgr.ts +296 -0
- package/assets/Scripts/Framework/Manager/AudioMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/BaseMgr.ts +130 -0
- package/assets/Scripts/Framework/Manager/BaseMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/EventMgr.ts +102 -0
- package/assets/Scripts/Framework/Manager/EventMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/ExcelMgr.ts +188 -0
- package/assets/Scripts/Framework/Manager/ExcelMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/LifeCycleMgr.ts +142 -0
- package/assets/Scripts/Framework/Manager/LifeCycleMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/NodePoolMgr.ts +385 -0
- package/assets/Scripts/Framework/Manager/NodePoolMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/PrivacyMgr.ts +189 -0
- package/assets/Scripts/Framework/Manager/PrivacyMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/ResMgr.ts +420 -0
- package/assets/Scripts/Framework/Manager/ResMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/SocialMgr.ts +250 -0
- package/assets/Scripts/Framework/Manager/SocialMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/SystemMgr.ts +264 -0
- package/assets/Scripts/Framework/Manager/SystemMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/TimerMgr.ts +80 -0
- package/assets/Scripts/Framework/Manager/TimerMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/UIMgr.ts +267 -0
- package/assets/Scripts/Framework/Manager/UIMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager/UserMgr.ts +162 -0
- package/assets/Scripts/Framework/Manager/UserMgr.ts.meta +9 -0
- package/assets/Scripts/Framework/Manager.meta +9 -0
- package/assets/Scripts/Framework/Utils/BezierUtils.ts +273 -0
- package/assets/Scripts/Framework/Utils/BezierUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils/CSVUtils.ts +396 -0
- package/assets/Scripts/Framework/Utils/CSVUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils/LogUtils.ts +32 -0
- package/assets/Scripts/Framework/Utils/LogUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils/NumberUtils.ts +51 -0
- package/assets/Scripts/Framework/Utils/NumberUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils/TaskUtils.ts +27 -0
- package/assets/Scripts/Framework/Utils/TaskUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils/TimeUtils.ts +38 -0
- package/assets/Scripts/Framework/Utils/TimeUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils/WXBizDataCryptUtils.ts +54 -0
- package/assets/Scripts/Framework/Utils/WXBizDataCryptUtils.ts.meta +9 -0
- package/assets/Scripts/Framework/Utils.meta +9 -0
- package/assets/Scripts/Framework.meta +9 -0
- package/assets/Scripts/index.ts +39 -0
- package/assets/Scripts.meta +9 -0
- package/package.json +2 -4
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { AbsPlatformAdapter } from "../Adapter/PlatformAdapter/AbsPlatformAdapter";
|
|
2
|
+
import { PlatformAdapterBilibili } from "../Adapter/PlatformAdapter/PlatformAdapterBilibili";
|
|
3
|
+
import { PlatformAdapterDesktopBrowser } from "../Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser";
|
|
4
|
+
import { PlatformAdapterDouYin } from "../Adapter/PlatformAdapter/PlatformAdapterDouYin";
|
|
5
|
+
import { PlatformAdapterHonor } from "../Adapter/PlatformAdapter/PlatformAdapterHonor";
|
|
6
|
+
import { PlatformAdapterHuaWei } from "../Adapter/PlatformAdapter/PlatformAdapterHuaWei";
|
|
7
|
+
import { PlatformAdapterJingDong } from "../Adapter/PlatformAdapter/PlatformAdapterJingDong";
|
|
8
|
+
import { PlatformAdapterKuaiShou } from "../Adapter/PlatformAdapter/PlatformAdapterKuaiShou";
|
|
9
|
+
import { PlatformAdapterOppo } from "../Adapter/PlatformAdapter/PlatformAdapterOppo";
|
|
10
|
+
import { PlatformAdapterTapTap } from "../Adapter/PlatformAdapter/PlatformAdapterTapTap";
|
|
11
|
+
import { PlatformAdapterVivo } from "../Adapter/PlatformAdapter/PlatformAdapterVivo";
|
|
12
|
+
import { PlatformAdapterWeiXin } from "../Adapter/PlatformAdapter/PlatformAdapterWeiXin";
|
|
13
|
+
import { PlatformAdapterXiaoMi } from "../Adapter/PlatformAdapter/PlatformAdapterXiaoMi";
|
|
14
|
+
import { PlatformAdapterZhiFuBao } from "../Adapter/PlatformAdapter/PlatformAdapterZhiFuBao";
|
|
15
|
+
import { AppItem, CopyrightInfo, ICPItem, PlatformID } from "../Definition/SystemDefinition";
|
|
16
|
+
import { LogUtils } from "../Utils/LogUtils";
|
|
17
|
+
import { BaseMgr } from "./BaseMgr";
|
|
18
|
+
|
|
19
|
+
export class SystemMgr extends BaseMgr {
|
|
20
|
+
public static Instance: SystemMgr = null;
|
|
21
|
+
static TAG: string = "SystemMgr";
|
|
22
|
+
|
|
23
|
+
private appItem: AppItem = null;
|
|
24
|
+
private copyrightInfo: CopyrightInfo = null;
|
|
25
|
+
private localGame: boolean = true;
|
|
26
|
+
|
|
27
|
+
onLoad(): void {
|
|
28
|
+
super.onLoad();
|
|
29
|
+
|
|
30
|
+
if (SystemMgr.Instance === null) {
|
|
31
|
+
SystemMgr.Instance = this;
|
|
32
|
+
} else {
|
|
33
|
+
this.destroy();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public init(appItem: AppItem, copyrightInfo: CopyrightInfo): void {
|
|
39
|
+
this.appItem = appItem;
|
|
40
|
+
this.copyrightInfo = copyrightInfo;
|
|
41
|
+
|
|
42
|
+
let currPlatformID: PlatformID = BaseMgr.Instance.getCurrentPlatformID();
|
|
43
|
+
|
|
44
|
+
if (this.appItem !== null && this.appItem.appIDMap !== null &&
|
|
45
|
+
this.appItem.appIDMap.has(currPlatformID)) {
|
|
46
|
+
LogUtils.Instance.log(SystemMgr.TAG, "appID=" + this.appItem.appIDMap.get(currPlatformID));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.copyrightInfo && this.copyrightInfo.icpMap &&
|
|
50
|
+
this.copyrightInfo.icpMap.has(currPlatformID)) {
|
|
51
|
+
let icpItem: ICPItem = this.copyrightInfo.icpMap.get(currPlatformID);
|
|
52
|
+
if (icpItem !== null) {
|
|
53
|
+
this.localGame = icpItem.isLocalGame;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
LogUtils.Instance.log(SystemMgr.TAG, "isLocalGame=" + this.localGame);
|
|
57
|
+
|
|
58
|
+
let platformAdapterImpl: AbsPlatformAdapter = null;
|
|
59
|
+
switch(currPlatformID) {
|
|
60
|
+
case PlatformID.ID_H5_DesktopBrowser:
|
|
61
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterDesktopBrowser);
|
|
62
|
+
break;
|
|
63
|
+
case PlatformID.ID_MiniGame_WeiXin:
|
|
64
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterWeiXin);
|
|
65
|
+
break;
|
|
66
|
+
case PlatformID.ID_MiniGame_DouYin:
|
|
67
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterDouYin);
|
|
68
|
+
break;
|
|
69
|
+
case PlatformID.ID_MiniGame_KuaiShou:
|
|
70
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterKuaiShou);
|
|
71
|
+
break;
|
|
72
|
+
case PlatformID.ID_MiniGame_ZhiFuBao:
|
|
73
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterZhiFuBao);
|
|
74
|
+
break;
|
|
75
|
+
case PlatformID.ID_MiniGame_Bilibili:
|
|
76
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterBilibili);
|
|
77
|
+
break;
|
|
78
|
+
case PlatformID.ID_MiniGame_TapTap:
|
|
79
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterTapTap);
|
|
80
|
+
break;
|
|
81
|
+
case PlatformID.ID_MiniGame_JingDong:
|
|
82
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterJingDong);
|
|
83
|
+
break;
|
|
84
|
+
case PlatformID.ID_QuickGame_XiaoMi:
|
|
85
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterXiaoMi);
|
|
86
|
+
break;
|
|
87
|
+
case PlatformID.ID_QuickGame_Oppo:
|
|
88
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterOppo);
|
|
89
|
+
break;
|
|
90
|
+
case PlatformID.ID_QuickGame_Honor:
|
|
91
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterHonor);
|
|
92
|
+
break;
|
|
93
|
+
case PlatformID.ID_QuickGame_Vivo:
|
|
94
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterVivo);
|
|
95
|
+
break;
|
|
96
|
+
case PlatformID.ID_QuickGame_HuaWei:
|
|
97
|
+
platformAdapterImpl = this.node.addComponent(PlatformAdapterHuaWei);
|
|
98
|
+
break;
|
|
99
|
+
default:
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (platformAdapterImpl !== null) {
|
|
103
|
+
BaseMgr.Instance.setPlatformAdapter(platformAdapterImpl);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (this.getPlatformAdapter() !== null) {
|
|
107
|
+
this.getPlatformAdapter().onInit(this);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
LogUtils.Instance.log(SystemMgr.TAG, "init() finished.");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public getAppItem(): AppItem {
|
|
114
|
+
return this.appItem;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public isLocalGame(): boolean {
|
|
118
|
+
return this.localGame;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public getScreenBrightness(callback: Function): void {
|
|
122
|
+
if (this.getPlatformAdapter() === null) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.getPlatformAdapter().getScreenBrightness(callback);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public setScreenBrightness(value: number): void {
|
|
130
|
+
if (value < 0) {
|
|
131
|
+
value = 0;
|
|
132
|
+
}
|
|
133
|
+
if (value > 1) {
|
|
134
|
+
value = 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (this.getPlatformAdapter() === null) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.getPlatformAdapter().setScreenBrightness(value);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public setKeepScreenOn(keepScreenOn: boolean): void {
|
|
145
|
+
if (this.getPlatformAdapter() === null) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.getPlatformAdapter().setKeepScreenOn(keepScreenOn);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public exitGame(): void {
|
|
153
|
+
if (this.getPlatformAdapter() === null) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this.getPlatformAdapter().exitGame();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getSDKVersion(): string {
|
|
161
|
+
if (this.getPlatformAdapter() === null) {
|
|
162
|
+
return "";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return this.getPlatformAdapter().getSDKVersion();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public navigateToMiniProgram(appid: string, path?: string): void {
|
|
169
|
+
if (this.getPlatformAdapter() === null) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this.getPlatformAdapter().navigateToMiniProgram(appid, path);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public reportEvent(eventId: string, data: JSON): void {
|
|
177
|
+
if (this.getPlatformAdapter() === null) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.getPlatformAdapter().reportEvent(eventId, data);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public supportRequest(): boolean {
|
|
185
|
+
let platformSupport: boolean = false;
|
|
186
|
+
switch (this.getCurrentPlatformID()) {
|
|
187
|
+
case PlatformID.ID_QuickGame_Oppo:
|
|
188
|
+
case PlatformID.ID_QuickGame_Honor:
|
|
189
|
+
case PlatformID.ID_QuickGame_HuaWei:
|
|
190
|
+
platformSupport = false;
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
platformSupport = true;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return platformSupport && !this.isLocalGame();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public requestGet(path: string, requestParams: Map<string, string>|null, success: Function, fail: Function): void {
|
|
201
|
+
if (this.getPlatformAdapter() === null) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (success === null || fail === null) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!this.supportRequest()) {
|
|
210
|
+
fail();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let url = path;
|
|
215
|
+
if (requestParams && requestParams.size > 0) {
|
|
216
|
+
let paramIndex = 0;
|
|
217
|
+
|
|
218
|
+
for (let entry of requestParams.entries()) {
|
|
219
|
+
paramIndex++;
|
|
220
|
+
url += (paramIndex === 1) ? "?" : "&";
|
|
221
|
+
url += entry[0] + "=" + entry[1];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
LogUtils.Instance.log(SystemMgr.TAG, "requestGet", url);
|
|
225
|
+
|
|
226
|
+
this.getPlatformAdapter().requestGet(url, success, fail);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public requestPost(path: string, data: string, success: Function, fail: Function): void {
|
|
230
|
+
if (this.getPlatformAdapter() === null) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (success === null || fail === null) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!this.supportRequest()) {
|
|
239
|
+
fail();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
LogUtils.Instance.log(SystemMgr.TAG, "requestPost", path, data);
|
|
244
|
+
|
|
245
|
+
this.getPlatformAdapter().requestPost(path, data, success, fail);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public downloadFile(fileUrl: string, success: Function, fail: Function): void {
|
|
249
|
+
if (this.getPlatformAdapter() === null) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (success === null || fail === null) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!this.supportRequest()) {
|
|
258
|
+
fail();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this.getPlatformAdapter().downloadFile(fileUrl, success, fail);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { LogUtils } from "../Utils/LogUtils";
|
|
2
|
+
import { BaseMgr } from "./BaseMgr";
|
|
3
|
+
|
|
4
|
+
interface ITimer {
|
|
5
|
+
tick: number;
|
|
6
|
+
interval: number;
|
|
7
|
+
repeat: number;
|
|
8
|
+
func: Function;
|
|
9
|
+
target: Object;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class TimerMgr extends BaseMgr {
|
|
13
|
+
public static Instance: TimerMgr = null;
|
|
14
|
+
static TAG: string = "TimerMgr";
|
|
15
|
+
|
|
16
|
+
private timers: ITimer[] = [];
|
|
17
|
+
|
|
18
|
+
onLoad(): void {
|
|
19
|
+
super.onLoad();
|
|
20
|
+
|
|
21
|
+
if (TimerMgr.Instance === null) {
|
|
22
|
+
TimerMgr.Instance = this;
|
|
23
|
+
} else {
|
|
24
|
+
this.destroy();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public init(): void {
|
|
30
|
+
this.timers = [];
|
|
31
|
+
|
|
32
|
+
LogUtils.Instance.log(TimerMgr.TAG, "init() finished.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public addTimer(delay: number, interval: number, repeat: number, func: Function, target: Object) {
|
|
36
|
+
if (repeat === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.removeTimer(func, target);
|
|
41
|
+
|
|
42
|
+
this.timers.push({
|
|
43
|
+
tick: 0 - delay,
|
|
44
|
+
interval: interval,
|
|
45
|
+
repeat: repeat,
|
|
46
|
+
func: func,
|
|
47
|
+
target: target,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public removeTimer(func: Function, target: Object) {
|
|
53
|
+
for (let index = 0; index < this.timers.length; index++) {
|
|
54
|
+
const item = this.timers[index];
|
|
55
|
+
if (item.func === func && item.target === target) {
|
|
56
|
+
this.timers.splice(index, 1);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected update(dt: number): void {
|
|
63
|
+
for (let index = 0; index < this.timers.length; index++) {
|
|
64
|
+
const item = this.timers[index];
|
|
65
|
+
item.tick += dt * 1000;
|
|
66
|
+
if (item.tick >= item.interval) {
|
|
67
|
+
item.tick -= item.interval;
|
|
68
|
+
item.func.call(item.target);
|
|
69
|
+
|
|
70
|
+
if (item.repeat > 0) {
|
|
71
|
+
item.repeat--;
|
|
72
|
+
if (item.repeat === 0) {
|
|
73
|
+
this.timers.splice(index, 1);
|
|
74
|
+
index--;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Component, Node, Button, Prefab, instantiate, screen, UITransform, v3, view, ResolutionPolicy, math, Tween, tween, Label, UIComponent, Color, UIOpacity, Sprite, SpriteFrame, BlockInputEvents, Texture2D, gfx, Vec3, v2 } from 'cc';
|
|
2
|
+
import { ResMgr } from './ResMgr';
|
|
3
|
+
import { LogUtils } from '../Utils/LogUtils';
|
|
4
|
+
import { ToastDuration } from '../Definition/UIDefinition';
|
|
5
|
+
import { BaseMgr } from './BaseMgr';
|
|
6
|
+
|
|
7
|
+
export class UICtrl extends Component {
|
|
8
|
+
protected views: Map<string, Node> = new Map<string, Node>();
|
|
9
|
+
|
|
10
|
+
onLoad(): void {
|
|
11
|
+
this.views = new Map<string, Node>();
|
|
12
|
+
this.load_all_object(this.node, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private load_all_object(root: Node, path: string): void {
|
|
16
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
17
|
+
this.views.set(path + root.children[i].name, root.children[i]);
|
|
18
|
+
this.load_all_object(root.children[i], path + root.children[i].name + "/");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public set_button_listener(view_name: string, clickListener: Function, target?: Component) {
|
|
23
|
+
let view_node: Node = this.views.get(view_name);
|
|
24
|
+
|
|
25
|
+
if (!view_node) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let button: Button = view_node.getComponent(Button);
|
|
30
|
+
if (!button) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
button.node.on("click", clickListener, target);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class UIMgr extends BaseMgr {
|
|
39
|
+
public static Instance: UIMgr = null;
|
|
40
|
+
static TAG: string = "UIMgr";
|
|
41
|
+
|
|
42
|
+
private canvas: Node = null;
|
|
43
|
+
private uiMap: Map<string, Array<Node>> = null;
|
|
44
|
+
|
|
45
|
+
private windowWidth: number = 0;
|
|
46
|
+
private windowHeight: number = 0;
|
|
47
|
+
|
|
48
|
+
private node_toastRoot: Node = null;
|
|
49
|
+
private tween_toast: Tween<Node> = null;
|
|
50
|
+
|
|
51
|
+
private node_dialogRoot: Node = null;
|
|
52
|
+
|
|
53
|
+
public print(): void {
|
|
54
|
+
LogUtils.Instance.log("", this.uiMap);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onLoad(): void {
|
|
58
|
+
super.onLoad();
|
|
59
|
+
|
|
60
|
+
if (UIMgr.Instance === null) {
|
|
61
|
+
UIMgr.Instance = this;
|
|
62
|
+
} else {
|
|
63
|
+
this.destroy();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public init(): void {
|
|
69
|
+
this.canvas = this.node.parent;
|
|
70
|
+
this.uiMap = new Map<string, Array<Node>>();
|
|
71
|
+
|
|
72
|
+
let designSize: math.Size = view.getDesignResolutionSize();
|
|
73
|
+
view.setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy.SHOW_ALL);
|
|
74
|
+
|
|
75
|
+
this.windowWidth = screen.windowSize.width;
|
|
76
|
+
this.windowHeight = screen.windowSize.height;
|
|
77
|
+
|
|
78
|
+
this.node_toastRoot = null;
|
|
79
|
+
this.tween_toast = null;
|
|
80
|
+
|
|
81
|
+
LogUtils.Instance.log(UIMgr.TAG, "init() finished.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public create_ui(ui_name: string, parent?: Node): Node {
|
|
85
|
+
let uiPrefab: Prefab = ResMgr.Instance.getAsset("GUI", "UIPrefabs/" + ui_name);
|
|
86
|
+
if (!uiPrefab) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let uiNode: Node = instantiate(uiPrefab);
|
|
91
|
+
if (!uiNode) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (parent) {
|
|
96
|
+
parent.addChild(uiNode);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
uiNode.addComponent(ui_name + "_Ctrl");
|
|
100
|
+
|
|
101
|
+
let array: Array<Node> = null;
|
|
102
|
+
if (this.uiMap.has(ui_name)) {
|
|
103
|
+
array = this.uiMap.get(ui_name);
|
|
104
|
+
}
|
|
105
|
+
if (array === null) {
|
|
106
|
+
array = new Array<Node>();
|
|
107
|
+
}
|
|
108
|
+
array.push(uiNode);
|
|
109
|
+
|
|
110
|
+
this.uiMap.set(ui_name, array);
|
|
111
|
+
|
|
112
|
+
return uiNode;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public destroy_ui(ui_name: string, node: Node) {
|
|
116
|
+
if (this.uiMap.has(ui_name)) {
|
|
117
|
+
let array: Array<Node> = this.uiMap.get(ui_name);
|
|
118
|
+
|
|
119
|
+
if (array !== null) {
|
|
120
|
+
let index = array.indexOf(node);
|
|
121
|
+
if (index >= 0) {
|
|
122
|
+
node.removeFromParent();
|
|
123
|
+
node.destroy();
|
|
124
|
+
array.splice(index, 1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (array === null || array.length === 0) {
|
|
129
|
+
this.uiMap.delete(ui_name);
|
|
130
|
+
} else {
|
|
131
|
+
this.uiMap.set(ui_name, array);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public destroy_ui_all(ui_name: string) {
|
|
137
|
+
if (this.uiMap.has(ui_name)) {
|
|
138
|
+
let array: Array<Node> = this.uiMap.get(ui_name);
|
|
139
|
+
if (array !== null) {
|
|
140
|
+
for (let i = 0; i < array.length; i++) {
|
|
141
|
+
let node: Node = array[i];
|
|
142
|
+
node.removeFromParent();
|
|
143
|
+
node.destroy();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.uiMap.delete(ui_name);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public clear_ui_all() {
|
|
151
|
+
for (let ui_name of this.uiMap.keys()) {
|
|
152
|
+
this.destroy_ui_all(ui_name);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public adaptScreen(node: Node) {
|
|
157
|
+
// 用于背景适配整个屏幕
|
|
158
|
+
let nodeWidth = node.getComponent(UITransform).width;
|
|
159
|
+
let nodeHeight = node.getComponent(UITransform).height;
|
|
160
|
+
|
|
161
|
+
let scrScaleForShowAll = Math.min(this.windowWidth / nodeWidth, this.windowHeight / nodeHeight);
|
|
162
|
+
let realWidth = nodeWidth * scrScaleForShowAll;
|
|
163
|
+
let realHeight = nodeHeight * scrScaleForShowAll;
|
|
164
|
+
|
|
165
|
+
let scaleRatio = Math.max(this.windowWidth / realWidth, this.windowHeight / realHeight);
|
|
166
|
+
node.scale = v3(scaleRatio, scaleRatio, 1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public setToastRootNode(node: Node): void {
|
|
170
|
+
this.node_toastRoot = node;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public showToast(content: string, toastDuration: ToastDuration = ToastDuration.Duration_Short): void {
|
|
174
|
+
if (this.node_toastRoot === null) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (this.tween_toast !== null) {
|
|
179
|
+
this.tween_toast.stop();
|
|
180
|
+
this.tween_toast = null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let showTime: number = 1.5;
|
|
184
|
+
if (toastDuration === ToastDuration.Duration_Long) {
|
|
185
|
+
showTime = 3;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let labelComponent: Label = this.node_toastRoot.getChildByName("Label").getComponent(Label);
|
|
189
|
+
labelComponent.string = content;
|
|
190
|
+
labelComponent.updateRenderData(true);
|
|
191
|
+
let textWidth: number = labelComponent.node.getComponent(UITransform).contentSize.width;
|
|
192
|
+
|
|
193
|
+
this.node_toastRoot.active = true;
|
|
194
|
+
this.node_toastRoot.getComponent(UITransform).width = textWidth + 80;
|
|
195
|
+
this.tween_toast = tween(this.node_toastRoot)
|
|
196
|
+
.delay(showTime)
|
|
197
|
+
.call(() => {
|
|
198
|
+
this.tween_toast = null;
|
|
199
|
+
this.node_toastRoot.active = false;
|
|
200
|
+
});
|
|
201
|
+
this.tween_toast.start();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public setDialogRootNode(node: Node): void {
|
|
205
|
+
this.node_dialogRoot = node;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public openDialog(ui_name: string, maskColor?: Color): Node {
|
|
209
|
+
if (!maskColor) {
|
|
210
|
+
maskColor = new Color(51, 51, 51, 230);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const whitePixelData = new Uint8Array([maskColor.r, maskColor.g, maskColor.b, maskColor.a]);
|
|
214
|
+
const texture = new Texture2D();
|
|
215
|
+
texture.reset({
|
|
216
|
+
width: 1,
|
|
217
|
+
height: 1,
|
|
218
|
+
});
|
|
219
|
+
texture.uploadData(whitePixelData);
|
|
220
|
+
let sf: SpriteFrame = new SpriteFrame();
|
|
221
|
+
sf.texture = texture;
|
|
222
|
+
|
|
223
|
+
let node_mask: Node = new Node("Node_Mask");
|
|
224
|
+
let sprite: Sprite = node_mask.addComponent(Sprite);
|
|
225
|
+
sprite.spriteFrame = sf;
|
|
226
|
+
|
|
227
|
+
let designSize: math.Size = view.getDesignResolutionSize();
|
|
228
|
+
node_mask.getComponent(UITransform).width = designSize.width;
|
|
229
|
+
node_mask.getComponent(UITransform).height = designSize.height;
|
|
230
|
+
UIMgr.Instance.adaptScreen(node_mask);
|
|
231
|
+
|
|
232
|
+
node_mask.addComponent(BlockInputEvents);
|
|
233
|
+
|
|
234
|
+
let node_agent: Node = new Node();
|
|
235
|
+
node_agent.addChild(node_mask);
|
|
236
|
+
|
|
237
|
+
let node_dialog: Node = this.create_ui(ui_name, node_agent);
|
|
238
|
+
if (node_dialog) {
|
|
239
|
+
this.node_dialogRoot.addChild(node_agent);
|
|
240
|
+
this.node_dialogRoot.active = true;
|
|
241
|
+
} else {
|
|
242
|
+
node_agent.destroy();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return node_dialog;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public closeDialog(ui_name: string, node: Node): void {
|
|
249
|
+
let hasNode: boolean = false;
|
|
250
|
+
if (this.uiMap.has(ui_name)) {
|
|
251
|
+
let array: Array<Node> = this.uiMap.get(ui_name);
|
|
252
|
+
|
|
253
|
+
if (array !== null) {
|
|
254
|
+
let index = array.indexOf(node);
|
|
255
|
+
if (index >= 0) {
|
|
256
|
+
hasNode = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (hasNode) {
|
|
262
|
+
let node_agent: Node = node.parent;
|
|
263
|
+
this.destroy_ui(ui_name, node);
|
|
264
|
+
node_agent.destroy();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|