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