81 lines
1.9 KiB
C#
81 lines
1.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class NoteUI : MonoBehaviour
|
|
{
|
|
private const string PanelKey = "NoteUI";
|
|
|
|
public static NoteUI Instance { get; private set; }
|
|
|
|
[SerializeField] private GameObject notePanel;
|
|
[SerializeField] private Text titleText;
|
|
[SerializeField] private Text contentText;
|
|
[SerializeField] private Button closeButton;
|
|
|
|
public bool IsOpen => notePanel != null && notePanel.activeSelf;
|
|
|
|
public void Configure(GameObject panel, Text titleLabel, Text contentLabel, Button closePanelButton)
|
|
{
|
|
notePanel = panel;
|
|
titleText = titleLabel;
|
|
contentText = contentLabel;
|
|
closeButton = closePanelButton;
|
|
|
|
if (notePanel != null)
|
|
{
|
|
notePanel.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
|
|
if (closeButton != null)
|
|
{
|
|
closeButton.onClick.RemoveListener(CloseNote);
|
|
closeButton.onClick.AddListener(CloseNote);
|
|
}
|
|
}
|
|
|
|
public void ShowNote(string noteTitle, string noteContent)
|
|
{
|
|
if (notePanel == null || titleText == null || contentText == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Inventory.Instance != null && Inventory.Instance.IsOpen)
|
|
{
|
|
Inventory.Instance.CloseInventory();
|
|
}
|
|
|
|
if (DialogueUI.Instance != null && DialogueUI.Instance.IsOpen)
|
|
{
|
|
DialogueUI.Instance.CloseDialogue();
|
|
}
|
|
|
|
titleText.text = noteTitle;
|
|
contentText.text = noteContent;
|
|
notePanel.SetActive(true);
|
|
GameUIState.SetPanelOpen(PanelKey, true);
|
|
}
|
|
|
|
public void CloseNote()
|
|
{
|
|
if (notePanel == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
notePanel.SetActive(false);
|
|
GameUIState.SetPanelOpen(PanelKey, false);
|
|
}
|
|
}
|