2024-11-30 11:53:38 +00:00
|
|
|
using System;
|
|
|
|
using BlueWater.Uis;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
|
|
|
public class TitleQuitUi : PopupUi
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private GameObject _panel;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Button _confirmButton;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Button _cancelButton;
|
|
|
|
|
2024-12-18 16:00:39 +00:00
|
|
|
[SerializeField]
|
|
|
|
private UiEventsController _uiEventsController;
|
2024-11-30 11:53:38 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2024-12-18 16:00:39 +00:00
|
|
|
base.Open();
|
2024-11-30 11:53:38 +00:00
|
|
|
_panel.SetActive(true);
|
2024-12-18 16:00:39 +00:00
|
|
|
// EventSystem.current.SetSelectedGameObject(_cancelButton.gameObject);
|
2024-11-30 11:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Close()
|
|
|
|
{
|
|
|
|
_panel.SetActive(false);
|
2024-12-18 16:00:39 +00:00
|
|
|
base.Close();
|
|
|
|
EventSystem.current.SetSelectedGameObject(null);
|
2024-11-30 11:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void EnableInput()
|
|
|
|
{
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
|
|
_closeOptionsAction.performed += OnCloseOptions;
|
|
|
|
|
2024-12-18 16:00:39 +00:00
|
|
|
_uiEventsController.EnableAutoNavigate(_cancelButton.gameObject);
|
2024-11-30 11:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void DisableInput()
|
|
|
|
{
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
|
|
_closeOptionsAction.performed -= OnCloseOptions;
|
|
|
|
|
2024-12-18 16:00:39 +00:00
|
|
|
_uiEventsController.DisableAutoNavigate();
|
2024-11-30 11:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|