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

255 lines
8.0 KiB
C#
Raw Normal View History

using System;
2025-08-16 23:57:23 +00:00
using System.Collections.Generic;
2025-08-17 12:51:51 +00:00
using System.Linq;
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-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-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
[SerializeField] private Image _completeBatchFilledImage;
[SerializeField] private float _holdCompleteTime = 1f;
private float _elapsedTime;
private bool _isHolding;
2025-08-17 12:51:51 +00:00
private const string ChecklistFailedMessageKey = "checklist_failed_message";
2025-08-04 11:01:43 +00:00
protected override void Update()
{
base.Update();
if (_isHolding)
{
2025-08-17 12:51:51 +00:00
UpdateHoldProgress();
2025-08-04 11:01:43 +00:00
}
}
2025-07-24 08:41:20 +00:00
2025-08-17 12:51:51 +00:00
private void UpdateHoldProgress()
{
if (_holdCompleteTime <= 0f)
{
HandleInteract2Canceled();
ProcessCompleteBatchAction();
return;
}
_completeBatchFilledImage.fillAmount = _elapsedTime;
var multiply = 1f / _holdCompleteTime;
if (_elapsedTime >= 1f)
{
HandleInteract2Canceled();
ProcessCompleteBatchAction();
return;
}
_elapsedTime += Time.deltaTime * multiply;
}
private void ProcessCompleteBatchAction()
{
if (RestaurantController.Instance.RestaurantState.ManagementState.GetChecklistStates().Any(state => state == false))
2025-08-17 12:51:51 +00:00
{
ShowChecklistFailedPopup();
}
else
{
Close();
}
}
private void ShowChecklistFailedPopup()
{
var evt = GameEvents.OpenPopupUiEvent;
evt.UiType = typeof(ConfirmUi);
evt.IsCancelButtonVisible = true;
evt.NewMessageKey = ChecklistFailedMessageKey;
evt.OnConfirm = ClosePanel;
EventBus.Broadcast(evt);
}
2025-07-29 15:56:47 +00:00
protected override GameObject GetInitialSelected()
{
var inventoryViewInitialSelectedObject = _inventoryView.GetInitialSelected();
if (inventoryViewInitialSelectedObject) return inventoryViewInitialSelectedObject;
2025-08-16 23:57:23 +00:00
var menuCategoryFirstButton = _menuCategoryTabs.GetFirstInteractableButton();
if (menuCategoryFirstButton != null && menuCategoryFirstButton.activeInHierarchy)
{
return menuCategoryFirstButton;
}
var cookwareCategoryFirstButton = _cookwareCategoryTabs.GetFirstInteractableButton();
if (cookwareCategoryFirstButton != null && cookwareCategoryFirstButton.activeInHierarchy)
2025-08-03 23:09:01 +00:00
{
2025-08-16 23:57:23 +00:00
return cookwareCategoryFirstButton;
2025-08-03 23:09:01 +00:00
}
2025-08-16 23:57:23 +00:00
return null;
2025-07-29 15:56:47 +00:00
}
public override void Open(OpenPopupUiEvent evt)
2025-07-24 08:41:20 +00:00
{
2025-08-05 04:00:01 +00:00
base.Open(evt);
2025-08-17 12:51:51 +00:00
InitializeViews();
2025-08-16 23:57:23 +00:00
SetupCategoryTabs();
2025-08-17 12:51:51 +00:00
InitializeTabGroups();
SelectInitialTabs();
RegisterEventHandlers();
}
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-16 23:57:23 +00:00
/// <summary>
/// 각 그룹별로 허용된 카테고리를 설정합니다.
/// </summary>
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();
}
private void RegisterEventHandlers()
{
EventBus.Register<TodayMenuRemovedEvent>(this);
}
2025-07-28 11:33:04 +00:00
public override void Close()
{
base.Close();
2025-08-17 12:51:51 +00:00
2025-07-28 11:33:04 +00:00
EventBus.Unregister<TodayMenuRemovedEvent>(this);
2025-07-24 08:41:20 +00:00
}
2025-08-05 04:00:01 +00:00
protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
2025-08-05 04:00:01 +00:00
if (base.OnInputPerformed(actionEnum, context) == false) return false;
2025-08-17 12:51:51 +00:00
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
}
2025-08-05 04:00:01 +00:00
return true;
2025-08-04 11:01:43 +00:00
}
2025-08-17 12:51:51 +00:00
2025-08-05 04:00:01 +00:00
protected override bool OnInputCanceled(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
2025-08-04 11:01:43 +00:00
{
2025-08-05 04:00:01 +00:00
if (base.OnInputPerformed(actionEnum, context) == false) return false;
2025-08-17 12:51:51 +00:00
2025-08-04 11:01:43 +00:00
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-05 04:00:01 +00:00
return true;
}
2025-08-04 11:01:43 +00:00
private void HandleCancelPerformed()
{
2025-08-05 04:00:01 +00:00
Close();
}
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-17 12:51:51 +00:00
2025-08-04 11:01:43 +00:00
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-08-16 23:57:23 +00:00
private void OnSectionTabSelected(int sectionValue)
2025-07-24 08:41:20 +00:00
{
2025-08-16 23:57:23 +00:00
var section = (SectionButtonType)sectionValue;
2025-07-30 10:38:12 +00:00
switch (section)
{
2025-08-16 23:57:23 +00:00
case SectionButtonType.Menu:
2025-07-30 10:38:12 +00:00
_menuCategoryTabs.SelectFirstTab();
break;
2025-08-16 23:57:23 +00:00
case SectionButtonType.Cookware:
2025-07-30 10:38:12 +00:00
_cookwareCategoryTabs.SelectFirstTab();
break;
default:
throw new ArgumentOutOfRangeException(nameof(section), section, null);
}
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-16 23:57:23 +00:00
var category = (InventoryCategoryType)categoryValue;
2025-07-27 19:32:41 +00:00
_inventoryView.UpdateCategoryView(category);
2025-07-28 11:33:04 +00:00
_itemDetailView.UpdateCategory(category);
}
2025-08-17 12:51:51 +00:00
2025-07-28 11:33:04 +00:00
public void Invoke(TodayMenuRemovedEvent evt)
{
2025-08-16 23:57:23 +00:00
_menuCategoryTabs.SelectTab((int)evt.InventoryCategoryType);
2025-07-24 08:41:20 +00:00
}
}
}