ProjectDDD/Assets/_DDD/_Scripts/Restaurant/Ui/RestaurantSettlementUi/SettlementUi.cs

75 lines
2.6 KiB
C#
Raw Normal View History

2025-09-02 09:44:20 +00:00
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()
{
2025-09-02 12:34:18 +00:00
_viewModel.OnCompletedSettlement += HandleCompleteSettlement;
_confirmButton.AddListener(HandleCompleteSettlement);
2025-09-02 09:44:20 +00:00
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();
}
2025-09-02 12:34:18 +00:00
private void HandleCompleteSettlement()
{
Close();
_viewModel.SettlementState.CompleteSettlement();
}
2025-09-02 09:44:20 +00:00
}
}