ProjectDDD/Assets/_DDD/_Scripts/Restaurant/Ui/RestaurantSettlementUi/SettlementUi.cs
2025-09-02 21:34:18 +09:00

75 lines
2.6 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace DDD.Restaurant
{
[RequireComponent(typeof(SettlementViewModel))]
public class SettlementUi : PopupUi<RestaurantUiActions, SettlementViewModel>
{
[SerializeField] private CommonButton _confirmButton;
[SerializeField] private TextMeshProUGUI _totalRevenueLabel;
[SerializeField] private TextMeshProUGUI _normalCustomersLabel;
[SerializeField] private TextMeshProUGUI _specialCustomersLabel;
[SerializeField] private Transform _soldCookingParent;
protected override GameObject GetInitialSelected()
{
return _confirmButton.gameObject;
}
protected override void OnCreatedInitializePopup()
{
_viewModel.OnCompletedSettlement += HandleCompleteSettlement;
_confirmButton.AddListener(HandleCompleteSettlement);
BindingHelper.BindText(_bindingContext, _totalRevenueLabel, nameof(_viewModel.TotalRevenue));
BindingHelper.BindText(_bindingContext, _normalCustomersLabel, nameof(_viewModel.NormalCustomers));
BindingHelper.BindText(_bindingContext, _specialCustomersLabel, nameof(_viewModel.SpecialCustomers));
}
protected override void OnOpenedEventsPopup(OpenPopupUiEvent evt)
{
_viewModel.UpdateSettlement(_soldCookingParent);
}
protected override void OnClosedEventsPopup(ClosePopupUiEvent evt)
{
}
protected override void OnInputStartedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
switch (actionEnum)
{
case RestaurantUiActions.Interact1:
HandleInteract1();
break;
}
}
protected override void OnInputPerformedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
}
protected override void OnInputCanceledPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
}
private void HandleInteract1()
{
var selected = EventSystem.current.currentSelectedGameObject;
var interactable = selected?.GetComponent<IInteractableUi>();
interactable?.OnInteract();
}
private void HandleCompleteSettlement()
{
Close();
_viewModel.SettlementState.CompleteSettlement();
}
}
}