Files
ft/Client/Assets/Scripts/UI/Setting/AccountSwitchPopupPanel.cs
2026-06-29 21:18:33 +08:00

95 lines
2.8 KiB
C#

using System;
using asap.core;
using game;
using GameCore;
using TMPro;
using tysdk;
using UnityEngine;
using UnityEngine.UI;
public class AccountSwitchPopupPanel : MonoBehaviour
{
[SerializeField]
private Head currentAvatar;
[SerializeField]
private TMP_Text currentDisplayName;
[SerializeField]
private TMP_Text currentLevel;
[SerializeField]
private Toggle usingCurrentAccount;
[SerializeField]
private Head savedAvatar;
[SerializeField]
private TMP_Text savedDisplayName;
[SerializeField]
private TMP_Text savedLevel;
[SerializeField]
private Toggle usingSavedAccount;
[SerializeField]
private Button confirmBtn;
private AccountSwitchConfirmPopupPanel.ChangeLinkAccountData changeLinkAccountData = null;
private void OnEnable()
{
confirmBtn.onClick.AddListener(OnConfirm);
}
private void OnDisable()
{
confirmBtn.onClick.RemoveListener(OnConfirm);
}
public void SetData(string otherDisplayName, string otherAvatar, int otherLevel, int otherUserId, EAccoutType otherAccoutType)
{
var userService = GContext.container.Resolve<IUserService>();
var playerData = GContext.container.Resolve<PlayerData>();
currentDisplayName.text = userService.DisplayName;
currentAvatar.SetData(userService.AvatarUrl);
currentLevel.text = playerData.lv.ToString();
usingCurrentAccount.isOn = otherLevel < playerData.lv;
savedDisplayName.text = otherDisplayName;
savedAvatar.SetData(otherAvatar);
savedLevel.text = otherLevel.ToString();
usingSavedAccount.isOn = otherLevel >= playerData.lv;
changeLinkAccountData = new AccountSwitchConfirmPopupPanel.ChangeLinkAccountData()
{
accoutType = otherAccoutType,
oldUserId = otherUserId,
newUserId = int.Parse(userService.CustomId)
};
}
private async void OnConfirm()
{
try
{
var confirmGo = await UIManager.Instance.GetUIAsync(UITypes.AccountSwitchConfirmPopupPanel);
var confirmPanel = confirmGo.GetComponent<AccountSwitchConfirmPopupPanel>();
var isUsingSavedAccount = usingSavedAccount.isOn;
if (isUsingSavedAccount)
{
confirmPanel.SetData(savedDisplayName.text, savedAvatar.icon_head.sprite, int.Parse(savedLevel.text));
}
else
{
confirmPanel.SetData(currentDisplayName.text, currentAvatar.icon_head.sprite, int.Parse(currentLevel.text),
changeLinkAccountData);
}
UIManager.Instance.DestroyUI(UITypes.AccountSwitchPopupPanel);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
}