ui 작업

This commit is contained in:
NTG_DESKTOP 2025-08-04 08:09:01 +09:00
parent ce1b220f9b
commit 4012878fad
20 changed files with 404 additions and 128 deletions

View File

@ -20,20 +20,28 @@ public class RestaurantManagementSo : GameFlowTask
public Color FoodTasteOutlineColor = Color.magenta; public Color FoodTasteOutlineColor = Color.magenta;
public Color DrinkTasteOutlineColor = Color.magenta; public Color DrinkTasteOutlineColor = Color.magenta;
[Title("오늘의 메뉴")] [Title("오늘의 레스토랑 상태")]
public int MaxFoodCount = 8; public int MaxFoodCount = 8;
public int MaxDrinkCount = 6; public int MaxDrinkCount = 6;
public int MaxCookwareCount = 6;
private Dictionary<string, int> _foodRecipeIds = new(); [Title("실시간 데이터")]
private Dictionary<string, int> _drinkRecipeIds = new(); [ReadOnly, ShowInInspector] private Dictionary<string, int> _todayFoodRecipeIds = new();
[ReadOnly, ShowInInspector] private Dictionary<string, int> _todayDrinkRecipeIds = new();
[ReadOnly, ShowInInspector] private List<string> _todayWorkerIds = new();
[ReadOnly, ShowInInspector] private List<string> _todayCookwareIds = new();
public IReadOnlyDictionary<string, int> FoodRecipeIds => _foodRecipeIds; public IReadOnlyDictionary<string, int> TodayFoodRecipeIds => _todayFoodRecipeIds;
public IReadOnlyDictionary<string, int> DrinkRecipeIds => _drinkRecipeIds; public IReadOnlyDictionary<string, int> TodayDrinkRecipeIds => _todayDrinkRecipeIds;
public IReadOnlyList<string> TodayWorkerIds => _todayWorkerIds;
public IReadOnlyList<string> TodayCookwareIds => _todayCookwareIds;
public override Task OnReadyNewFlow(GameFlowState newFlowState) public override Task OnReadyNewFlow(GameFlowState newFlowState)
{ {
_foodRecipeIds.Clear(); _todayFoodRecipeIds.Clear();
_drinkRecipeIds.Clear(); _todayDrinkRecipeIds.Clear();
_todayWorkerIds.Clear();
_todayCookwareIds.Clear();
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -50,24 +58,24 @@ public bool TryAddTodayMenu(ItemSlotUi itemSlotUi)
if (recipeData.RecipeType == RecipeType.FoodRecipe) if (recipeData.RecipeType == RecipeType.FoodRecipe)
{ {
if (_foodRecipeIds.Count >= MaxFoodCount || _foodRecipeIds.ContainsKey(recipeId)) return false; if (_todayFoodRecipeIds.Count >= MaxFoodCount || _todayFoodRecipeIds.ContainsKey(recipeId)) return false;
var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(recipeData.RecipeResult); var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(recipeData.RecipeResult);
var craftableCount = foodData.GetCraftableCount(); var craftableCount = foodData.GetCraftableCount();
foodData.ConsumeAllCraftableIngredients(); foodData.ConsumeAllCraftableIngredients();
_foodRecipeIds[recipeId] = craftableCount; _todayFoodRecipeIds[recipeId] = craftableCount;
added = true; added = true;
} }
else if (recipeData.RecipeType == RecipeType.DrinkRecipe) else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{ {
if (_drinkRecipeIds.Count >= MaxDrinkCount || _drinkRecipeIds.ContainsKey(recipeId)) return false; if (_todayDrinkRecipeIds.Count >= MaxDrinkCount || _todayDrinkRecipeIds.ContainsKey(recipeId)) return false;
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(recipeData.RecipeResult); var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(recipeData.RecipeResult);
var craftableCount = drinkData.GetCraftableCount(); var craftableCount = drinkData.GetCraftableCount();
drinkData.ConsumeAllCraftableIngredients(); drinkData.ConsumeAllCraftableIngredients();
_drinkRecipeIds[recipeId] = craftableCount; _todayDrinkRecipeIds[recipeId] = craftableCount;
added = true; added = true;
} }
@ -91,9 +99,9 @@ public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
if (recipeData.RecipeType == RecipeType.FoodRecipe) if (recipeData.RecipeType == RecipeType.FoodRecipe)
{ {
if (_foodRecipeIds.TryGetValue(recipeId, out refundCount)) if (_todayFoodRecipeIds.TryGetValue(recipeId, out refundCount))
{ {
removed = _foodRecipeIds.Remove(recipeId); removed = _todayFoodRecipeIds.Remove(recipeId);
evt.RecipeType = RecipeType.FoodRecipe; evt.RecipeType = RecipeType.FoodRecipe;
if (removed) if (removed)
@ -105,9 +113,9 @@ public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
} }
else if (recipeData.RecipeType == RecipeType.DrinkRecipe) else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{ {
if (_drinkRecipeIds.TryGetValue(recipeId, out refundCount)) if (_todayDrinkRecipeIds.TryGetValue(recipeId, out refundCount))
{ {
removed = _drinkRecipeIds.Remove(recipeId); removed = _todayDrinkRecipeIds.Remove(recipeId);
evt.RecipeType = RecipeType.DrinkRecipe; evt.RecipeType = RecipeType.DrinkRecipe;
if (removed) if (removed)
@ -124,6 +132,33 @@ public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
return true; return true;
} }
public bool IsContainTodayMenu(string recipeId)=> _foodRecipeIds.ContainsKey(recipeId) || _drinkRecipeIds.ContainsKey(recipeId); public bool TryAddTodayCookware(ItemSlotUi itemSlotUi)
{
var itemId = itemSlotUi.Model.Id;
if (itemSlotUi.Model.Count <= 0 || DataManager.Instance.GetDataSo<CookwareDataSo>().TryGetDataById(itemId, out CookwareData cookwareData) == false) return false;
if (_todayCookwareIds.Count >= MaxCookwareCount || _todayCookwareIds.Contains(itemId)) return false;
_todayCookwareIds.Add(itemId);
EventBus.Broadcast(RestaurantEvents.TodayMenuAddedEvent);
return true;
}
public bool TryRemoveTodayCookware(ItemSlotUi itemSlotUi)
{
var itemId = itemSlotUi.Model.Id;
if (DataManager.Instance.GetDataSo<CookwareDataSo>().TryGetDataById(itemId, out CookwareData cookwareData) == false) return false;
if (_todayCookwareIds.Remove(itemId) == false) return false;
EventBus.Broadcast( RestaurantEvents.TodayMenuRemovedEvent);
return true;
}
public bool IsContainTodayMenu(string recipeId)=> _todayFoodRecipeIds.ContainsKey(recipeId) || _todayDrinkRecipeIds.ContainsKey(recipeId);
} }
} }

View File

@ -7,15 +7,12 @@ public class InventorySlotUiStrategy : IItemSlotUiStrategy
{ {
public string AnimatorControllerKey => "InventorySlotUi"; public string AnimatorControllerKey => "InventorySlotUi";
public Task Setup(ItemSlotUi ui, ItemViewModel model) public void Setup(ItemSlotUi ui, ItemViewModel model)
{ {
ui.SetIcon(model.ItemSprite); ui.SetIcon(model.ItemSprite);
ui.SetCount(model.Count); ui.ShowCountText();
ui.ShowCount();
ui.HideMark(); ui.HideMark();
ui.SetButtonInteractable(true); ui.SetButtonInteractable(true);
return Task.CompletedTask;
} }
public async Task<RuntimeAnimatorController> GetAnimatorController() public async Task<RuntimeAnimatorController> GetAnimatorController()
@ -28,7 +25,7 @@ public void OnInventoryChanged(ItemSlotUi ui)
if (ui.Model == null) return; if (ui.Model == null) return;
ui.Model.UpdateCount(); ui.Model.UpdateCount();
ui.SetCount(ui.Model.Count); ui.ShowCountText();
} }
public bool CanCrafting(ItemSlotUi ui) public bool CanCrafting(ItemSlotUi ui)

View File

@ -50,8 +50,18 @@ public async Task Initialize()
await slot.Initialize(model, new InventorySlotUiStrategy()); await slot.Initialize(model, new InventorySlotUiStrategy());
itemSlotUi.name = ItemSlotUiName + model.Id; itemSlotUi.name = ItemSlotUiName + model.Id;
var interactor = itemSlotUi.GetComponent<TodayMenuInteractor>(); var interactor = itemSlotUi.GetComponent<ItemSlotInteractor>();
interactor.Initialize(TodayMenuEventType.Add); if (model.ItemType == ItemType.Recipe)
{
await interactor.Initialize(TodayMenuEventType.Add, new TodayMenuInteractorStrategy());
}
else
{
if (DataManager.Instance.GetDataSo<CookwareDataSo>().TryGetDataById(model.Id, out var cookwareData))
{
await interactor.Initialize(TodayMenuEventType.Add, new TodayCookwareInteractorStrategy());
}
}
_slotLookup[model.Id] = slot; _slotLookup[model.Id] = slot;
} }

