//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Saturday, September 02, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using LitJson;
|
|
namespace vnxbqy.UI
|
{
|
|
public class LoginWin : Window
|
{
|
public static bool firstOpenEnd { get; private set; }
|
|
private string m_ServerIP = "mobile.173on.com";
|
private int m_Port = 9090;
|
private int m_GamePort = 19006;
|
|
[SerializeField] Image m_Logo;
|
[SerializeField] UIAlphaTween m_AlphaTween;
|
[SerializeField] RectTransform m_WaitServerList;
|
[SerializeField] RectTransform m_ContainerEnterGame;
|
[SerializeField] RectTransform m_ContainerAccount;
|
[SerializeField] Image m_ServerState;
|
[SerializeField] Text m_ServerStateDescription;
|
[SerializeField] Text m_ServerName;
|
[SerializeField] protected InputField m_Account;
|
[SerializeField] Button m_EnterGame;
|
[SerializeField] Button m_QQLogin;
|
[SerializeField] Button m_WXLogin;
|
[SerializeField] Button m_ServerSelect;
|
[SerializeField] Button m_SwitchAccount;
|
[SerializeField] Button m_Notice;
|
[SerializeField] Button m_UserHelp;
|
[SerializeField] RichText m_BanHao;
|
[SerializeField] RichText[] m_BanHaos;
|
[SerializeField] Button m_CleanCache;
|
|
LoginModel model { get { return ModelCenter.Instance.GetModel<LoginModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
#if UNITY_EDITOR
|
m_Account.onEndEdit.AddListener(x => { EnterGame(); });
|
#endif
|
m_EnterGame.SetListener(EnterGame);
|
m_QQLogin.SetListener(QQLogin);
|
m_WXLogin.SetListener(WXLogin);
|
m_ServerSelect.SetListener(OpenServerListWin);
|
m_SwitchAccount.SetListener(SwitchAccount);
|
m_Notice.SetListener(VeiwNotice);
|
if (m_UserHelp)
|
{
|
m_UserHelp.SetListener(OpenUserHelp);
|
}
|
|
m_CleanCache.SetListener(ResourcesPath.Instance.CleanCache);
|
}
|
|
protected override void OnPreOpen()
|
{
|
ServerListCenter.Instance.RequestPlayerServerList();
|
model.isLogined = false;
|
ServerListCenter.Instance.FiltrateDefaultServerAndServerGroup();
|
m_BanHao.text = string.IsNullOrEmpty(VersionConfig.Get().banHao) ? string.Empty : VersionConfig.Get().banHao;
|
int banhaoFlag;
|
if (!int.TryParse(VersionConfig.Get().banHao, out banhaoFlag))
|
{
|
banhaoFlag = 1;
|
}
|
for (int i = 0; i < m_BanHaos.Length; i++)
|
{
|
m_BanHaos[i].SetActive(i == (banhaoFlag - 1));
|
}
|
var sprite = BuiltInLoader.LoadSprite("TB_DL_Logo");
|
m_Logo.overrideSprite = sprite;
|
m_Logo.SetNativeSize();
|
m_Logo.rectTransform.anchoredPosition = VersionConfig.Get().logoPosition;
|
m_Notice.SetActive(GameNotice.HasNotice());
|
|
m_AlphaTween.SetStartState();
|
|
if (FuncSwitchConfig.Has(2))
|
{
|
var switchAccountJson = JsonMapper.ToObject(FuncSwitchConfig.Get(2).AppIdSwitch);
|
if (switchAccountJson.Keys.Contains(VersionConfig.Get().appId) && switchAccountJson[VersionConfig.Get().appId].ToString() == "0")
|
{
|
m_SwitchAccount.SetActive(false);
|
}
|
else
|
{
|
m_SwitchAccount.SetActive(true);
|
}
|
}
|
else
|
{
|
m_SwitchAccount.SetActive(true);
|
}
|
|
if (m_UserHelp)
|
{
|
var appId = VersionConfig.Get().appId;
|
var branch = VersionConfig.Get().branch;
|
m_UserHelp.SetActive(ContactConfig.GetConfig(appId, branch) != null);
|
}
|
|
m_WaitServerList.SetActive(!ServerListCenter.Instance.serverListGot);
|
m_ContainerEnterGame.SetActive(ServerListCenter.Instance.serverListGot);
|
m_ContainerAccount.SetActive(ServerListCenter.Instance.serverListGot
|
&& (VersionConfig.Get().versionAuthority == VersionAuthority.InterTest || VersionConfig.Get().isBanShu));
|
|
if (ServerListCenter.Instance.serverListGot)
|
{
|
ChangeServerInfo(ServerListCenter.Instance.currentServer);
|
}
|
|
ChangeUserInfo(model.localSaveAccountName);
|
|
|
m_EnterGame.SetActive(true);
|
m_QQLogin.SetActive(false);
|
m_WXLogin.SetActive(false);
|
|
}
|
|
private void OnLoginOk(ynmbxxjUtil.FP_LoginOk arg0)
|
{
|
}
|
|
protected override void OnAfterOpen()
|
{
|
ServerListCenter.Instance.serverSelectEvent += OnServerChange;
|
ServerListCenter.Instance.onServerListRefreshEvent += OnServerListRefresh;
|
}
|
|
protected override void OnPreClose()
|
{
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
ServerListCenter.Instance.serverSelectEvent -= OnServerChange;
|
ServerListCenter.Instance.onServerListRefreshEvent -= OnServerListRefresh;
|
ynmbxxjUtil.Instance.onFreePlatformLoginOk -= OnLoginOk;
|
ynmbxxjUtil.Instance.SendShowFloatWin();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
m_AlphaTween.Play();
|
m_AlphaTween.Play(() => { firstOpenEnd = true; });
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
|
windowInfo.raycastTarget = true;
|
model.RequestServerListLoop();
|
}
|
#endregion
|
|
private void ChangeUserInfo(string user)
|
{
|
m_Account.text = user;
|
}
|
|
|
private void ChangeServerInfo(ServerData _serverData)
|
{
|
m_ServerName.text = _serverData.name.Replace("@gm", "");
|
m_ServerIP = _serverData.region_domain;
|
m_Port = _serverData.login_port;
|
m_GamePort = _serverData.game_port;
|
|
switch ((ServerState)_serverData.running_status)
|
{
|
case ServerState.Maintain:
|
case ServerState.Predicted:
|
m_ServerState.SetSprite("XT_FWQ_TB4");
|
m_ServerStateDescription.text = Language.GetFromLocal(29);
|
break;
|
case ServerState.Normal:
|
m_ServerState.SetSprite("XT_FWQ_TB2");
|
m_ServerStateDescription.text = Language.GetFromLocal(28);
|
break;
|
case ServerState.Busy:
|
m_ServerState.SetSprite("XT_FWQ_TB3");
|
m_ServerStateDescription.text = Language.GetFromLocal(27);
|
break;
|
case ServerState.Hot:
|
m_ServerState.SetSprite("XT_FWQ_TB1");
|
m_ServerStateDescription.text = Language.GetFromLocal(26);
|
break;
|
}
|
}
|
|
private void OnServerChange()
|
{
|
ChangeServerInfo(ServerListCenter.Instance.currentServer);
|
}
|
|
private void OnServerListRefresh()
|
{
|
m_WaitServerList.SetActive(!ServerListCenter.Instance.serverListGot);
|
m_ContainerEnterGame.SetActive(ServerListCenter.Instance.serverListGot);
|
m_ContainerAccount.SetActive(ServerListCenter.Instance.serverListGot
|
&& (VersionConfig.Get().versionAuthority == VersionAuthority.InterTest || VersionConfig.Get().isBanShu));
|
}
|
|
protected virtual void EnterGame()
|
{
|
|
if (!ConfigInitiator.IsCreateRoleConfigInited)
|
{
|
return;
|
}
|
|
ynmbxxjUtil.Instance.SendHideFloatWin();
|
|
Login();
|
|
//到这里一定是下载表结束
|
InGameDownLoad.Instance.SetDownloadMark();
|
}
|
|
protected void QQLogin()
|
{
|
ynmbxxjUtil.Instance.TencentLogin("Login");
|
}
|
|
protected void WXLogin()
|
{
|
ynmbxxjUtil.Instance.TencentLogin("Loginwx");
|
}
|
|
protected void Login()
|
{
|
var allow = false;
|
if (DebugUtility.Instance.isWhiteListAccount)
|
{
|
allow = true;
|
}
|
else
|
{
|
if (ServerListCenter.Instance.currentServer.running_status == (int)ServerState.Maintain
|
|| ServerListCenter.Instance.currentServer.running_status == (int)ServerState.Predicted)
|
{
|
allow = false;
|
}
|
else
|
{
|
allow = true;
|
}
|
}
|
|
if (!allow)
|
{
|
switch ((ServerState)ServerListCenter.Instance.currentServer.running_status)
|
{
|
case ServerState.Maintain:
|
SysNotifyMgr.Instance.ShowTip("ServerDown");
|
break;
|
case ServerState.Predicted:
|
SysNotifyMgr.Instance.ShowTip("ServerOpen", ServerListCenter.Instance.currentServer.start_date.ToString("dd-MM HH:mm"));
|
break;
|
}
|
|
return;
|
}
|
|
if (GameNetSystem.Instance.netState == GameNetSystem.NetState.NerverConnect)
|
{
|
switch (VersionConfig.Get().versionAuthority)
|
{
|
case VersionAuthority.InterTest:
|
if (string.IsNullOrEmpty(m_Account.text))
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1095"));
|
return;
|
}
|
|
model.AccountLogin(m_Account.text, m_ServerIP, m_Port, m_GamePort);
|
break;
|
case VersionAuthority.Release:
|
model.AccountLogin(m_ServerIP, m_Port, m_GamePort);
|
break;
|
}
|
|
OperationLogCollect.Instance.RecordLauchEvent(6);
|
OperationLogCollect.Instance.RecordEvent(7);
|
}
|
|
}
|
|
private void OpenServerListWin()
|
{
|
WindowCenter.Instance.Open<ServerListWin>();
|
}
|
|
private void SwitchAccount()
|
{
|
ynmbxxjUtil.Instance.FreePlatformLoginout();
|
var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
|
loginModel.sdkLogined = false;
|
}
|
|
private void VeiwNotice()
|
{
|
GameNotice.OpenGameNoticeForce();
|
}
|
|
private void OpenUserHelp()
|
{
|
WindowCenter.Instance.OpenFromLocal<UserHelpWin>();
|
}
|
|
}
|
|
}
|
|
|
|
|