LoadingViewComp.ts 5.2 KB

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