View File

@ -3,7 +3,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization.Components; using UnityEngine.Localization.Components;
using UnityEngine.UI; using UnityEngine.UI;
@ -72,7 +71,7 @@ public async void Show(ItemViewModel model)
{ {
viewItemKey = _currentItemViewModel.GetRecipeResultKey; viewItemKey = _currentItemViewModel.GetRecipeResultKey;
} }
else if (_currentItemViewModel.ItemType == ItemType.Ingredient) else
{ {
viewItemKey = _currentItemViewModel.Id; viewItemKey = _currentItemViewModel.Id;
} }

View File

@ -1,7 +1,9 @@
using System.Threading.Tasks;
namespace DDD namespace DDD
{ {
public interface IInteractableUi public interface IInteractableUi
{ {
void OnInteract(); Task OnInteract();
} }
} }

View File

@ -0,0 +1,8 @@
namespace DDD
{
public interface IItemSlotInteractorStrategy
{
void OnAdded(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo);
void OnRemoved(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo);
}
}

View File

@ -6,7 +6,7 @@ namespace DDD
public interface IItemSlotUiStrategy public interface IItemSlotUiStrategy
{ {
string AnimatorControllerKey { get; } string AnimatorControllerKey { get; }
Task Setup(ItemSlotUi ui, ItemViewModel model); void Setup(ItemSlotUi ui, ItemViewModel model);
Task<RuntimeAnimatorController> GetAnimatorController(); Task<RuntimeAnimatorController> GetAnimatorController();
} }
} }

