2025-08-12 19:49:50 +08:00
|
|
|
import {
|
|
|
|
|
_decorator,
|
|
|
|
|
AssetManager,
|
|
|
|
|
AudioClip,
|
2025-08-15 09:41:24 +08:00
|
|
|
BufferAsset,
|
2025-08-12 19:49:50 +08:00
|
|
|
Button,
|
|
|
|
|
Component,
|
|
|
|
|
ImageAsset,
|
2025-09-20 18:41:10 +08:00
|
|
|
instantiate,
|
2025-08-12 19:49:50 +08:00
|
|
|
JsonAsset,
|
|
|
|
|
Label,
|
|
|
|
|
Material,
|
|
|
|
|
Node,
|
|
|
|
|
Prefab,
|
|
|
|
|
ProgressBar,
|
|
|
|
|
Sprite,
|
|
|
|
|
SpriteFrame,
|
2025-09-20 20:44:55 +08:00
|
|
|
VideoPlayer,
|
2025-08-12 19:49:50 +08:00
|
|
|
} from "cc";
|
|
|
|
|
import { GButton } from "../../Main/Common/GButton";
|
|
|
|
|
import ResManager from "../../Main/Manager/ResManager";
|
|
|
|
|
import { SDKManager } from "../../Main/Channel/SDKManager";
|
|
|
|
|
import HttpUnit from "../../Main/Common/HttpUnit";
|
|
|
|
|
import GlobalValue from "../../Main/Common/GlobalValue";
|
|
|
|
|
import Utils from "../../Main/Common/Utils";
|
|
|
|
|
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
|
|
|
|
|
import { promptItem } from "../Item/promptItem";
|
|
|
|
|
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
|
2025-09-20 18:41:10 +08:00
|
|
|
import { DataId, DataManager } from "../../chat18x/data/DataManager";
|
2025-09-01 16:26:37 +08:00
|
|
|
import { ConfigManager } from "../../chat18x/manager/ConfigManager";
|
2025-08-15 16:19:23 +08:00
|
|
|
import { AppConfig } from "db://assets/Scripts/chat18x/config/env/appConfig";
|
|
|
|
|
import DeviceIdService from "db://assets/Scripts/chat18x/foundation/identity/DeviceIdService";
|
2025-09-20 18:41:10 +08:00
|
|
|
import { AccountData } from "../../chat18x/data/AccountData";
|
|
|
|
|
import { EnvData } from "../../chat18x/data/EnvData";
|
|
|
|
|
import { GlobalData } from "../../chat18x/data/GlobalData";
|
2025-09-20 20:36:59 +08:00
|
|
|
import { AiCharacterData } from "../../chat18x/data/AiCharacterData";
|
2025-09-20 18:41:10 +08:00
|
|
|
import { LoginData } from "../../chat18x/data/LoginData";
|
|
|
|
|
import { PlayerData } from "../../chat18x/data/PlayerData";
|
|
|
|
|
import { WalletData } from "../../chat18x/data/WalletData";
|
|
|
|
|
import MachineInfoService from "../../chat18x/foundation/identity/MachineInfoService";
|
|
|
|
|
import { AuthService } from "../../chat18x/network/services/AuthService";
|
|
|
|
|
import { CommonService } from "../../chat18x/network/services/CommonService";
|
|
|
|
|
import { PlayerDataService } from "../../chat18x/network/services/PlayerDataService";
|
|
|
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
|
|
|
import { ViewManager } from "../../Main/Manager/ViewManager";
|
|
|
|
|
import { MainScene } from "../MainScene";
|
2025-09-21 13:14:13 +08:00
|
|
|
import { prodConfig } from "../../chat18x/config/env/prod";
|
2025-09-21 19:49:08 +08:00
|
|
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
2025-09-25 11:20:03 +08:00
|
|
|
import AudioManager from "../../Main/Manager/AudioManager";
|
|
|
|
|
import { Config18x } from "../../Main/Config/Config18x";
|
2025-09-25 15:09:04 +08:00
|
|
|
import { MainController } from "../../chat18x/core/MainController";
|
|
|
|
|
import GameRootUI from "../../Main/Common/GameRootUI";
|
|
|
|
|
import { TipsPanel } from "../../chat18x/ui/panels/TipsPanel";
|
2025-08-18 10:58:38 +08:00
|
|
|
|
2025-07-17 17:18:21 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
@ccclass("PreloadUI")
|
2025-07-17 17:18:21 +08:00
|
|
|
export class PreloadUI extends Component {
|
2025-09-20 18:41:10 +08:00
|
|
|
@property(MainScene)
|
|
|
|
|
mainScene: MainScene = null;
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-09-20 18:41:10 +08:00
|
|
|
private _nodeTab: any = {};
|
|
|
|
|
|
|
|
|
|
private preloadFinish = false; //资源加载完成
|
|
|
|
|
private loginFinish = false; //登录完成
|
|
|
|
|
|
|
|
|
|
loginBtn: Node;
|
2025-08-12 19:49:50 +08:00
|
|
|
private jinduBar: Node = null;
|
|
|
|
|
private jinduFilled: Sprite = null;
|
2025-09-20 20:44:55 +08:00
|
|
|
private VideoPlayer: VideoPlayer;
|
2025-09-21 13:14:13 +08:00
|
|
|
|
|
|
|
|
private appVersion: Label;
|
2025-08-12 19:49:50 +08:00
|
|
|
start() {
|
|
|
|
|
//Utils.addInnerEL(InnerMsgCode.UI_ShowPrompt, this, this.resiveShowPrompt)
|
2025-09-20 18:41:10 +08:00
|
|
|
Utils.parseNode(this.node, this._nodeTab);
|
|
|
|
|
|
2025-09-21 16:04:51 +08:00
|
|
|
// 添加新的事件监听
|
|
|
|
|
|
2025-09-21 13:14:13 +08:00
|
|
|
this.appVersion = this._nodeTab.appVersion.getComponent(Label);
|
2025-09-20 18:41:10 +08:00
|
|
|
this.loginBtn = this._nodeTab.btnLogin;
|
|
|
|
|
this.loginBtn.active = false;
|
2025-09-21 13:14:13 +08:00
|
|
|
this.appVersion.string = `app version: ${prodConfig.appVersion}`;
|
2025-09-20 20:44:55 +08:00
|
|
|
this.VideoPlayer = this._nodeTab.VideoPlayer.getComponent(VideoPlayer);
|
|
|
|
|
|
2025-09-21 16:04:51 +08:00
|
|
|
this.VideoPlayer.node.on(
|
|
|
|
|
VideoPlayer.EventType.META_LOADED,
|
|
|
|
|
this.onVideoReadyToPlay,
|
|
|
|
|
this
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-20 18:41:10 +08:00
|
|
|
GButton.BandClick(this.loginBtn, this.onLogin, this);
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
this.jinduBar = this.node.getChildByName("jinduBar");
|
|
|
|
|
this.jinduFilled = this.jinduBar
|
|
|
|
|
.getChildByName("jinduFilled")
|
|
|
|
|
.getComponent(Sprite);
|
2025-09-09 14:50:51 +08:00
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
//适配背景图
|
2025-09-20 18:41:10 +08:00
|
|
|
//let BG = this.node.getChildByName("BG");
|
|
|
|
|
//Utils.adjustBgPixelRatio(BG, 1);
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
this.jinduFilled.fillRange = 0;
|
2025-08-15 09:41:24 +08:00
|
|
|
|
2025-09-20 20:44:55 +08:00
|
|
|
if (!this.VideoPlayer.isPlaying) this.VideoPlayer.play();
|
|
|
|
|
|
2025-08-18 10:22:46 +08:00
|
|
|
// 初始化配置
|
|
|
|
|
ConfigManager.I.init();
|
2025-09-21 19:49:08 +08:00
|
|
|
//logger.log(ConfigManager.tables.TbGlobalConfig.GameName);
|
2025-08-15 16:19:23 +08:00
|
|
|
// 初始化环境配置
|
|
|
|
|
AppConfig.I;
|
2025-08-14 16:30:08 +08:00
|
|
|
// 初始化数据层
|
2025-08-15 14:59:08 +08:00
|
|
|
DataManager.I.init();
|
2025-08-15 16:19:23 +08:00
|
|
|
// 设备号
|
|
|
|
|
DeviceIdService.I.init();
|
2025-08-15 14:59:08 +08:00
|
|
|
|
2025-09-25 11:20:03 +08:00
|
|
|
AudioManager.I.PlayMusic(Config18x.AudioConfig.MainBGM);
|
|
|
|
|
|
2025-09-18 23:33:06 +08:00
|
|
|
SDKManager.init();
|
2025-08-12 19:49:50 +08:00
|
|
|
|
2025-09-18 23:33:06 +08:00
|
|
|
this.preloadFiles();
|
2025-09-25 15:09:04 +08:00
|
|
|
|
|
|
|
|
this.mainScene.init();
|
2025-08-12 19:49:50 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-21 16:04:51 +08:00
|
|
|
protected onDestroy(): void {}
|
2025-08-12 19:49:50 +08:00
|
|
|
|
2025-09-21 16:04:51 +08:00
|
|
|
onVideoReadyToPlay() {
|
2025-09-21 19:49:08 +08:00
|
|
|
logger.log("Video Ready");
|
2025-09-21 16:04:51 +08:00
|
|
|
this._nodeTab.VideoPlayer.getComponent(VideoPlayer).play();
|
|
|
|
|
}
|
2025-08-12 19:49:50 +08:00
|
|
|
update(deltaTime: number) {
|
2025-09-20 18:41:10 +08:00
|
|
|
if (!this.preloadFinish) {
|
|
|
|
|
return;
|
|
|
|
|
//this.goToLoginScene();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.loginFinish) {
|
|
|
|
|
this.loginFinish = false;
|
2025-09-10 12:29:05 +08:00
|
|
|
this.preloadFinish = false;
|
2025-09-20 18:41:10 +08:00
|
|
|
|
|
|
|
|
this.enterGame();
|
2025-07-17 17:18:21 +08:00
|
|
|
}
|
2025-08-12 19:49:50 +08:00
|
|
|
}
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
//预加载文件
|
|
|
|
|
preloadFiles() {
|
|
|
|
|
let preloadTab = [
|
|
|
|
|
{ path: "ChatPanel", bundleName: "Chat18x", ftype: Prefab },
|
|
|
|
|
{ path: "GirlDetailPanel", bundleName: "Chat18x", ftype: Prefab },
|
|
|
|
|
{ path: "GirlListPanel", bundleName: "Chat18x", ftype: Prefab },
|
2025-08-15 09:41:24 +08:00
|
|
|
{ path: "tblanguage", bundleName: "DataTable", ftype: BufferAsset },
|
2025-08-12 19:49:50 +08:00
|
|
|
];
|
|
|
|
|
let num_prefab = 0; //已加载数量
|
|
|
|
|
let num_succeed = 0; //加载成功数量
|
|
|
|
|
let preloadFunc = () => {
|
|
|
|
|
if (num_prefab < preloadTab.length) {
|
|
|
|
|
let cfg = preloadTab[num_prefab];
|
|
|
|
|
ResManager.I.preLoadSubpackageFile(
|
|
|
|
|
cfg.path,
|
|
|
|
|
cfg.bundleName,
|
|
|
|
|
cfg.ftype,
|
|
|
|
|
(ret) => {
|
|
|
|
|
num_prefab++;
|
|
|
|
|
num_succeed++;
|
|
|
|
|
let percent = 0.45 * (num_prefab / preloadTab.length);
|
|
|
|
|
this.showLoadProgress(0.55 + percent);
|
2025-09-21 19:49:08 +08:00
|
|
|
logger.log("加载成功:", cfg.path);
|
2025-08-12 19:49:50 +08:00
|
|
|
preloadFunc();
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
num_prefab++;
|
2025-09-21 19:49:08 +08:00
|
|
|
logger.log("加载失败:", err);
|
2025-08-12 19:49:50 +08:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
if (num_succeed >= num_prefab) {
|
2025-09-20 18:41:10 +08:00
|
|
|
this.startloginProcess();
|
2025-07-17 17:18:21 +08:00
|
|
|
}
|
2025-08-12 19:49:50 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
preloadFunc();
|
|
|
|
|
}
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
//加载配置表
|
2025-09-20 18:41:10 +08:00
|
|
|
startloginProcess() {
|
|
|
|
|
this.jinduBar.active = false;
|
|
|
|
|
this.preloadFinish = true;
|
|
|
|
|
this.loginBtn.active = true;
|
2025-08-12 19:49:50 +08:00
|
|
|
}
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-08-12 19:49:50 +08:00
|
|
|
//显示加载进度
|
|
|
|
|
showLoadProgress(percent) {
|
|
|
|
|
this.jinduFilled.fillRange = percent;
|
|
|
|
|
}
|
2025-07-17 17:18:21 +08:00
|
|
|
|
2025-09-10 12:29:05 +08:00
|
|
|
// 跳转到登录场景
|
2025-09-20 18:41:10 +08:00
|
|
|
// private goToLoginScene() {
|
|
|
|
|
// this.jinduBar.active = false;
|
|
|
|
|
// ResManager.I.goCustomScene("LoginScene");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
async onLogin() {
|
|
|
|
|
const deviceId = DeviceIdService.I.id;
|
|
|
|
|
const os = MachineInfoService.I.getMachineOs();
|
|
|
|
|
const reqData = {
|
|
|
|
|
platType: "guest",
|
|
|
|
|
userId: deviceId,
|
|
|
|
|
device: deviceId,
|
|
|
|
|
os,
|
|
|
|
|
};
|
2025-09-21 19:49:08 +08:00
|
|
|
logger.log("登录请求数据:", reqData);
|
2025-09-20 18:41:10 +08:00
|
|
|
let res = await AuthService.I.login(reqData);
|
2025-09-21 19:49:08 +08:00
|
|
|
logger.log("登录响应数据:", res);
|
2025-09-20 18:41:10 +08:00
|
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
|
|
|
const resData = res.data;
|
|
|
|
|
const loginData = DataManager.I.getDataById<LoginData>(DataId.Login);
|
|
|
|
|
loginData.token = resData.token;
|
|
|
|
|
loginData.refreshToken = resData.refreshToken;
|
|
|
|
|
loginData.expire = Number(resData.expire);
|
|
|
|
|
const playerData = DataManager.I.getDataById<PlayerData>(DataId.Player);
|
|
|
|
|
playerData.name = resData.name;
|
|
|
|
|
const accountData = DataManager.I.getDataById<AccountData>(
|
|
|
|
|
DataId.Account
|
|
|
|
|
);
|
|
|
|
|
accountData.accId = resData.accId;
|
|
|
|
|
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
|
|
|
|
envData.cdn = resData.cdn;
|
|
|
|
|
|
|
|
|
|
this.loginFinish = true;
|
|
|
|
|
this.reqMyInfo();
|
|
|
|
|
this.reqGlobalData();
|
2025-09-20 20:36:59 +08:00
|
|
|
this.reqAiCharacterData();
|
2025-09-25 15:09:04 +08:00
|
|
|
} else {
|
|
|
|
|
TipsPanel.show(LanguageUtils.getText("error_code_" + res.code));
|
2025-09-20 18:41:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 请求个人数据
|
|
|
|
|
private async reqMyInfo() {
|
|
|
|
|
const reqData = {};
|
|
|
|
|
let res = await PlayerDataService.I.reqMyInfo(reqData);
|
2025-09-21 19:49:08 +08:00
|
|
|
logger.log("个人信息响应数据:", res);
|
2025-09-20 18:41:10 +08:00
|
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
|
|
|
const resData = res.data;
|
|
|
|
|
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
|
|
|
|
walletData.balance = Number(resData.balance);
|
|
|
|
|
walletData.vipExpire = Number(resData.vipExpire);
|
2025-09-25 15:09:04 +08:00
|
|
|
} else {
|
|
|
|
|
TipsPanel.show(LanguageUtils.getText("error_code_" + res.code));
|
2025-09-20 18:41:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 请求全局数据
|
|
|
|
|
private async reqGlobalData() {
|
|
|
|
|
const reqData = {
|
|
|
|
|
resName: "TbGlobalConfig",
|
|
|
|
|
};
|
|
|
|
|
let res = await CommonService.I.reqResConfig(reqData);
|
|
|
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
|
|
|
// 保存数据
|
|
|
|
|
const globalData = DataManager.I.getDataById<GlobalData>(DataId.Global);
|
|
|
|
|
globalData.globals = res.data;
|
2025-09-25 15:09:04 +08:00
|
|
|
} else {
|
|
|
|
|
TipsPanel.show(LanguageUtils.getText("error_code_" + res.code));
|
2025-09-20 18:41:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-20 20:36:59 +08:00
|
|
|
// 请求Ai角色配置
|
|
|
|
|
private async reqAiCharacterData() {
|
|
|
|
|
const reqData = {
|
|
|
|
|
resName: "TbAiCharacters",
|
|
|
|
|
};
|
|
|
|
|
let res = await CommonService.I.reqResConfig(reqData);
|
|
|
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
|
|
|
// 保存数据
|
2025-09-20 20:44:55 +08:00
|
|
|
const aiCharacterData = DataManager.I.getDataById<AiCharacterData>(
|
|
|
|
|
DataId.AiCharacter
|
|
|
|
|
);
|
2025-09-20 20:36:59 +08:00
|
|
|
aiCharacterData.aiCharacter = res.data;
|
2025-09-25 15:09:04 +08:00
|
|
|
} else {
|
|
|
|
|
TipsPanel.show(LanguageUtils.getText("error_code_" + res.code));
|
2025-09-20 20:36:59 +08:00
|
|
|
}
|
2025-09-20 20:44:55 +08:00
|
|
|
}
|
2025-09-20 20:36:59 +08:00
|
|
|
|
2025-09-25 15:09:04 +08:00
|
|
|
private async enterGame() {
|
|
|
|
|
await MainController.I.init();
|
2025-09-20 18:41:10 +08:00
|
|
|
this.node.destroy();
|
2025-09-25 15:09:04 +08:00
|
|
|
GameRootUI.I.showDefault();
|
2025-09-20 18:41:10 +08:00
|
|
|
//ResManager.I.goMainScene();
|
2025-08-16 01:07:42 +08:00
|
|
|
}
|
2025-07-17 17:18:21 +08:00
|
|
|
}
|