88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.Localization.Components;
|
|
using UnityEngine.UI;
|
|
|
|
namespace DDD
|
|
{
|
|
public class ConfirmUi : PopupUi<RestaurantUiActions>
|
|
{
|
|
[SerializeField] private TextMeshProUGUI _messageLabel;
|
|
[SerializeField] private LocalizeStringEvent _messageLabelLocalizeStringEvent;
|
|
[SerializeField] private Button _cancelButton;
|
|
[SerializeField] private Button _confirmButton;
|
|
|
|
private Action _onCancel;
|
|
private Action _onConfirm;
|
|
|
|
protected override GameObject GetInitialSelected()
|
|
{
|
|
return _confirmButton.gameObject;
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
_messageLabel.text = string.Empty;
|
|
}
|
|
|
|
public override void Open(OpenPopupUiEvent evt)
|
|
{
|
|
base.Open(evt);
|
|
|
|
_messageLabelLocalizeStringEvent.StringReference = LocalizationManager.Instance.GetLocalizedString(evt.NewMessageKey);
|
|
|
|
_cancelButton.onClick.RemoveAllListeners();
|
|
_confirmButton.onClick.RemoveAllListeners();
|
|
|
|
_onCancel = () =>
|
|
{
|
|
evt.OnCancel?.Invoke();
|
|
Close();
|
|
};
|
|
|
|
_onConfirm = () =>
|
|
{
|
|
evt.OnConfirm?.Invoke();
|
|
Close();
|
|
};
|
|
|
|
_cancelButton.onClick.AddListener(() => _onCancel?.Invoke());
|
|
_confirmButton.onClick.AddListener(() => _onConfirm?.Invoke());
|
|
|
|
_cancelButton.gameObject.SetActive(evt.IsCancelButtonVisible);
|
|
}
|
|
|
|
|
|
protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
|
|
{
|
|
if (base.OnInputPerformed(actionEnum, context) == false) return false;
|
|
|
|
switch (actionEnum)
|
|
{
|
|
case RestaurantUiActions.Cancel:
|
|
HandleCancelPerformed();
|
|
break;
|
|
case RestaurantUiActions.Interact1:
|
|
HandleInteract1Performed();
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void HandleCancelPerformed()
|
|
{
|
|
_onCancel?.Invoke();
|
|
}
|
|
|
|
private void HandleInteract1Performed()
|
|
{
|
|
EventSystem.current.currentSelectedGameObject?.GetComponent<Button>()?.onClick?.Invoke();
|
|
}
|
|
}
|
|
} |