LoadingViewComp.ts 6.6 KB

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