UILoading.ts 15 KB

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