View File

@ -12,66 +12,45 @@ public enum TodayMenuEventType
Remove Remove
} }
public class TodayMenuInteractor : MonoBehaviour, IInteractableUi public class ItemSlotInteractor : MonoBehaviour, IInteractableUi
{ {
private ItemSlotUi _itemSlotUi; private ItemSlotUi _itemSlotUi;
private RestaurantManagementSo _restaurantManagementSo; private RestaurantManagementSo _restaurantManagementSo;
private TaskCompletionSource<bool> _isInitialized = new(); private TaskCompletionSource<bool> _isInitialized = new();
private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None; private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None;
public IItemSlotInteractorStrategy Strategy { get; private set; }
private void Awake() private void Awake()
{ {
_itemSlotUi = GetComponent<ItemSlotUi>(); _itemSlotUi = GetComponent<ItemSlotUi>();
} }
public async void Initialize(TodayMenuEventType todayMenuEventType) public async Task Initialize(TodayMenuEventType todayMenuEventType, IItemSlotInteractorStrategy strategy)
{ {
_todayMenuEventType = todayMenuEventType; _todayMenuEventType = todayMenuEventType;
Strategy = strategy;
_restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo); _restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
_isInitialized.SetResult(true); _isInitialized.SetResult(true);
} }
public async void OnInteract() public async Task OnInteract()
{ {
await _isInitialized.Task; await _isInitialized.Task;
switch (_todayMenuEventType) switch (_todayMenuEventType)
{ {
case TodayMenuEventType.Add: case TodayMenuEventType.Add:
OnAdded(); Strategy.OnAdded(_itemSlotUi, _restaurantManagementSo);
break; break;
case TodayMenuEventType.Remove: case TodayMenuEventType.Remove:
OnRemoved(); Strategy.OnRemoved(_itemSlotUi, _restaurantManagementSo);
break; break;
case TodayMenuEventType.None: case TodayMenuEventType.None:
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
} }
private void OnAdded()
{
if (_itemSlotUi.Strategy is not InventorySlotUiStrategy inventorySlotUiStrategy) return;
if (inventorySlotUiStrategy.CanCrafting(_itemSlotUi))
{
_restaurantManagementSo.TryAddTodayMenu(_itemSlotUi);
}
else
{
var evt = GameEvents.RequestShowGlobalMessageEvent;
// TODO : 테스트용 메세지 추후 삭제 및 변경
evt.NewMessageKey = "today_menu_added_error_message_001";
evt.FadeDuration = 0.5f;
evt.ShowDuration = 1f;
EventBus.Broadcast(evt);
}
}
private void OnRemoved()
{
_restaurantManagementSo.TryRemoveTodayMenu(_itemSlotUi);
}
} }
} }

