projectEli/Assets/Inventory System/Scripts/UI/ContextMenuManagerUI.cs
2023-03-16 15:44:34 -07:00

121 lines
3.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace SimpleInventorySystem
{
public class ContextMenuManagerUI : MonoBehaviour
{
public static ContextMenuManagerUI instance;
public GameObject itemInspectMenu;
[HideInInspector] public ItemUI inspectItem;
public GameObject TacticalRigInspectionWindow;
private void Awake()
{
instance = this;
}
public bool IsInspectingItem()
{
return inspectItem != null;
}
public bool ItemInspectMenuHasFocus()
{
return InventorySystem.IsMouseOverUI(itemInspectMenu);
}
public void OpenContextMenu(ItemUI uiContext)
{
if(inspectItem != null)
{
CloseContextMenu();
}
//ContextMenuUI.transform.SetParent(uiContext, false);
itemInspectMenu.SetActive(true);
itemInspectMenu.transform.position = uiContext.transform.position;
inspectItem = uiContext;
//ContextMenuUI.transform.localScale = new Vector3(1, 1, 1);
Button inspectButton = itemInspectMenu.transform.Find("Inspect").GetComponent<Button>();
uiContext.SetInteractable(false);
Debug.Log("ContextMenuManager: " + inspectButton);
if (inspectButton != null)
{
inspectButton.onClick.AddListener(OpenInspectionWindow);
}
Button dropButton = itemInspectMenu.transform.Find("Drop").GetComponent<Button>();
Debug.Log("ContextMenuManager: " + inspectButton);
if (inspectButton != null)
{
dropButton.onClick.AddListener(DropItem);
}
}
public void OpenInspectionWindow()
{
Debug.Log("Open");
if (inspectItem != null)
{
//
//(TacticalRigInspectionWindow, InventorySystem.instance.inventoryUI.transform);
//inspectItem.ContextWindows.Add(TacticalRigInspectionWindow);
//TacticalRigInspectionWindow.SetActive(true);
inspectItem.ShowInspectionWindow();
CloseContextMenu();
}
}
public void DropItem()
{
Debug.Log("Drop");
if (inspectItem != null)
{
inspectItem.DropItemAway();
CloseContextMenu();
}
}
public void CloseContextMenu()
{
if(inspectItem != null)
{
Button inspectButton = itemInspectMenu.transform.Find("Inspect").GetComponent<Button>();
if (inspectButton != null)
{
inspectButton.onClick.RemoveListener(OpenInspectionWindow);
}
Button dropButton = itemInspectMenu.transform.Find("Drop").GetComponent<Button>();
if (dropButton != null)
{
dropButton.onClick.RemoveListener(DropItem);
}
inspectItem.SetInteractable(true);
}
inspectItem = null;
itemInspectMenu.SetActive(false);
}
// Start is called before the first frame update
void Start()
{
itemInspectMenu.SetActive(false);
TacticalRigInspectionWindow.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
//itemInspectMenu.SetActive(false);
}
}
}
}