LoadingViewComp.ts 5.2 KB

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