View File

@ -1,8 +1,6 @@
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
@ -17,7 +15,7 @@ public class ItemSlotUi : MonoBehaviour, ISelectHandler
[SerializeField] private Image _markImage; [SerializeField] private Image _markImage;
[SerializeField] private Animator _animator; [SerializeField] private Animator _animator;
public ItemViewModel Model { get; private set; } [field: SerializeField] public ItemViewModel Model { get; private set; }
public IItemSlotUiStrategy Strategy { get; private set; } public IItemSlotUiStrategy Strategy { get; private set; }
public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy) public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
@ -27,17 +25,18 @@ public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
var controller = await strategy.GetAnimatorController(); var controller = await strategy.GetAnimatorController();
_animator.runtimeAnimatorController = controller; _animator.runtimeAnimatorController = controller;
await Strategy.Setup(this, model); Strategy.Setup(this, model);
} }
public void SetIcon(Sprite sprite) => _icon.sprite = sprite; public void SetIcon(Sprite sprite) => _icon.sprite = sprite;
public void SetCount(int count) public void ShowCountText()
{ {
int count = Model.Count;
_countText.text = count.ToString(); _countText.text = count.ToString();
_countText.color = count > 0 ? Color.white : Color.red; _countText.color = count > 0 ? Color.white : Color.red;
_countText.gameObject.SetActive(true);
} }
public void ShowCount() => _countText.gameObject.SetActive(true); public void HideCountText() => _countText.gameObject.SetActive(false);
public void HideCount() => _countText.gameObject.SetActive(false);
public void ShowMark(Sprite sprite) public void ShowMark(Sprite sprite)
{ {
_markImage.sprite = sprite; _markImage.sprite = sprite;

View File

@ -1,13 +1,29 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace DDD namespace DDD
{ {
[Serializable]
public class ItemViewModel public class ItemViewModel
{ {
public string Id; [field: SerializeField] public string Id { get; private set; }
public ItemType ItemType; [field: SerializeField] public ItemType ItemType { get; private set; }
public int Count; [field: SerializeField] public int Count { get; private set; }
public ItemViewModel(string id, ItemType itemType, int count)
{
Id = id;
ItemType = itemType;
Count = count;
}
public ItemViewModel(string id, ItemType itemType)
{
Id = id;
ItemType = itemType;
Count = 0;
}
public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.GetDataSo<RecipeDataSo>().GetDataById(Id).RecipeType : RecipeType.None; public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.GetDataSo<RecipeDataSo>().GetDataById(Id).RecipeType : RecipeType.None;
public Sprite ItemSprite public Sprite ItemSprite
@ -70,6 +86,8 @@ public List<TasteData> GetTasteDatas
} }
} }
public void SetCount(int count) => Count = count;
public void UpdateCount() public void UpdateCount()
{ {
if (ItemType == ItemType.Recipe) if (ItemType == ItemType.Recipe)
@ -90,7 +108,7 @@ public void UpdateCount()
Count = craftableCount; Count = craftableCount;
} }
else if (ItemType == ItemType.Ingredient) else
{ {
Count = InventoryManager.Instance.GetItemCount(Id); Count = InventoryManager.Instance.GetItemCount(Id);
} }

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace DDD namespace DDD
{ {
@ -8,28 +7,18 @@ public static class ItemViewModelFactory
public static List<ItemViewModel> CreateRestaurantManagementInventoryItem() public static List<ItemViewModel> CreateRestaurantManagementInventoryItem()
{ {
var result = new List<ItemViewModel>(); var result = new List<ItemViewModel>();
var recipeDataMap = DataManager.Instance.GetDataSo<RecipeDataSo>().GetDataList().ToDictionary(r => r.Id, r => r);
var foodDataMap = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataList().ToDictionary(f => f.Id, f => f);
var drinkDataMap = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataList().ToDictionary(d => d.Id, d => d);
var ingredientDataMap = DataManager.Instance.GetDataSo<IngredientDataSo>().GetDataList().ToDictionary(i => i.Id, i => i);
foreach (var kvp in InventoryManager.Instance.InventoryItems) foreach (var kvp in InventoryManager.Instance.InventoryItems)
{ {
var id = kvp.Key; var id = kvp.Key;
var item = InventoryManager.Instance.GetItemDataByIdOrNull(id); var item = InventoryManager.Instance.GetItemDataByIdOrNull(id);
if (item == null) continue; if (item == null) continue;
var model = new ItemViewModel var modelCount = item.ItemType switch
{ {
Id = item.Id, ItemType.Recipe => CalculateCraftableCount(item.Id),
ItemType = item.ItemType, _ => InventoryManager.Instance.GetItemCount(id)
Count = item.ItemType switch
{
ItemType.Recipe => CalculateCraftableCount(item.Id),
ItemType.Ingredient => InventoryManager.Instance.GetItemCount(id),
_ => 0
}
}; };
var model = new ItemViewModel(item.Id, item.ItemType, modelCount);
result.Add(model); result.Add(model);
} }
@ -55,20 +44,15 @@ private static int CalculateCraftableCount(string recipeId)
}; };
} }
public static ItemViewModel CreateByRecipeId(string recipeId) public static ItemViewModel CreateByItemId(string itemId)
{ {
var recipeSo = DataManager.Instance.GetDataSo<RecipeDataSo>(); var itemSo = DataManager.Instance.GetDataSo<ItemDataSo>();
if (!recipeSo.TryGetDataById(recipeId, out var recipe)) return null; if (!itemSo.TryGetDataById(itemId, out var itemData)) return null;
var item = InventoryManager.Instance.GetItemDataByIdOrNull(recipeId); if (InventoryManager.Instance.GetItemDataByIdOrNull(itemId) == null) return null;
if (item == null) return null;
var model = new ItemViewModel
{
Id = recipeId,
ItemType = item.ItemType,
};
var model = new ItemViewModel(itemId, itemData.ItemType);
return model; return model;
} }
} }

