Updated buttons interactivity

Also changed image compression
This commit is contained in:
Pasha Bibko
2026-04-21 15:40:45 +01:00
parent bbb419d3ff
commit 103ae9c645
39 changed files with 601 additions and 292 deletions

View File

@@ -1,10 +1,11 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Fruitomation.Game;
using UnityEngine.UI;
using UnityEngine;
using System.Linq;
using System;
using System.Text.RegularExpressions;
using PashaBibko.Pacore.Attributes;
namespace Fruitomation.UI
{
@@ -38,9 +39,10 @@ namespace Fruitomation.UI
private (LineRenderer, BasicUpgradeButton, LineInfo)[] UpgradeLines;
private UpgradeState State = UpgradeState.Hidden;
private Button AttachedButton;
private Text AttachedText;
[Header("Read Only")]
[SerializeField, InspectorReadOnly] private UpgradeState State = UpgradeState.Hidden;
[SerializeField, InspectorReadOnly] private Button AttachedButton;
[SerializeField, InspectorReadOnly] private Text AttachedText;
private void Awake()
{
@@ -52,7 +54,7 @@ namespace Fruitomation.UI
AttachedButton = GetComponent<Button>();
AttachedButton.onClick.AddListener(() => { UpgradeManager.Unlock(Upgrade); });
AttachedButton.onClick.AddListener(OnButtonClicked);
/* Stops null reference */
RequiredUpgrades ??= Array.Empty<BasicUpgradeButton>();
@@ -97,14 +99,19 @@ namespace Fruitomation.UI
UpgradeLines = lines.ToArray();
}
private void OnButtonClicked()
{
UpgradeManager.Unlock(Upgrade);
}
private bool IsUnlockable =>
RequiredUpgrades.Length == 0 ||
RequiredUpgrades.All(required => required.IsUnlocked);
private bool IsViewable =>
RequiredUpgrades.Length == 0 ||
RequiredUpgrades.Any(required => required.IsUnlocked);
RequiredUpgrades.Any(required => required.IsUnlockable);
private void Update()
{
foreach ((LineRenderer lr, BasicUpgradeButton button, LineInfo info) in UpgradeLines)
@@ -119,7 +126,7 @@ namespace Fruitomation.UI
{
lr.positionCount = info.LinePoints.Length;
int index = 0;
foreach (RectTransform point in info.LinePoints)
{
lr.SetPosition(index++, point.position);
@@ -131,12 +138,12 @@ namespace Fruitomation.UI
{
State = UpgradeState.Unlocked;
}
else if (IsUnlockable)
{
State = UpgradeState.Unlockable;
}
else if (IsViewable)
{
State = UpgradeState.Viewable;
@@ -146,14 +153,21 @@ namespace Fruitomation.UI
{
State = UpgradeState.Hidden;
}
AttachedButton.interactable = State == UpgradeState.Unlockable;
// https://stackoverflow.com/questions/27040325/c-sharp-regex-to-convert-camelcase-to-sentence-case
string formatted = Regex.Replace(Upgrade.ToString(), @"[A-Z]", " $0")[1..];
AttachedText.text = State == UpgradeState.Hidden
? "???"
: $"{formatted}\n{Cost.AsString()}";
AttachedText.text = State switch
{
UpgradeState.Hidden => "???",
UpgradeState.Viewable => $"{formatted}",
UpgradeState.Unlockable => $"{formatted}\n{Cost.AsString()}",
UpgradeState.Unlocked => $"{formatted}\nUnlocked",
_ => throw new ArgumentOutOfRangeException()
};
}
private bool IsUnlocked => State == UpgradeState.Unlocked;
}