增加loading界面
This commit is contained in:
1 parent
a3f61a29d0
commit
e84e14783e
69 files changed
+1394
-31
No files matched your search
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "59d8d637-a831-4d49-b6f2-52a04f638720",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { _decorator, Component, Label, Node, Sprite, SpriteFrame, UITransform } from 'cc';
|
||||
import { GuestLoginView } from '../../login/scripts/GuestLoginView';
|
||||
import type { LoginState } from '../../login/scripts/GuestLoginPresenter';
|
||||
import { StartupProgress } from './StartupProgress';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 加载展示与认证解耦;仅显隐控件,不禁用拥有请求生命周期的节点。 / Display controls without disabling the node that owns authentication. */
|
||||
@ccclass('StartupLoadingView')
|
||||
export class StartupLoadingView extends Component {
|
||||
static readonly READY = 'startup-preparation-ready';
|
||||
@property({ type: GuestLoginView }) login: GuestLoginView | null = null;
|
||||
@property({ type: Node }) panel: Node | null = null;
|
||||
@property({ type: [Node] }) loginControls: Node[] = [];
|
||||
@property({ type: Sprite }) meter: Sprite | null = null;
|
||||
@property({ type: Label }) percentage: Label | null = null;
|
||||
@property({ type: Label }) caption: Label | null = null;
|
||||
@property({ type: SpriteFrame }) frameArtwork: SpriteFrame | null = null;
|
||||
@property({ type: SpriteFrame }) fillArtwork: SpriteFrame | null = null;
|
||||
private readonly progress = new StartupProgress();
|
||||
private notified = false;
|
||||
private completedFor = 0;
|
||||
private visible = false;
|
||||
private readonly previousVisibility = new Map<Node, boolean>();
|
||||
onLoad(): void {
|
||||
if (!this.login || !this.panel || !this.meter || !this.percentage || !this.caption) {
|
||||
throw new Error('Startup loading controls are not fully bound.');
|
||||
}
|
||||
this.login.node.on(GuestLoginView.STATE_CHANGED, this.onLoginState, this);
|
||||
this.show(false);
|
||||
}
|
||||
onEnable(): void {
|
||||
this.show(this.progress.phase !== 'idle' && !this.notified);
|
||||
if (this.visible) this.draw();
|
||||
}
|
||||
private onLoginState(state: LoginState): void {
|
||||
if (state.phase === 'signing-in') {
|
||||
this.notified = false;
|
||||
this.completedFor = 0;
|
||||
this.progress.begin();
|
||||
this.show(this.enabledInHierarchy);
|
||||
this.draw();
|
||||
} else if (state.phase === 'authenticated') {
|
||||
this.progress.finish();
|
||||
this.draw();
|
||||
} else {
|
||||
this.progress.reset();
|
||||
this.show(false);
|
||||
}
|
||||
}
|
||||
update(dt: number): void {
|
||||
if (this.progress.phase === 'idle') return;
|
||||
this.progress.tick(dt);
|
||||
this.draw();
|
||||
if (this.progress.phase === 'complete') this.completedFor += Math.max(0, Math.min(.1, dt));
|
||||
if (this.progress.phase === 'complete' && this.completedFor >= .12 && !this.notified) {
|
||||
this.notified = true;
|
||||
// 当前无主场景,收尾后返回既有认证成功落点;后续由就绪接口承接。 / Until a game scene exists, retain the existing authenticated landing state.
|
||||
this.show(false);
|
||||
this.node.emit(StartupLoadingView.READY);
|
||||
}
|
||||
}
|
||||
private draw(): void {
|
||||
// 认证状态可更新文字,但加载层收尾前不显示到同一位置。 / Keep the latest auth message hidden until the loading overlay finishes.
|
||||
if (this.visible && this.login?.statusLabel) this.login.statusLabel.node.active = false;
|
||||
if (this.meter) {
|
||||
this.meter.node.active = this.progress.value > 0;
|
||||
this.meter.getComponent(UITransform)?.setContentSize(906 * this.progress.value, 102);
|
||||
}
|
||||
if (this.percentage) this.percentage.string = `${Math.floor(this.progress.value * 100)}%`;
|
||||
if (this.caption) this.caption.string = 'Getting things ready';
|
||||
}
|
||||
private show(visible: boolean): void {
|
||||
if (this.panel) this.panel.active = visible;
|
||||
if (visible === this.visible) return;
|
||||
this.visible = visible;
|
||||
for (const control of this.loginControls) {
|
||||
if (!control.isValid) continue;
|
||||
if (visible) {
|
||||
this.previousVisibility.set(control, control.active);
|
||||
control.active = false;
|
||||
} else {
|
||||
control.active = control === this.login?.statusLabel?.node
|
||||
? this.login.statusLabel.string.length > 0
|
||||
: (this.previousVisibility.get(control) ?? control.active);
|
||||
}
|
||||
}
|
||||
if (!visible) this.previousVisibility.clear();
|
||||
}
|
||||
onDisable(): void { this.show(false); }
|
||||
onDestroy(): void {
|
||||
if (this.login?.isValid) this.login.node.off(GuestLoginView.STATE_CHANGED, this.onLoginState, this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e4def002-3baf-403c-a08f-77f1340f98bc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
export type PreparationPhase = 'idle' | 'loading' | 'finishing' | 'complete';
|
||||
|
||||
/** 未知耗时只估算到上限,真实完成才允许满格。 / Estimated waiting progress is capped until actual completion. */
|
||||
export class StartupProgress {
|
||||
phase: PreparationPhase = 'idle';
|
||||
value = 0;
|
||||
private elapsed = 0;
|
||||
private finishElapsed = 0;
|
||||
private finishFrom = 0;
|
||||
begin(): void { this.reset(); this.phase = 'loading'; this.value = .03; }
|
||||
reset(): void { this.phase = 'idle'; this.value = 0; this.elapsed = 0; this.finishElapsed = 0; this.finishFrom = 0; }
|
||||
finish(): void {
|
||||
if (this.phase !== 'loading') return;
|
||||
this.phase = 'finishing'; this.finishFrom = this.value;
|
||||
}
|
||||
tick(seconds: number): number {
|
||||
const dt = Number.isFinite(seconds) ? Math.min(.1, Math.max(0, seconds)) : 0;
|
||||
if (this.phase === 'loading') {
|
||||
this.elapsed += dt;
|
||||
const target = .08 + .82 * (1 - Math.exp(-this.elapsed / 8));
|
||||
this.value = Math.min(.9, this.value + Math.max(0, target - this.value) * (1 - Math.exp(-dt * 7)));
|
||||
} else if (this.phase === 'finishing') {
|
||||
this.finishElapsed += dt;
|
||||
const t = Math.min(1, this.finishElapsed / .24);
|
||||
this.value = this.finishFrom + (1 - this.finishFrom) * (1 - (1 - t) ** 3);
|
||||
if (t === 1) { this.value = 1; this.phase = 'complete'; }
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bd350eaf-d6b7-4516-9d17-78534f4862a6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "6d3c346b-a6f3-4b4f-922e-7a4ea7eff1f4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "6cc8cbd1-ca56-4bf5-9bd0-48a6a05f8de3",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "6cc8cbd1-ca56-4bf5-9bd0-48a6a05f8de3@6c48a",
|
||||
"displayName": "prep-meter-fill",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "6cc8cbd1-ca56-4bf5-9bd0-48a6a05f8de3",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "6cc8cbd1-ca56-4bf5-9bd0-48a6a05f8de3@f9941",
|
||||
"displayName": "prep-meter-fill",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 2,
|
||||
"trimY": 5,
|
||||
"width": 653,
|
||||
"height": 90,
|
||||
"rawWidth": 657,
|
||||
"rawHeight": 100,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 48,
|
||||
"borderRight": 48,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-326.5,
|
||||
-45,
|
||||
0,
|
||||
326.5,
|
||||
-45,
|
||||
0,
|
||||
-326.5,
|
||||
45,
|
||||
0,
|
||||
326.5,
|
||||
45,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
2,
|
||||
95,
|
||||
655,
|
||||
95,
|
||||
2,
|
||||
5,
|
||||
655,
|
||||
5
|
||||
],
|
||||
"nuv": [
|
||||
0.0030441400304414,
|
||||
0.05,
|
||||
0.9969558599695586,
|
||||
0.05,
|
||||
0.0030441400304414,
|
||||
0.95,
|
||||
0.9969558599695586,
|
||||
0.95
|
||||
],
|
||||
"minPos": [
|
||||
-326.5,
|
||||
-45,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
326.5,
|
||||
45,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "6cc8cbd1-ca56-4bf5-9bd0-48a6a05f8de3@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "auto"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"hasAlpha": true,
|
||||
"redirect": "6cc8cbd1-ca56-4bf5-9bd0-48a6a05f8de3@6c48a"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "7a1db310-5d4f-4897-986f-3a1e216406d3",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "7a1db310-5d4f-4897-986f-3a1e216406d3@6c48a",
|
||||
"displayName": "prep-meter-frame",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "7a1db310-5d4f-4897-986f-3a1e216406d3",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "7a1db310-5d4f-4897-986f-3a1e216406d3@f9941",
|
||||
"displayName": "prep-meter-frame",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 13,
|
||||
"trimY": 2,
|
||||
"width": 930,
|
||||
"height": 161,
|
||||
"rawWidth": 956,
|
||||
"rawHeight": 165,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-465,
|
||||
-80.5,
|
||||
0,
|
||||
465,
|
||||
-80.5,
|
||||
0,
|
||||
-465,
|
||||
80.5,
|
||||
0,
|
||||
465,
|
||||
80.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
13,
|
||||
163,
|
||||
943,
|
||||
163,
|
||||
13,
|
||||
2,
|
||||
943,
|
||||
2
|
||||
],
|
||||
"nuv": [
|
||||
0.013598326359832637,
|
||||
0.012121212121212121,
|
||||
0.9864016736401674,
|
||||
0.012121212121212121,
|
||||
0.013598326359832637,
|
||||
0.9878787878787879,
|
||||
0.9864016736401674,
|
||||
0.9878787878787879
|
||||
],
|
||||
"minPos": [
|
||||
-465,
|
||||
-80.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
465,
|
||||
80.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "7a1db310-5d4f-4897-986f-3a1e216406d3@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "auto"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"hasAlpha": true,
|
||||
"redirect": "7a1db310-5d4f-4897-986f-3a1e216406d3@6c48a"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user