95 lines
2.7 KiB
C#
95 lines
2.7 KiB
C#
using System;
|
|
using BlueWater.Uis;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public class TitleQuitUi : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private Button _confirmButton;
|
|
|
|
[SerializeField]
|
|
private Button _cancelButton;
|
|
|
|
[FormerlySerializedAs("_uiNavigationController")] [SerializeField]
|
|
private UiEventsController uiEventsController;
|
|
|
|
private InputAction _interactionEAction;
|
|
private InputAction _closeOptionsAction;
|
|
public Action CloseQuit;
|
|
|
|
private void Start()
|
|
{
|
|
_interactionEAction =
|
|
PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
_closeOptionsAction =
|
|
PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.Cancel);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_interactionEAction != null)
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
|
|
if (_closeOptionsAction != null)
|
|
{
|
|
_closeOptionsAction.performed -= OnCloseOptions;
|
|
}
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
EventSystem.current.SetSelectedGameObject(_cancelButton.gameObject);
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
IsOpened = false;
|
|
}
|
|
|
|
public override void EnableInput()
|
|
{
|
|
_interactionEAction.performed += OnInteractionE;
|
|
_closeOptionsAction.performed += OnCloseOptions;
|
|
|
|
uiEventsController.EnableAutoNavigate(_cancelButton.gameObject);
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
_closeOptionsAction.performed -= OnCloseOptions;
|
|
|
|
uiEventsController.DisableAutoNavigate();
|
|
}
|
|
|
|
public void OnInteractionE(InputAction.CallbackContext context)
|
|
{
|
|
var current = EventSystem.current.currentSelectedGameObject;
|
|
if (!current) return;
|
|
|
|
var currenButton = current.GetComponent<Button>();
|
|
currenButton?.onClick?.Invoke();
|
|
}
|
|
|
|
public void OnCloseOptions(InputAction.CallbackContext context)
|
|
{
|
|
CloseQuit?.Invoke();
|
|
}
|
|
}
|
|
} |