View File

@ -2,7 +2,6 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.Serialization;
namespace DDD namespace DDD
{ {
@ -19,7 +18,12 @@ protected override GameObject GetInitialSelected()
var inventoryViewInitialSelectedObject = _inventoryView.GetInitialSelected(); var inventoryViewInitialSelectedObject = _inventoryView.GetInitialSelected();
if (inventoryViewInitialSelectedObject) return inventoryViewInitialSelectedObject; if (inventoryViewInitialSelectedObject) return inventoryViewInitialSelectedObject;
return _menuCategoryTabs.GetFirstInteractableButton; if (_menuCategoryTabs.GetFirstInteractableButton.activeInHierarchy)
{
return _menuCategoryTabs.GetFirstInteractableButton;
}
return _cookwareCategoryTabs.GetFirstInteractableButton;
} }
public async override void Open() public async override void Open()

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
@ -85,9 +86,10 @@ private void SetActiveContents(bool isActive)
content.SetActive(isActive); content.SetActive(isActive);
} }
} }
public void OnInteract() public Task OnInteract()
{ {
_onSelected?.Invoke(TabType); _onSelected?.Invoke(TabType);
return Task.CompletedTask;
} }
} }
} }

View File

@ -0,0 +1,31 @@
namespace DDD
{
public class TodayMenuInteractorStrategy : IItemSlotInteractorStrategy
{
public void OnAdded(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo)
{
if (itemSlotUi.Strategy is not InventorySlotUiStrategy inventorySlotUiStrategy) return;
if (inventorySlotUiStrategy.CanCrafting(itemSlotUi))
{
restaurantManagementSo.TryAddTodayMenu(itemSlotUi);
}
else
{
var evt = GameEvents.RequestShowGlobalMessageEvent;
// TODO : 테스트용 메세지 추후 삭제 및 변경
evt.NewMessageKey = "today_menu_added_error_message_001";
evt.FadeDuration = 0.5f;
evt.ShowDuration = 1f;
EventBus.Broadcast(evt);
}
}
public void OnRemoved(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo)
{
if (itemSlotUi.Strategy is InventorySlotUiStrategy) return;
restaurantManagementSo.TryRemoveTodayMenu(itemSlotUi);
}
}
}

