2017-10-03 04:15:13 -05:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class InteractionPanelController : MonoBehaviour {
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
[SerializeField]
|
|
|
|
|
private Text interactionText;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject mainPanel;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Dropdown interactionsDropdown;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject interactionItemPrefab;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject requestPanel;
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Text requestedInteractionText;
|
2017-10-03 04:15:13 -05:00
|
|
|
|
private static InteractionPanelController activePanel;
|
2017-10-09 02:03:39 -05:00
|
|
|
|
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)";
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-03 04:15:13 -05:00
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
ActivePanel = this;
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
public void SelectInteractionReveal(StateController controller)
|
2017-10-03 04:15:13 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
_controller = controller;
|
|
|
|
|
if (mainPanel.activeInHierarchy)
|
|
|
|
|
return;
|
|
|
|
|
interactionsDropdown.ClearOptions();
|
2017-10-10 12:43:11 -05:00
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
var optionsList = new List<Dropdown.OptionData>();
|
|
|
|
|
foreach (Interaction interaction in controller.SelectedObject.interactions)
|
|
|
|
|
{
|
|
|
|
|
var data = new InteractionData(interaction, false);
|
|
|
|
|
optionsList.Add(data);
|
|
|
|
|
}
|
2017-10-10 12:43:11 -05:00
|
|
|
|
if (controller.SelectedObject.CompareTag("Spy"))
|
2017-10-09 02:03:39 -05:00
|
|
|
|
{
|
2017-10-10 12:43:11 -05:00
|
|
|
|
foreach (Interaction interaction in controller.SelectedObject.spyInteractions)
|
|
|
|
|
{
|
|
|
|
|
var data = new InteractionData(interaction, true);
|
|
|
|
|
optionsList.Add(data);
|
|
|
|
|
}
|
2017-10-09 02:03:39 -05:00
|
|
|
|
}
|
2017-10-10 12:43:11 -05:00
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
interactionsDropdown.AddOptions(optionsList);
|
2017-10-10 14:26:28 -05:00
|
|
|
|
if (interactionsDropdown.value > interactionsDropdown.options.Count)
|
|
|
|
|
interactionsDropdown.value = 0;
|
2017-10-09 02:03:39 -05:00
|
|
|
|
_controller.SelectedInteraction = ((InteractionData)(interactionsDropdown.options[interactionsDropdown.value])).interaction;
|
2017-10-05 03:13:27 -05:00
|
|
|
|
ActivePanel.mainPanel.SetActive(true);
|
2017-10-03 04:15:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 02:03:39 -05:00
|
|
|
|
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;
|
2017-10-12 14:48:42 -05:00
|
|
|
|
requestedInteractionText.GetComponent<Text>().text = "Press 'E' to " + description;
|
2017-10-09 02:03:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Hide()
|
2017-10-03 04:15:13 -05:00
|
|
|
|
{
|
2017-10-09 02:03:39 -05:00
|
|
|
|
mainPanel.SetActive(false);
|
|
|
|
|
requestPanel.SetActive(false);
|
|
|
|
|
interactionsDropdown.Hide();
|
2017-10-03 04:15:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-05 03:13:27 -05:00
|
|
|
|
|
|
|
|
|
public static bool InteractionPrompted()
|
|
|
|
|
{
|
|
|
|
|
return ActivePanel.mainPanel.activeInHierarchy;
|
|
|
|
|
}
|
2017-10-03 04:15:13 -05:00
|
|
|
|
}
|