UILoading.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. import Gamecfg from "../../../common/gameCfg";
  2. import { gameMethod } from "../../../common/gameMethod";
  3. import { xlsPackageInfo } from "../../../common/xlsConfig";
  4. import Config from "../../../Config";
  5. import auto_loading from "../../../data/autoui/scene/auto_loading";
  6. import { GameEvent, LoadEvent, ServerEvent, TimeEvent } from "../../../data/const/EventConst";
  7. import { AudioConst, InGame, NoticeType, PlatformType } from "../../../data/const/TypeConst";
  8. import GameDataCenter from "../../../data/GameDataCenter";
  9. import { eg } from "../../../frameWork/eg";
  10. import FguiMgr from "../../../frameWork/fgui/FguiMgr";
  11. import GameController from "../../../GameController";
  12. import EventMng from "../../../manager/EventMng";
  13. import UIMng from "../../../manager/UIMng";
  14. import AssetMgr from "../../../utils/AssetMgr";
  15. import { I18n } from "../../../utils/I18nUtil";
  16. import Load from "../../../utils/Load";
  17. import { uiCommon } from "../../../utils/UICommon";
  18. import UIHelp, { DialogParams } from "../UIHelp";
  19. const { ccclass, menu, property } = cc._decorator;
  20. @ccclass
  21. @menu("UI/scene/UILoading")
  22. export default class UILoading extends cc.Component {
  23. @property(cc.Prefab)
  24. clickEft: cc.Prefab = null
  25. @property(cc.SpriteFrame)
  26. loadingBg0: cc.SpriteFrame = null
  27. @property(cc.SpriteFrame)
  28. loadingBg1: cc.SpriteFrame = null
  29. ui: auto_loading = null;
  30. togglePolicy: cc.Toggle = null
  31. progressBar: cc.Sprite
  32. enterGameSid: string = ""
  33. loginTipTime: number = 0 // 登录
  34. isLoginAccountSuccess: boolean = false //账号是否登录成功
  35. packageInfo: xlsPackageInfo
  36. protected onLoad(): void {
  37. eg.init();
  38. this.ui = this.node.addComponent(auto_loading);
  39. this.togglePolicy = this.ui.toggle.getComponent(cc.Toggle)
  40. this.progressBar = this.ui.progress.getComponent(cc.Sprite)
  41. //初始化fgui
  42. FguiMgr.Instance.Init();
  43. this.packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  44. Load.loadTexture(this.ui.imgLogo, "platAsset/logo/" + (this.packageInfo.logo || "base"))
  45. this.ui.btnService.active = Config.kefu == "1"
  46. if ((Config.showTips == "1")) {
  47. if (!gameMethod.isEmpty(Config.showTipType)) {
  48. Load.loadTexture(this.ui.tip, "platAsset/tip" + Config.showTipType)
  49. Load.loadTexture(this.ui.biaoshi, "platAsset/biaoshi" + Config.showTipType)
  50. Load.loadTexture(this.ui.TipBtn, "platAsset/kaijuwenzi" + Config.showTipType)
  51. this.ui.tip.active = true
  52. this.ui.biaoshi.active = true
  53. this.ui.TipBtn.active = true
  54. } else {
  55. this.ui.tip.active = false
  56. this.ui.biaoshi.active = false
  57. this.ui.TipBtn.active = false
  58. }
  59. // Load.loadTexture(this.ui.imgLogo, "platAsset/logo/" + (this.packageInfo.logo || "base") + "1")
  60. } else {
  61. this.ui.tip.active = false
  62. this.ui.biaoshi.active = false
  63. this.ui.TipBtn.active = false
  64. }
  65. //动态加载适龄提示图片
  66. if (!gameMethod.isEmpty(Config.showAgeTip)) {
  67. Load.loadTexture(this.ui.imgAgeTips, "platAsset/imgTip" + Config.showAgeTip);
  68. }
  69. if (!gameMethod.isEmpty(Config.showBgType)) {
  70. this.ui.background.getComponent(cc.Sprite).spriteFrame = this["loadingBg" + Config.showBgType]
  71. }
  72. // 某些渠道不展示版号软著信息
  73. if (gameMethod.isEmpty(this.packageInfo.loadingTips1) && gameMethod.isEmpty(this.packageInfo.loadingTips2)) {
  74. this.ui.imgAgeTips.y = 50
  75. this.ui.txtJiankang.y = 50
  76. this.ui.txtTips1.active = false
  77. this.ui.txtTips2.active = false
  78. } else {
  79. uiCommon.setLabel(this.ui.txtTips1, this.packageInfo.loadingTips1)
  80. uiCommon.setLabel(this.ui.txtTips2, this.packageInfo.loadingTips2)
  81. }
  82. console.log("初始化游戏配置表")
  83. let startTime = new Date().getTime()
  84. this.setProgress(0, "json");
  85. Gamecfg.init((isSucc: boolean) => {
  86. console.log("初始化游戏配置表流程结束,消耗时长:" + (new Date().getTime() - startTime) + "ms")
  87. if (isSucc) {
  88. this.ui.gProgress.active = false
  89. console.log("解析成功")
  90. // 初始化数据模块
  91. GameDataCenter.initModule();
  92. // GameDataCenter.adVideo.setAdOpen()
  93. // //初始化数数
  94. // ThinkingDataMgr.TDInit();
  95. GameDataCenter.loading.jsonLoadSucc = true
  96. this.ui.btnEnter.active = this.isLoginAccountSuccess
  97. GameDataCenter.loading.checkEnterGame()
  98. } else {
  99. console.log("解析失败")
  100. }
  101. }, (finish: number, total: number) => {
  102. this.setProgress(finish / total, "json");
  103. })
  104. }
  105. protected onEnable(): void {
  106. if (cc.sys.platform == cc.sys.WECHAT_GAME) {
  107. this.ui.btnClearCache.active = true
  108. } else {
  109. this.ui.btnClearCache.active = false
  110. }
  111. // 监听btnLogin点击事件
  112. uiCommon.onRegisterEvent(this.ui.btnEnter, this.onClickEnterGame, this);
  113. uiCommon.onRegisterEvent(this.ui.gServer, this.onClickServer, this);
  114. uiCommon.onRegisterEvent(this.ui.btnGonggao, this.onClickGonggao, this)
  115. uiCommon.onRegisterEvent(this.ui.btnService, this.onClickService, this)
  116. uiCommon.onRegisterEvent(this.ui.btnClearCache, this.onClickClearCache, this)
  117. // uiCommon.onRegisterEvent(this.ui.txtPolicy, this.onClickPolicy, this)
  118. uiCommon.onRegisterEvent(this.ui.imgAgeTips, this.onClickAgeTips, this)
  119. uiCommon.onRegisterEvent(this.ui.btnGzh, this.onClickGzh, this)
  120. uiCommon.onRegisterEvent(this.ui.TipsBtn, this.onClickTipsBtn, this)
  121. uiCommon.onRegisterEvent(this.ui.txtTips2, this.onClickBeiAnBtn, this)
  122. // 监听事件
  123. EventMng.on(GameEvent.LOGIN_ACCOUNT_SUCC, this.onLoginAccountSuccess, this);
  124. EventMng.on(GameEvent.LOGIN_USER_SUCC, this.onLoginUserSucc, this);
  125. EventMng.on(GameEvent.LOGIN_USER_FAIL, this.onLoginUserFail, this);
  126. EventMng.on(LoadEvent.LOAD_PROGRESS, this.setProgress, this)
  127. EventMng.on(LoadEvent.LOAD_POLICY_AGREE, this.onAgreeEvent, this)
  128. EventMng.on(LoadEvent.LOAD_POLICY_TIP_AGREE, this.onAgreeTipEvent, this)
  129. EventMng.on(GameEvent.CLOSE_GZH, this.fixBtnEnterPos, this)
  130. EventMng.on(ServerEvent.SET_LOGIN_SID, this.setLoginSid, this)
  131. EventMng.on(TimeEvent.TIME_CD, this.onTimeCd, this)
  132. EventMng.on(LoadEvent.LOAD_MESSAGE, this.showLbMsg, this)
  133. EventMng.on(LoadEvent.SHOW_LOGIN_BTN, this.ShowLoginBtn, this)
  134. }
  135. protected onDisable(): void {
  136. // 取消监听btnLogin点击事件
  137. uiCommon.unRegisterEvent(this.ui.btnEnter);
  138. uiCommon.unRegisterEvent(this.ui.gServer);
  139. uiCommon.unRegisterEvent(this.ui.btnGonggao);
  140. uiCommon.unRegisterEvent(this.ui.btnService);
  141. // uiCommon.unRegisterEvent(this.ui.txtPolicy)
  142. uiCommon.unRegisterEvent(this.ui.imgAgeTips)
  143. uiCommon.unRegisterEvent(this.ui.btnGzh)
  144. uiCommon.unRegisterEvent(this.ui.txtTips2)
  145. // 取消监听事件
  146. EventMng.off(GameEvent.LOGIN_ACCOUNT_SUCC, this.onLoginAccountSuccess, this);
  147. EventMng.off(GameEvent.LOGIN_USER_SUCC, this.onLoginUserSucc, this);
  148. EventMng.off(GameEvent.LOGIN_USER_FAIL, this.onLoginUserFail, this);
  149. EventMng.off(LoadEvent.LOAD_PROGRESS, this.setProgress, this)
  150. EventMng.off(LoadEvent.LOAD_POLICY_AGREE, this.onAgreeEvent, this)
  151. EventMng.off(LoadEvent.LOAD_POLICY_TIP_AGREE, this.onAgreeTipEvent, this)
  152. EventMng.off(GameEvent.CLOSE_GZH, this.fixBtnEnterPos, this)
  153. EventMng.off(ServerEvent.SET_LOGIN_SID, this.setLoginSid, this)
  154. EventMng.off(TimeEvent.TIME_CD, this.onTimeCd, this)
  155. EventMng.off(LoadEvent.LOAD_MESSAGE, this.showLbMsg, this)
  156. EventMng.off(LoadEvent.SHOW_LOGIN_BTN, this.ShowLoginBtn, this)
  157. }
  158. // 账号登录成功
  159. onLoginAccountSuccess() {
  160. this.ui.gProgress.active = false
  161. this.isLoginAccountSuccess = true
  162. //不管老玩家还是新玩家直接进游戏
  163. // this.ui.btnGonggao.active = true
  164. // this.enterGameSid = GameDataCenter.sevBack.playerInfo.sid
  165. // this.onClickEnterGame()
  166. // 检测是否为新玩家并且后台配置默认勾选隐私协议的,直接进入游戏
  167. //quickh5的,新玩家不能直接进入游
  168. if (GameDataCenter.plat.type != PlatformType.bth5 && gameMethod.isEmpty(GameDataCenter.sevBack.playerInfo.list) && Config.policy != "0") {
  169. // 新玩家,直接进入游戏
  170. this.enterGameSid = GameDataCenter.sevBack.playerInfo.sid
  171. this.onClickEnterGame()
  172. } else {
  173. // 老玩家,展示登录按钮
  174. this.ui.btnEnter.active = GameDataCenter.loading.jsonLoadSucc
  175. this.ui.gServer.active = true
  176. this.ui.btnGonggao.active = true
  177. //quick渠道包隐藏
  178. this.ui.gToggle.active = GameDataCenter.plat.type == PlatformType.bth5 || GameDataCenter.plat.type == PlatformType.XXGame ? false : true
  179. // this.checkCreateUserBtn()
  180. this.setLoginSid(GameDataCenter.sevBack.playerInfo.sid)
  181. }
  182. let showPolicy = GameDataCenter.sevBack.switch?.["showPolicy"]?.[Config.pid] ?? 0;
  183. if (this.togglePolicy.isChecked == false && showPolicy == 1) {
  184. this.onClickPolicy();
  185. }
  186. }
  187. // 角色登录成功
  188. onLoginUserSucc() {
  189. // 登录成功,隐藏提示
  190. this.loginTipTime = 0
  191. this.ui.txtLoginTips.active = false
  192. Config.inGame = InGame.loginUser
  193. GameDataCenter.loading.loginSucc = true
  194. GameDataCenter.loading.checkEnterGame()
  195. }
  196. // 角色登录失败
  197. onLoginUserFail() {
  198. // 重置为登录角色前状态,即直接调用账号登录成功方法
  199. this.onLoginAccountSuccess()
  200. }
  201. protected start(): void {
  202. uiCommon.setI18nTextLabel(this.ui.txtVersion, 'loading_txtVersion', Config.appVersion);
  203. // 加载一些常驻节点
  204. AssetMgr.instantiate(cc.director.getScene(), this.clickEft);
  205. this.isLoginAccountSuccess = false;
  206. this.ui.btnEnter.active = false;
  207. this.ui.gServer.active = false;
  208. this.ui.gToggle.active = false;
  209. this.ui.gProgress.active = false;
  210. // this.ui.gInfo.active = false;
  211. this.ui.btnGonggao.active = false;
  212. // 根据平台展示登录窗口
  213. GameDataCenter.plat.instance.showLoginView();
  214. if (GameDataCenter.plat.type == PlatformType.bth5) {
  215. //quick隐私在启动页处理了
  216. GameDataCenter.login.savePolicy(true);
  217. }
  218. this.togglePolicy.isChecked = GameDataCenter.login.getPolicy()
  219. // GameDataCenter.audio.playMusic(AudioConst.bgm_base)
  220. // 加载资源
  221. GameDataCenter.loading.loadMainAssets()
  222. }
  223. onClickEnterGame() {
  224. if (this.togglePolicy.isChecked == false) {
  225. UIHelp.ShowI18nTips("loading_showtips_1");
  226. this.onClickPolicy();
  227. return
  228. }
  229. if (this.enterGameSid == "" && GameDataCenter.sevBack?.playerInfo) {
  230. this.enterGameSid = GameDataCenter.sevBack?.playerInfo?.sid
  231. }
  232. if (GameDataCenter.sevBack?.qufuList[this.enterGameSid]?.status == "4") {
  233. UIHelp.ShowI18nTips("loading_showtips_2")
  234. return
  235. }
  236. // 此区无号,且是锁服状态
  237. if (GameDataCenter.sevBack?.playerInfo?.list[this.enterGameSid] == null && GameDataCenter.sevBack?.qufuList[this.enterGameSid]?.suofu > 0) {
  238. UIHelp.ShowI18nTips("loading_showtips_3")
  239. return
  240. }
  241. this.ui.btnEnter.active = false
  242. this.ui.gServer.active = false
  243. // this.ui.gInfo.active = false
  244. this.ui.gToggle.active = false
  245. GameDataCenter.login.sendEnterGame(this.enterGameSid)
  246. this.loginTipTime = 16
  247. this.onTimeCd()
  248. }
  249. onClickServer() {
  250. // cc.assetManager.loadBundle("commonView", () => {
  251. // FguiMgr.Instance.openUI(ServerViewView, ViewZorder.POP)
  252. // })
  253. }
  254. setProgress(val: number, type: "res" | "login" | "json") {
  255. if (GameDataCenter.loading.loginSucc == false && type == "res") {
  256. // 登录流程未走完,不展示资源加载进度条
  257. return
  258. }
  259. this.ui.gProgress.active = true
  260. this.progressBar.fillRange = val
  261. this.ui.imgRole.x = -this.ui.progress.width / 2 + val * this.ui.progress.width
  262. uiCommon.setLabel(this.ui.txtProgress, Math.floor(val * 100) + "%")
  263. uiCommon.setI18nTextLabel(this.ui.txtProgressTips, type == "login" ? "loading_txtProgressTips_1" : type == "res" ? "loading_txtProgressTips_2" : "loading_txtProgressTips_3")
  264. }
  265. onToggle() {
  266. GameDataCenter.login.savePolicy(this.togglePolicy.isChecked)
  267. }
  268. onAgreeEvent(agree: boolean) {
  269. this.togglePolicy.isChecked = agree
  270. this.onToggle()
  271. }
  272. onAgreeTipEvent(agree: boolean) {
  273. if ((Config.pid == "1108" || Config.pid == "1107") && agree) {
  274. GameDataCenter.plat.instance.showLoginView()
  275. }
  276. }
  277. // 公告
  278. onClickGonggao() {
  279. // if (gameMethod.isEmpty(GameDataCenter?.sevBack?.noticeWais)) {
  280. // UIHelp.ShowI18nTips("loading_showtips_4")
  281. // return
  282. // }
  283. // FguiMgr.Instance.openUI(GongGaoViewView, ViewZorder.POP, null, NoticeType.outside)
  284. }
  285. // 客服
  286. onClickService() {
  287. GameDataCenter.plat.instance.openService()
  288. }
  289. //清理缓存
  290. onClickClearCache() {
  291. //小游戏平台,清理缓存,重启游戏
  292. let data: DialogParams = {
  293. content: I18n.getI18nText("ClearCache"),
  294. cbConfirm: () => {
  295. cc.assetManager.cacheManager?.clearCache()
  296. GameController.clear()
  297. // cc.game.restart()
  298. if (GameDataCenter.plat.canRestartApp()) {
  299. wx.restartMiniProgram()
  300. } else {
  301. cc.game.end()
  302. }
  303. }
  304. };
  305. UIHelp.ShowDialog(data)
  306. }
  307. // 隐私政策
  308. onClickPolicy() {
  309. // if (GameDataCenter.plat.type == PlatformType.bth5) {
  310. // QuickSDK.showPrivace(function (retMsg) {
  311. // if (retMsg) {
  312. // } else {
  313. // QuickSDK.callExtFunction("exit", {});
  314. // }
  315. // });
  316. // } else {
  317. // FguiMgr.Instance.openUI(PolicyView, ViewZorder.POP, () => { }, { type: 0, isHideBtn: false });
  318. // }
  319. }
  320. //适龄提示
  321. onClickAgeTips() {
  322. // FguiMgr.Instance.openUI(AgeTipsView, ViewZorder.POP, null);
  323. }
  324. // 公众号
  325. onClickGzh() {
  326. this.fixBtnEnterPos(false)
  327. // UIHelp.ShowUI(UIGzhView)
  328. }
  329. //跳转备案号
  330. onClickTipsBtn() {
  331. if (GameDataCenter.plat.instance.isMiniClient()) {
  332. GameDataCenter.plat.instance.openUrl("https://beian.miit.gov.cn/");
  333. } else {
  334. cc.sys.openURL("https://beian.miit.gov.cn/");
  335. }
  336. }
  337. setLoginSid(sid: string) {
  338. this.enterGameSid = sid
  339. let qufuInfo = GameDataCenter.sevBack.qufuList[sid]
  340. uiCommon.setLabel(this.ui.txtServer, GameDataCenter.sevBack.qufuList[sid].name)
  341. let iconUrl = "resources/server/img_server_"
  342. if (qufuInfo.status == "1") {
  343. iconUrl += "new"
  344. // 1新服 2拥挤 3爆满 4维护
  345. } else if (qufuInfo.status == "4") {
  346. iconUrl += "weihu"
  347. } else {
  348. iconUrl += "hot"
  349. }
  350. Load.loadTexture(this.ui.imgServerState, iconUrl)
  351. }
  352. // 打开公众号时隐藏进入游戏按钮
  353. fixBtnEnterPos(show: boolean) {
  354. if (show) {
  355. this.ui.btnEnter.x = 0
  356. this.ui.gToggle.x = 0
  357. } else {
  358. this.ui.btnEnter.x = 2000
  359. this.ui.gToggle.x = 2000
  360. }
  361. }
  362. onTimeCd() {
  363. if (this.loginTipTime <= 0) {
  364. return
  365. }
  366. this.loginTipTime -= 1
  367. if (this.loginTipTime == 0) {
  368. // 此时已超时,由超时模块弹出提示弹窗
  369. this.ui.txtLoginTips.active = false
  370. } else {
  371. uiCommon.setI18nTextLabel(this.ui.txtLoginTips, 'loading_txtLoginTips', this.loginTipTime)
  372. this.ui.txtLoginTips.active = this.loginTipTime <= 14
  373. }
  374. }
  375. showLbMsg(str: string) {
  376. this.ui.lb_msg.getComponent(cc.Label).string = str;
  377. }
  378. onClickBeiAnBtn() {
  379. if (GameDataCenter.plat.type == PlatformType.wan17 || GameDataCenter.plat.type == PlatformType.wan17H5) {
  380. GameDataCenter.plat.instance.openUrl(Config.beianUrl);
  381. }
  382. }
  383. ShowLoginBtn() {
  384. this.ui.btnLogin.active = true
  385. }
  386. //拉取登录
  387. onClickLogin() {
  388. this.ui.btnLogin.active = false
  389. GameDataCenter.plat.instance.reShowLogInView();
  390. }
  391. protected onDestroy(): void {
  392. FguiMgr.Instance.Dispose()
  393. }
  394. protected update(dt: number): void {
  395. FguiMgr.Instance.OnUpdate(dt)
  396. }
  397. protected lateUpdate(dt: number): void {
  398. FguiMgr.Instance.OnLateUpdate(dt)
  399. }
  400. }