219 lines
6.1 KiB
C#
219 lines
6.1 KiB
C#
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
/// <summary>
|
|
/// 레스토랑 관리 UI의 ViewModel
|
|
/// 기존 RestaurantManagementUi의 상태 관리와 비즈니스 로직을 담당
|
|
/// </summary>
|
|
public class RestaurantManagementViewModel : SimpleViewModel, IEventHandler<TodayMenuRemovedEvent>
|
|
{
|
|
// 홀드 진행 상태 관리
|
|
[SerializeField] private float _holdCompleteTime = 1f;
|
|
private bool _isHolding;
|
|
|
|
private float _holdProgress;
|
|
public float HoldProgress
|
|
{
|
|
get => _holdProgress;
|
|
private set
|
|
{
|
|
if (SetField(ref _holdProgress, value))
|
|
{
|
|
OnPropertyChanged(nameof(NormalizedHoldProgress));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 홀드 진행률을 0~1 범위로 변환한 값
|
|
/// </summary>
|
|
public float NormalizedHoldProgress => _holdCompleteTime <= 0f ? 0f : Mathf.Clamp01(_holdProgress / _holdCompleteTime);
|
|
|
|
// 탭 상태 관리
|
|
private SectionButtonType _currentSection = SectionButtonType.Menu;
|
|
private InventoryCategoryType _currentCategory = InventoryCategoryType.Food;
|
|
|
|
/// <summary>
|
|
/// 현재 선택된 섹션
|
|
/// </summary>
|
|
public SectionButtonType CurrentSection
|
|
{
|
|
get => _currentSection;
|
|
set => SetField(ref _currentSection, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 선택된 카테고리
|
|
/// </summary>
|
|
public InventoryCategoryType CurrentCategory
|
|
{
|
|
get => _currentCategory;
|
|
set => SetField(ref _currentCategory, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 배치 완료 가능 여부 (체크리스트 완료 상태)
|
|
/// </summary>
|
|
public bool CanCompleteBatch => RestaurantState.Instance.ManagementState.GetChecklistStates().All(state => state);
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
RegisterEvents();
|
|
ResetHoldState();
|
|
}
|
|
|
|
public override void Cleanup()
|
|
{
|
|
base.Cleanup();
|
|
UnregisterEvents();
|
|
}
|
|
|
|
private void RegisterEvents()
|
|
{
|
|
EventBus.Register<TodayMenuRemovedEvent>(this);
|
|
}
|
|
|
|
private void UnregisterEvents()
|
|
{
|
|
EventBus.Unregister<TodayMenuRemovedEvent>(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 홀드 진행 업데이트 (View에서 Update마다 호출)
|
|
/// </summary>
|
|
public void UpdateHoldProgress()
|
|
{
|
|
if (_isHolding == false) return;
|
|
|
|
if (_holdCompleteTime <= 0f)
|
|
{
|
|
ProcessCompleteBatch();
|
|
return;
|
|
}
|
|
|
|
var deltaTime = Time.deltaTime;
|
|
HoldProgress += deltaTime;
|
|
|
|
if (HoldProgress >= _holdCompleteTime)
|
|
{
|
|
ProcessCompleteBatch();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 홀드 시작
|
|
/// </summary>
|
|
public void StartHold()
|
|
{
|
|
_isHolding = true;
|
|
HoldProgress = 0f;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 홀드 취소
|
|
/// </summary>
|
|
public void CancelHold()
|
|
{
|
|
ResetHoldState();
|
|
}
|
|
|
|
private void ResetHoldState()
|
|
{
|
|
_isHolding = false;
|
|
HoldProgress = 0f;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 배치 완료 처리
|
|
/// </summary>
|
|
private void ProcessCompleteBatch()
|
|
{
|
|
ResetHoldState();
|
|
|
|
if (CanCompleteBatch)
|
|
{
|
|
// 배치 완료 - UI 닫기 이벤트 발생
|
|
OnBatchCompleted?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
// 체크리스트 미완료 - 실패 팝업 표시 이벤트 발생
|
|
OnChecklistFailed?.Invoke();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 섹션 탭 선택 처리
|
|
/// </summary>
|
|
public void SetSection(SectionButtonType section)
|
|
{
|
|
CurrentSection = section;
|
|
|
|
// 섹션 변경 시 해당 섹션의 첫 번째 카테고리로 설정
|
|
switch (section)
|
|
{
|
|
case SectionButtonType.Menu:
|
|
OnMenuSectionSelected?.Invoke();
|
|
break;
|
|
case SectionButtonType.Cookware:
|
|
OnCookwareSectionSelected?.Invoke();
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카테고리 탭 선택 처리
|
|
/// </summary>
|
|
public void SetCategory(InventoryCategoryType category)
|
|
{
|
|
CurrentCategory = category;
|
|
OnCategoryChanged?.Invoke(category);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 이동 (이전/다음)
|
|
/// </summary>
|
|
public void MoveTab(int direction)
|
|
{
|
|
OnTabMoved?.Invoke(direction);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 선택된 UI 요소와 상호작용
|
|
/// </summary>
|
|
public void InteractWithSelected()
|
|
{
|
|
OnInteractRequested?.Invoke();
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI 닫기
|
|
/// </summary>
|
|
public void CloseUi()
|
|
{
|
|
OnCloseRequested?.Invoke();
|
|
}
|
|
|
|
// View에서 구독할 이벤트들
|
|
public System.Action OnBatchCompleted;
|
|
public System.Action OnChecklistFailed;
|
|
public System.Action OnMenuSectionSelected;
|
|
public System.Action OnCookwareSectionSelected;
|
|
public System.Action<InventoryCategoryType> OnCategoryChanged;
|
|
public System.Action<int> OnTabMoved;
|
|
public System.Action OnInteractRequested;
|
|
public System.Action OnCloseRequested;
|
|
|
|
// 이벤트 핸들러
|
|
public void Invoke(TodayMenuRemovedEvent evt)
|
|
{
|
|
SetCategory(evt.InventoryCategoryType);
|
|
OnMenuCategorySelected?.Invoke(evt.InventoryCategoryType);
|
|
}
|
|
|
|
public System.Action<InventoryCategoryType> OnMenuCategorySelected;
|
|
}
|
|
} |