View File

@ -1,12 +1,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DDD namespace DDD
{ {
public class TodayMenuSlotUiStrategy : IItemSlotUiStrategy public class TodayMenuSlotUiStrategy : IItemSlotUiStrategy
{ {
private RestaurantManagementSo _restaurantManagementSo;
private readonly RecipeType _recipeType; private readonly RecipeType _recipeType;
public string AnimatorControllerKey => "TodayMenuSlotUi"; public string AnimatorControllerKey => "TodayMenuSlotUi";
@ -16,13 +14,8 @@ public TodayMenuSlotUiStrategy(RecipeType recipeType)
_recipeType = recipeType; _recipeType = recipeType;
} }
public async Task Setup(ItemSlotUi ui, ItemViewModel model) public void Setup(ItemSlotUi ui, ItemViewModel model)
{ {
if (!_restaurantManagementSo)
{
_restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
}
if (model == null) if (model == null)
{ {
string emptySpriteKey = null; string emptySpriteKey = null;
@ -36,14 +29,14 @@ public async Task Setup(ItemSlotUi ui, ItemViewModel model)
} }
ui.SetIcon(DataManager.Instance.GetSprite(emptySpriteKey)); ui.SetIcon(DataManager.Instance.GetSprite(emptySpriteKey));
ui.HideCount(); ui.HideCountText();
ui.HideMark(); ui.HideMark();
ui.SetButtonInteractable(false); ui.SetButtonInteractable(false);
return; return;
} }
ui.SetIcon(model.ItemSprite); ui.SetIcon(model.ItemSprite);
ui.HideCount(); ui.HideCountText();
ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭 ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭
ui.SetButtonInteractable(true); ui.SetButtonInteractable(true);
} }

View File

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DDD namespace DDD
{ {
@ -36,15 +35,15 @@ private async Task Initialize()
Destroy(child.gameObject); Destroy(child.gameObject);
} }
int maxFoodCount = _restaurantManagementSo.MaxFoodCount; int maxFoodCount = _restaurantManagementSo!.MaxFoodCount;
_foodSlots = new List<ItemSlotUi>(maxFoodCount); _foodSlots = new List<ItemSlotUi>(maxFoodCount);
for (int i = 0; i < _restaurantManagementSo.MaxFoodCount; i++) for (int i = 0; i < _restaurantManagementSo.MaxFoodCount; i++)
{ {
var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayFoodContent); var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayFoodContent);
var slot = go.GetComponent<ItemSlotUi>(); var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe)); await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
var todayMenuInteractor = go.GetComponent<TodayMenuInteractor>(); var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
todayMenuInteractor.Initialize(TodayMenuEventType.Remove); await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
_foodSlots.Add(slot); _foodSlots.Add(slot);
} }
@ -61,8 +60,8 @@ private async Task Initialize()
var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayDrinkContent); var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayDrinkContent);
var slot = go.GetComponent<ItemSlotUi>(); var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe)); await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
var todayMenuInteractor = go.GetComponent<TodayMenuInteractor>(); var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
todayMenuInteractor.Initialize(TodayMenuEventType.Remove); await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
_drinkSlots.Add(slot); _drinkSlots.Add(slot);
} }
@ -86,41 +85,37 @@ public void Invoke(TodayMenuRemovedEvent evt)
private void UpdateView() private void UpdateView()
{ {
int foodIndex = 0; int foodIndex = 0;
foreach (var kvp in _restaurantManagementSo.FoodRecipeIds) foreach (var foodRecipeIdCountPair in _restaurantManagementSo.TodayFoodRecipeIds)
{ {
if (foodIndex >= _foodSlots.Count) break; if (foodIndex >= _foodSlots.Count) break;
string recipeId = kvp.Key; var model = ItemViewModelFactory.CreateByItemId(foodRecipeIdCountPair.Key);
var model = ItemViewModelFactory.CreateByRecipeId(recipeId);
var foodSlot = _foodSlots[foodIndex]; var foodSlot = _foodSlots[foodIndex];
_ = foodSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe)); _ = foodSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
foodSlot.SetCount(kvp.Value); foodSlot.Model.SetCount(foodRecipeIdCountPair.Value);
foodIndex++; foodIndex++;
} }
for (int i = foodIndex; i < _foodSlots.Count; i++) for (int i = foodIndex; i < _foodSlots.Count; i++)
{ {
_ = _foodSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe)); _ = _foodSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
} }
int drinkIndex = 0; int drinkIndex = 0;
foreach (var kvp in _restaurantManagementSo.DrinkRecipeIds) foreach (var drinkRecipeIdCountPair in _restaurantManagementSo.TodayDrinkRecipeIds)
{ {
if (drinkIndex >= _drinkSlots.Count) break; if (drinkIndex >= _drinkSlots.Count) break;
string recipeId = kvp.Key; var model = ItemViewModelFactory.CreateByItemId(drinkRecipeIdCountPair.Key);
var model = ItemViewModelFactory.CreateByRecipeId(recipeId);
var drinkSlot = _drinkSlots[drinkIndex]; var drinkSlot = _drinkSlots[drinkIndex];
_ = drinkSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe)); _ = drinkSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
drinkSlot.SetCount(kvp.Value); drinkSlot.Model.SetCount(drinkRecipeIdCountPair.Value);
drinkIndex++; drinkIndex++;
} }
for (int i = drinkIndex; i < _drinkSlots.Count; i++) for (int i = drinkIndex; i < _drinkSlots.Count; i++)
{ {
_ = _drinkSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe)); _ = _drinkSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
} }
} }
} }

