NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_StartGameInterfaceContro...

315 lines
8.3 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Toggle = UnityEngine.UI.Toggle;
using ScrollView = PhxhSDK.PhxhScrollView;
using Framework;
2024-07-15 12:20:03 +08:00
using Gameplay.Net;
public class UI_StartGameInterfaceController : UIWindow
{
2024-07-15 12:20:03 +08:00
enum LoginType
{
Account,
PhoneCode
}
#region UI_obj
//UI GameObj
///Auto Gen Start///
public Image Image_Bg;
public Image Image_BgDark;
public Button Button_StartGame;
public Image Image_LoginBg;
public Button Button_AccountLogin_1;
public Image Image_YellowLine_Account_1;
public Button Button_VerifyCodeLogin_1;
public Image Image_YellowLine_VerifyCode_1;
public TMP_InputField InputField_Account;
public Image Image_AccountIcon;
public TMP_InputField InputField_Password;
public Image Image_PasswordIcon;
public Toggle Toggle_RememberPassword;
public TMP_Text Text_RememberPassword;
public Toggle Toggle_Agreement_1;
public TMP_Text Text_Agreement_1;
public Button Button_UnLogin_1;
public Button Button_Login_1;
public TMP_InputField InputField_PhoneNumber;
public Image Image_PhoneIcon;
public TMP_InputField InputField_VerifyCode;
public Image Image_VerifyCodeIcon;
public Button Button_GetVerifyCode;
public Button Button_GetVerifyCodeCooling;
public Toggle Toggle_Agreement_2;
public TMP_Text Text_Agreement_2;
2024-07-15 12:20:03 +08:00
public Button Button_UnLogin_2;
public Button Button_Login_2;
public Image Image_UpdateBg;
public Button Button_Confirm;
public Button Button_Cancle;
public Image Image_BottomLine;
public Button Button_UserCenter;
public Button Button_Notice;
public TMP_Text Text_UID;
public TMP_Text Text_Version;
public Image Image_DarkSide;
2024-07-15 12:20:03 +08:00
public GameObject AccountLoginPanel;
public GameObject VerifyCodeLoginPanel;
///Auto Gen End///
#endregion
LoginType loginType;
LoginData loginSaveData;
// deal with input data
public override void PreLoad(object data = null)
2024-07-15 12:20:03 +08:00
{
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
if (loginSaveData == null)
loginSaveData = new();
}
// Use this for initialization
public override void OnInit()
{
//bind UI GameObj
UI_StartGameInterfaceBinder.GetComponents(this);
2024-07-15 12:20:03 +08:00
AccountLoginPanel = FindObj("UI_LoginWindow/Image_LoginBg/LoginPanel/AccountLogin");
VerifyCodeLoginPanel = FindObj("UI_LoginWindow/Image_LoginBg/LoginPanel/VerifyCodeLogin");
BindButton(Button_AccountLogin_1, () => SetLoginType(LoginType.Account));
BindButton(Button_VerifyCodeLogin_1, () => SetLoginType(LoginType.PhoneCode));
BindButton(Button_Login_1, OnButtonLogin);
BindButton(Button_Login_2, OnButtonLogin);
BindButton(Button_UserCenter, OnUserCenterButton);
BindButton(Button_StartGame, OnStartGame);
Toggle_RememberPassword.onValueChanged.AddListener(OnRememberPassword);
Toggle_Agreement_1.onValueChanged.AddListener(OnAgreementAccept);
Toggle_Agreement_2.onValueChanged.AddListener(OnAgreementAccept);
InputField_Account.onEndEdit.AddListener(AccountEditEnd);
InputField_Password.onEndEdit.AddListener(PasswordEditEnd);
Text_Version.text = "version:" + Application.version;
Text_UID.gameObject.SetActive(false);
if (loginSaveData.LoginByAccount && loginSaveData.rememberPassword)
{
DebugUtil.Log("<22><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>¼");
Button_StartGame.gameObject.SetActive(true);
HideLoginPanel();
Text_UID.gameObject.SetActive(true);
Text_UID.text = "ac: " + loginSaveData.account;
}
else
{
if (loginSaveData.LoginByPhone)
{
SetLoginType(LoginType.PhoneCode);
}
else
{
SetLoginType(LoginType.Account);
}
}
}
2024-07-15 12:20:03 +08:00
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>˺ŵ<CBBA>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
/// </summary>
/// <param name="type"></param>
void SetLoginType(LoginType type)
{
loginType = type;
Button_StartGame.gameObject.SetActive(false);
switch (loginType)
{
case LoginType.Account://<2F>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
Image_LoginBg.gameObject.SetActive(true);
Image_UpdateBg.gameObject.SetActive(false);
Image_YellowLine_Account_1.gameObject.SetActive(true);
Image_YellowLine_VerifyCode_1.gameObject.SetActive(false);
Toggle_RememberPassword.isOn = loginSaveData.rememberPassword;
Toggle_Agreement_1.isOn = loginSaveData.agreement;
AccountLoginPanel.SetActive(true);
VerifyCodeLoginPanel.SetActive(false);
if (loginSaveData.account != default)
{
InputField_Account.text = loginSaveData.account;
}
if (loginSaveData.password != default && loginSaveData.rememberPassword)
{
InputField_Password.text = loginSaveData.password;
}
else
{
InputField_Password.text = string.Empty;
}
break;
case LoginType.PhoneCode://<2F>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>¼
Image_LoginBg.gameObject.SetActive(true);
Image_UpdateBg.gameObject.SetActive(false);
Image_YellowLine_Account_1.gameObject.SetActive(false);
Image_YellowLine_VerifyCode_1.gameObject.SetActive(true);
Toggle_Agreement_2.isOn = loginSaveData.agreement;
AccountLoginPanel.SetActive(false);
VerifyCodeLoginPanel.SetActive(true);
break;
default:
DebugUtil.LogError("SetLoginType error");
break;
}
CheckLoginButton();
}
void HideLoginPanel()
{
2024-07-15 12:20:03 +08:00
Image_LoginBg.gameObject.SetActive(false);
}
void CheckLoginButton()
{
switch (loginType)
{
case LoginType.Account:
if(InputField_Account.text.Length > 0 && InputField_Password.text.Length > 0 && loginSaveData.agreement)
{
Button_Login_1.gameObject.SetActive(true);
}
else
{
Button_Login_1.gameObject.SetActive(false);
}
break;
}
}
//invoke when open window
protected override void OnShowWindow(object data = null)
{
DebugUtil.Log("<22>°<EFBFBD><C2B0><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>棡Ŀǰ<C4BF><C7B0>֧<EFBFBD>ֵ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>: ====");
DebugUtil.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸǰ<CFB7>޸<EFBFBD>DebugStart<72>ڵ<EFBFBD><DAB5><EFBFBD>CmpFakeStart<72><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>ѡ<EEA3AC><D1A1><EFBFBD>ɰ<EFBFBD><C9B0><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>");
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
//invoke when close window
protected override void OnHideWindow()
{
}
//invoke when destroy
public override void OnRelease()
{
base.OnRelease();
}
2024-07-15 12:20:03 +08:00
#region Button_Listener
void OnRememberPassword(bool isOn)
{
loginSaveData.rememberPassword = isOn;
}
void OnAgreementAccept(bool isOn)
{
loginSaveData.agreement = isOn;
CheckLoginButton();
}
void AccountEditEnd(string text)
{
loginSaveData.account = text;
InputField_Password.text = string.Empty;
CheckLoginButton();
}
void PasswordEditEnd(string text)
{
loginSaveData.password = text;
CheckLoginButton();
}
void OnButtonLogin()
{
DebugUtil.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>߼<EFBFBD><DFBC>ڴ<EFBFBD>ʵ<EFBFBD><CAB5>");
//if <20><>¼<EFBFBD>ɹ<EFBFBD>
Button_StartGame.gameObject.SetActive(true);
HideLoginPanel();
loginSaveData.LoginByAccount = true;
if (!loginSaveData.rememberPassword)
{
loginSaveData.password = default;
}
StorageMgr.Instance.SyncForce = true;
DebugUtil.LogWarning("<22><><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD>͵<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><DFBC>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>");
Text_UID.gameObject.SetActive(true);
Text_UID.text = "ac: " + loginSaveData.account;
}
void OnUserCenterButton()
{
if (loginSaveData.LoginByPhone)
{
SetLoginType(LoginType.PhoneCode);
}
else
{
SetLoginType(LoginType.Account);
}
}
void OnStartGame()
{
var serverInfos = AppConfig.Instance.GetServerInfo();
AppConfig.Instance.Select(0);
for (int i = 0; i < serverInfos.Count; i++)
{
if (serverInfos[i].name == "<22><><EFBFBD>Է<EFBFBD>1")
AppConfig.Instance.Select(i);
}
Gameplay.Net.Actor.Instance.StartLogin(NLDPB.LoginType.Phxh, loginSaveData.account);
}
#endregion
class LoginData
{
public bool LoginByAccount = false;
public bool LoginByPhone = false;
public string account;
public string password;
public bool rememberPassword;
public bool agreement;
public string phoneNumber;
}
}