keytops-game-framework 1.0.17 → 1.0.18
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/dist/app/module/view/ViewManager.d.ts +10 -2
- package/dist/index.js +77 -23
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ export type ViewAnalyticsInfo = {
|
|
|
16
16
|
name: string;
|
|
17
17
|
group?: string;
|
|
18
18
|
};
|
|
19
|
+
export type TouchLockToken = symbol;
|
|
19
20
|
/**
|
|
20
21
|
* 视图管理类
|
|
21
22
|
*/
|
|
@@ -28,6 +29,7 @@ export declare class ViewManager {
|
|
|
28
29
|
private _currentStack;
|
|
29
30
|
private _viewCache;
|
|
30
31
|
private _currentMaskView;
|
|
32
|
+
private _touchLocks;
|
|
31
33
|
private _viewEvent;
|
|
32
34
|
private static created;
|
|
33
35
|
/**
|
|
@@ -94,16 +96,21 @@ export declare class ViewManager {
|
|
|
94
96
|
scene<T extends IScene>(): T;
|
|
95
97
|
/**
|
|
96
98
|
* 开启当前场景的可交互性
|
|
99
|
+
* @param token closeTouch返回的触摸锁令牌。传入时仅释放该锁,所有锁释放后才会真正开启触摸;不传则清空全部触摸锁并开启触摸。
|
|
97
100
|
*/
|
|
98
|
-
openTouch(): void;
|
|
101
|
+
openTouch(token?: TouchLockToken): void;
|
|
99
102
|
/**
|
|
100
103
|
* 关闭当前场景的可交互性
|
|
101
104
|
* @param maskViewConfig 可选参数,默认为空白,要显示的遮罩试图。
|
|
102
105
|
* @param delay 可选参数,默认200毫秒,显示maskView的延迟时间。
|
|
106
|
+
* @returns 当前触摸锁令牌,可传给openTouch精确释放本次锁。
|
|
103
107
|
*/
|
|
104
108
|
closeTouch(maskViewConfig?: {
|
|
105
109
|
prototype: IView;
|
|
106
|
-
} | ViewConfig | string, delay?: number): Promise<
|
|
110
|
+
} | ViewConfig | string, delay?: number): Promise<TouchLockToken>;
|
|
111
|
+
private _lockTouch;
|
|
112
|
+
private _applyTouchState;
|
|
113
|
+
private _showMaskView;
|
|
107
114
|
/**
|
|
108
115
|
* 当前主视图
|
|
109
116
|
* @returns
|
|
@@ -136,6 +143,7 @@ export declare class ViewManager {
|
|
|
136
143
|
} | ViewConfig | string, parent?: IView, ...datas: any[]): Promise<T>;
|
|
137
144
|
private _addView;
|
|
138
145
|
private _addViewbyConfig;
|
|
146
|
+
private _loadViewByConfig;
|
|
139
147
|
/**
|
|
140
148
|
* 加载视图到内存,之后还需要调用loader.initView接口获取view
|
|
141
149
|
* @param config 要加载的视图配置|Class|名称
|
package/dist/index.js
CHANGED
|
@@ -6912,6 +6912,7 @@ class ViewManager {
|
|
|
6912
6912
|
this._viewAnalyticsMap = new Map();
|
|
6913
6913
|
this._currentStack = [];
|
|
6914
6914
|
this._viewCache = new Map();
|
|
6915
|
+
this._touchLocks = new Set();
|
|
6915
6916
|
if (ViewManager.created) {
|
|
6916
6917
|
throw new Error("ViewManager 是单例");
|
|
6917
6918
|
}
|
|
@@ -6965,36 +6966,75 @@ class ViewManager {
|
|
|
6965
6966
|
}
|
|
6966
6967
|
/**
|
|
6967
6968
|
* 开启当前场景的可交互性
|
|
6969
|
+
* @param token closeTouch返回的触摸锁令牌。传入时仅释放该锁,所有锁释放后才会真正开启触摸;不传则清空全部触摸锁并开启触摸。
|
|
6968
6970
|
*/
|
|
6969
|
-
openTouch() {
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
this._currentMaskView.removeFromParent(true);
|
|
6973
|
-
this._currentMaskView = null;
|
|
6971
|
+
openTouch(token) {
|
|
6972
|
+
if (token) {
|
|
6973
|
+
this._touchLocks.delete(token);
|
|
6974
6974
|
}
|
|
6975
|
-
|
|
6976
|
-
this.
|
|
6975
|
+
else {
|
|
6976
|
+
this._touchLocks.clear();
|
|
6977
6977
|
}
|
|
6978
|
+
this._applyTouchState();
|
|
6978
6979
|
}
|
|
6979
6980
|
/**
|
|
6980
6981
|
* 关闭当前场景的可交互性
|
|
6981
6982
|
* @param maskViewConfig 可选参数,默认为空白,要显示的遮罩试图。
|
|
6982
6983
|
* @param delay 可选参数,默认200毫秒,显示maskView的延迟时间。
|
|
6984
|
+
* @returns 当前触摸锁令牌,可传给openTouch精确释放本次锁。
|
|
6983
6985
|
*/
|
|
6984
6986
|
closeTouch(maskViewConfig = null, delay = 200) {
|
|
6985
6987
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
+
const token = this._lockTouch();
|
|
6989
|
+
let config = maskViewConfig && this._getViewConfig(maskViewConfig);
|
|
6990
|
+
if (!config) {
|
|
6991
|
+
return token;
|
|
6992
|
+
}
|
|
6993
|
+
if (delay <= 0) {
|
|
6994
|
+
yield this._showMaskView(config, token);
|
|
6995
|
+
return token;
|
|
6996
|
+
}
|
|
6997
|
+
timer.once(delay, this, this._showMaskView, [config, token]);
|
|
6998
|
+
return token;
|
|
6999
|
+
});
|
|
7000
|
+
}
|
|
7001
|
+
_lockTouch() {
|
|
7002
|
+
const token = Symbol("touch-lock");
|
|
7003
|
+
this._touchLocks.add(token);
|
|
7004
|
+
this._applyTouchState();
|
|
7005
|
+
return token;
|
|
7006
|
+
}
|
|
7007
|
+
_applyTouchState() {
|
|
7008
|
+
const locked = this._touchLocks.size > 0;
|
|
7009
|
+
if (!locked) {
|
|
7010
|
+
timer.clear(this, this._showMaskView);
|
|
7011
|
+
if (this._currentMaskView) {
|
|
7012
|
+
this._currentMaskView.removeFromParent(true);
|
|
7013
|
+
this._currentMaskView = null;
|
|
6988
7014
|
}
|
|
6989
|
-
|
|
6990
|
-
|
|
7015
|
+
}
|
|
7016
|
+
if (this._scene) {
|
|
7017
|
+
this._scene.touchEnabled = !locked;
|
|
7018
|
+
}
|
|
7019
|
+
}
|
|
7020
|
+
_showMaskView(maskViewConfig, token) {
|
|
7021
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7022
|
+
if (!this._scene || !this._touchLocks.has(token) || this._currentMaskView) {
|
|
6991
7023
|
return;
|
|
6992
7024
|
}
|
|
6993
|
-
|
|
6994
|
-
|
|
7025
|
+
let view = this.getCacheView(maskViewConfig);
|
|
7026
|
+
if (view) {
|
|
7027
|
+
view = yield this._addView(view, this._scene);
|
|
7028
|
+
}
|
|
7029
|
+
else {
|
|
7030
|
+
view = yield this._loadViewByConfig(maskViewConfig, this._scene, "显示遮罩视图错误");
|
|
7031
|
+
this.cacheView(view);
|
|
7032
|
+
}
|
|
7033
|
+
if (!this._touchLocks.has(token)) {
|
|
7034
|
+
view.removeFromParent(true);
|
|
6995
7035
|
return;
|
|
6996
7036
|
}
|
|
6997
|
-
|
|
7037
|
+
this._currentMaskView = view;
|
|
6998
7038
|
});
|
|
6999
7039
|
}
|
|
7000
7040
|
/**
|
|
@@ -7061,12 +7101,13 @@ class ViewManager {
|
|
|
7061
7101
|
}
|
|
7062
7102
|
_switchViewByConfig(viewConfig, ...datas) {
|
|
7063
7103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7064
|
-
this.
|
|
7104
|
+
const touchToken = this._lockTouch();
|
|
7065
7105
|
let loader;
|
|
7066
7106
|
try {
|
|
7067
7107
|
loader = yield this.loadView(viewConfig);
|
|
7068
7108
|
}
|
|
7069
7109
|
catch (error) {
|
|
7110
|
+
this.openTouch(touchToken);
|
|
7070
7111
|
console.error(`切换视图错误 code:${error.code}, msg:${error.msg || error.message}`);
|
|
7071
7112
|
throw new Error(`切换视图错误 code:${error.code}, msg:${error.msg || error.message}`);
|
|
7072
7113
|
}
|
|
@@ -7085,7 +7126,7 @@ class ViewManager {
|
|
|
7085
7126
|
this._scene.addView(view, viewConfig.zIndex);
|
|
7086
7127
|
}
|
|
7087
7128
|
timer.frameNext(this, () => {
|
|
7088
|
-
this.openTouch();
|
|
7129
|
+
this.openTouch(touchToken);
|
|
7089
7130
|
view.setData(...datas);
|
|
7090
7131
|
});
|
|
7091
7132
|
return view;
|
|
@@ -7124,14 +7165,31 @@ class ViewManager {
|
|
|
7124
7165
|
}
|
|
7125
7166
|
_addViewbyConfig(config, parent, ...datas) {
|
|
7126
7167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7127
|
-
this.
|
|
7168
|
+
const touchToken = this._lockTouch();
|
|
7169
|
+
let view;
|
|
7170
|
+
try {
|
|
7171
|
+
view = yield this._loadViewByConfig(config, parent, "添加视图错误");
|
|
7172
|
+
}
|
|
7173
|
+
catch (error) {
|
|
7174
|
+
this.openTouch(touchToken);
|
|
7175
|
+
throw error;
|
|
7176
|
+
}
|
|
7177
|
+
timer.frameNext(this, () => {
|
|
7178
|
+
this.openTouch(touchToken);
|
|
7179
|
+
view.setData(...datas);
|
|
7180
|
+
});
|
|
7181
|
+
return view;
|
|
7182
|
+
});
|
|
7183
|
+
}
|
|
7184
|
+
_loadViewByConfig(config, parent, errorPrefix) {
|
|
7185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7128
7186
|
let loader;
|
|
7129
7187
|
try {
|
|
7130
7188
|
loader = yield this.loadView(config);
|
|
7131
7189
|
}
|
|
7132
7190
|
catch (error) {
|
|
7133
|
-
console.error(
|
|
7134
|
-
throw new Error(
|
|
7191
|
+
console.error(`${errorPrefix} code:${error.code}, msg:${error.msg || error.message}`);
|
|
7192
|
+
throw new Error(`${errorPrefix} code:${error.code}, msg:${error.msg || error.message}`);
|
|
7135
7193
|
}
|
|
7136
7194
|
let name = config.name || config.path.substring(config.path.lastIndexOf("/") + 1);
|
|
7137
7195
|
let view = loader.initView(name, true);
|
|
@@ -7139,10 +7197,6 @@ class ViewManager {
|
|
|
7139
7197
|
view.config = config;
|
|
7140
7198
|
view.analyticsInfo = this._viewAnalyticsMap.get(config.name);
|
|
7141
7199
|
parent.addView(view, config.zIndex);
|
|
7142
|
-
timer.frameNext(this, () => {
|
|
7143
|
-
this.openTouch();
|
|
7144
|
-
view.setData(...datas);
|
|
7145
|
-
});
|
|
7146
7200
|
return view;
|
|
7147
7201
|
});
|
|
7148
7202
|
}
|