ProjectDDD/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi/RestaurantManagementUi.cs

185 lines
6.3 KiB
C#
Raw Normal View History

using System;
2025-07-24 08:41:20 +00:00
using UnityEngine;
2025-07-25 07:58:53 +00:00
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
2025-08-04 11:01:43 +00:00
using UnityEngine.UI;
namespace DDD
{
2025-07-28 11:33:04 +00:00
public class RestaurantManagementUi : PopupUi<RestaurantUiActions>, IEventHandler<TodayMenuRemovedEvent>
{
2025-07-25 07:58:53 +00:00
[SerializeField] private InventoryView _inventoryView;
2025-07-28 11:33:04 +00:00
[SerializeField] private ItemDetailView _itemDetailView;
2025-07-25 07:58:53 +00:00
[SerializeField] private TabGroupUi<RestaurantManagementSectionType> _sectionTabs;
2025-07-30 10:38:12 +00:00
[SerializeField] private TabGroupUi<InventoryCategoryType> _menuCategoryTabs;
[SerializeField] private TabGroupUi<InventoryCategoryType> _cookwareCategoryTabs;
2025-08-04 11:01:43 +00:00
[SerializeField] private Image _completeBatchFilledImage;
[SerializeField] private float _holdCompleteTime = 1f;
private float _elapsedTime;
private bool _isHolding;
protected override void Update()
{
base.Update();
if (_isHolding)
{
_completeBatchFilledImage.fillAmount = _elapsedTime;
var multiply = _holdCompleteTime / 1f;
if (_elapsedTime >= 1f)
{
HandleInteract2Canceled(); // TODO : 추후에 팝업 연결
var evt = GameEvents.ShowConfirmPopupUiEvent;
evt.IsCancelButtonVisible = true;
evt.NewMessageKey = "Global_Message_001";
evt.OnConfirm = Close;
EventBus.Broadcast(evt);
//HandleCancelPerformed();
return;
}
_elapsedTime += Time.deltaTime * multiply;
}
}
2025-07-24 08:41:20 +00:00
2025-07-29 15:56:47 +00:00
protected override GameObject GetInitialSelected()
{
var inventoryViewInitialSelectedObject = _inventoryView.GetInitialSelected();
if (inventoryViewInitialSelectedObject) return inventoryViewInitialSelectedObject;
2025-08-03 23:09:01 +00:00
if (_menuCategoryTabs.GetFirstInteractableButton.activeInHierarchy)
{
return _menuCategoryTabs.GetFirstInteractableButton;
}
return _cookwareCategoryTabs.GetFirstInteractableButton;
2025-07-29 15:56:47 +00:00
}
2025-07-29 18:52:13 +00:00
public async override void Open()
2025-07-24 08:41:20 +00:00
{
2025-07-29 20:57:19 +00:00
base.Open();
2025-07-29 18:52:13 +00:00
await _inventoryView.Initialize();
2025-07-25 07:58:53 +00:00
_sectionTabs.Initialize(OnSectionTabSelected);
2025-07-30 10:38:12 +00:00
_menuCategoryTabs.Initialize(OnCategoryTabSelected);
_cookwareCategoryTabs.Initialize(OnCategoryTabSelected);
_sectionTabs.SelectFirstTab();
_menuCategoryTabs.SelectFirstTab();
2025-07-28 11:33:04 +00:00
EventBus.Register<TodayMenuRemovedEvent>(this);
}
public override void Close()
{
base.Close();
EventBus.Unregister<TodayMenuRemovedEvent>(this);
2025-07-24 08:41:20 +00:00
}
protected override void OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
2025-08-04 11:01:43 +00:00
base.OnInputPerformed(actionEnum, context);
switch (actionEnum)
{
case RestaurantUiActions.Cancel:
2025-08-04 11:01:43 +00:00
HandleCancelPerformed();
break;
case RestaurantUiActions.PreviousTab:
2025-08-04 11:01:43 +00:00
HandleMoveTabPerformed(-1);
break;
case RestaurantUiActions.NextTab:
2025-08-04 11:01:43 +00:00
HandleMoveTabPerformed(1);
break;
case RestaurantUiActions.Interact1:
2025-08-04 11:01:43 +00:00
HandleInteract1Performed();
break;
case RestaurantUiActions.Interact2:
HandleInteract2Performed();
break;
2025-08-04 11:01:43 +00:00
}
}
protected override void OnInputCanceled(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
base.OnInputCanceled(actionEnum, context);
switch (actionEnum)
{
2025-07-25 07:58:53 +00:00
case RestaurantUiActions.Interact2:
2025-08-04 11:01:43 +00:00
HandleInteract2Canceled();
2025-07-25 07:58:53 +00:00
break;
}
}
2025-08-04 11:01:43 +00:00
private void HandleCancelPerformed()
{
var evt = GameEvents.ClosePopupUiEvent;
evt.UiType = GetType();
EventBus.Broadcast(evt);
}
2025-08-04 11:01:43 +00:00
private void HandleMoveTabPerformed(int direction)
{
2025-07-25 07:58:53 +00:00
_sectionTabs.Move(direction);
}
2025-08-04 11:01:43 +00:00
private void HandleInteract1Performed()
2025-07-25 07:58:53 +00:00
{
var selected = EventSystem.current.currentSelectedGameObject;
var interactable = selected?.GetComponent<IInteractableUi>();
interactable?.OnInteract();
}
2025-08-04 11:01:43 +00:00
// TODO : 버튼과 연동
private void HandleInteract2Performed()
{
_isHolding = true;
}
private void HandleInteract2Canceled()
{
2025-08-04 11:01:43 +00:00
_isHolding = false;
_elapsedTime = 0f;
_completeBatchFilledImage.fillAmount = 0f;
}
2025-07-24 08:41:20 +00:00
2025-07-25 07:58:53 +00:00
private void OnSectionTabSelected(RestaurantManagementSectionType section)
2025-07-24 08:41:20 +00:00
{
2025-07-30 10:38:12 +00:00
switch (section)
{
case RestaurantManagementSectionType.Menu:
_menuCategoryTabs.SelectFirstTab();
break;
case RestaurantManagementSectionType.Cookware:
_cookwareCategoryTabs.SelectFirstTab();
break;
default:
throw new ArgumentOutOfRangeException(nameof(section), section, null);
}
2025-07-27 19:32:41 +00:00
// TODO : 추후 Menu, Cookware, Worker에 맞춰 다른 콘텐츠 노출 처리
2025-07-24 08:41:20 +00:00
}
2025-07-25 07:58:53 +00:00
private void OnCategoryTabSelected(InventoryCategoryType category)
2025-07-24 08:41:20 +00:00
{
2025-07-27 19:32:41 +00:00
_inventoryView.UpdateCategoryView(category);
2025-07-28 11:33:04 +00:00
_itemDetailView.UpdateCategory(category);
}
public void Invoke(TodayMenuRemovedEvent evt)
{
InventoryCategoryType newInventoryCategoryType = evt.RecipeType switch
{
RecipeType.FoodRecipe => InventoryCategoryType.Food,
RecipeType.DrinkRecipe => InventoryCategoryType.Drink,
_ => InventoryCategoryType.None
};
if (newInventoryCategoryType == InventoryCategoryType.None) return;
2025-07-30 10:38:12 +00:00
_menuCategoryTabs.SelectTab(newInventoryCategoryType);
2025-07-24 08:41:20 +00:00
}
}
}