View File

@ -0,0 +1,31 @@
namespace DDD
{
public class TodayCookwareInteractorStrategy : IItemSlotInteractorStrategy
{
public void OnAdded(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo)
{
if (itemSlotUi.Strategy is not InventorySlotUiStrategy inventorySlotUiStrategy) return;
if (inventorySlotUiStrategy.CanCrafting(itemSlotUi))
{
restaurantManagementSo.TryAddTodayCookware(itemSlotUi);
}
else
{
var evt = GameEvents.RequestShowGlobalMessageEvent;
// TODO : 테스트용 메세지 추후 삭제 및 변경
evt.NewMessageKey = "today_menu_added_error_message_001";
evt.FadeDuration = 0.5f;
evt.ShowDuration = 1f;
EventBus.Broadcast(evt);
}
}
public void OnRemoved(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo)
{
if (itemSlotUi.Strategy is InventorySlotUiStrategy) return;
restaurantManagementSo.TryRemoveTodayCookware(itemSlotUi);
}
}
}

View File

@ -0,0 +1,34 @@
using System.Threading.Tasks;
using UnityEngine;
namespace DDD
{
public class TodayCookwareSlotUiStrategy : IItemSlotUiStrategy
{
private RestaurantManagementSo _restaurantManagementSo;
public string AnimatorControllerKey => "TodayMenuSlotUi";
public void Setup(ItemSlotUi ui, ItemViewModel model)
{
if (model == null)
{
ui.SetIcon(DataManager.Instance.GetSprite(SpriteConstants.EmptyFoodSpriteKey));
ui.HideCountText();
ui.HideMark();
ui.SetButtonInteractable(false);
return;
}
ui.SetIcon(model.ItemSprite);
ui.HideCountText();
ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭
ui.SetButtonInteractable(true);
}
public async Task<RuntimeAnimatorController> GetAnimatorController()
{
return await AssetManager.LoadAsset<RuntimeAnimatorController>(AnimatorControllerKey);
}
}
}

View File

