Files
source/Assets/Scripts/StatsMenu.cs

106 lines
5.2 KiB
C#

using System;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class StatsMenu : MonoBehaviour
{
[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 goldenBerryStat;
[SerializeField] private TMP_Text coinStat;
[SerializeField] private Image playerIcon;
[SerializeField] private Image playerOverlay;
[SerializeField] private TMP_Text xpUsernameText;
[SerializeField] private TMP_Text xpText;
[SerializeField] private TMP_Text xpLevelText;
[SerializeField] private RectTransform progressFilledRect;
void Start()
{
normalBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalNormalBerries());
poisonBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalPoisonBerries());
slowBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalSlowBerries());
ultraBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalUltraBerries());
speedyBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalSpeedyBerries());
coinBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalCoinBerries());
randomBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalRandomBerries());
antiBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalAntiBerries());
goldenBerryStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetGameStoreTotalGoldenBerries());
coinStat.text = Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance);
var customIcon = BazookaManager.Instance.GetCustomBirdIconData().Selected;
if (customIcon == null)
{
int icon = BazookaManager.Instance.GetBirdIcon();
int overlay = BazookaManager.Instance.GetBirdOverlay();
var iconColor = BazookaManager.Instance.GetColorSettingIcon();
var overlayColor = BazookaManager.Instance.GetColorSettingOverlay();
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
if (icon == 1) playerIcon.sprite = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
playerOverlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlay);
if (overlay != 0) playerOverlay.gameObject.SetActive(true);
if (overlay == 8) playerOverlay.rectTransform.localPosition = new Vector3(-27.6232f, 23.42824f, 0f);
else if (overlay == 11) playerOverlay.rectTransform.localPosition = new Vector3(-24.5611f, 32.250931f, 0f);
else if (overlay == 13) playerOverlay.rectTransform.localPosition = new Vector3(-27.56624f, 23.25544f, 0f);
try
{
playerIcon.color = new Color(
int.Parse(iconColor[0].ToString()) / 255f,
int.Parse(iconColor[1].ToString()) / 255f,
int.Parse(iconColor[2].ToString()) / 255f
);
playerOverlay.color = new Color(
int.Parse(overlayColor[0].ToString()) / 255f,
int.Parse(overlayColor[1].ToString()) / 255f,
int.Parse(overlayColor[2].ToString()) / 255f
);
}
catch
{
playerIcon.color = Color.white;
playerOverlay.color = Color.white;
}
}
else
{
var waitingForCustomIcon = playerIcon.gameObject.AddComponent<WaitingForCustomIcon>();
waitingForCustomIcon.ID = customIcon;
CustomIconLoader.Init(new[] { waitingForCustomIcon });
}
var (_, level, currentXpInLevel, totalXpForLevel, percentDone) = Tools.GetLevelInfo();
xpUsernameText.text = BazookaManager.Instance.GetAccountName() ?? "";
xpText.text = $"{Tools.FormatWithCommas(currentXpInLevel.ToString())}/{Tools.FormatWithCommas(totalXpForLevel.ToString())} xp";
xpLevelText.text = "Level " + Tools.FormatWithCommas(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);
}
}