feedback report 3 done
This commit is contained in:
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
|
||||
public class MainMenuManager : MonoBehaviour
|
||||
{
|
||||
@@ -59,6 +60,11 @@ public class MainMenuManager : MonoBehaviour
|
||||
public ToggleButton toggleSfx;
|
||||
public ToggleButton toggleMusic;
|
||||
|
||||
[Header("Info popups")]
|
||||
public RectTransform gameModesInfoPopup;
|
||||
public RectTransform withdrawalInfoPopup;
|
||||
|
||||
|
||||
/// <summary>Default play cost (coin units) if <c>/settings</c> is not loaded yet.</summary>
|
||||
const int FallbackEntryFeeCoins = 21;
|
||||
|
||||
@@ -66,12 +72,27 @@ public class MainMenuManager : MonoBehaviour
|
||||
|
||||
public static MainMenuManager instance;
|
||||
|
||||
/// <summary>Last settings profile successfully loaded this session. Survives scene reloads.</summary>
|
||||
public static PlayerProfileApiResponse CachedSettingsProfile { get; private set; }
|
||||
|
||||
public static void ClearCachedSettingsProfile()
|
||||
{
|
||||
CachedSettingsProfile = null;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(LoginManager.instance==null){
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
instance = this;
|
||||
|
||||
// Awake runs before the first frame, so a leftover address cannot show until this assignment.
|
||||
if (inputCryptoAddress != null)
|
||||
inputCryptoAddress.text = PlayerPrefs.GetString(CryptoAddressPrefsKey, string.Empty);
|
||||
|
||||
// Scene text is placeholder account data. Replace it before the first frame.
|
||||
ApplyCachedSettingsProfileOrClearPlaceholders();
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -81,6 +102,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
usernameText.text = "";
|
||||
ccText.text = "";
|
||||
rcText.text = "";
|
||||
ApplyCachedSettingsProfileOrClearPlaceholders();
|
||||
LoginManager.instance.GetUserData((success, error, user) => {
|
||||
if (success)
|
||||
{
|
||||
@@ -91,8 +113,12 @@ public class MainMenuManager : MonoBehaviour
|
||||
{
|
||||
if (btnPlay != null)
|
||||
btnPlay.interactable = false;
|
||||
if (rcPlayText != null)
|
||||
rcPlayText.text = string.IsNullOrEmpty(error) ? "Could not load profile. Try again." : error;
|
||||
if (!TryGetCachedSettingsProfile(out _))
|
||||
ShowSettingsProfileUnavailable();
|
||||
if (rcPlayText != null){
|
||||
string errorMsg = string.IsNullOrEmpty(error) ? "Could not load profile. Try again." : error;
|
||||
MessageBoxDialog.ShowBasic(errorMsg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -103,10 +129,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnBuyUsd50.onClick.AddListener(() => OnBuy(RcPack.Usd50));
|
||||
|
||||
if (inputCryptoAddress != null)
|
||||
{
|
||||
inputCryptoAddress.text = PlayerPrefs.GetString(CryptoAddressPrefsKey, string.Empty);
|
||||
inputCryptoAddress.onValueChanged.AddListener(OnCryptoAddressChanged);
|
||||
}
|
||||
|
||||
if (txtWithdrawStatus != null)
|
||||
txtWithdrawStatus.gameObject.SetActive(false);
|
||||
@@ -144,6 +167,23 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnLogout.onClick.RemoveListener(OnLogout);
|
||||
if (btnWithdrawal != null)
|
||||
btnWithdrawal.onClick.RemoveListener(OnWithdrawalPressed);
|
||||
if (inputCryptoAddress != null)
|
||||
inputCryptoAddress.onValueChanged.RemoveListener(OnCryptoAddressChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops the saved wallet address before logout deletes prefs.
|
||||
/// The field listener is removed first so scene unload cannot write the old address back.
|
||||
/// </summary>
|
||||
public void ClearWithdrawalAddress()
|
||||
{
|
||||
if (inputCryptoAddress != null)
|
||||
{
|
||||
inputCryptoAddress.onValueChanged.RemoveListener(OnCryptoAddressChanged);
|
||||
inputCryptoAddress.text = string.Empty;
|
||||
}
|
||||
|
||||
PlayerPrefs.DeleteKey(CryptoAddressPrefsKey);
|
||||
}
|
||||
|
||||
void OnLogout()
|
||||
@@ -269,6 +309,16 @@ public class MainMenuManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Shown when matchmaking is on screen and the matchmaker cannot be reached.</summary>
|
||||
public void ShowMatchmakingNoInternet()
|
||||
{
|
||||
const string message = "No internet connection, Please try again later";
|
||||
if (MessageBoxDialog.IsAvailable)
|
||||
MessageBoxDialog.ShowBasic(message);
|
||||
else
|
||||
Debug.LogError(message);
|
||||
}
|
||||
|
||||
void ShowWithdrawalMessage(string message, bool basic)
|
||||
{
|
||||
if (MessageBoxDialog.IsAvailable)
|
||||
@@ -456,40 +506,128 @@ public class MainMenuManager : MonoBehaviour
|
||||
RefreshSettingsProfile();
|
||||
}
|
||||
|
||||
void ApplyCachedSettingsProfileOrClearPlaceholders()
|
||||
{
|
||||
if (TryGetCachedSettingsProfile(out PlayerProfileApiResponse cached))
|
||||
ApplySettingsProfile(cached);
|
||||
else
|
||||
ClearSettingsProfilePlaceholders();
|
||||
}
|
||||
|
||||
/// <summary>Cache is only shown when it belongs to the signed-in player.</summary>
|
||||
static bool TryGetCachedSettingsProfile(out PlayerProfileApiResponse profile)
|
||||
{
|
||||
profile = CachedSettingsProfile;
|
||||
if (profile == null)
|
||||
return false;
|
||||
|
||||
UserData user = LoginManager.CurrentUser;
|
||||
if (user == null || profile.player_id != user.id)
|
||||
{
|
||||
profile = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RefreshSettingsProfile()
|
||||
{
|
||||
bool hasCache = TryGetCachedSettingsProfile(out PlayerProfileApiResponse cached);
|
||||
if (hasCache)
|
||||
ApplySettingsProfile(cached);
|
||||
|
||||
if (profileInfoFetcher == null)
|
||||
{
|
||||
if (!hasCache)
|
||||
ShowSettingsProfileUnavailable();
|
||||
return;
|
||||
}
|
||||
|
||||
UserData user = LoginManager.CurrentUser;
|
||||
if (user == null)
|
||||
{
|
||||
if (!hasCache)
|
||||
ClearSettingsProfilePlaceholders();
|
||||
return;
|
||||
}
|
||||
|
||||
profileInfoFetcher.GetPlayerProfile(user.id, (success, error, profile) =>
|
||||
{
|
||||
if (!success || profile == null)
|
||||
if (!success || profile == null || profile.player_id != user.id)
|
||||
{
|
||||
Debug.LogWarning("Settings profile fetch failed: " + (error ?? "unknown"));
|
||||
if (TryGetCachedSettingsProfile(out PlayerProfileApiResponse last))
|
||||
ApplySettingsProfile(last);
|
||||
else
|
||||
ShowSettingsProfileUnavailable();
|
||||
return;
|
||||
}
|
||||
|
||||
CachedSettingsProfile = profile;
|
||||
ApplySettingsProfile(profile);
|
||||
});
|
||||
}
|
||||
|
||||
void ApplySettingsProfile(PlayerProfileApiResponse profile)
|
||||
void ClearSettingsProfilePlaceholders()
|
||||
{
|
||||
if (txtUsername != null)
|
||||
txtUsername.text = profile.username ?? "";
|
||||
if (txtEmail != null)
|
||||
txtEmail.text = profile.email ?? "";
|
||||
if (txtId != null)
|
||||
txtId.text = profile.player_id.ToString();
|
||||
if (txtAge != null)
|
||||
txtAge.text = profile.days_since_registration.ToString();
|
||||
if (txtMatches != null)
|
||||
txtMatches.text = profile.matches_played.ToString();
|
||||
if (txtWinRatio != null)
|
||||
txtWinRatio.text = (profile.win_ratio * 100f).ToString("0.#") + "%";
|
||||
SetSettingsProfileText(txtUsername, "-");
|
||||
SetSettingsProfileText(txtEmail, "-");
|
||||
SetSettingsProfileText(txtId, "-");
|
||||
SetSettingsProfileText(txtAge, "-");
|
||||
SetSettingsProfileText(txtMatches, "-");
|
||||
SetSettingsProfileText(txtWinRatio, "-");
|
||||
}
|
||||
|
||||
void ShowSettingsProfileUnavailable()
|
||||
{
|
||||
SetSettingsProfileText(txtUsername, "Unavailable");
|
||||
SetSettingsProfileText(txtEmail, "Profile data cannot be loaded");
|
||||
SetSettingsProfileText(txtId, "-");
|
||||
SetSettingsProfileText(txtAge, "-");
|
||||
SetSettingsProfileText(txtMatches, "-");
|
||||
SetSettingsProfileText(txtWinRatio, "-");
|
||||
}
|
||||
|
||||
static void SetSettingsProfileText(TMP_Text label, string value)
|
||||
{
|
||||
if (label != null)
|
||||
label.text = value;
|
||||
}
|
||||
|
||||
void ApplySettingsProfile(PlayerProfileApiResponse profile)
|
||||
{
|
||||
SetSettingsProfileText(txtUsername, profile.username ?? "");
|
||||
SetSettingsProfileText(txtEmail, profile.email ?? "");
|
||||
SetSettingsProfileText(txtId, profile.player_id.ToString());
|
||||
SetSettingsProfileText(txtAge, profile.days_since_registration.ToString());
|
||||
SetSettingsProfileText(txtMatches, profile.matches_played.ToString());
|
||||
SetSettingsProfileText(txtWinRatio, (profile.win_ratio * 100f).ToString("0.#") + "%");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ShowGameModesInfoPopup(){
|
||||
gameModesInfoPopup.localScale = Vector3.zero;
|
||||
gameModesInfoPopup.gameObject.SetActive(true);
|
||||
gameModesInfoPopup.DOScale(Vector3.one, 0.3f).SetEase(Ease.OutBack);
|
||||
}
|
||||
|
||||
public void ShowWithdrawalInfoPopup(){
|
||||
withdrawalInfoPopup.localScale = Vector3.zero;
|
||||
withdrawalInfoPopup.gameObject.SetActive(true);
|
||||
withdrawalInfoPopup.DOScale(Vector3.one, 0.3f).SetEase(Ease.OutBack);
|
||||
}
|
||||
|
||||
public void HideGameModesInfoPopup(){
|
||||
gameModesInfoPopup.DOScale(Vector3.zero, 0.3f).SetEase(Ease.InBack).OnComplete(() => {
|
||||
gameModesInfoPopup.gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void HideWithdrawalInfoPopup(){
|
||||
withdrawalInfoPopup.DOScale(Vector3.zero, 0.3f).SetEase(Ease.InBack).OnComplete(() => {
|
||||
withdrawalInfoPopup.gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user