Finished upgrade menu

This commit is contained in:
Pasha Bibko
2026-05-05 11:37:07 +01:00
parent 066b3bc958
commit 528ed9f413
3 changed files with 419 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
using PashaBibko.Pacore.Attributes;
using Fruitomation.Game;
using UnityEngine;
using UnityEngine.Rendering;
namespace Fruitomation.Global
{
@@ -17,6 +18,12 @@ namespace Fruitomation.Global
Instance.InternalCurrentMoney += amount;
}
public static bool CouldBuy(double amount)
{
double val = Instance.InternalCurrentMoney - amount;
return val > 0f;
}
public static bool CanBuy(double amount)
{
double val = Instance.InternalCurrentMoney - amount;

View File

@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Fruitomation.Game.Items;
using Fruitomation.Game;
using Fruitomation.Global;
using UnityEngine.UI;
using UnityEngine;
@@ -16,9 +18,15 @@ namespace Fruitomation.UI
[SerializeField] private GameObject BuildingDisplay;
[SerializeField] private GameObject LeftArrow;
[SerializeField] private GameObject SpawnerText;
[SerializeField] private Button UnlockButton;
[SerializeField] private GameObject UnlockedText;
[SerializeField] private GameObject PoorPeopleText;
private readonly Dictionary<AutomationBuildingType, GameObject> BuildingRegistry = new();
private readonly List<GameObject> ChildrenToKill = new();
private BasicUpgrade CurrentUpgrade;
private double CurrentCost;
private void Start()
{
@@ -35,6 +43,12 @@ namespace Fruitomation.UI
BuildingRegistry.Add(info.Type, info.Prefab);
}
}
UnlockButton.onClick.AddListener(() =>
{
MoneyController.CanBuy(CurrentCost);
UpgradeManager.Unlock(CurrentUpgrade);
});
}
public void Enable
@@ -47,7 +61,11 @@ namespace Fruitomation.UI
)
// Wow, those function params are horrible
{
CurrentUpgrade = upgrade;
CurrentCost = cost;
BoardGO.SetActive(true);
foreach (ItemType input in inputs)
{
ItemInfo info = ItemInfoRegistry.Get(input);
@@ -92,6 +110,34 @@ namespace Fruitomation.UI
}
}
private void Update()
{
if (UpgradeManager.Is(CurrentUpgrade))
{
UnlockedText.SetActive(true);
UnlockButton.gameObject.SetActive(false);
PoorPeopleText.SetActive(false);
}
else
{
UnlockedText.SetActive(false);
if (MoneyController.CouldBuy(CurrentCost))
{
UnlockButton.gameObject.SetActive(true);
PoorPeopleText.SetActive(false);
}
else
{
UnlockButton.gameObject.SetActive(false);
PoorPeopleText.SetActive(true);
}
}
}
private void Disable()
{
BoardGO.SetActive(false);