LoadingViewComp.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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-01 18:30:47
  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. AndroidMessageCenter.getInstance().init();
  45. }
  46. enter() {
  47. this.addEvent();
  48. //查看缓存有没有同意过,也要向服务器发送登录请求,如果有过登录就直接拿数据登录,没有就显示微信登录
  49. let data = oops.storage.get("agree");
  50. if (data == null || data == "") {
  51. //打开温馨提示
  52. oops.gui.open(UIID.KindTips);
  53. return;
  54. } else {
  55. //同意过
  56. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  57. } else {
  58. //非原生,网页的
  59. this.loadRes();
  60. }
  61. }
  62. }
  63. private addEvent() {
  64. this.on(AndroidEvent.AgreePrivacy, this.onAgreePrivacy, this);
  65. this.on(GameEvent.WechatLoginSuss, this.loginSuss, this)
  66. }
  67. private loginSuss() {
  68. //关闭按钮
  69. //加载资源
  70. }
  71. private onAgreePrivacy() {
  72. console.log("同意隐私协议");
  73. oops.storage.set("agree", true);
  74. oops.gui.remove(UIID.KindTips);
  75. //如果是客户端就显示微信登录按钮
  76. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  77. this.showWxLogin();
  78. } else {
  79. this.loadRes();
  80. }
  81. }
  82. /** 加载资源 */
  83. private async loadRes() {
  84. this.data.progress = 0;
  85. await this.loadCustom();
  86. this.loadGameRes();
  87. }
  88. /** 加载游戏本地JSON数据(自定义内容) */
  89. private loadCustom() {
  90. // 加载游戏本地JSON数据的多语言提示文本
  91. this.data.prompt = oops.language.getLangByID("loading_load_json");
  92. }
  93. /** 加载初始游戏内容资源 */
  94. private loadGameRes() {
  95. // 加载初始游戏内容资源的多语言提示文本
  96. this.data.prompt = oops.language.getLangByID("loading_load_game");
  97. oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
  98. }
  99. /** 加载进度事件 */
  100. private onProgressCallback(finished: number, total: number, item: any) {
  101. this.data.finished = finished;
  102. this.data.total = total;
  103. var progress = finished / total;
  104. if (progress > this.progress) {
  105. this.progress = progress;
  106. this.data.progress = (progress * 100).toFixed(2);
  107. }
  108. }
  109. /** 加载完成事件 */
  110. private async onCompleteCallback() {
  111. // 获取用户信息的多语言提示文本
  112. this.data.prompt = oops.language.getLangByID("loading_load_player");
  113. await ModuleUtil.addViewUiAsync(smc.account, EliminateViewComp, UIID.Eliminate);
  114. ModuleUtil.removeViewUi(this.ent, LoadingViewComp, UIID.Loading);
  115. }
  116. /**
  117. * @description: 微信登录
  118. * @return {*}
  119. */
  120. private async btn_wxlogin() {
  121. //跟安卓交互
  122. //登录完要隐藏微信按钮然后加载进度
  123. let result = await CocosHandler.inst.wechat_login();
  124. if (result.code) {
  125. //登录成功
  126. //存数据
  127. const wxNode = this.node.getChildByName("login_node");
  128. if (wxNode) {
  129. wxNode.active = false;
  130. }
  131. this.loadRes();
  132. } else {
  133. oops.gui.toast("登录失败,请重试")
  134. }
  135. }
  136. /**
  137. * @description: 显示微信登录
  138. * @return {*}
  139. */
  140. showWxLogin() {
  141. const wxNode = this.node.getChildByName("login_node");
  142. if (wxNode) {
  143. wxNode.active = true;
  144. }
  145. }
  146. reset(): void { }
  147. /**
  148. * 保存关卡,分数,目标分数
  149. *
  150. *
  151. */
  152. }