@ -0,0 +1,121 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
namespace DDD
{
public class TodayRestaurantStateView : MonoBehaviour, IEventHandler<TodayMenuAddedEvent>, IEventHandler<TodayMenuRemovedEvent>
{
[SerializeField] private Transform _todayWorkerContent;
[SerializeField] private Transform _todayCookwareContent;
private List<ItemSlotUi> _workerSlots;
private List<ItemSlotUi> _cookwareSlots;
private RestaurantManagementSo _restaurantManagementSo;
private void Start()
{
_ = Initialize();
}
private void OnDestroy()
{
EventBus.Unregister<TodayMenuAddedEvent>(this);
EventBus.Unregister<TodayMenuRemovedEvent>(this);
}
private async Task Initialize()
{
_restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
Debug.Assert(_restaurantManagementSo != null, "_restaurantManagementSo != null");
foreach (Transform child in _todayWorkerContent)
{
Destroy(child.gameObject);
}
int maxCookwareCount = _restaurantManagementSo!.MaxCookwareCount;
_workerSlots = new List<ItemSlotUi>(maxCookwareCount);
for (int i = 0; i < _restaurantManagementSo.MaxCookwareCount; i++)
{
var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayWorkerContent);
var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayWorkerSlotUiStrategy());
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayCookwareInteractorStrategy());
_workerSlots.Add(slot);
}
foreach (Transform child in _todayCookwareContent)
{
Destroy(child.gameObject);
}
_cookwareSlots = new List<ItemSlotUi>(maxCookwareCount);
for (int i = 0; i < _restaurantManagementSo.MaxCookwareCount; i++)
{
var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayCookwareContent);
var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayCookwareSlotUiStrategy());
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayCookwareInteractorStrategy());
_cookwareSlots.Add(slot);
}
UpdateView();
EventBus.Register<TodayMenuAddedEvent>(this);
EventBus.Register<TodayMenuRemovedEvent>(this);
}
public void Invoke(TodayMenuAddedEvent evt)
{
UpdateView();
}
public void Invoke(TodayMenuRemovedEvent evt)
{
UpdateView();
}
private void UpdateView()
{
int workerIndex = 0;
foreach (var workerKey in _restaurantManagementSo.TodayWorkerIds)
{
if (workerIndex >= _workerSlots.Count) break;
var model = ItemViewModelFactory.CreateByItemId(workerKey);
var newWorkerSlot = _workerSlots[workerIndex];
_ = newWorkerSlot.Initialize(model, new TodayWorkerSlotUiStrategy());
newWorkerSlot.Model.SetCount(1);
workerIndex++;
}
for (int i = workerIndex; i < _workerSlots.Count; i++)
{
_ = _workerSlots[i].Initialize(null, new TodayWorkerSlotUiStrategy());
}
int cookwareIndex = 0;
foreach (var cookwareKey in _restaurantManagementSo.TodayCookwareIds)
{
if (cookwareIndex >= _cookwareSlots.Count) break;
var model = ItemViewModelFactory.CreateByItemId(cookwareKey);
var newCookwareSlot = _cookwareSlots[cookwareIndex];
_ = newCookwareSlot.Initialize(model, new TodayCookwareSlotUiStrategy());
newCookwareSlot.Model.SetCount(1);
cookwareIndex++;
}
for (int i = cookwareIndex; i < _cookwareSlots.Count; i++)
{
_ = _cookwareSlots[i].Initialize(null, new TodayCookwareSlotUiStrategy());
}
}
}
}

View File

@ -0,0 +1,34 @@
using System.Threading.Tasks;
using UnityEngine;
namespace DDD
{
public class TodayWorkerSlotUiStrategy : IItemSlotUiStrategy
{
private RestaurantManagementSo _restaurantManagementSo;
public string AnimatorControllerKey => "TodayMenuSlotUi";
public void Setup(ItemSlotUi ui, ItemViewModel model)
{
if (model == null)
{
ui.SetIcon(DataManager.Instance.GetSprite(SpriteConstants.EmptyFoodSpriteKey)); // TODO : 점원 빈칸 이미지로 변경
ui.HideCountText();
ui.HideMark();
ui.SetButtonInteractable(false);
return;
}
ui.SetIcon(model.ItemSprite);
ui.HideCountText();
ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭
ui.SetButtonInteractable(true);
}
public async Task<RuntimeAnimatorController> GetAnimatorController()
{
return await AssetManager.LoadAsset<RuntimeAnimatorController>(AnimatorControllerKey);
}
}
}