Added the unlock menu thing
This commit is contained in:
@@ -1,22 +1,105 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Fruitomation.Game.Items;
|
||||
using Fruitomation.Game;
|
||||
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;
|
||||
|
||||
private readonly Dictionary<AutomationBuildingType, GameObject> BuildingRegistry = new();
|
||||
private readonly List<GameObject> ChildrenToKill = new();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
public void Enable
|
||||
(
|
||||
BasicUpgrade upgrade,
|
||||
ItemType[] inputs,
|
||||
ItemType[] outputs,
|
||||
AutomationBuildingType building,
|
||||
double cost
|
||||
)
|
||||
// Wow, those function params are horrible
|
||||
{
|
||||
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<Building>().Sprite;
|
||||
BuildingDisplay.GetComponent<Image>().sprite = sprite;
|
||||
|
||||
if (building == AutomationBuildingType.HeatExchanger)
|
||||
{
|
||||
RectTransform rt = BuildingDisplay.GetComponent<RectTransform>();
|
||||
rt.sizeDelta = new Vector2(125f, 250f);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
RectTransform rt = BuildingDisplay.GetComponent<RectTransform>();
|
||||
rt.sizeDelta = new Vector2(250f, 250f);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
BuildingDisplay.SetActive(false);
|
||||
LeftArrow.SetActive(false);
|
||||
SpawnerText.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
private void Disable()
|
||||
{
|
||||
BoardGO.SetActive(false);
|
||||
foreach (GameObject child in ChildrenToKill)
|
||||
{
|
||||
Destroy(child);
|
||||
}
|
||||
ChildrenToKill.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user