LoadingViewComp.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-19 16:23:51
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-02 15:04:39
  6. * @Description: loading界面
  7. */
  8. import { _decorator, sys } from "cc";
  9. import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
  10. import { ModuleUtil } from "db://oops-framework/module/common/ModuleUtil";
  11. import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
  12. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  13. import { CCVMParentComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCVMParentComp";
  14. import { AndroidEvent } from "../../common/config/AndroidEvent";
  15. import { UIID } from "../../common/config/GameUIConfig";
  16. import { AndroidMessageCenter } from '../../common/manager/AndroidMessageCenter';
  17. import { smc } from "../../common/SingletonModuleComp";
  18. import { EliminateViewComp } from "../../eliminate/view/EliminateViewComp";
  19. import { CocosHandler } from "../../common/manager/CocosHandler";
  20. import { GameEvent } from "../../common/config/GameEvent";
  21. const { ccclass, property } = _decorator;
  22. /** 游戏资源加载 */
  23. @ccclass('LoadingViewComp')
  24. @ecs.register('LoadingView', false)
  25. export class LoadingViewComp extends CCVMParentComp {
  26. /** VM 组件绑定数据 */
  27. data: any = {
  28. /** 加载资源当前进度 */
  29. finished: 0,
  30. /** 加载资源最大进度 */
  31. total: 0,
  32. /** 加载资源进度比例值 */
  33. progress: "0",
  34. /** 加载流程中提示文本 */
  35. prompt: "",
  36. /**btn_show*/
  37. btn_show: 0
  38. };
  39. private progress: number = 0;
  40. start() {
  41. this.enter();
  42. this.setButton();
  43. }
  44. enter() {
  45. this.addEvent();
  46. //查看缓存有没有同意过,也要向服务器发送登录请求,如果有过登录就直接拿数据登录,没有就显示微信登录
  47. // let data = oops.storage.get("agree");
  48. // if (data == null || data == "") {
  49. // //打开温馨提示
  50. // oops.gui.open(UIID.KindTips);
  51. // return;
  52. // } else {
  53. // //同意过
  54. // if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  55. // } else {
  56. // //非原生,网页的
  57. // this.loadRes();
  58. // }
  59. // }
  60. this.loadRes();
  61. }
  62. private addEvent() {
  63. this.on(AndroidEvent.AgreePrivacy, this.onAgreePrivacy, this);
  64. this.on(GameEvent.WechatLoginSuss, this.loginSuss, this)
  65. }
  66. private loginSuss() {
  67. //关闭按钮
  68. //加载资源
  69. }
  70. private onAgreePrivacy() {
  71. console.log("同意隐私协议");
  72. oops.storage.set("agree", true);
  73. oops.gui.remove(UIID.KindTips);
  74. //如果是客户端就显示微信登录按钮
  75. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  76. this.showWxLogin();
  77. } else {
  78. this.loadRes();
  79. }
  80. }
  81. /** 加载资源 */
  82. private async loadRes() {
  83. this.data.progress = 0;
  84. await this.loadCustom();
  85. this.loadGameRes();
  86. }
  87. /** 加载游戏本地JSON数据(自定义内容) */
  88. private loadCustom() {
  89. // 加载游戏本地JSON数据的多语言提示文本
  90. this.data.prompt = oops.language.getLangByID("loading_load_json");
  91. }
  92. /** 加载初始游戏内容资源 */
  93. private loadGameRes() {
  94. // 加载初始游戏内容资源的多语言提示文本
  95. this.data.prompt = oops.language.getLangByID("loading_load_game");
  96. oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
  97. }
  98. /** 加载进度事件 */
  99. private onProgressCallback(finished: number, total: number, item: any) {
  100. this.data.finished = finished;
  101. this.data.total = total;
  102. var progress = finished / total;
  103. if (progress > this.progress) {
  104. this.progress = progress;
  105. this.data.progress = (progress * 100).toFixed(2);
  106. }
  107. }
  108. /** 加载完成事件 */
  109. private async onCompleteCallback() {
  110. // 获取用户信息的多语言提示文本
  111. this.data.prompt = oops.language.getLangByID("loading_load_player");
  112. await ModuleUtil.addViewUiAsync(smc.account, EliminateViewComp, UIID.Eliminate);
  113. ModuleUtil.removeViewUi(this.ent, LoadingViewComp, UIID.Loading);
  114. }
  115. /**
  116. * @description: 微信登录
  117. * @return {*}
  118. */
  119. private async btn_wxlogin() {
  120. //跟安卓交互
  121. //登录完要隐藏微信按钮然后加载进度
  122. let result = await CocosHandler.inst.wechat_login();
  123. if (result.code) {
  124. //登录成功
  125. //存数据
  126. const wxNode = this.node.getChildByName("login_node");
  127. if (wxNode) {
  128. wxNode.active = false;
  129. }
  130. this.loadRes();
  131. } else {
  132. oops.gui.toast("登录失败,请重试")
  133. }
  134. }
  135. /**
  136. * @description: 显示微信登录
  137. * @return {*}
  138. */
  139. showWxLogin() {
  140. const wxNode = this.node.getChildByName("login_node");
  141. if (wxNode) {
  142. wxNode.active = true;
  143. }
  144. }
  145. reset(): void { }
  146. /**
  147. * 保存关卡,分数,目标分数
  148. *
  149. *
  150. */
  151. }