2022-10-29 19:56:00 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace SimpleInventorySystem
|
|
|
|
|
{
|
|
|
|
|
public class ContextMenuManagerUI : MonoBehaviour
|
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
|
public static ContextMenuManagerUI instance;
|
2022-10-29 19:56:00 +00:00
|
|
|
|
public GameObject itemInspectMenu;
|
|
|
|
|
[HideInInspector] public ItemUI inspectItem;
|
|
|
|
|
public GameObject TacticalRigInspectionWindow;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
|
instance = this;
|
|
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
|
public bool IsInspectingItem()
|
|
|
|
|
{
|
|
|
|
|
return inspectItem != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ItemInspectMenuHasFocus()
|
|
|
|
|
{
|
|
|
|
|
return InventorySystem.IsMouseOverUI(itemInspectMenu);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenContextMenu(ItemUI uiContext)
|
|
|
|
|
{
|
2022-12-11 03:03:30 +00:00
|
|
|
|
if(inspectItem != null)
|
|
|
|
|
{
|
|
|
|
|
CloseContextMenu();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
|
//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>();
|
2022-12-11 03:03:30 +00:00
|
|
|
|
uiContext.SetInteractable(false);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
Debug.Log("ContextMenuManager: " + inspectButton);
|
|
|
|
|
if (inspectButton != null)
|
|
|
|
|
{
|
|
|
|
|
inspectButton.onClick.AddListener(OpenInspectionWindow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenInspectionWindow()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Open");
|
|
|
|
|
if (inspectItem != null && inspectItem.ItemTag == ItemTags.TacticalRig && inspectItem.Equipped)
|
|
|
|
|
{
|
2022-11-06 02:28:29 +00:00
|
|
|
|
//
|
|
|
|
|
//(TacticalRigInspectionWindow, InventorySystem.instance.inventoryUI.transform);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
inspectItem.ContextWindows.Add(TacticalRigInspectionWindow);
|
|
|
|
|
TacticalRigInspectionWindow.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-11 03:03:30 +00:00
|
|
|
|
public void DropItem()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Drop");
|
|
|
|
|
if (inspectItem != null)
|
|
|
|
|
{
|
2022-12-23 03:50:16 +00:00
|
|
|
|
inspectItem.DropItemAway();
|
2022-12-11 03:03:30 +00:00
|
|
|
|
CloseContextMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
|
public void CloseContextMenu()
|
|
|
|
|
{
|
|
|
|
|
if(inspectItem != null)
|
|
|
|
|
{
|
|
|
|
|
Button inspectButton = itemInspectMenu.transform.Find("Inspect").GetComponent<Button>();
|
|
|
|
|
if (inspectButton != null)
|
|
|
|
|
{
|
|
|
|
|
inspectButton.onClick.RemoveListener(OpenInspectionWindow);
|
|
|
|
|
}
|
2022-12-11 03:03:30 +00:00
|
|
|
|
inspectItem.SetInteractable(true);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|