194 lines
4.8 KiB
C#
194 lines
4.8 KiB
C#
using Framework;
|
|
using Gameplay.Net;
|
|
using System;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Gameplay;
|
|
using PhxhSDK;
|
|
|
|
public class UINewLoginController : UIWindow
|
|
{
|
|
private TMPro.TMP_InputField _Input;
|
|
private TMP_Dropdown dropdown;
|
|
|
|
Button TapTapBtn;
|
|
Button NormalBtn;
|
|
Button ExitBtn;
|
|
GameObject TipsObj;
|
|
Button SwitchBtn;
|
|
public override void OnAwake()
|
|
{
|
|
//bind UI GameObj
|
|
TapTapBtn = GetComponent<Button>("taptap/TapTapBtn");
|
|
NormalBtn = GetComponent<Button>("NormalBtn");
|
|
ExitBtn = GetComponent<Button>("taptap/Exit");
|
|
SwitchBtn = GetComponent<Button>("taptap/Switch");
|
|
|
|
BindButton(TapTapBtn, OnTapTapBtnOnClick);
|
|
BindButton(NormalBtn, OnNormalBtnOnClick);
|
|
BindButton(ExitBtn, OnExitBtnOnClick);
|
|
BindButton(SwitchBtn, OnExitBtnOnClick);
|
|
|
|
dropdown = GameObject.Find("Dropdown_LogIn").GetComponent<TMP_Dropdown>();
|
|
dropdown.onValueChanged.AddListener(onValueChanged);
|
|
|
|
UpadteDropdownSeverName();
|
|
|
|
_Input = FindObj("InputField_LogIn").GetComponent<TMPro.TMP_InputField>();
|
|
string account = PlayerPrefs.GetString("LoginAccount", "");
|
|
_Input.text = account;
|
|
BindButton("Login/Login", OnButtonLogin);
|
|
|
|
|
|
TipsObj = FindObj("Tip");
|
|
}
|
|
|
|
private void OnExitBtnOnClick()
|
|
{
|
|
#if SDK_TAPTAP
|
|
var helper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.TapTap) as TapTapSdkHelper;
|
|
helper.Logout();
|
|
OnRecvNewLoginTips("已退出,请重新登录");
|
|
#endif
|
|
}
|
|
private void RegisterEvent()
|
|
{
|
|
EventManager.Instance.Register(EventManager.EventName.EN_UINewLoginTips, (Action<string>)OnRecvNewLoginTips);
|
|
}
|
|
|
|
private void OnRecvNewLoginTips(string obj)
|
|
{
|
|
TipsObj.SetActive(true);
|
|
CommonUtils.GetComponent<TMP_Text>(TipsObj, "label").text = obj;
|
|
|
|
IEnumerator coroutine = waitTime();
|
|
StartCoroutine(coroutine);
|
|
}
|
|
private IEnumerator waitTime()
|
|
{
|
|
yield return new WaitForSeconds(2f);
|
|
TipsObj.SetActive(false);
|
|
|
|
}
|
|
private void UnRegisterEvent()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.EN_UINewLoginTips, (Action<string>)OnRecvNewLoginTips);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void OnNormalBtnOnClick()
|
|
{
|
|
await UIManager.Instance.OpenWindow(UINameConst.UILogin);
|
|
CloseWindow();
|
|
|
|
}
|
|
|
|
private void OnTapTapBtnOnClick()
|
|
{
|
|
//TapTapSdkHelper.Instance.StartLogin();
|
|
Actor.Instance.Login.StartLogin(NLDPB.LoginType.TapTap);
|
|
|
|
}
|
|
|
|
//invoke when open window
|
|
protected override void OnOpenWindow()
|
|
{
|
|
RefreshTapTapBtn();
|
|
RegisterEvent();
|
|
}
|
|
|
|
private void RefreshTapTapBtn()
|
|
{
|
|
//#if SDK_TAPTAP
|
|
FindObj("taptap").SetActive(true);
|
|
//#else
|
|
// FindObj("taptap").SetActive(false);
|
|
//#endif
|
|
|
|
}
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when close window
|
|
protected override void OnCloseWindow()
|
|
{
|
|
UnRegisterEvent();
|
|
}
|
|
public void onValueChanged(int value)
|
|
{
|
|
AppConfig.Instance.Select(value);
|
|
|
|
PlayerPrefs.SetInt("ServerIndex", value);
|
|
|
|
|
|
|
|
return;
|
|
}
|
|
|
|
private void UpadteDropdownSeverName()
|
|
{
|
|
dropdown.options.Clear();
|
|
var serverInfo = AppConfig.Instance.GetServerInfo();
|
|
if (serverInfo.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var item in serverInfo)
|
|
{
|
|
dropdown.options.Add(new TMP_Dropdown.OptionData() { text = item.name });
|
|
}
|
|
var index = PlayerPrefs.GetInt("ServerIndex", 0);
|
|
|
|
if (index >= 0 && index <= serverInfo.Count)
|
|
{
|
|
dropdown.captionText.text = serverInfo[index].name;
|
|
dropdown.value = index;
|
|
}
|
|
else
|
|
{
|
|
dropdown.captionText.text = serverInfo[0].name;
|
|
dropdown.value = 0;
|
|
}
|
|
|
|
AppConfig.Instance.Select(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Select(int nIndex)
|
|
{
|
|
var serverInfo = AppConfig.Instance.GetServerInfo();
|
|
var getCurrent = AppConfig.Instance.GetCurrent();
|
|
if (nIndex >= serverInfo.Count)
|
|
{
|
|
getCurrent = serverInfo[0];
|
|
DebugUtil.LogError("AppConfig Select nIndex:{0} >= m_ServerInfos.Count:{1}, set default as 0", nIndex, serverInfo.Count);
|
|
return;
|
|
}
|
|
getCurrent = serverInfo[nIndex];
|
|
|
|
}
|
|
|
|
private async void OnButtonLogin()
|
|
{
|
|
PlayerPrefs.SetString("LoginAccount", _Input.text);
|
|
Gameplay.Net.Actor.Instance.StartLogin(NLDPB.LoginType.Phxh, _Input.text);
|
|
CloseWindow();
|
|
}
|
|
|
|
|
|
private void OnDestroy()
|
|
{
|
|
// EventManager.Instance.Unregister(EventManager.EventName.NetLoginServerInfo, OnNameSend);
|
|
}
|
|
}
|