Improved upgrade menu look
This commit is contained in:
53
Assets/Scripts/Game/CurrencyAmount.cs
Normal file
53
Assets/Scripts/Game/CurrencyAmount.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace Fruitomation.Game
|
||||
{
|
||||
public enum CurrencyMagnitude
|
||||
{
|
||||
Ones,
|
||||
Thousands,
|
||||
Millions,
|
||||
Billions,
|
||||
Trillions
|
||||
}
|
||||
|
||||
[Serializable] public class CurrencyAmount
|
||||
{
|
||||
[SerializeField] private CurrencyMagnitude Magnitude;
|
||||
[SerializeField] private float Ammount;
|
||||
|
||||
public string AsString()
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.Append(
|
||||
Ammount > 10f
|
||||
? $"${Ammount:I}"
|
||||
: $"${Ammount:F1}"
|
||||
);
|
||||
|
||||
switch (Magnitude)
|
||||
{
|
||||
case CurrencyMagnitude.Ones:
|
||||
break;
|
||||
case CurrencyMagnitude.Thousands:
|
||||
builder.Append("K");
|
||||
break;
|
||||
case CurrencyMagnitude.Millions:
|
||||
builder.Append("M");
|
||||
break;
|
||||
case CurrencyMagnitude.Billions:
|
||||
builder.Append("B");
|
||||
break;
|
||||
case CurrencyMagnitude.Trillions:
|
||||
builder.Append("T");
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/CurrencyAmount.cs.meta
Normal file
3
Assets/Scripts/Game/CurrencyAmount.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e9afb637ef14ed4b34fd226298272d5
|
||||
timeCreated: 1776767993
|
||||
@@ -4,6 +4,7 @@ using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Fruitomation.UI
|
||||
{
|
||||
@@ -24,8 +25,9 @@ namespace Fruitomation.UI
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private BasicUpgrade Upgrade;
|
||||
[SerializeField] private int UpgradeCost;
|
||||
[SerializeField] private bool DrawDefaultLines;
|
||||
[SerializeField] private CurrencyAmount Cost;
|
||||
[SerializeField] private bool BigText;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private BasicUpgradeButton[] RequiredUpgrades;
|
||||
@@ -43,6 +45,8 @@ namespace Fruitomation.UI
|
||||
private void Awake()
|
||||
{
|
||||
AttachedText = gameObject.GetComponentInChildren<Text>();
|
||||
AttachedText.fontSize = 30;
|
||||
|
||||
AttachedButton = GetComponent<Button>();
|
||||
|
||||
AttachedButton.onClick.AddListener(() => { UpgradeManager.Unlock(Upgrade); });
|
||||
@@ -63,6 +67,7 @@ namespace Fruitomation.UI
|
||||
|
||||
LineRenderer lr = go.AddComponent<LineRenderer>();
|
||||
lr.material = LineMaterial;
|
||||
lr.widthMultiplier = 0.1f;
|
||||
lr.positionCount = 2;
|
||||
|
||||
lines.Add((lr, required, null));
|
||||
@@ -81,6 +86,7 @@ namespace Fruitomation.UI
|
||||
|
||||
LineRenderer lr = go.AddComponent<LineRenderer>();
|
||||
lr.material = LineMaterial;
|
||||
lr.widthMultiplier = 0.1f;
|
||||
|
||||
lines.Add((lr, null, line));
|
||||
}
|
||||
@@ -138,11 +144,11 @@ namespace Fruitomation.UI
|
||||
State = UpgradeState.Hidden;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// https://stackoverflow.com/questions/27040325/c-sharp-regex-to-convert-camelcase-to-sentence-case
|
||||
string formatted = Regex.Replace(Upgrade.ToString(), @"[A-Z]", " $0");
|
||||
AttachedText.text = State == UpgradeState.Hidden
|
||||
? "???"
|
||||
: $"{Upgrade.ToString()} [{UpgradeCost}]";
|
||||
: $"{formatted}\n{Cost.AsString()}";
|
||||
}
|
||||
|
||||
private bool IsUnlocked => State == UpgradeState.Unlocked;
|
||||
|
||||
Reference in New Issue
Block a user