ui 작업
This commit is contained in:
parent
ce1b220f9b
commit
4012878fad
@ -20,20 +20,28 @@ public class RestaurantManagementSo : GameFlowTask
|
||||
public Color FoodTasteOutlineColor = Color.magenta;
|
||||
public Color DrinkTasteOutlineColor = Color.magenta;
|
||||
|
||||
[Title("오늘의 메뉴")]
|
||||
[Title("오늘의 레스토랑 상태")]
|
||||
public int MaxFoodCount = 8;
|
||||
public int MaxDrinkCount = 6;
|
||||
public int MaxCookwareCount = 6;
|
||||
|
||||
private Dictionary<string, int> _foodRecipeIds = new();
|
||||
private Dictionary<string, int> _drinkRecipeIds = new();
|
||||
[Title("실시간 데이터")]
|
||||
[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> DrinkRecipeIds => _drinkRecipeIds;
|
||||
public IReadOnlyDictionary<string, int> TodayFoodRecipeIds => _todayFoodRecipeIds;
|
||||
public IReadOnlyDictionary<string, int> TodayDrinkRecipeIds => _todayDrinkRecipeIds;
|
||||
public IReadOnlyList<string> TodayWorkerIds => _todayWorkerIds;
|
||||
public IReadOnlyList<string> TodayCookwareIds => _todayCookwareIds;
|
||||
|
||||
public override Task OnReadyNewFlow(GameFlowState newFlowState)
|
||||
{
|
||||
_foodRecipeIds.Clear();
|
||||
_drinkRecipeIds.Clear();
|
||||
_todayFoodRecipeIds.Clear();
|
||||
_todayDrinkRecipeIds.Clear();
|
||||
_todayWorkerIds.Clear();
|
||||
_todayCookwareIds.Clear();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -50,24 +58,24 @@ public bool TryAddTodayMenu(ItemSlotUi itemSlotUi)
|
||||
|
||||
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 craftableCount = foodData.GetCraftableCount();
|
||||
foodData.ConsumeAllCraftableIngredients();
|
||||
|
||||
_foodRecipeIds[recipeId] = craftableCount;
|
||||
_todayFoodRecipeIds[recipeId] = craftableCount;
|
||||
added = true;
|
||||
}
|
||||
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 craftableCount = drinkData.GetCraftableCount();
|
||||
drinkData.ConsumeAllCraftableIngredients();
|
||||
|
||||
_drinkRecipeIds[recipeId] = craftableCount;
|
||||
_todayDrinkRecipeIds[recipeId] = craftableCount;
|
||||
added = true;
|
||||
}
|
||||
|
||||
@ -91,9 +99,9 @@ public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
|
||||
|
||||
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;
|
||||
|
||||
if (removed)
|
||||
@ -105,9 +113,9 @@ public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
|
||||
}
|
||||
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;
|
||||
|
||||
if (removed)
|
||||
@ -124,6 +132,33 @@ public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
|
||||
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);
|
||||
}
|
||||
}
|
@ -7,15 +7,12 @@ public class InventorySlotUiStrategy : IItemSlotUiStrategy
|
||||
{
|
||||
public string AnimatorControllerKey => "InventorySlotUi";
|
||||
|
||||
public Task Setup(ItemSlotUi ui, ItemViewModel model)
|
||||
public void Setup(ItemSlotUi ui, ItemViewModel model)
|
||||
{
|
||||
ui.SetIcon(model.ItemSprite);
|
||||
ui.SetCount(model.Count);
|
||||
ui.ShowCount();
|
||||
ui.ShowCountText();
|
||||
ui.HideMark();
|
||||
ui.SetButtonInteractable(true);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<RuntimeAnimatorController> GetAnimatorController()
|
||||
@ -28,7 +25,7 @@ public void OnInventoryChanged(ItemSlotUi ui)
|
||||
if (ui.Model == null) return;
|
||||
|
||||
ui.Model.UpdateCount();
|
||||
ui.SetCount(ui.Model.Count);
|
||||
ui.ShowCountText();
|
||||
}
|
||||
|
||||
public bool CanCrafting(ItemSlotUi ui)
|
||||
|
@ -50,8 +50,18 @@ public async Task Initialize()
|
||||
await slot.Initialize(model, new InventorySlotUiStrategy());
|
||||
itemSlotUi.name = ItemSlotUiName + model.Id;
|
||||
|
||||
var interactor = itemSlotUi.GetComponent<TodayMenuInteractor>();
|
||||
interactor.Initialize(TodayMenuEventType.Add);
|
||||
var interactor = itemSlotUi.GetComponent<ItemSlotInteractor>();
|
||||
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;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.Localization.Components;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -72,7 +71,7 @@ public async void Show(ItemViewModel model)
|
||||
{
|
||||
viewItemKey = _currentItemViewModel.GetRecipeResultKey;
|
||||
}
|
||||
else if (_currentItemViewModel.ItemType == ItemType.Ingredient)
|
||||
else
|
||||
{
|
||||
viewItemKey = _currentItemViewModel.Id;
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
public interface IInteractableUi
|
||||
{
|
||||
void OnInteract();
|
||||
Task OnInteract();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace DDD
|
||||
{
|
||||
public interface IItemSlotInteractorStrategy
|
||||
{
|
||||
void OnAdded(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo);
|
||||
void OnRemoved(ItemSlotUi itemSlotUi, RestaurantManagementSo restaurantManagementSo);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace DDD
|
||||
public interface IItemSlotUiStrategy
|
||||
{
|
||||
string AnimatorControllerKey { get; }
|
||||
Task Setup(ItemSlotUi ui, ItemViewModel model);
|
||||
void Setup(ItemSlotUi ui, ItemViewModel model);
|
||||
Task<RuntimeAnimatorController> GetAnimatorController();
|
||||
}
|
||||
}
|
@ -12,66 +12,45 @@ public enum TodayMenuEventType
|
||||
Remove
|
||||
}
|
||||
|
||||
public class TodayMenuInteractor : MonoBehaviour, IInteractableUi
|
||||
public class ItemSlotInteractor : MonoBehaviour, IInteractableUi
|
||||
{
|
||||
private ItemSlotUi _itemSlotUi;
|
||||
private RestaurantManagementSo _restaurantManagementSo;
|
||||
private TaskCompletionSource<bool> _isInitialized = new();
|
||||
private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None;
|
||||
|
||||
public IItemSlotInteractorStrategy Strategy { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_itemSlotUi = GetComponent<ItemSlotUi>();
|
||||
}
|
||||
|
||||
public async void Initialize(TodayMenuEventType todayMenuEventType)
|
||||
public async Task Initialize(TodayMenuEventType todayMenuEventType, IItemSlotInteractorStrategy strategy)
|
||||
{
|
||||
_todayMenuEventType = todayMenuEventType;
|
||||
Strategy = strategy;
|
||||
|
||||
_restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
|
||||
_isInitialized.SetResult(true);
|
||||
}
|
||||
|
||||
public async void OnInteract()
|
||||
public async Task OnInteract()
|
||||
{
|
||||
await _isInitialized.Task;
|
||||
|
||||
switch (_todayMenuEventType)
|
||||
{
|
||||
case TodayMenuEventType.Add:
|
||||
OnAdded();
|
||||
Strategy.OnAdded(_itemSlotUi, _restaurantManagementSo);
|
||||
break;
|
||||
case TodayMenuEventType.Remove:
|
||||
OnRemoved();
|
||||
Strategy.OnRemoved(_itemSlotUi, _restaurantManagementSo);
|
||||
break;
|
||||
case TodayMenuEventType.None:
|
||||
default:
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -17,7 +15,7 @@ public class ItemSlotUi : MonoBehaviour, ISelectHandler
|
||||
[SerializeField] private Image _markImage;
|
||||
[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 async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
|
||||
@ -27,17 +25,18 @@ public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
|
||||
|
||||
var controller = await strategy.GetAnimatorController();
|
||||
_animator.runtimeAnimatorController = controller;
|
||||
await Strategy.Setup(this, model);
|
||||
Strategy.Setup(this, model);
|
||||
}
|
||||
|
||||
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.color = count > 0 ? Color.white : Color.red;
|
||||
_countText.gameObject.SetActive(true);
|
||||
}
|
||||
public void ShowCount() => _countText.gameObject.SetActive(true);
|
||||
public void HideCount() => _countText.gameObject.SetActive(false);
|
||||
public void HideCountText() => _countText.gameObject.SetActive(false);
|
||||
public void ShowMark(Sprite sprite)
|
||||
{
|
||||
_markImage.sprite = sprite;
|
||||
|
@ -1,13 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
[Serializable]
|
||||
public class ItemViewModel
|
||||
{
|
||||
public string Id;
|
||||
public ItemType ItemType;
|
||||
public int Count;
|
||||
[field: SerializeField] public string Id { get; private set; }
|
||||
[field: SerializeField] public ItemType ItemType { get; private set; }
|
||||
[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 Sprite ItemSprite
|
||||
@ -70,6 +86,8 @@ public List<TasteData> GetTasteDatas
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCount(int count) => Count = count;
|
||||
|
||||
public void UpdateCount()
|
||||
{
|
||||
if (ItemType == ItemType.Recipe)
|
||||
@ -90,7 +108,7 @@ public void UpdateCount()
|
||||
|
||||
Count = craftableCount;
|
||||
}
|
||||
else if (ItemType == ItemType.Ingredient)
|
||||
else
|
||||
{
|
||||
Count = InventoryManager.Instance.GetItemCount(Id);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
@ -8,28 +7,18 @@ public static class ItemViewModelFactory
|
||||
public static List<ItemViewModel> CreateRestaurantManagementInventoryItem()
|
||||
{
|
||||
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)
|
||||
{
|
||||
var id = kvp.Key;
|
||||
var item = InventoryManager.Instance.GetItemDataByIdOrNull(id);
|
||||
if (item == null) continue;
|
||||
|
||||
var model = new ItemViewModel
|
||||
var modelCount = item.ItemType switch
|
||||
{
|
||||
Id = item.Id,
|
||||
ItemType = item.ItemType,
|
||||
Count = item.ItemType switch
|
||||
{
|
||||
ItemType.Recipe => CalculateCraftableCount(item.Id),
|
||||
ItemType.Ingredient => InventoryManager.Instance.GetItemCount(id),
|
||||
_ => 0
|
||||
}
|
||||
ItemType.Recipe => CalculateCraftableCount(item.Id),
|
||||
_ => InventoryManager.Instance.GetItemCount(id)
|
||||
};
|
||||
var model = new ItemViewModel(item.Id, item.ItemType, modelCount);
|
||||
|
||||
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>();
|
||||
if (!recipeSo.TryGetDataById(recipeId, out var recipe)) return null;
|
||||
|
||||
var item = InventoryManager.Instance.GetItemDataByIdOrNull(recipeId);
|
||||
if (item == null) return null;
|
||||
|
||||
var model = new ItemViewModel
|
||||
{
|
||||
Id = recipeId,
|
||||
ItemType = item.ItemType,
|
||||
};
|
||||
var itemSo = DataManager.Instance.GetDataSo<ItemDataSo>();
|
||||
if (!itemSo.TryGetDataById(itemId, out var itemData)) return null;
|
||||
|
||||
if (InventoryManager.Instance.GetItemDataByIdOrNull(itemId) == null) return null;
|
||||
|
||||
var model = new ItemViewModel(itemId, itemData.ItemType);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
@ -19,7 +18,12 @@ protected override GameObject GetInitialSelected()
|
||||
var inventoryViewInitialSelectedObject = _inventoryView.GetInitialSelected();
|
||||
if (inventoryViewInitialSelectedObject) return inventoryViewInitialSelectedObject;
|
||||
|
||||
return _menuCategoryTabs.GetFirstInteractableButton;
|
||||
if (_menuCategoryTabs.GetFirstInteractableButton.activeInHierarchy)
|
||||
{
|
||||
return _menuCategoryTabs.GetFirstInteractableButton;
|
||||
}
|
||||
|
||||
return _cookwareCategoryTabs.GetFirstInteractableButton;
|
||||
}
|
||||
|
||||
public async override void Open()
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
@ -85,9 +86,10 @@ private void SetActiveContents(bool isActive)
|
||||
content.SetActive(isActive);
|
||||
}
|
||||
}
|
||||
public void OnInteract()
|
||||
public Task OnInteract()
|
||||
{
|
||||
_onSelected?.Invoke(TabType);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
public class TodayMenuSlotUiStrategy : IItemSlotUiStrategy
|
||||
{
|
||||
private RestaurantManagementSo _restaurantManagementSo;
|
||||
private readonly RecipeType _recipeType;
|
||||
|
||||
public string AnimatorControllerKey => "TodayMenuSlotUi";
|
||||
@ -16,13 +14,8 @@ public TodayMenuSlotUiStrategy(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)
|
||||
{
|
||||
string emptySpriteKey = null;
|
||||
@ -36,14 +29,14 @@ public async Task Setup(ItemSlotUi ui, ItemViewModel model)
|
||||
}
|
||||
|
||||
ui.SetIcon(DataManager.Instance.GetSprite(emptySpriteKey));
|
||||
ui.HideCount();
|
||||
ui.HideCountText();
|
||||
ui.HideMark();
|
||||
ui.SetButtonInteractable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.SetIcon(model.ItemSprite);
|
||||
ui.HideCount();
|
||||
ui.HideCountText();
|
||||
ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭
|
||||
ui.SetButtonInteractable(true);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
@ -36,15 +35,15 @@ private async Task Initialize()
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
int maxFoodCount = _restaurantManagementSo.MaxFoodCount;
|
||||
int maxFoodCount = _restaurantManagementSo!.MaxFoodCount;
|
||||
_foodSlots = new List<ItemSlotUi>(maxFoodCount);
|
||||
for (int i = 0; i < _restaurantManagementSo.MaxFoodCount; i++)
|
||||
{
|
||||
var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayFoodContent);
|
||||
var slot = go.GetComponent<ItemSlotUi>();
|
||||
await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
|
||||
var todayMenuInteractor = go.GetComponent<TodayMenuInteractor>();
|
||||
todayMenuInteractor.Initialize(TodayMenuEventType.Remove);
|
||||
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
|
||||
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
|
||||
|
||||
_foodSlots.Add(slot);
|
||||
}
|
||||
@ -61,8 +60,8 @@ private async Task Initialize()
|
||||
var go = Instantiate(_restaurantManagementSo.ItemSlotUiPrefab, _todayDrinkContent);
|
||||
var slot = go.GetComponent<ItemSlotUi>();
|
||||
await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
|
||||
var todayMenuInteractor = go.GetComponent<TodayMenuInteractor>();
|
||||
todayMenuInteractor.Initialize(TodayMenuEventType.Remove);
|
||||
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
|
||||
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
|
||||
|
||||
_drinkSlots.Add(slot);
|
||||
}
|
||||
@ -86,41 +85,37 @@ public void Invoke(TodayMenuRemovedEvent evt)
|
||||
private void UpdateView()
|
||||
{
|
||||
int foodIndex = 0;
|
||||
foreach (var kvp in _restaurantManagementSo.FoodRecipeIds)
|
||||
foreach (var foodRecipeIdCountPair in _restaurantManagementSo.TodayFoodRecipeIds)
|
||||
{
|
||||
if (foodIndex >= _foodSlots.Count) break;
|
||||
|
||||
string recipeId = kvp.Key;
|
||||
|
||||
var model = ItemViewModelFactory.CreateByRecipeId(recipeId);
|
||||
|
||||
var model = ItemViewModelFactory.CreateByItemId(foodRecipeIdCountPair.Key);
|
||||
var foodSlot = _foodSlots[foodIndex];
|
||||
_ = foodSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
|
||||
foodSlot.SetCount(kvp.Value);
|
||||
foodSlot.Model.SetCount(foodRecipeIdCountPair.Value);
|
||||
foodIndex++;
|
||||
}
|
||||
|
||||
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;
|
||||
foreach (var kvp in _restaurantManagementSo.DrinkRecipeIds)
|
||||
foreach (var drinkRecipeIdCountPair in _restaurantManagementSo.TodayDrinkRecipeIds)
|
||||
{
|
||||
if (drinkIndex >= _drinkSlots.Count) break;
|
||||
|
||||
string recipeId = kvp.Key;
|
||||
|
||||
var model = ItemViewModelFactory.CreateByRecipeId(recipeId);
|
||||
|
||||
var model = ItemViewModelFactory.CreateByItemId(drinkRecipeIdCountPair.Key);
|
||||
var drinkSlot = _drinkSlots[drinkIndex];
|
||||
_ = drinkSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
|
||||
drinkSlot.SetCount(kvp.Value);
|
||||
drinkSlot.Model.SetCount(drinkRecipeIdCountPair.Value);
|
||||
drinkIndex++;
|
||||
}
|
||||
|
||||
for (int i = drinkIndex; i < _drinkSlots.Count; i++)
|
||||
{
|
||||
_ = _drinkSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
|
||||
_ = _drinkSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user