loading失败可以重试
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
TJH 2025-12-30 13:30:52 +08:00
parent 87e7307d0d
commit 04084da893
3 changed files with 252 additions and 292 deletions

View File

@ -23,7 +23,7 @@
"_active": true,
"_components": [],
"_prefab": {
"__id__": 89
"__id__": 86
},
"_lpos": {
"__type__": "cc.Vec3",
@ -54,7 +54,7 @@
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 90
"__id__": 87
},
"_id": "6c29a3fe-b10e-44a5-98e3-55595b231767"
},
@ -77,25 +77,25 @@
"__id__": 8
},
{
"__id__": 67
"__id__": 64
},
{
"__id__": 70
"__id__": 67
}
],
"_active": true,
"_components": [
{
"__id__": 82
},
{
"__id__": 83
},
{
"__id__": 84
},
{
"__id__": 85
},
{
"__id__": 86
},
{
"__id__": 87
},
{
"__id__": 88
}
],
"_prefab": null,
@ -341,22 +341,22 @@
"__id__": 9
},
{
"__id__": 60
"__id__": 57
}
],
"_active": true,
"_components": [
{
"__id__": 60
},
{
"__id__": 61
},
{
"__id__": 62
},
{
"__id__": 63
},
{
"__id__": 64
},
{
"__id__": 65
},
{
"__id__": 66
}
],
"_prefab": null,
@ -427,18 +427,15 @@
},
{
"__id__": 46
},
{
"__id__": 49
}
],
"_active": true,
"_components": [
{
"__id__": 58
"__id__": 55
},
{
"__id__": 59
"__id__": 56
}
],
"_prefab": null,
@ -1782,138 +1779,6 @@
"_shadowBlur": 2,
"_id": "2380yWt0tOa6GJutBEnRsb"
},
{
"__type__": "cc.Node",
"_name": "retryLabel",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 9
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 47
},
{
"__id__": 48
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": -650,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "14e7XZMaJFYLTkByEFJD19"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 46
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 1021.423828125,
"height": 56.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 1
},
"_id": "569fDE9xdENZpBizWSQ/8L"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 46
},
"_enabled": true,
"__prefab": null,
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_string": "",
"_horizontalAlign": 1,
"_verticalAlign": 1,
"_actualFontSize": 38,
"_fontSize": 38,
"_fontFamily": "Arial",
"_lineHeight": 40,
"_overflow": 3,
"_enableWrapText": true,
"_font": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_isItalic": false,
"_isBold": true,
"_isUnderline": false,
"_underlineHeight": 2,
"_cacheMode": 0,
"_enableOutline": true,
"_outlineColor": {
"__type__": "cc.Color",
"r": 36,
"g": 37,
"b": 46,
"a": 255
},
"_outlineWidth": 3,
"_enableShadow": false,
"_shadowColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_shadowOffset": {
"__type__": "cc.Vec2",
"x": 2,
"y": 2
},
"_shadowBlur": 2,
"_id": "e95YoCoCNIG4q/RXhLojDR"
},
{
"__type__": "cc.Node",
"_name": "Btn",
@ -1924,26 +1789,26 @@
},
"_children": [
{
"__id__": 50
"__id__": 47
}
],
"_active": false,
"_components": [
{
"__id__": 54
"__id__": 51
},
{
"__id__": 55
"__id__": 52
},
{
"__id__": 56
"__id__": 53
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": -610,
"y": -600,
"z": 0
},
"_lrot": {
@ -1975,19 +1840,19 @@
"_objFlags": 512,
"__editorExtras__": {},
"_parent": {
"__id__": 49
"__id__": 46
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 51
"__id__": 48
},
{
"__id__": 52
"__id__": 49
},
{
"__id__": 53
"__id__": 50
}
],
"_prefab": null,
@ -2026,7 +1891,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 50
"__id__": 47
},
"_enabled": true,
"__prefab": null,
@ -2048,7 +1913,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 50
"__id__": 47
},
"_enabled": true,
"__prefab": null,
@ -2110,7 +1975,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 50
"__id__": 47
},
"_enabled": true,
"__prefab": null,
@ -2123,7 +1988,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 49
"__id__": 46
},
"_enabled": true,
"__prefab": null,
@ -2145,7 +2010,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 49
"__id__": 46
},
"_enabled": true,
"__prefab": null,
@ -2184,13 +2049,13 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 49
"__id__": 46
},
"_enabled": true,
"__prefab": null,
"clickEvents": [
{
"__id__": 57
"__id__": 54
}
],
"_interactable": true,
@ -2242,7 +2107,7 @@
"_duration": 0.1,
"_zoomScale": 1.2,
"_target": {
"__id__": 49
"__id__": 46
},
"_id": "54j4lwPyZHbqqANZE+r9Tj"
},
@ -2320,10 +2185,10 @@
"_active": true,
"_components": [
{
"__id__": 61
"__id__": 58
},
{
"__id__": 62
"__id__": 59
}
],
"_prefab": null,
@ -2362,7 +2227,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 60
"__id__": 57
},
"_enabled": true,
"__prefab": null,
@ -2384,7 +2249,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 60
"__id__": 57
},
"_enabled": true,
"__prefab": null,
@ -2528,10 +2393,10 @@
"_active": true,
"_components": [
{
"__id__": 68
"__id__": 65
},
{
"__id__": 69
"__id__": 66
}
],
"_prefab": null,
@ -2570,7 +2435,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 67
"__id__": 64
},
"_enabled": true,
"__prefab": null,
@ -2592,7 +2457,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 67
"__id__": 64
},
"_enabled": true,
"__prefab": null,
@ -2635,22 +2500,22 @@
},
"_children": [
{
"__id__": 71
"__id__": 68
},
{
"__id__": 75
"__id__": 72
},
{
"__id__": 80
"__id__": 77
}
],
"_active": false,
"_components": [
{
"__id__": 83
"__id__": 80
},
{
"__id__": 84
"__id__": 81
}
],
"_prefab": null,
@ -2689,19 +2554,19 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 67
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 72
"__id__": 69
},
{
"__id__": 73
"__id__": 70
},
{
"__id__": 74
"__id__": 71
}
],
"_prefab": null,
@ -2740,7 +2605,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 71
"__id__": 68
},
"_enabled": true,
"__prefab": null,
@ -2762,7 +2627,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 71
"__id__": 68
},
"_enabled": true,
"__prefab": null,
@ -2774,7 +2639,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 71
"__id__": 68
},
"_enabled": true,
"__prefab": null,
@ -2813,22 +2678,22 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 67
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 73
},
{
"__id__": 74
},
{
"__id__": 75
},
{
"__id__": 76
},
{
"__id__": 77
},
{
"__id__": 78
},
{
"__id__": 79
}
],
"_prefab": null,
@ -2867,7 +2732,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 75
"__id__": 72
},
"_enabled": true,
"__prefab": null,
@ -2889,7 +2754,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 75
"__id__": 72
},
"_enabled": true,
"__prefab": null,
@ -2951,7 +2816,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 75
"__id__": 72
},
"_enabled": true,
"__prefab": null,
@ -2964,7 +2829,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 75
"__id__": 72
},
"_enabled": true,
"__prefab": null,
@ -2994,16 +2859,16 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 67
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 81
"__id__": 78
},
{
"__id__": 82
"__id__": 79
}
],
"_prefab": null,
@ -3042,7 +2907,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 80
"__id__": 77
},
"_enabled": true,
"__prefab": null,
@ -3064,7 +2929,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 80
"__id__": 77
},
"_enabled": true,
"__prefab": null,
@ -3103,7 +2968,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 70
"__id__": 67
},
"_enabled": true,
"__prefab": null,
@ -3125,7 +2990,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 70
"__id__": 67
},
"_enabled": true,
"__prefab": null,
@ -3216,18 +3081,27 @@
"__id__": 37
},
"startBtnNode": {
"__id__": 49
"__id__": 46
},
"LoadingUINode": {
"__id__": 9
},
"rb7Logo": {
"__id__": 67
"__id__": 64
},
"languageJson": {
"__uuid__": "65d2a408-9396-47e4-99de-73423a590b7f",
"__expectedType__": "cc.JsonAsset"
},
"tipLabel": {
"__id__": 45
},
"startBtn": {
"__id__": 53
},
"startBtnLabel": {
"__id__": 49
},
"_id": "402ZKZqylO5qV7VlV8TRcy"
},
{
@ -3244,10 +3118,10 @@
"__id__": 5
},
"Logo": {
"__id__": 67
"__id__": 64
},
"rotateNode": {
"__id__": 70
"__id__": 67
},
"_id": "d8F/UwpTxNpZhwSJjDvnkk"
},
@ -3262,28 +3136,28 @@
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 91
"__id__": 88
},
"shadows": {
"__id__": 92
"__id__": 89
},
"_skybox": {
"__id__": 93
"__id__": 90
},
"fog": {
"__id__": 94
"__id__": 91
},
"octree": {
"__id__": 95
"__id__": 92
},
"skin": {
"__id__": 96
"__id__": 93
},
"lightProbeInfo": {
"__id__": 97
"__id__": 94
},
"postSettings": {
"__id__": 98
"__id__": 95
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false

View File

@ -32,7 +32,7 @@ export function getHistoryUrl() {
}
export function getLanguage() {
// return 'zh';
return 'zh';
return language;
}

View File

@ -1,18 +1,32 @@
import { _decorator, Component, Node, ProgressBar, Label, UITransform, tween, JsonAsset } from 'cc';
import { callGameApi, getIsRB7, getLanguage, initReqAddr } from './comm';
import { DEBUG } from 'cc/env';
import { initErrorManager } from './manager/ErrorManager';
import { I18nManager } from './manager/I18nManager';
import { LocalizedSprite } from './i18n/LocalizedSprite';
import { AudioManager } from './manager/AudioManager';
import { GameDataManager } from './manager/GameDataManager';
import { ResManager } from './manager/ResManager';
import { NodePoolManager } from './manager/NodePoolManager';
import {
_decorator,
Component,
Node,
ProgressBar,
Label,
UITransform,
tween,
JsonAsset,
Button,
} from "cc";
import {
callGameApi,
getIsRB7,
getLanguage,
initReqAddr,
} from "./comm";
import { DEBUG } from "cc/env";
import { initErrorManager } from "./manager/ErrorManager";
import { I18nManager } from "./manager/I18nManager";
import { LocalizedSprite } from "./i18n/LocalizedSprite";
import { AudioManager } from "./manager/AudioManager";
import { GameDataManager } from "./manager/GameDataManager";
import { ResManager } from "./manager/ResManager";
import { NodePoolManager } from "./manager/NodePoolManager";
const { ccclass, property } = _decorator;
@ccclass('Loading')
@ccclass("Loading")
export class Loading extends Component {
// UI组件
@property(Node) progressNode: Node = null;
@ -25,7 +39,18 @@ export class Loading extends Component {
@property(Node) LoadingUINode: Node = null;
@property(Node) rb7Logo: Node = null;
@property(JsonAsset) languageJson: JsonAsset = null;
@property(Label)
tipLabel: Label = null;
@property(Button)
startBtn: Button = null;
@property(Label)
startBtnLabel: Label = null;
private _networkComplete = false;
private _retryCount = 0;
private readonly MAX_RETRY = 5;
// 加载状态
private isNetworkReady = false;
private readonly PROGRESS_ANIMATION_DURATION = 0.3;
@ -40,7 +65,6 @@ export class Loading extends Component {
private gameContainer: Node = null;
private gameNode: Node = null;
protected async onLoad() {
initReqAddr();
let language = getLanguage();
@ -54,8 +78,11 @@ export class Loading extends Component {
}
initErrorManager();
await I18nManager.instance.ensureI18nSprite(language, '2');
this.node.getChildByPath('Mask/LoadingUINode/msg').getComponent(LocalizedSprite).updateSpriteForPreload(language);
await I18nManager.instance.ensureI18nSprite(language, "2");
this.node
.getChildByPath('Mask/LoadingUINode/msg')
.getComponent(LocalizedSprite)
.updateSpriteForPreload(language);
this.node.getChildByPath('Mask/LoadingUINode/msg').active = true;
await I18nManager.instance.init(language, this.languageJson);
@ -68,15 +95,15 @@ export class Loading extends Component {
try {
await this.initializeSystem();
AudioManager.instance.init();
this.updateLoadingText('AID_LOADING');
this.updateLoadingText("AID_LOADING");
// 延迟一下让用户看到进度条开始
this.scheduleOnce(() => {
this.startNetworkLoading();
}, 0.2);
} catch (error) {
console.error('Network initialization failed:', error);
// this.handleError(error);
console.error("Network initialization failed:", error);
this.handleError(error);
}
}
@ -84,15 +111,13 @@ export class Loading extends Component {
/** 初始化系统 */
private async initializeSystem() {
this.rb7Logo.active = getIsRB7();
// if (DEBUG) {
// await getTestToken('nova006', 'faketrans');
// }
}
/** 初始化UI */
private initializeUI() {
this.startBtnNode.active = false;
this.gameContainer = this.node.getChildByPath('Mask/GameNode')
this.gameContainer = this.node
.getChildByPath('Mask/GameNode')
// 初始化进度条为0
this.updateProgress(0);
@ -100,7 +125,7 @@ export class Loading extends Component {
/** 开始网络加载 */
private async startNetworkLoading() {
this.updateLoadingText('AID_LOADING');
this.updateLoadingText("AID_LOADING");
try {
let gameInfo = await callGameApi("gameinfo", {});
@ -116,27 +141,67 @@ export class Loading extends Component {
this.startResourceLoading();
}, 0.3);
} catch (error) {
console.error("Network initialization failed:", error);
this.handleError(error);
}
}
private handleError(error: Error) {
this._retryCount++;
if (this._retryCount <= this.MAX_RETRY) {
// 自动重试
// this.tipLabel.string = `retry(${this._retryCount}/${this.MAX_RETRY})...`;
switch (this._retryCount) {
case 1:
this.tipLabel.string = I18nManager.instance.t("AID_NETWORK_RETRY_1");
break;
case 2:
this.tipLabel.string = I18nManager.instance.t("AID_NETWORK_RETRY_2");
break;
case 3:
this.tipLabel.string = I18nManager.instance.t("AID_NETWORK_RETRY_3");
break;
case 4:
this.tipLabel.string = I18nManager.instance.t("AID_NETWORK_RETRY_4");
break;
case 5:
this.tipLabel.string = I18nManager.instance.t("AID_NETWORK_RETRY_5");
break;
}
this.scheduleOnce(() => {
if (!this._networkComplete) {
this.startNetworkLoading();
} else {
this.startResourceLoading();
}
}, 2);
} else {
// 显示重试按钮
this.tipLabel.string = I18nManager.instance.t("AID_LOADING");
this.startBtn.node.active = true;
this.progressBar.node.active = false;
this.progressLabel.node.active = false;
this.startBtnLabel.string = I18nManager.instance.t(
"AID_ERROR_RETRY_BUTTON"
);
}
}
/** 开始资源加载 */
private async startResourceLoading() {
if (!this.isNetworkReady) return;
// this.updateLoadingText('Loading More...');
this.tipLabel.string = I18nManager.instance.t("AID_LOADING");
this.startBtnNode.active = false;
this.gameNode = await ResManager.instance.loadPrefabFromBundle(
'Game',
'SlotScene',
"Game",
"SlotScene",
(finished: number, total: number) => {
if (total > 0) {
// 资源加载进度从50%到90%
const resourceProgress = finished / total;
const currentProgress = this.PROGRESS_NETWORK +
(resourceProgress * (this.PROGRESS_RESOURCE - this.PROGRESS_NETWORK));
const currentProgress =
this.PROGRESS_NETWORK +
resourceProgress * (this.PROGRESS_RESOURCE - this.PROGRESS_NETWORK);
this.updateProgress(currentProgress);
}
}
@ -166,29 +231,37 @@ export class Loading extends Component {
/** 更新进度条 */
private updateProgress(progress: number) {
tween(this.progressBar)
.to(this.PROGRESS_ANIMATION_DURATION, { progress }, {
easing: 'smooth',
.to(
this.PROGRESS_ANIMATION_DURATION,
{ progress },
{
easing: "smooth",
onUpdate: (target: any) => {
const currentProgress = target.progress;
this.progressLabel.string = `${Math.floor(currentProgress * 100)}%`;
this.maskSpineNode.getComponent(UITransform).setContentSize(currentProgress * 509, 100);
this.lightSpineNode.setPosition(currentProgress * 509 - 278, -612, 0)
this.maskSpineNode
.getComponent(UITransform)
.setContentSize(currentProgress * 509, 100);
this.lightSpineNode.setPosition(
currentProgress * 509 - 268,
-612,
0
);
},
}
})
)
.start();
}
/** 更新加载文本 */
private updateLoadingText(key: string) {
this.loadingLabel.string = `${I18nManager.instance.t(key)}...`;
this.loadingLabel.string = I18nManager.instance.t("AID_LOADING");
}
/** 加载完成 */
private onLoadComplete() {
this.startBtnLabel.string = I18nManager.instance.t("AID_GET_STARTED");
this.hideProgressUI();
this.showStartButton();
}
@ -207,27 +280,40 @@ export class Loading extends Component {
this.startBtnNode.active = true;
}
/** 开始游戏 */
// private startGame() {
// if (!this.gameContainer) {
// console.error('Game container not found');
// return;
// }
private startGame() {
if (!this.gameContainer) {
console.error("Game container not found");
return;
}
// this.gameContainer.addChild(this.gameNode);
// // this.node.destroy();
// }
/** 按钮点击事件 */
onStartBtnClick() {
this.rb7Logo.active = false;
// 添加到场景
this.gameContainer.addChild(this.gameNode);
// 隐藏加载界面
this.LoadingUINode.destroy();
}
/** 按钮点击事件 */
onStartBtnClick() {
if (
this.startBtnLabel.string ===
I18nManager.instance.t("AID_ERROR_RETRY_BUTTON")
) {
// 重试逻辑
this._retryCount = 0;
this.startBtn.node.active = false;
this.progressBar.node.active = true;
this.progressLabel.node.active = true;
if (!this._networkComplete) {
this.startNetworkLoading();
} else {
this.startResourceLoading();
}
} else {
this.startGame();
}
}
onDestroy() {
this.unscheduleAllCallbacks();
tween(this.progressBar).stop();