Added all upgrade buttons

This commit is contained in:
Pasha Bibko
2026-04-16 14:07:10 +01:00
parent 646ef895c3
commit a41696e4db
6 changed files with 6495 additions and 64 deletions

View File

@@ -0,0 +1,83 @@
using Fruitomation.Game;
using UnityEngine.UI;
using UnityEngine;
using System.Linq;
using System;
namespace Fruitomation.UI
{
public class BasicUpgradeButton : MonoBehaviour
{
private enum UpgradeState
{
Unlocked,
Unlockable,
Viewable,
Hidden,
}
[Header("Settings")]
[SerializeField] private BasicUpgrade Upgrade;
[SerializeField] private int UpgradeCost;
[Header("References")]
[SerializeField] private BasicUpgradeButton[] RequiredUpgrades;
private UpgradeState State = UpgradeState.Hidden;
private Button AttachedButton;
private Text AttachedText;
private void Awake()
{
AttachedText = gameObject.GetComponentInChildren<Text>();
AttachedButton = GetComponent<Button>();
AttachedButton.onClick.AddListener(() =>
{
UpgradeManager.Unlock(Upgrade);
});
/* Stops null reference */
RequiredUpgrades ??= Array.Empty<BasicUpgradeButton>();
}
private bool IsUnlockable =>
RequiredUpgrades.Length == 0 ||
RequiredUpgrades.All(required => required.IsUnlocked);
private bool IsViewable =>
RequiredUpgrades.Length == 0 ||
RequiredUpgrades.Any(required => required.IsUnlocked);
private void Update()
{
if (UpgradeManager.Is(Upgrade))
{
State = UpgradeState.Unlocked;
}
else if (IsUnlockable)
{
State = UpgradeState.Unlockable;
}
else if (IsViewable)
{
State = UpgradeState.Viewable;
}
else
{
State = UpgradeState.Hidden;
}
//
AttachedText.text = State == UpgradeState.Hidden
? "???"
: $"{Upgrade.ToString()} [{UpgradeCost}]";
}
private bool IsUnlocked => State == UpgradeState.Unlocked;
}
}