ProjectDDD/Assets/_DDD/_Scripts/GameUi/New/TodayMenuInteractor.cs

76 lines
2.2 KiB
C#
Raw Normal View History

2025-07-27 19:32:41 +00:00
using System;
2025-07-25 07:58:53 +00:00
using System.Threading.Tasks;
using UnityEngine;
namespace DDD
{
2025-07-27 19:32:41 +00:00
public enum TodayMenuEventType
{
None = 0,
Add,
Remove
}
2025-07-25 07:58:53 +00:00
public class TodayMenuInteractor : MonoBehaviour, IInteractableUi
{
2025-07-29 15:56:47 +00:00
private ItemSlotUi _itemSlotUi;
2025-07-27 19:51:11 +00:00
private RestaurantManagementSo _restaurantManagementSo;
2025-07-25 07:58:53 +00:00
private TaskCompletionSource<bool> _isInitialized = new();
2025-07-27 19:32:41 +00:00
private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None;
2025-07-25 07:58:53 +00:00
private void Awake()
{
2025-07-29 15:56:47 +00:00
_itemSlotUi = GetComponent<ItemSlotUi>();
2025-07-25 07:58:53 +00:00
}
2025-07-27 19:32:41 +00:00
public async void Initialize(TodayMenuEventType todayMenuEventType)
2025-07-25 07:58:53 +00:00
{
2025-07-27 19:32:41 +00:00
_todayMenuEventType = todayMenuEventType;
2025-07-27 19:51:11 +00:00
_restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
2025-07-25 07:58:53 +00:00
_isInitialized.SetResult(true);
}
public async void OnInteract()
{
await _isInitialized.Task;
2025-07-27 19:32:41 +00:00
switch (_todayMenuEventType)
2025-07-25 07:58:53 +00:00
{
2025-07-27 19:32:41 +00:00
case TodayMenuEventType.Add:
OnAdded();
break;
case TodayMenuEventType.Remove:
OnRemoved();
break;
case TodayMenuEventType.None:
default:
throw new ArgumentOutOfRangeException();
2025-07-25 07:58:53 +00:00
}
2025-07-27 19:32:41 +00:00
}
2025-07-25 07:58:53 +00:00
2025-07-27 19:32:41 +00:00
private void OnAdded()
{
2025-07-29 15:56:47 +00:00
if (_itemSlotUi.Strategy is not InventorySlotUiStrategy inventorySlotUiStrategy) return;
if (inventorySlotUiStrategy.CanCrafting(_itemSlotUi))
{
_restaurantManagementSo.TryAddTodayMenu(_itemSlotUi);
}
else
2025-07-27 19:32:41 +00:00
{
var evt = GameEvents.RequestShowGlobalMessageEvent;
// TODO : 테스트용 메세지 추후 삭제 및 변경
evt.NewMessageKey = "today_menu_added_error_message_001";
evt.FadeDuration = 0.5f;
evt.ShowDuration = 1f;
EventBus.Broadcast(evt);
2025-07-25 07:58:53 +00:00
}
2025-07-27 19:32:41 +00:00
}
2025-07-25 07:58:53 +00:00
2025-07-27 19:32:41 +00:00
private void OnRemoved()
{
2025-07-29 15:56:47 +00:00
_restaurantManagementSo.TryRemoveTodayMenu(_itemSlotUi);
2025-07-25 07:58:53 +00:00
}
}
}