| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /*
- * @Author: mojunshou 1637302775@qq.com
- * @Date: 2025-03-19 16:23:51
- * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-03-31 15:06:48
- * @Description: loading界面
- */
- import { _decorator, sys } from "cc";
- import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
- import { ModuleUtil } from "db://oops-framework/module/common/ModuleUtil";
- import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
- import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
- import { CCVMParentComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCVMParentComp";
- import { AndroidEvent } from "../../common/config/AndroidEvent";
- import { UIID } from "../../common/config/GameUIConfig";
- import { AndroidMessageCenter } from '../../common/manager/AndroidMessageCenter';
- import { smc } from "../../common/SingletonModuleComp";
- import { EliminateViewComp } from "../../eliminate/view/EliminateViewComp";
- import { CocosHandler } from "../../common/manager/CocosHandler";
- const { ccclass, property } = _decorator;
- /** 游戏资源加载 */
- @ccclass('LoadingViewComp')
- @ecs.register('LoadingView', false)
- export class LoadingViewComp extends CCVMParentComp {
- /** VM 组件绑定数据 */
- data: any = {
- /** 加载资源当前进度 */
- finished: 0,
- /** 加载资源最大进度 */
- total: 0,
- /** 加载资源进度比例值 */
- progress: "0",
- /** 加载流程中提示文本 */
- prompt: "",
- /**btn_show*/
- btn_show: 0
- };
- private progress: number = 0;
- start() {
- this.enter();
- this.setButton();
- // 初始化安卓消息处理中心
- AndroidMessageCenter.getInstance().init();
- }
- enter() {
- this.addEvent();
- //查看缓存有没有同意过,也要向服务器发送登录请求,如果有过登录就直接拿数据登录,没有就显示微信登录
- let data = oops.storage.get("agree");
- if (data == null || data == "") {
- //打开温馨提示
- oops.gui.open(UIID.KindTips);
- return;
- } else {
- //同意过
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- } else {
- //非原生,网页的
- this.loadRes();
- }
- }
- }
- private addEvent() {
- this.on(AndroidEvent.AgreePrivacy, this.onAgreePrivacy, this);
- }
- private onAgreePrivacy() {
- console.log("同意隐私协议");
- oops.storage.set("agree", true);
- oops.gui.remove(UIID.KindTips);
- //如果是客户端就显示微信登录按钮
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- this.showWxLogin();
- } else {
- this.loadRes();
- }
- }
- /** 加载资源 */
- private async loadRes() {
- this.data.progress = 0;
- await this.loadCustom();
- this.loadGameRes();
- }
- /** 加载游戏本地JSON数据(自定义内容) */
- private loadCustom() {
- // 加载游戏本地JSON数据的多语言提示文本
- this.data.prompt = oops.language.getLangByID("loading_load_json");
- }
- /** 加载初始游戏内容资源 */
- private loadGameRes() {
- // 加载初始游戏内容资源的多语言提示文本
- this.data.prompt = oops.language.getLangByID("loading_load_game");
- oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
- }
- /** 加载进度事件 */
- private onProgressCallback(finished: number, total: number, item: any) {
- this.data.finished = finished;
- this.data.total = total;
- var progress = finished / total;
- if (progress > this.progress) {
- this.progress = progress;
- this.data.progress = (progress * 100).toFixed(2);
- }
- }
- /** 加载完成事件 */
- private async onCompleteCallback() {
- // 获取用户信息的多语言提示文本
- this.data.prompt = oops.language.getLangByID("loading_load_player");
- await ModuleUtil.addViewUiAsync(smc.account, EliminateViewComp, UIID.Eliminate);
- ModuleUtil.removeViewUi(this.ent, LoadingViewComp, UIID.Loading);
- }
- /**
- * @description: 微信登录
- * @return {*}
- */
- private async btn_wxlogin() {
- //跟安卓交互
- //登录完要隐藏微信按钮然后加载进度
- let result = await CocosHandler.getInstance().wechat_login();
- if (result.code) {
- //登录成功
- //存数据
- const wxNode = this.node.getChildByName("login_node");
- if (wxNode) {
- wxNode.active = false;
- }
- this.loadRes();
- } else {
- oops.gui.toast("登录失败,请重试")
- }
- }
- /**
- * @description: 显示微信登录
- * @return {*}
- */
- showWxLogin() {
- const wxNode = this.node.getChildByName("login_node");
- if (wxNode) {
- wxNode.active = true;
- }
- }
- reset(): void { }
- /**
- * 保存关卡,分数,目标分数
- *
- *
- */
- }
|