Organize custom scripts under Assets/Baba_yaga and merge Opsive folders to Assets root
This commit is contained in:
135
Assets/Baba_yaga/UI/ProfileController.cs
Normal file
135
Assets/Baba_yaga/UI/ProfileController.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Baba_yaga.Game;
|
||||
using Baba_yaga.UI;
|
||||
|
||||
namespace Baba_yaga.UI
|
||||
{
|
||||
[UnityEngine.Scripting.APIUpdating.MovedFrom(true, sourceNamespace: "Hallucinate.UI", sourceAssembly: "Opsive.UltimateCharacterController")]
|
||||
public class ProfileController : BaseUIController
|
||||
{
|
||||
private Label _username;
|
||||
private Label _rank;
|
||||
private Label _eloLabel;
|
||||
private ProgressBar _winRateBar;
|
||||
private Label _winRateText;
|
||||
private Button _logoutBtn;
|
||||
|
||||
// Future authentication schema placeholders
|
||||
private string _googleIdPlaceholder = "";
|
||||
private string _avatarUrlPlaceholder = "";
|
||||
|
||||
public override void Initialize(VisualElement uxmlRoot, UIManager manager)
|
||||
{
|
||||
base.Initialize(uxmlRoot, manager);
|
||||
|
||||
_username = root.Q<Label>("Username");
|
||||
_rank = root.Q<Label>("Rank");
|
||||
_eloLabel = root.Q<Label>("EloLabel");
|
||||
_winRateBar = root.Q<ProgressBar>("WinRateBar");
|
||||
_winRateText = root.Q<Label>("WinRateText");
|
||||
_logoutBtn = root.Q<Button>("LogoutBtn");
|
||||
|
||||
/*root.Q<Button>("BackBtn").clicked += async () => await uiManager.Pop();*/
|
||||
|
||||
/*if (_logoutBtn != null)
|
||||
{
|
||||
_logoutBtn.clicked += Logout;
|
||||
}*/
|
||||
|
||||
if (LocalizationManager.Instance != null)
|
||||
{
|
||||
LocalizationManager.Instance.OnLanguageChanged += ApplyLocalization;
|
||||
ApplyLocalization();
|
||||
}
|
||||
|
||||
LoadProfileData();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (LocalizationManager.Instance != null)
|
||||
{
|
||||
LocalizationManager.Instance.OnLanguageChanged -= ApplyLocalization;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyLocalization()
|
||||
{
|
||||
if (LocalizationManager.Instance == null) return;
|
||||
|
||||
root.Query<Label>().ForEach(l => {
|
||||
if (l.text == "WIN RATE") l.text = LocalizationManager.Instance.GetLocalizedString("PROFILE_WIN_RATE");
|
||||
if (l.text == "INVENTORY") l.text = LocalizationManager.Instance.GetLocalizedString("PROFILE_INVENTORY");
|
||||
});
|
||||
|
||||
var backBtn = root.Q<Button>("BackBtn");
|
||||
if (backBtn != null) backBtn.text = LocalizationManager.Instance.GetLocalizedString("PROFILE_BACK");
|
||||
|
||||
if (_logoutBtn != null) _logoutBtn.text = LocalizationManager.Instance.GetLocalizedString("PROFILE_LOGOUT");
|
||||
}
|
||||
|
||||
/*public override async Task PlayTransitionIn()
|
||||
{
|
||||
await LoadProfileData(); // Refresh data every time we show the profile
|
||||
await base.PlayTransitionIn();
|
||||
}*/
|
||||
|
||||
private async Task LoadProfileData()
|
||||
{
|
||||
// Load saved username or fallback
|
||||
string savedName = PlayerPrefs.GetString("Username", "Unknown Player");
|
||||
_username.text = savedName.ToUpper();
|
||||
|
||||
// Future schema mockup (Google Sign-In)
|
||||
_googleIdPlaceholder = PlayerPrefs.GetString("GoogleID", "NOT_LINKED");
|
||||
_avatarUrlPlaceholder = PlayerPrefs.GetString("AvatarURL", "");
|
||||
|
||||
// Fetch real Elo data
|
||||
var eloData = await FirebaseService.GetPlayerData(savedName);
|
||||
|
||||
if (_eloLabel != null) _eloLabel.text = eloData.Rating.ToString();
|
||||
|
||||
if (_rank != null)
|
||||
{
|
||||
_rank.text = EloSystem.GetRank(eloData.Rating).ToUpper();
|
||||
if (ColorUtility.TryParseHtmlString(EloSystem.GetRankColor(eloData.Rating), out Color rankColor))
|
||||
{
|
||||
_rank.style.color = rankColor;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate Win Rate from GamesPlayed (requires adding wins to schema, but for now we use mock/partial)
|
||||
if (eloData.GamesPlayed > 0)
|
||||
{
|
||||
// Note: To show a real winrate, we'd need to store 'Wins' in PlayerEloData.
|
||||
// For now, keeping the mock or setting a placeholder.
|
||||
_winRateText.text = "CALCULATING...";
|
||||
}
|
||||
}
|
||||
|
||||
/*private async void Logout()
|
||||
{
|
||||
// Clear local save data
|
||||
PlayerPrefs.DeleteKey("Username");
|
||||
PlayerPrefs.DeleteKey("GoogleID");
|
||||
PlayerPrefs.DeleteKey("AvatarURL");
|
||||
PlayerPrefs.Save();
|
||||
|
||||
Debug.Log("[Profile] User logged out.");
|
||||
|
||||
// Disconnect from network if currently running
|
||||
var runner = Object.FindFirstObjectByType<Fusion.NetworkRunner>();
|
||||
if (runner != null && runner.IsRunning)
|
||||
{
|
||||
await runner.Shutdown();
|
||||
}
|
||||
|
||||
// Redirect to Login Screen
|
||||
await uiManager.Push<LoginController>();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user