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

276 lines
9.0 KiB
C#
Raw Normal View History

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;
2025-08-20 09:08:41 +00:00
using DDD.MVVM;
namespace DDD
{
2025-08-20 09:08:41 +00:00
/// <summary>
/// MVVM 패턴을 적용한 새로운 레스토랑 관리 UI
/// 기존 RestaurantManagementUi의 기능을 ViewModel과 분리하여 구현
/// </summary>
[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")]
[SerializeField, BindTo(nameof(RestaurantManagementViewModel.NormalizedHoldProgress))]
private Image _completeBatchFilledImage;
2025-08-04 11:01:43 +00:00
2025-08-20 09:08:41 +00:00
protected override void Awake()
{
base.Awake();
SetupViewModelEvents();
}
2025-08-17 12:51:51 +00:00
2025-08-04 11:01:43 +00:00
protected override void Update()
{
base.Update();
2025-08-20 09:08:41 +00:00
if (_viewModel != null && _viewModel.IsHolding)
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-20 09:08:41 +00:00
public override void Open(OpenPopupUiEvent evt)
2025-08-17 12:51:51 +00:00
{
2025-08-20 09:08:41 +00:00
base.Open(evt);
InitializeViews();
SetupTabs();
}
protected override GameObject GetInitialSelected()
{
// ViewModel의 현재 상태에 따라 초기 선택 UI 결정
var inventoryInitialSelected = _inventoryView.GetInitialSelected();
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)
return menuCategoryButton;
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)
return cookwareCategoryButton;
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-20 09:08:41 +00:00
// Attribute 기반 자동 바인딩이 처리됨
// 추가적인 수동 바인딩이 필요한 경우 여기에 구현
2025-08-17 12:51:51 +00:00
}
2025-08-20 09:08:41 +00:00
protected override void HandleCustomPropertyChanged(string propertyName)
2025-07-29 15:56:47 +00:00
{
2025-08-20 09:08:41 +00:00
switch (propertyName)
2025-08-16 23:57:23 +00:00
{
2025-08-20 09:08:41 +00:00
case nameof(RestaurantManagementViewModel.CurrentSection):
UpdateSectionTabs();
break;
case nameof(RestaurantManagementViewModel.CurrentCategory):
UpdateCategoryTabs();
break;
2025-08-03 23:09:01 +00:00
}
2025-07-29 15:56:47 +00:00
}
2025-08-20 09:08:41 +00:00
private void SetupViewModelEvents()
2025-07-24 08:41:20 +00:00
{
2025-08-20 09:08:41 +00:00
if (!_viewModel) return;
_viewModel.OnBatchCompleted = HandleBatchCompleted;
_viewModel.OnChecklistFailed = HandleChecklistFailed;
_viewModel.OnMenuSectionSelected = HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected = HandleCookwareSectionSelected;
_viewModel.OnCategoryChanged = HandleCategoryChanged;
_viewModel.OnTabMoved = HandleTabMoved;
_viewModel.OnInteractRequested = HandleInteractRequested;
_viewModel.OnCloseRequested = HandleCloseRequested;
_viewModel.OnMenuCategorySelected = HandleMenuCategorySelected;
2025-08-17 12:51:51 +00:00
}
private void InitializeViews()
{
_checklistView.Initalize();
_inventoryView.Initialize();
_itemDetailView.Initialize();
2025-08-18 04:26:18 +00:00
_todayMenuView.Initialize();
_todayRestaurantStateView.Initialize();
2025-07-28 11:33:04 +00:00
}
2025-08-20 09:08:41 +00:00
private void SetupTabs()
{
SetupCategoryTabs();
InitializeTabGroups();
SelectInitialTabs();
}
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);
}
private void SelectInitialTabs()
{
_sectionTabs.SelectFirstTab();
_menuCategoryTabs.SelectFirstTab();
}
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-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 HandleCategoryChanged(InventoryCategoryType category)
{
2025-08-20 09:08:41 +00:00
_inventoryView.UpdateCategoryView(category);
_itemDetailView.UpdateCategory(category);
}
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-20 09:08:41 +00:00
var isHandled = base.OnInputPerformed(actionEnum, context);
if (isHandled && _viewModel != null)
{
switch (actionEnum)
{
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;
}
}
return isHandled;
}
protected override bool OnInputCanceled(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
var isHandled = base.OnInputCanceled(actionEnum, context);
if (isHandled && _viewModel != null)
{
switch (actionEnum)
{
case RestaurantUiActions.Interact2:
_viewModel.CancelHold();
break;
}
}
return isHandled;
2025-07-24 08:41:20 +00:00
}
}
}