LoadingViewComp.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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-10 15:16:01
  6. * @Description: loading界面
  7. */
  8. import { _decorator, Toggle } 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 { GameEvent } from "../../common/config/GameEvent";
  16. import { UIID } from "../../common/config/GameUIConfig";
  17. import { CocosHandler } from "../../common/manager/CocosHandler";
  18. import { smc } from "../../common/SingletonModuleComp";
  19. import { AD_TYPE } from "../../common/config/GameDefine";
  20. import { EliminateViewComp } from "../../view/EliminateViewComp";
  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.addEvent();
  43. this.setButton();
  44. this.updateToggleState();
  45. }
  46. private addEvent() {
  47. this.on(AndroidEvent.AgreePrivacy, this.onAgreePrivacy, this);
  48. this.on(GameEvent.WechatLoginSuss, this.loginSuss, this)
  49. this.on(GameEvent.UserLogin, this.userLogin, this);
  50. }
  51. async enter() {
  52. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  53. const state = await CocosHandler.inst.getPrivacyStatus();
  54. console.log("隐私状态>>>>>>>>>>>>>>>>", state);
  55. if (state.data.result) {
  56. //同意之后都加载一次启屏广告
  57. // CocosHandler.inst.ad_interstitial_start();
  58. CocosHandler.inst.show_ad(AD_TYPE.Start);
  59. } else {
  60. oops.gui.open(UIID.KindTips);
  61. }
  62. } else {
  63. //非原生,网页的
  64. this.setWxLoginBtnState(false);
  65. this.loadRes();
  66. }
  67. }
  68. private userLogin() {
  69. const isLogin = smc.account.AccountModel.isLogined;
  70. console.log("登录状态>>>>>>>>>>>>>>>>", isLogin);
  71. //暂时隐藏
  72. // if (isLogin) {
  73. // //登录过
  74. // this.setWxLoginBtnState(false);
  75. // this.loadRes();
  76. // } else {
  77. // this.setWxLoginBtnState(true);
  78. // }
  79. this.loadRes();
  80. }
  81. private loginSuss() {
  82. this.setWxLoginBtnState(false);
  83. this.loadRes();
  84. }
  85. private onAgreePrivacy() {
  86. console.log("同意隐私协议");
  87. oops.storage.set("agree", true);
  88. oops.gui.remove(UIID.KindTips);
  89. //如果是客户端就显示微信登录按钮
  90. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  91. //const show
  92. this.setWxLoginBtnState(true);
  93. //
  94. } else {
  95. this.loadRes();
  96. }
  97. }
  98. /** 加载资源 */
  99. private async loadRes() {
  100. this.data.progress = 0;
  101. await this.loadCustom();
  102. this.loadGameRes();
  103. }
  104. /** 加载游戏本地JSON数据(自定义内容) */
  105. private loadCustom() {
  106. // 加载游戏本地JSON数据的多语言提示文本
  107. this.data.prompt = oops.language.getLangByID("loading_load_json");
  108. }
  109. /** 加载初始游戏内容资源 */
  110. private loadGameRes() {
  111. // 加载初始游戏内容资源的多语言提示文本
  112. this.data.prompt = oops.language.getLangByID("loading_load_game");
  113. oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
  114. }
  115. /** 加载进度事件 */
  116. private onProgressCallback(finished: number, total: number, item: any) {
  117. this.data.finished = finished;
  118. this.data.total = total;
  119. var progress = finished / total;
  120. if (progress > this.progress) {
  121. this.progress = progress;
  122. this.data.progress = (progress * 100).toFixed(2);
  123. }
  124. }
  125. /** 加载完成事件 */
  126. private async onCompleteCallback() {
  127. // 获取用户信息的多语言提示文本
  128. this.data.prompt = oops.language.getLangByID("loading_load_player");
  129. await ModuleUtil.addViewUiAsync(smc.account, EliminateViewComp, UIID.Eliminate);
  130. ModuleUtil.removeViewUi(this.ent, LoadingViewComp, UIID.Loading);
  131. }
  132. /**
  133. * @description: 微信登录
  134. * @return {*}
  135. */
  136. private async btn_wxlogin() {
  137. //是否同意了我们的隐私政策
  138. const agree = oops.storage.getBoolean("agree");
  139. if (!agree) {
  140. // oops.gui.open(UIID.KindTips);
  141. oops.gui.toast("请同意隐私政策")
  142. return;
  143. }
  144. //暂时跳过这个登录
  145. // CocosHandler.inst.wechat_login();
  146. //直接获取信息
  147. CocosHandler.inst.getAccountInfo();
  148. }
  149. /**
  150. * @description: 显示微信登录
  151. * @return {*}
  152. */
  153. setWxLoginBtnState(state: boolean) {
  154. const wxNode = this.node.getChildByName("login_node");
  155. if (wxNode) {
  156. wxNode.active = state;
  157. }
  158. //load条相反
  159. const loadNode = this.node.getChildByName("pro_progress");
  160. if (loadNode) {
  161. loadNode.active = !state;
  162. }
  163. }
  164. /**
  165. * @description:隐私政策toggle
  166. * @return {*}
  167. */
  168. onToggleChick(toggle: Toggle) {
  169. if (toggle.isChecked) {
  170. oops.storage.set("agree", true);
  171. } else {
  172. oops.storage.set("agree", false);
  173. }
  174. }
  175. //更新toggle状态
  176. updateToggleState() {
  177. const agree = oops.storage.getBoolean("agree");
  178. const toggle = this.node.getChildByPath("login_node/login_bg/tog_agree")!.uiToggle;
  179. if (agree) {
  180. toggle.isChecked = true;
  181. } else {
  182. toggle.isChecked = false;
  183. }
  184. }
  185. reset(): void { }
  186. /**
  187. * 保存关卡,分数,目标分数
  188. *
  189. *
  190. */
  191. }