ProjectDDD/Assets/_DDD/_Scripts/Restaurant/Ui/RestaurantManagementUi/RestaurantManagementUi.cs

295 lines
9.6 KiB
C#
Raw Normal View History

2025-08-24 11:44:32 +00:00
using System.Collections.Generic;
2025-07-24 08:41:20 +00:00
using UnityEngine;
2025-08-20 09:08:41 +00:00
using UnityEngine.UI;
2025-07-25 07:58:53 +00:00
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace DDD.Restaurant
{
2025-08-20 09:08:41 +00:00
[RequireComponent(typeof(RestaurantManagementViewModel))]
public class RestaurantManagementUi : PopupUi<RestaurantUiActions, RestaurantManagementViewModel>
{
2025-08-20 09:08:41 +00:00
[Header("Sub Views")]
2025-08-17 12:51:51 +00:00
[SerializeField] private ChecklistView _checklistView;
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-08-18 04:26:18 +00:00
[SerializeField] private TodayMenuView _todayMenuView;
[SerializeField] private TodayRestaurantStateView _todayRestaurantStateView;
2025-08-20 09:08:41 +00:00
[Header("Tab Groups")]
2025-08-17 07:23:05 +00:00
[SerializeField] private TabGroupUi _sectionTabs;
[SerializeField] private TabGroupUi _menuCategoryTabs;
[SerializeField] private TabGroupUi _cookwareCategoryTabs;
2025-08-04 11:01:43 +00:00
2025-08-20 09:08:41 +00:00
[Header("Hold Progress UI")]
2025-08-21 07:25:27 +00:00
[SerializeField] private Image _completeBatchFilledImage;
2025-08-24 11:44:32 +00:00
private List<IUiView<RestaurantManagementViewModel>> _subViews;
2025-08-21 07:25:27 +00:00
2025-08-04 11:01:43 +00:00
protected override void Update()
{
base.Update();
2025-08-20 09:08:41 +00:00
2025-08-21 07:25:27 +00:00
if (_viewModel)
2025-08-04 11:01:43 +00:00
{
2025-08-20 09:08:41 +00:00
_viewModel.UpdateHoldProgress();
2025-08-04 11:01:43 +00:00
}
}
2025-07-24 08:41:20 +00:00
2025-08-24 11:44:32 +00:00
protected override void OnCreatedInitialize()
2025-08-21 07:25:27 +00:00
{
2025-08-24 11:44:32 +00:00
base.OnCreatedInitialize();
2025-08-21 07:25:27 +00:00
2025-08-24 11:44:32 +00:00
InitializeViews();
InitializeTabGroups();
SetupCategoryTabs();
2025-08-21 07:25:27 +00:00
}
2025-08-24 11:44:32 +00:00
protected override void OnOpenedEvents()
2025-08-17 12:51:51 +00:00
{
2025-08-24 11:44:32 +00:00
base.OnOpenedEvents();
_sectionTabs.SelectFirstTab();
_menuCategoryTabs.SelectFirstTab();
2025-08-21 10:11:47 +00:00
2025-08-24 11:44:32 +00:00
if (_viewModel)
{
_viewModel.OnBatchCompleted += HandleBatchCompleted;
_viewModel.OnChecklistFailed += HandleChecklistFailed;
_viewModel.OnMenuSectionSelected += HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected += HandleCookwareSectionSelected;
_viewModel.OnTabMoved += HandleTabMoved;
_viewModel.OnInteractRequested += HandleInteractRequested;
_viewModel.OnCloseRequested += HandleCloseRequested;
_viewModel.OnMenuCategorySelected += HandleMenuCategorySelected;
}
foreach (var view in _subViews)
{
view.OnOpenedEvents();
}
2025-08-21 10:11:47 +00:00
IsInitialized = true;
2025-08-20 09:08:41 +00:00
}
2025-08-24 11:44:32 +00:00
protected override void OnClosedEvents()
{
base.OnClosedEvents();
if (_viewModel)
{
_viewModel.OnBatchCompleted -= HandleBatchCompleted;
_viewModel.OnChecklistFailed -= HandleChecklistFailed;
_viewModel.OnMenuSectionSelected -= HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected -= HandleCookwareSectionSelected;
_viewModel.OnTabMoved -= HandleTabMoved;
_viewModel.OnInteractRequested -= HandleInteractRequested;
_viewModel.OnCloseRequested -= HandleCloseRequested;
_viewModel.OnMenuCategorySelected -= HandleMenuCategorySelected;
}
foreach (var view in _subViews)
{
view.OnClosedEvents();
}
}
2025-08-20 09:08:41 +00:00
protected override GameObject GetInitialSelected()
{
2025-08-21 10:11:47 +00:00
if (IsInitialized == false) return null;
2025-08-20 09:08:41 +00:00
var inventoryInitialSelected = _inventoryView.GetInitialSelected();
2025-08-21 10:11:47 +00:00
if (inventoryInitialSelected)
{
return inventoryInitialSelected;
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
var menuCategoryButton = _menuCategoryTabs.GetFirstInteractableButton();
if (menuCategoryButton != null && menuCategoryButton.activeInHierarchy)
2025-08-21 10:11:47 +00:00
{
2025-08-20 09:08:41 +00:00
return menuCategoryButton;
2025-08-21 10:11:47 +00:00
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
var cookwareCategoryButton = _cookwareCategoryTabs.GetFirstInteractableButton();
if (cookwareCategoryButton != null && cookwareCategoryButton.activeInHierarchy)
2025-08-21 10:11:47 +00:00
{
2025-08-20 09:08:41 +00:00
return cookwareCategoryButton;
2025-08-21 10:11:47 +00:00
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
return null;
2025-08-17 12:51:51 +00:00
}
2025-08-20 09:08:41 +00:00
protected override void SetupBindings()
2025-08-17 12:51:51 +00:00
{
2025-08-25 05:00:03 +00:00
base.SetupBindings();
2025-08-21 07:25:27 +00:00
BindingHelper.BindImageFilled(_bindingContext, _completeBatchFilledImage, nameof(RestaurantManagementViewModel.NormalizedHoldProgress));
2025-08-24 20:12:05 +00:00
_itemDetailView.SetupBindings(_bindingContext);
2025-08-17 12:51:51 +00:00
}
2025-08-24 11:44:32 +00:00
private void InitializeViews()
2025-07-29 15:56:47 +00:00
{
2025-08-24 11:44:32 +00:00
_subViews = new List<IUiView<RestaurantManagementViewModel>>
2025-08-16 23:57:23 +00:00
{
2025-08-24 11:44:32 +00:00
_checklistView,
_inventoryView,
_itemDetailView,
_todayMenuView,
_todayRestaurantStateView
};
foreach (var uiView in _subViews)
{
uiView.Initialize(_viewModel);
2025-08-03 23:09:01 +00:00
}
2025-07-29 15:56:47 +00:00
}
2025-08-16 23:57:23 +00:00
private void SetupCategoryTabs()
{
_menuCategoryTabs.UseDefaultAllowedValues();
_cookwareCategoryTabs.UseDefaultAllowedValues();
}
2025-08-17 12:51:51 +00:00
private void InitializeTabGroups()
{
_sectionTabs.Initialize(OnSectionTabSelected);
_menuCategoryTabs.Initialize(OnCategoryTabSelected);
_cookwareCategoryTabs.Initialize(OnCategoryTabSelected);
}
2025-08-20 09:08:41 +00:00
private void UpdateSectionTabs()
2025-07-28 11:33:04 +00:00
{
2025-08-20 09:08:41 +00:00
if (_viewModel == null) return;
_sectionTabs.SelectTab((int)_viewModel.CurrentSection);
2025-07-24 08:41:20 +00:00
}
2025-08-20 09:08:41 +00:00
private void UpdateCategoryTabs()
{
2025-08-20 09:08:41 +00:00
if (_viewModel == null) return;
switch (_viewModel.CurrentSection)
{
2025-08-20 09:08:41 +00:00
case SectionButtonType.Menu:
_menuCategoryTabs.SelectTab((int)_viewModel.CurrentCategory);
2025-08-04 11:01:43 +00:00
break;
2025-08-20 09:08:41 +00:00
case SectionButtonType.Cookware:
_cookwareCategoryTabs.SelectTab((int)_viewModel.CurrentCategory);
break;
2025-08-04 11:01:43 +00:00
}
2025-08-20 09:08:41 +00:00
}
2025-08-24 11:44:32 +00:00
protected override void HandleCustomPropertyChanged(string propertyName)
{
switch (propertyName)
{
case nameof(RestaurantManagementViewModel.CurrentSection):
UpdateSectionTabs();
break;
case nameof(RestaurantManagementViewModel.CurrentCategory):
UpdateCategoryTabs();
break;
}
}
2025-08-05 04:00:01 +00:00
2025-08-20 09:08:41 +00:00
// ViewModel 이벤트 핸들러들
private void HandleBatchCompleted()
{
Close();
2025-08-04 11:01:43 +00:00
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
private void HandleChecklistFailed()
2025-08-04 11:01:43 +00:00
{
2025-08-20 09:08:41 +00:00
var evt = GameEvents.OpenPopupUiEvent;
evt.UiType = typeof(ConfirmUi);
evt.IsCancelButtonVisible = true;
evt.NewMessageKey = "checklist_failed_message";
evt.OnConfirm = ClosePanel;
EventBus.Broadcast(evt);
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
private void HandleMenuSectionSelected()
{
_menuCategoryTabs.SelectFirstTab();
}
2025-08-05 04:00:01 +00:00
2025-08-20 09:08:41 +00:00
private void HandleCookwareSectionSelected()
{
_cookwareCategoryTabs.SelectFirstTab();
}
2025-08-20 09:08:41 +00:00
private void HandleTabMoved(int direction)
{
2025-07-25 07:58:53 +00:00
_sectionTabs.Move(direction);
}
2025-08-20 09:08:41 +00:00
private void HandleInteractRequested()
2025-07-25 07:58:53 +00:00
{
var selected = EventSystem.current.currentSelectedGameObject;
var interactable = selected?.GetComponent<IInteractableUi>();
interactable?.OnInteract();
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
private void HandleCloseRequested()
2025-08-04 11:01:43 +00:00
{
2025-08-20 09:08:41 +00:00
Close();
2025-08-04 11:01:43 +00:00
}
2025-08-20 09:08:41 +00:00
private void HandleMenuCategorySelected(InventoryCategoryType category)
{
2025-08-20 09:08:41 +00:00
_menuCategoryTabs.SelectTab((int)category);
}
2025-07-24 08:41:20 +00:00
2025-08-20 09:08:41 +00:00
// UI 이벤트 핸들러들 (TabGroupUi 콜백)
2025-08-16 23:57:23 +00:00
private void OnSectionTabSelected(int sectionValue)
2025-07-24 08:41:20 +00:00
{
2025-08-20 09:08:41 +00:00
_viewModel?.SetSection((SectionButtonType)sectionValue);
2025-07-24 08:41:20 +00:00
}
2025-08-16 23:57:23 +00:00
private void OnCategoryTabSelected(int categoryValue)
2025-07-24 08:41:20 +00:00
{
2025-08-20 09:08:41 +00:00
_viewModel?.SetCategory((InventoryCategoryType)categoryValue);
2025-07-28 11:33:04 +00:00
}
2025-08-17 12:51:51 +00:00
2025-08-20 09:08:41 +00:00
// 입력 처리 - ViewModel로 위임
protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
2025-07-28 11:33:04 +00:00
{
2025-08-26 11:56:15 +00:00
if (base.OnInputPerformed(actionEnum, context) == false) return false;
2025-08-20 09:08:41 +00:00
2025-08-26 11:56:15 +00:00
switch (actionEnum)
2025-08-20 09:08:41 +00:00
{
2025-08-26 11:56:15 +00:00
case RestaurantUiActions.Cancel:
_viewModel.CloseUi();
break;
case RestaurantUiActions.PreviousTab:
_viewModel.MoveTab(-1);
break;
case RestaurantUiActions.NextTab:
_viewModel.MoveTab(1);
break;
case RestaurantUiActions.Interact1:
_viewModel.InteractWithSelected();
break;
case RestaurantUiActions.Interact2:
_viewModel.StartHold();
break;
2025-08-20 09:08:41 +00:00
}
2025-08-26 11:56:15 +00:00
return true;
2025-08-20 09:08:41 +00:00
}
protected override bool OnInputCanceled(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
2025-08-26 11:56:15 +00:00
if (base.OnInputPerformed(actionEnum, context) == false) return false;
2025-08-20 09:08:41 +00:00
2025-08-26 11:56:15 +00:00
switch (actionEnum)
2025-08-20 09:08:41 +00:00
{
2025-08-26 11:56:15 +00:00
case RestaurantUiActions.Interact2:
_viewModel.CancelHold();
break;
2025-08-20 09:08:41 +00:00
}
2025-08-26 11:56:15 +00:00
return true;
2025-07-24 08:41:20 +00:00
}
}
}