Add XP calculation to stats menu
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Text;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -6,27 +6,54 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class StatsMenu : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text statText;
|
||||
[SerializeField] private GameObject panel;
|
||||
|
||||
[SerializeField] private TMP_Text normalBerryStat;
|
||||
[SerializeField] private TMP_Text poisonBerryStat;
|
||||
[SerializeField] private TMP_Text slowBerryStat;
|
||||
[SerializeField] private TMP_Text ultraBerryStat;
|
||||
[SerializeField] private TMP_Text speedyBerryStat;
|
||||
[SerializeField] private TMP_Text coinBerryStat;
|
||||
[SerializeField] private TMP_Text randomBerryStat;
|
||||
[SerializeField] private TMP_Text antiBerryStat;
|
||||
[SerializeField] private TMP_Text coinStat;
|
||||
|
||||
[SerializeField] private TMP_Text xpUsernameText;
|
||||
[SerializeField] private TMP_Text xpText;
|
||||
[SerializeField] private TMP_Text xpLevelText;
|
||||
|
||||
[SerializeField] private RectTransform progressFilledRect;
|
||||
|
||||
void Start()
|
||||
{
|
||||
var text = new StringBuilder();
|
||||
text.AppendLine("High Score: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreHighScore()));
|
||||
text.AppendLine("Total Normal Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalNormalBerries()));
|
||||
text.AppendLine("Total Poison Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalPoisonBerries()));
|
||||
text.AppendLine("Total Slow Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalSlowBerries()));
|
||||
text.AppendLine("Total Ultra Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalUltraBerries()));
|
||||
text.AppendLine("Total Speedy Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalSpeedyBerries()));
|
||||
text.AppendLine("Total Coin Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalCoinBerries()));
|
||||
text.AppendLine("Total Random Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalRandomBerries()));
|
||||
text.AppendLine("Total Anti Berries: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalAntiBerries()));
|
||||
text.AppendLine("Total Coins: " + Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance));
|
||||
text.AppendLine("Total Attempts: " + Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalAttepts()));
|
||||
statText.text = text.ToString();
|
||||
normalBerryStat.text = BazookaManager.Instance.GetGameStoreTotalNormalBerries().ToString();
|
||||
poisonBerryStat.text = BazookaManager.Instance.GetGameStoreTotalPoisonBerries().ToString();
|
||||
slowBerryStat.text = BazookaManager.Instance.GetGameStoreTotalSlowBerries().ToString();
|
||||
ultraBerryStat.text = BazookaManager.Instance.GetGameStoreTotalUltraBerries().ToString();
|
||||
speedyBerryStat.text = BazookaManager.Instance.GetGameStoreTotalSpeedyBerries().ToString();
|
||||
coinBerryStat.text = BazookaManager.Instance.GetGameStoreTotalCoinBerries().ToString();
|
||||
randomBerryStat.text = BazookaManager.Instance.GetGameStoreTotalRandomBerries().ToString();
|
||||
antiBerryStat.text = BazookaManager.Instance.GetGameStoreTotalAntiBerries().ToString();
|
||||
coinStat.text = BazookaManager.Instance.GetCustomBirdIconData().Balance.ToString();
|
||||
|
||||
var (_, level, currentXpInLevel, totalXpForLevel, percentDone) = Tools.GetLevelInfo();
|
||||
xpUsernameText.text = BazookaManager.Instance.GetAccountName() ?? "";
|
||||
xpText.text = currentXpInLevel.ToString() + "/" + totalXpForLevel.ToString() + " xp";
|
||||
xpLevelText.text = "Level " + level.ToString();
|
||||
SetXPProgressFilled((int)percentDone);
|
||||
|
||||
Tools.RefreshHierarchy(panel);
|
||||
}
|
||||
|
||||
async void Update()
|
||||
{
|
||||
if (Keyboard.current.escapeKey.wasPressedThisFrame) await SceneManager.LoadSceneAsync("MainMenu");
|
||||
}
|
||||
|
||||
void SetXPProgressFilled(int progress)
|
||||
{
|
||||
int newProgress = Math.Clamp(progress, 0, 100);
|
||||
progressFilledRect.sizeDelta = new Vector2(newProgress * 3, progressFilledRect.sizeDelta.y);
|
||||
progressFilledRect.anchoredPosition = new Vector2((newProgress * 3 - 300f) * 0.5f, progressFilledRect.anchoredPosition.y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user