This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Project Undercover/Assets/Scripts/UI/InteractionPanelController.cs

111 lines
No EOL
3.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InteractionPanelController : MonoBehaviour {
[SerializeField]
private Text interactionText;
[SerializeField]
private GameObject mainPanel;
[SerializeField]
private Dropdown interactionsDropdown;
[SerializeField]
private GameObject interactionItemPrefab;
[SerializeField]
private GameObject requestPanel;
[SerializeField]
private Text requestedInteractionText;
private static InteractionPanelController activePanel;
private List<Dropdown.OptionData> optionsList;
private StateController _controller;
public class InteractionData : Dropdown.OptionData
{
public Interaction interaction;
public bool isSpyInteraction;
public InteractionData(Interaction interaction, bool isSpyInteraction)
{
this.interaction = interaction;
this.isSpyInteraction = isSpyInteraction;
text = interaction.interactionDescription;
if (isSpyInteraction)
text = text + " (Spy)";
}
}
void Start()
{
ActivePanel = this;
optionsList = new List<Dropdown.OptionData>();
Hide();
}
public void SelectInteractionReveal(StateController controller)
{
_controller = controller;
if (mainPanel.activeInHierarchy)
return;
interactionsDropdown.ClearOptions();
var optionsList = new List<Dropdown.OptionData>();
foreach (Interaction interaction in controller.SelectedObject.interactions)
{
var data = new InteractionData(interaction, false);
optionsList.Add(data);
}
foreach (Interaction interaction in controller.SelectedObject.spyInteractions)
{
var data = new InteractionData(interaction, true);
optionsList.Add(data);
}
interactionsDropdown.AddOptions(optionsList);
_controller.SelectedInteraction = ((InteractionData)(interactionsDropdown.options[interactionsDropdown.value])).interaction;
ActivePanel.mainPanel.SetActive(true);
}
public void SetSelectedInteraction()
{
_controller.SelectedInteraction = ((InteractionData)(interactionsDropdown.options[interactionsDropdown.value])).interaction;
}
public void AcceptInteractionReveal(StateController controller)
{
_controller = controller;
requestPanel.SetActive(true);
string description = controller.Interactor.SelectedInteraction.receiverDescription;
requestedInteractionText.GetComponent<Text>().text = "Press 'E' to " + description; //+ "\n(or press 'D' to decline)";
}
public void Hide()
{
mainPanel.SetActive(false);
requestPanel.SetActive(false);
interactionsDropdown.Hide();
}
public static InteractionPanelController ActivePanel
{
get
{
if (activePanel)
return activePanel;
Debug.LogError("No interaction panels in scene");
return null;
}
set
{
if (!activePanel)
activePanel = value;
else
{
Debug.LogError("More than one interaction panel currently exists in the scene");
}
}
}
public static bool InteractionPrompted()
{
return ActivePanel.mainPanel.activeInHierarchy;
}
}