using System.Collections; using System.Collections.Generic; using UnityEngine; using Kill.Managers; using UnityEngine.UI; using Kill.Network; using System.Threading.Tasks; using Kill.UI.Components; namespace Kill.UI.Pages { public class SelfInfoPage : MonoBehaviour { UserInfo userInfo; public RawImage avatarImage; public Text nicknameText; public RenamePage renamePagePrefab; public Button renameButton; public Button backButton; public SelfVerificationCodePanel verificationCodePanelPrefab; public SelfSetPasswordPanel setPasswordPanelPrefab; public SelectCountry selectCountryPrefab; public Text countryText; public Button selectCountryButton; List passwordSetKeys = new List { "100200", "100201" }; /// /// 0设置 1修改 /// List passwordSet; /// /// /// 0简单密码 1复杂密码 /// public Button resetPassword; /// /// 注销账号入口 /// public Button cancelAccountButton; public SelfCancelAccountPage cancelAccountPagePrefab; public async Task Init(UserInfo userInfo) { this.userInfo = userInfo; UIManager.Instance.RegisterBackAction(OnBack); backButton.onClick.RemoveAllListeners(); backButton.onClick.AddListener(OnBack); resetPassword.onClick.RemoveAllListeners(); resetPassword.onClick.AddListener(OnSetPassword); // 注销账号入口 if (cancelAccountButton != null) { cancelAccountButton.onClick.RemoveAllListeners(); cancelAccountButton.onClick.AddListener(OnCancelAccount); } renameButton.onClick.RemoveAllListeners(); renameButton.onClick.AddListener(() => { RenamePage renamePage = Instantiate(renamePagePrefab, transform); renamePage.Init(userInfo.username, CloseRenamePage, 1); }); // 在这里初始化个人信息页面,显示用户信息 if (avatarImage != null) { // 设置头像 if (userInfo.avatar != null) { avatarImage.gameObject.SetActive(true); await NetworkCtrl.Instance.LoadImageToUIRawImageAsync(userInfo.avatar, avatarImage); avatarImage.transform.parent.GetComponent().showMaskGraphic = false; } } if (nicknameText != null) { nicknameText.text = userInfo.username; } // 国家展示与选择 if (countryText != null) UpdateCountryDisplay(userInfo.country_code); if (selectCountryButton != null) { selectCountryButton.onClick.RemoveAllListeners(); selectCountryButton.onClick.AddListener(OnSelectCountry); } } /// /// 更新国家显示文本 /// private void UpdateCountryDisplay(string code) { if (string.IsNullOrEmpty(code)) { countryText.text = ""; return; } var country = LanguageManager.Instance.countryList.Find(c => c.code == code); bool isZh = LanguageManager.Instance.languageType == LanguageManager.LanguageType.Chinese; countryText.text = country.code != null ? (isZh ? country.name_zh : country.name_en) : code; } /// /// 选择国家 /// private void OnSelectCountry() { var selectCountry = Instantiate(selectCountryPrefab, transform); selectCountry.Init(userInfo.country_code); selectCountry.onConfirm = (code) => { if (code != null) { userInfo.country_code = code; UpdateCountryDisplay(code); } Destroy(selectCountry.gameObject); UIManager.Instance.RegisterBackAction(OnBack); }; } public void InitLanguageText() { passwordSet = new List(); } public void CloseRenamePage(string newNickname) { if (nicknameText != null) { nicknameText.text = newNickname; } DataManager.Instance.userInfo.username = newNickname; UIManager.Instance.RegisterBackAction(OnBack); } SelfVerificationCodePanel verificationCodePanel; public void OnSetPassword() { verificationCodePanel = Instantiate(verificationCodePanelPrefab, transform); verificationCodePanel.Init(OnSureVerificationCode, OnBack); } SelfCancelAccountPage cancelAccountPage; /// /// 打开注销账号页面 /// public void OnCancelAccount() { if (cancelAccountPagePrefab == null) return; cancelAccountPage = Instantiate(cancelAccountPagePrefab, transform); cancelAccountPage.Init(OnCancelAccountBack); cancelAccountPage.gameObject.SetActive(true); } void OnCancelAccountBack() { UIManager.Instance.RegisterBackAction(OnBack); } SelfSetPasswordPanel setPasswordPanel; public void OnSureVerificationCode() { Destroy(verificationCodePanel.gameObject); setPasswordPanel = Instantiate(setPasswordPanelPrefab, transform); setPasswordPanel.Init(OnSetPasswordSuccess); } public void OnSetPasswordSuccess() { Destroy(setPasswordPanel.gameObject); GetComponentInParent().OnSignOut(); } public void OnBack() { UIManager.Instance.RegisterBackAction(GetComponentInParent().OnBack); GetComponentInParent().RefreshAsync(); Destroy(gameObject); } } }