using System; using System.Collections.Generic; using Fruitomation.Game.Items; using Fruitomation.Game; using Fruitomation.Global; using UnityEngine.UI; using UnityEngine; namespace Fruitomation.UI { public class UpgradeInfoBoard : MonoBehaviour { [SerializeField] private GameObject BoardGO; [SerializeField] private Button[] ExitButtons; [SerializeField] private BuildingRegistry Registry; [SerializeField] private GameObject InputParent; [SerializeField] private GameObject OutputParent; [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 BuildingRegistry = new(); private readonly List ChildrenToKill = new(); private BasicUpgrade CurrentUpgrade; private double CurrentCost; private void Start() { BoardGO.SetActive(false); foreach (Button b in ExitButtons) { b.onClick.AddListener(Disable); } foreach (BuildingRegistry.BuildingInfo info in Registry.GetBuildings()) { if (info.Type != AutomationBuildingType.None) { BuildingRegistry.Add(info.Type, info.Prefab); } } UnlockButton.onClick.AddListener(() => { MoneyController.CanBuy(CurrentCost); UpgradeManager.Unlock(CurrentUpgrade); }); } public void Enable ( BasicUpgrade upgrade, ItemType[] inputs, ItemType[] outputs, AutomationBuildingType building, double cost ) // Wow, those function params are horrible { CurrentUpgrade = upgrade; CurrentCost = cost; BoardGO.SetActive(true); foreach (ItemType input in inputs) { ItemInfo info = ItemInfoRegistry.Get(input); GameObject go = Instantiate(info.Prefab, InputParent.transform); ChildrenToKill.Add(go); } foreach (ItemType output in outputs) { ItemInfo info = ItemInfoRegistry.Get(output); GameObject go = Instantiate(info.Prefab, OutputParent.transform); ChildrenToKill.Add(go); } if (building != AutomationBuildingType.Spawner) { BuildingDisplay.SetActive(true); LeftArrow.SetActive(true); SpawnerText.SetActive(false); Sprite sprite = BuildingRegistry[building].GetComponent().Sprite; BuildingDisplay.GetComponent().sprite = sprite; if (building == AutomationBuildingType.HeatExchanger) { RectTransform rt = BuildingDisplay.GetComponent(); rt.sizeDelta = new Vector2(125f, 250f); } else { RectTransform rt = BuildingDisplay.GetComponent(); rt.sizeDelta = new Vector2(250f, 250f); } } else { BuildingDisplay.SetActive(false); LeftArrow.SetActive(false); SpawnerText.SetActive(true); } } 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); foreach (GameObject child in ChildrenToKill) { Destroy(child); } ChildrenToKill.Clear(); } } }