72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using NEG.UI.Area;
|
|
using NEG.UI.UnityUi.Buttons;
|
|
using NEG.UI.UnityUi.WindowSlot;
|
|
using NEG.UI.Window;
|
|
using NEG.UI.WindowSlot;
|
|
using NegUtils.NEG.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace NEG.UI.UnityUi.Window
|
|
{
|
|
public class MonoWindow : MonoBehaviour, IWindow
|
|
{
|
|
public event Action<object> OnOpened;
|
|
public event Action OnClosed;
|
|
public event Action<IControllable.BackUsed> OnBackUsed;
|
|
|
|
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
|
public IWindowSlot Parent { get; private set; }
|
|
|
|
public bool IsMainWindow { get; private set; }
|
|
|
|
private IWindowSlot DefaultWindowSlot => windowSlots[0];
|
|
public GameObject DefaultSelectedItem => defaultSelectedItem;
|
|
|
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
|
|
|
[SerializeField] private GameObject defaultSelectedItem;
|
|
|
|
public void SetOpenedState(IWindowSlot parentSlot, object data)
|
|
{
|
|
gameObject.SetActive(true);
|
|
Parent = parentSlot;
|
|
EventSystem.current.SetSelectedGameObject(defaultSelectedItem);
|
|
if (parentSlot.OpenWindowAsMain)
|
|
UiManager.Instance.SetMainWindow(this);
|
|
OnOpened?.Invoke(data);
|
|
}
|
|
|
|
public void SetClosedState()
|
|
{
|
|
gameObject.SetActive(false);
|
|
Parent = null;
|
|
((ISlotsHolder)this).CloseAllWindows();
|
|
UiManager.Instance.OnWindowClosed(this);
|
|
OnClosed?.Invoke();
|
|
}
|
|
|
|
public void SetHiddenState() => gameObject.SetActive(false);
|
|
|
|
public void SeVisibleState() => gameObject.SetActive(true);
|
|
|
|
private void Awake() => ((IWindow)this).SetHiddenState();
|
|
|
|
private void OnValidate()
|
|
{
|
|
#if !NEG_UI_DISABLE_WARNING_DEFAULT_SELECTION
|
|
if(defaultSelectedItem == null)
|
|
Debug.LogWarning($"Window {name} should have default selected item set");
|
|
#endif
|
|
}
|
|
|
|
public void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
|
|
|
|
public void SetDefaultSelectedItem(GameObject item) => defaultSelectedItem = item;
|
|
|
|
public void TryUseBack(ref IControllable.BackUsed backUsed) => OnBackUsed?.Invoke(backUsed);
|
|
}
|
|
} |