using UnityEngine; using FairyGUI; using UI.Login; using ET; using TapTap.Bootstrap; using System; using TapTap.Common; namespace GFGGame { public class LoginView : BaseView { private UI_LoginUI _ui; private GameObject _scenePrefab; private GameObject _sceneObject; public override void Dispose() { _ui = null; if (_sceneObject != null) { GameObject.Destroy(_sceneObject); _sceneObject = null; } if (_scenePrefab != null) { GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneMain")); _scenePrefab = null; } base.Dispose(); } protected override void Init() { base.Init(); packageName = UI_LoginUI.PACKAGE_NAME; _ui = UI_LoginUI.Create(); viewCom = _ui.target; isfullScreen = true; _scenePrefab = GFGAsset.Load(ResPathUtil.GetPrefabPath("SceneMain")); } protected override void OnInit() { base.OnInit(); _ui.m_txtVersion.text = GameGlobal.version; _ui.m_btnNotice.onClick.Add(OnClickBtnNotice); _ui.m_btnStart.onClick.Add(OnClickBtnStart); _ui.m_btnLogout.onClick.Add(OnClickBtnLogout); _ui.m_btnAge.onClick.Add(OnClickBtnAge); _ui.m_btnTapLogin.onClick.Add(OnClickBtnTabLogin); _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP; _ui.m_btnChange.onClick.Add(OnBtnChangeClick); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener); EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess); } protected override void OnShown() { base.OnShown(); MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT)); if (_sceneObject == null) { _sceneObject = GameObject.Instantiate(_scenePrefab); } SceneController.UpdateLoginScene(_sceneObject); ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo; UpdateServer(recentlyServerInfo); _ui.m_btnStart.visible = false; _ui.m_btnTapLogin.visible = false; _ui.m_btnLogout.visible = false; InitLoginStatus(serverInfosComponent).Coroutine(); } protected override void OnHide() { if (_sceneObject != null) { GameObject.Destroy(_sceneObject); _sceneObject = null; } base.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener); EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess); } private async ETTask InitLoginStatus(ServerInfosComponent serverInfosComponent) { if (PlatformManager.IsTaptap)//taptap平台 { var success = await PlatformTapManager.Instance.LoginCache(); _ui.m_btnTapLogin.visible = !success; } else//自有登录 { _ui.m_btnStart.visible = true; //尝试自动登录 if (serverInfosComponent.ServerInfoList.Count <= 0) { OnClickBtnStart(); } } } private void OnClickBtnTabLogin() { OnClickBtnTabLoginAsync().Coroutine(); } private async ETTask OnClickBtnTabLoginAsync() { var success = await PlatformTapManager.Instance.Login(); _ui.m_btnTapLogin.visible = !success; } private void UpdateServer(ServerInfo info) { ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); if (serverInfosComponent.ServerInfoList.Count == 0) { _ui.m_btnChange.visible = false; return; } _ui.m_btnChange.visible = serverInfosComponent.ServerInfoList.Count > 1; _ui.m_btnChange.title = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)info.Id), info.ServerName); LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer); } private void OnLoginSuccess(EventContext context) { _ui.m_btnLogout.visible = true; _ui.m_btnStart.visible = true; } private void OnSeverChangeListener(EventContext context) { ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); UpdateServer(serverInfosComponent.ServerInfoList[serverInfosComponent.CurrentServerId]); } private void OnBtnChangeClick() { ViewManager.Show(); } private void OnClickBtnNotice() { if (NoticeDataManager.Instance.LastNoticeInfo == null || NoticeDataManager.Instance.LastNoticeInfo.noticeId == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无公告发布"); return; } ViewManager.Show(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content }); } private void OnClickBtnStart() { if (PlatformManager.IsTaptap)//taptap平台 { LoginController.GetRoles().Coroutine(); } else { var serverInfosComponent = GameGlobal.zoneScene.GetComponent(); if (serverInfosComponent.ServerInfoList.Count <= 0) { bool login = GameController.CheckLoginCache(true); if (!login) { ViewManager.Show(); } } else { LoginController.GetRoles().Coroutine(); } } } private void OnClickBtnLogout() { GameController.QuitToLoginView(true); } private void OnClickBtnAge() { ViewManager.Show(new object[] { LoginController.ageTipsTitle, LoginController.ageTips }); } } }