TheMuseumProject/Assets/Scripts/Player/Interactions/ConstructSelector.cs

100 lines
3.2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Player.Information;
namespace Player.Interactions
{
public class ConstructSelector : MonoBehaviour
{
public GameObject foodMakerPrefab;
public GameObject player;
public Sprite foodMakerImage;
public GameObject waterMakerPrefab;
public Sprite waterMakerImage;
public GameObject healthAreaPrefab;
public Sprite healthAreaImage;
public Image constructImage;
public GameObject selectedImage;
public GameObject unselectedArrow;
private readonly List<ConstructMenuItem> choices = new();
public TMP_Text constructDesc;
public TMP_Text constructName;
private int currentIndex;
private int selectedIndex;
private PlayerStats playerStats;
// Start is called before the first frame update
private void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
playerStats = player.GetComponent<PlayerStats>();
choices.Add(new ConstructMenuItem("Nutrient Consolidator", foodMakerImage,
"Scrapes nutrients from the ground to make food.\n\nRelies on local biodensity.", foodMakerPrefab));
choices.Add(new ConstructMenuItem("Water Condenser", waterMakerImage,
"Condenses vapor from the atmosphere to make water.\n\nRelies on local humidity.", waterMakerPrefab));
choices.Add(new ConstructMenuItem("Regeneration Field", healthAreaImage,
"Distributes nanites onto organisms to repair tissue.\n\nRequires proximity.", healthAreaPrefab));
currentIndex = 0;
selectedIndex = 0;
RenderPanel();
}
// Update is called once per frame
private void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow) )
{
currentIndex--;
if (currentIndex < 0) currentIndex = choices.Count - 1;
RenderPanel();
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
currentIndex++;
if (currentIndex >= choices.Count) currentIndex = 0;
RenderPanel();
}
if (Input.GetKeyDown(KeyCode.UpArrow) )
{
selectedIndex = currentIndex;
RenderPanel();
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
}
}
public void RenderPanel()
{
constructName.SetText(choices[currentIndex].GetName());
constructImage.sprite = choices[currentIndex].GetImage();
constructDesc.SetText(choices[currentIndex].GetDesc());
if (selectedIndex == currentIndex)
{
selectedImage.SetActive(true);
unselectedArrow.SetActive(false);
}
else
{
selectedImage.SetActive(false);
unselectedArrow.SetActive(true);
}
}
public GameObject GetSelected()
{
return choices[selectedIndex].GetTarget();
}
}
}