diff --git a/Assets/_DDD/_Addressables/Sprites/RestaurantProps.spriteatlasv2.meta b/Assets/_DDD/_Addressables/Sprites/RestaurantProps.spriteatlasv2.meta index b1b1766a9..8fd66ba39 100644 --- a/Assets/_DDD/_Addressables/Sprites/RestaurantProps.spriteatlasv2.meta +++ b/Assets/_DDD/_Addressables/Sprites/RestaurantProps.spriteatlasv2.meta @@ -4,9 +4,9 @@ SpriteAtlasImporter: externalObjects: {} textureSettings: serializedVersion: 2 - anisoLevel: 0 - compressionQuality: 0 - maxTextureSize: 0 + anisoLevel: 1 + compressionQuality: 50 + maxTextureSize: 2048 textureCompression: 0 filterMode: 1 generateMipMaps: 0 @@ -17,10 +17,10 @@ SpriteAtlasImporter: packingSettings: serializedVersion: 2 padding: 4 - blockOffset: 0 + blockOffset: 1 allowAlphaSplitting: 0 - enableRotation: 0 - enableTightPacking: 0 + enableRotation: 1 + enableTightPacking: 1 enableAlphaDilation: 0 secondaryTextureSettings: {} variantMultiplier: 1 diff --git a/Assets/_DDD/_Raw/Sprites/RestaurantProps/Barrel01.png.meta b/Assets/_DDD/_Raw/Sprites/RestaurantProps/Barrel01.png.meta index 0d1af3d01..6e5922a66 100644 --- a/Assets/_DDD/_Raw/Sprites/RestaurantProps/Barrel01.png.meta +++ b/Assets/_DDD/_Raw/Sprites/RestaurantProps/Barrel01.png.meta @@ -119,6 +119,19 @@ TextureImporter: ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: iOS + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: [] diff --git a/Assets/_DDD/_ScriptAssets/Prefabs/UiManager.prefab b/Assets/_DDD/_ScriptAssets/Prefabs/UiManager.prefab index 88a93def4..805c33f73 100644 --- a/Assets/_DDD/_ScriptAssets/Prefabs/UiManager.prefab +++ b/Assets/_DDD/_ScriptAssets/Prefabs/UiManager.prefab @@ -6129,6 +6129,10 @@ PrefabInstance: propertyPath: m_fontSize value: 32 objectReference: {fileID: 0} + - target: {fileID: 2189377788458160067, guid: d11d5cf80be02d7469f07db925af284a, type: 3} + propertyPath: m_Navigation.m_Mode + value: 0 + objectReference: {fileID: 0} - target: {fileID: 2189377788458160067, guid: d11d5cf80be02d7469f07db925af284a, type: 3} propertyPath: m_Colors.m_NormalColor.b value: 0.45098042 @@ -6678,6 +6682,10 @@ PrefabInstance: propertyPath: m_fontSize value: 32 objectReference: {fileID: 0} + - target: {fileID: 2189377788458160067, guid: d11d5cf80be02d7469f07db925af284a, type: 3} + propertyPath: m_Navigation.m_Mode + value: 0 + objectReference: {fileID: 0} - target: {fileID: 2189377788458160067, guid: d11d5cf80be02d7469f07db925af284a, type: 3} propertyPath: m_Colors.m_NormalColor.b value: 0.45098042 @@ -7847,6 +7855,10 @@ PrefabInstance: propertyPath: m_fontSize value: 32 objectReference: {fileID: 0} + - target: {fileID: 2189377788458160067, guid: d11d5cf80be02d7469f07db925af284a, type: 3} + propertyPath: m_Navigation.m_Mode + value: 0 + objectReference: {fileID: 0} - target: {fileID: 2189377788458160067, guid: d11d5cf80be02d7469f07db925af284a, type: 3} propertyPath: m_Colors.m_NormalColor.b value: 0.45098042 diff --git a/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs b/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs index 1b57ea9b2..a07effd35 100644 --- a/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs +++ b/Assets/_DDD/_Scripts/GameEvent/GameEvents.cs @@ -19,7 +19,8 @@ public static class GameEvents public static class RestaurantEvents { public static ItemSlotSelectedEvent ItemSlotSelectedEvent = new(); - public static TodayMenuChangedEvent TodayMenuChangedEvent = new(); + public static TodayMenuAddedEvent TodayMenuAddedEvent = new(); + public static TodayMenuRemovedEvent TodayMenuRemovedEvent = new(); } // public static class VoyageEvents @@ -79,7 +80,12 @@ public class ItemSlotSelectedEvent : IEvent public ItemViewModel Model; } - public class TodayMenuChangedEvent : IEvent {} + public class TodayMenuAddedEvent : IEvent {} + + public class TodayMenuRemovedEvent : IEvent + { + public RecipeType RecipeType; + } #endregion } diff --git a/Assets/_DDD/_Scripts/GameState/TodayMenuDataSo.cs b/Assets/_DDD/_Scripts/GameState/TodayMenuDataSo.cs new file mode 100644 index 000000000..c93d5a04e --- /dev/null +++ b/Assets/_DDD/_Scripts/GameState/TodayMenuDataSo.cs @@ -0,0 +1,77 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Sirenix.OdinInspector; +using UnityEngine; + +namespace DDD +{ + [CreateAssetMenu(fileName = "TodayMenuDataSo", menuName = "GameState/TodayMenuDataSo")] + public class TodayMenuDataSo : GameFlowTask + { + [ReadOnly, SerializeField] private List _foodRecipeIds = new(); + [ReadOnly, SerializeField] private List _drinkRecipeIds = new(); + + public IReadOnlyList FoodRecipeIds => _foodRecipeIds; + public IReadOnlyList DrinkRecipeIds => _drinkRecipeIds; + + public int MaxFoodCount = 8; + public int MaxDrinkCount = 6; + + public override Task OnReadyNewFlow(GameFlowState newFlowState) + { + _foodRecipeIds.Clear(); + _drinkRecipeIds.Clear(); + + return Task.CompletedTask; + } + + public bool TryAddTodayMenu(IInventorySlotUi itemSlotUi) + { + string recipeId = itemSlotUi.Model.Id; + + if (_foodRecipeIds.Count >= MaxFoodCount || _foodRecipeIds.Contains(recipeId)) return false; + + if (itemSlotUi.Model.ItemType == ItemType.Recipe) + { + if (DataManager.Instance.RecipeDataSo.TryGetDataById(recipeId, out RecipeData recipeData)) + { + if (recipeData.RecipeType == RecipeType.FoodRecipe) + { + _foodRecipeIds.Add(recipeId); + } + else if (recipeData.RecipeType == RecipeType.DrinkRecipe) + { + _drinkRecipeIds.Add(recipeId); + } + } + } + + EventBus.Broadcast(RestaurantEvents.TodayMenuAddedEvent); + return true; + } + + public bool TryRemoveTodayMenu(IInventorySlotUi itemSlotUi) + { + string recipeId = itemSlotUi.Model.Id; + var evt = RestaurantEvents.TodayMenuRemovedEvent; + + if (_foodRecipeIds.Remove(recipeId)) + { + evt.RecipeType = RecipeType.FoodRecipe; + } + else if (_drinkRecipeIds.Remove(recipeId)) + { + evt.RecipeType = RecipeType.DrinkRecipe; + } + else + { + return false; + } + + EventBus.Broadcast(evt); + return true; + } + + public bool IsContainTodayMenu(string recipeId) => _foodRecipeIds.Contains(recipeId) || _drinkRecipeIds.Contains(recipeId); + } +} \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuDataSo.cs.meta b/Assets/_DDD/_Scripts/GameState/TodayMenuDataSo.cs.meta similarity index 100% rename from Assets/_DDD/_Scripts/GameUi/New/TodayMenuDataSo.cs.meta rename to Assets/_DDD/_Scripts/GameState/TodayMenuDataSo.cs.meta diff --git a/Assets/_DDD/_Scripts/GameUi/New/IInventorySlotUi.cs b/Assets/_DDD/_Scripts/GameUi/New/IInventorySlotUi.cs index 00a34b2c8..74343c27d 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/IInventorySlotUi.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/IInventorySlotUi.cs @@ -2,7 +2,9 @@ namespace DDD { public interface IInventorySlotUi { - void Initialize(ItemViewModel model); - void UpdateCount(int newCount); + ItemViewModel Model { get; } + void Initialize(ItemViewModel model, RecipeType recipeType = RecipeType.None); + bool CanCraft(); + void SetActive(bool value); } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/InventoryView.cs b/Assets/_DDD/_Scripts/GameUi/New/InventoryView.cs index 57eb66bf0..63d90aa0d 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/InventoryView.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/InventoryView.cs @@ -1,48 +1,104 @@ -using System; using System.Collections.Generic; +using System.Threading.Tasks; using UnityEngine; -using UnityEngine.EventSystems; namespace DDD { - public class InventoryView : MonoBehaviour, IEventHandler + public class InventoryView : MonoBehaviour, IEventHandler, IEventHandler, IEventHandler { [SerializeField] private Transform _slotParent; [SerializeField] private GameObject _slotPrefab; + private TodayMenuDataSo _todayMenuDataSo; + private InventoryCategoryType _currenInventoryCategoryType = InventoryCategoryType.None; + private readonly Dictionary _slotLookup = new(); + private readonly Dictionary _modelLookup = new(); private void OnEnable() { EventBus.Register(this); + EventBus.Register(this); + EventBus.Register(this); } private void OnDisable() { EventBus.Unregister(this); + EventBus.Unregister(this); + EventBus.Unregister(this); } - public void ShowItems(Func predicate) + public async Task Initialize() { + _todayMenuDataSo = await AssetManager.LoadAsset(DataConstants.TodayMenuDataSo); + Debug.Assert(_todayMenuDataSo != null, "_todayMenuDataSo != null"); + Clear(); - var models = ItemViewModelFactory.CreateRestaurantManagementInventoryItem(predicate); + var models = ItemViewModelFactory.CreateRestaurantManagementInventoryItem(); + _slotLookup.Clear(); + _modelLookup.Clear(); foreach (var model in models) { var go = Instantiate(_slotPrefab, _slotParent); var slot = go.GetComponent(); slot.Initialize(model); - // 슬롯 참조 저장 - _slotLookup[model.Id] = slot; - } + var interactor = go.GetComponent(); + interactor.Initialize(TodayMenuEventType.Add); - if (_slotParent.childCount > 0) - { - EventSystem.current.SetSelectedGameObject(_slotParent.GetChild(0).gameObject); + _slotLookup[model.Id] = slot; + _modelLookup[model.Id] = model; } } + + public void UpdateCategoryView(InventoryCategoryType category) + { + _currenInventoryCategoryType = category; + + foreach (var kvp in _slotLookup) + { + var id = kvp.Key; + var slot = kvp.Value; + var model = slot.Model; + + // 1. 오늘의 메뉴에 등록된 경우 필터링 + bool isRegisteredTodayMenu = model.ItemType == ItemType.Recipe && _todayMenuDataSo.IsContainTodayMenu(id); + + // 2. 현재 선택된 카테고리에 맞는지 필터링 + bool matchCategory = MatchesCategory(model, _currenInventoryCategoryType); + + // 3. 조건을 모두 만족할 경우만 활성화 + bool shouldShow = !isRegisteredTodayMenu && matchCategory; + slot.SetActive(shouldShow); + } + } + + private bool MatchesCategory(ItemViewModel model, InventoryCategoryType category) + { + switch (category) + { + case InventoryCategoryType.Food: + if (model.ItemType != ItemType.Recipe) return false; + + return DataManager.Instance.RecipeDataSo.TryGetDataById(model.Id, out var foodRecipe) && foodRecipe.RecipeType == RecipeType.FoodRecipe; + case InventoryCategoryType.Drink: + if (model.ItemType != ItemType.Recipe) return false; + + return DataManager.Instance.RecipeDataSo.TryGetDataById(model.Id, out var drinkRecipe) && drinkRecipe.RecipeType == RecipeType.DrinkRecipe; + case InventoryCategoryType.Ingredient: + return model.ItemType == ItemType.Ingredient; + default: + return false; + } + } + + public void UpdateView() + { + UpdateCategoryView(_currenInventoryCategoryType); + } private void Clear() { @@ -56,8 +112,18 @@ public void Invoke(InventoryChangedEvent evt) { if (_slotLookup.TryGetValue(evt.ItemId, out var slot)) { - slot.UpdateCount(evt.NewCount); + slot.Model.UpdateCount(evt.NewCount); } } + + public void Invoke(TodayMenuAddedEvent evt) + { + UpdateView(); + } + + public void Invoke(TodayMenuRemovedEvent evt) + { + UpdateView(); + } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/ItemSlotUi.cs b/Assets/_DDD/_Scripts/GameUi/New/ItemSlotUi.cs index 2dd8ebbeb..a5bdc0de8 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/ItemSlotUi.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/ItemSlotUi.cs @@ -17,10 +17,11 @@ public class ItemSlotUi : MonoBehaviour, IInventorySlotUi public ItemViewModel Model { get; private set; } - public void Initialize(ItemViewModel model) + public void Initialize(ItemViewModel model, RecipeType recipeType = RecipeType.None) { Model = model; + _button.onClick.RemoveAllListeners(); _button.onClick.AddListener(() => { RestaurantEvents.ItemSlotSelectedEvent.Model = Model; @@ -30,47 +31,59 @@ public void Initialize(ItemViewModel model) if (model != null) { _icon.sprite = model.Icon; - _countText.text = model.Count?.ToString() ?? string.Empty; - _countText.gameObject.SetActive(true); - _markImage.gameObject.SetActive(false); + _countText.text = model.Count.ToString(); + EnableCountText(); _button.interactable = true; } else { - _countText.gameObject.SetActive(false); - _markImage.gameObject.SetActive(true); + if (recipeType == RecipeType.FoodRecipe) + { + SetEmptyFood(); + } + else if (recipeType == RecipeType.DrinkRecipe) + { + SetEmptyDrink(); + } + + EnableMarkImage(); _button.interactable = false; } } - public void UpdateCount(int newCount) + public bool CanCraft() { - _countText.text = newCount.ToString(); - } - - public void SetMark(bool registered) - { - //_markImage.sprite = registered ? _checkSprite : _xSprite; - _countText.gameObject.SetActive(false); - _markImage.gameObject.SetActive(true); + return Model.Count > 0; } - public void ClearMark() + public void EnableCountText() { _countText.gameObject.SetActive(true); _markImage.gameObject.SetActive(false); } + + public void EnableMarkImage() + { + // TODO : 추후에 현재 등록된 요리도구와 매칭되는지 체크 + //_markImage.sprite = registered ? _checkSprite : _xSprite; + _countText.gameObject.SetActive(false); + _markImage.gameObject.SetActive(true); + } public void SetEmptyFood() { _icon.sprite = _emptyFoodSprite; _markImage.gameObject.SetActive(false); + _button.interactable = false; } public void SetEmptyDrink() { _icon.sprite = _emptyDrinkSprite; _markImage.gameObject.SetActive(false); + _button.interactable = false; } + + public void SetActive(bool value) => gameObject.SetActive(value); } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/ItemViewModel.cs b/Assets/_DDD/_Scripts/GameUi/New/ItemViewModel.cs index 55830cc9b..acfca3081 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/ItemViewModel.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/ItemViewModel.cs @@ -1,4 +1,3 @@ -using System; using UnityEngine; namespace DDD @@ -10,13 +9,30 @@ public class ItemViewModel public string NameKey; public string DescriptionKey; public Sprite Icon; - public int? Count; - - public Action OnCountChanged; + public int Count; - public void UpdateCount() + public RecipeType RecipeType => ItemType == ItemType.Recipe ? DataManager.Instance.RecipeDataSo.GetDataById(Id).RecipeType : RecipeType.None; + + public void UpdateCount(int newCount) { - OnCountChanged?.Invoke(this); + if (ItemType == ItemType.Recipe) + { + int craftableCount = 0; + if (RecipeType == RecipeType.FoodRecipe) + { + craftableCount = DataManager.Instance.FoodDataSo.GetDataById(Id).GetCraftableCount(); + } + else if (RecipeType == RecipeType.DrinkRecipe) + { + craftableCount = DataManager.Instance.DrinkDataSo.GetDataById(Id).GetCraftableCount(); + } + + Count = craftableCount; + } + else if (ItemType == ItemType.Ingredient) + { + Count = newCount; + } } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/ItemViewModelFactory.cs b/Assets/_DDD/_Scripts/GameUi/New/ItemViewModelFactory.cs index 5a2cbd4ba..969398a19 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/ItemViewModelFactory.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/ItemViewModelFactory.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; @@ -6,7 +5,7 @@ namespace DDD { public static class ItemViewModelFactory { - public static List CreateRestaurantManagementInventoryItem(Func predicate) + public static List CreateRestaurantManagementInventoryItem() { var result = new List(); var recipeDataMap = DataManager.Instance.RecipeDataSo.GetDataList().ToDictionary(r => r.Id, r => r); @@ -18,7 +17,7 @@ public static List CreateRestaurantManagementInventoryItem(Func CreateRestaurantManagementInventoryItem(Func CalculateCraftableCount(item.Id), ItemType.Ingredient => InventoryManager.Instance.GetItemCount(id), - _ => null + _ => 0 } }; @@ -45,6 +44,7 @@ public static List CreateRestaurantManagementInventoryItem(Func CreateRestaurantManagementInventoryItem(Func CreateRestaurantManagementInventoryItem(Func DataManager.Instance.FoodDataSo.TryGetDataById(itemKey, out var food) ? food.GetCraftableCount() : 0, - RecipeType.DrinkRecipe => DataManager.Instance.DrinkDataSo.TryGetDataById(itemKey, out var drink) ? drink.GetCraftableCount() : 0, + RecipeType.FoodRecipe => DataManager.Instance.FoodDataSo.TryGetDataById(itemKey, out var food) + ? food.GetCraftableCount() + : 0, + RecipeType.DrinkRecipe => DataManager.Instance.DrinkDataSo.TryGetDataById(itemKey, out var drink) + ? drink.GetCraftableCount() + : 0, _ => 0 }; } + + public static ItemViewModel CreateByRecipeId(string recipeId) + { + var recipeSo = DataManager.Instance.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, + Icon = DataManager.Instance.GetSprite(recipeId) + }; + + switch (recipe.RecipeType) + { + case RecipeType.FoodRecipe: + if (DataManager.Instance.FoodDataSo.TryGetDataById(recipe.ItemKey, out var food)) + { + model.NameKey = food.NameKey; + model.DescriptionKey = food.DescriptionKey; + } + + break; + case RecipeType.DrinkRecipe: + if (DataManager.Instance.DrinkDataSo.TryGetDataById(recipe.ItemKey, out var drink)) + { + model.NameKey = drink.NameKey; + model.DescriptionKey = drink.DescriptionKey; + } + + break; + } + + return model; + } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuDataSo.cs b/Assets/_DDD/_Scripts/GameUi/New/TodayMenuDataSo.cs deleted file mode 100644 index 8503c794f..000000000 --- a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuDataSo.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.Generic; -using Sirenix.OdinInspector; -using UnityEngine; - -namespace DDD -{ - [CreateAssetMenu(fileName = "TodayMenuDataSo", menuName = "GameState/TodayMenuDataSo")] - public class TodayMenuDataSo : ScriptableObject - { - [ReadOnly, SerializeField] private List _foodRecipeIds = new(); - [ReadOnly, SerializeField] private List _drinkRecipeIds = new(); - - public IReadOnlyList FoodRecipeIds => _foodRecipeIds; - public IReadOnlyList DrinkRecipeIds => _drinkRecipeIds; - - public int MaxFoodCount = 8; - public int MaxDrinkCount = 6; - - public bool TryAddFoodRecipe(string recipeId) - { - if (_foodRecipeIds.Count >= MaxFoodCount || _foodRecipeIds.Contains(recipeId)) - return false; - - _foodRecipeIds.Add(recipeId); - EventBus.Broadcast(RestaurantEvents.TodayMenuChangedEvent); - return true; - } - - public bool TryAddDrinkRecipe(string recipeId) - { - if (_drinkRecipeIds.Count >= MaxDrinkCount || _drinkRecipeIds.Contains(recipeId)) - return false; - - _drinkRecipeIds.Add(recipeId); - EventBus.Broadcast(RestaurantEvents.TodayMenuChangedEvent); - return true; - } - - public bool RemoveRecipe(string recipeId) - { - bool removed = _foodRecipeIds.Remove(recipeId) || _drinkRecipeIds.Remove(recipeId); - if (removed) - { - EventBus.Broadcast(RestaurantEvents.TodayMenuChangedEvent); - } - - return removed; - } - - public bool Contains(string recipeId) => _foodRecipeIds.Contains(recipeId) || _drinkRecipeIds.Contains(recipeId); - } -} \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuInteractor.cs b/Assets/_DDD/_Scripts/GameUi/New/TodayMenuInteractor.cs index 59b0b3386..1f7cefa9c 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuInteractor.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/TodayMenuInteractor.cs @@ -1,21 +1,32 @@ +using System; using System.Threading.Tasks; using UnityEngine; namespace DDD { + public enum TodayMenuEventType + { + None = 0, + Add, + Remove + } + public class TodayMenuInteractor : MonoBehaviour, IInteractableUi { - private ItemSlotUi _slotUi; + private IInventorySlotUi _inventorySlotUi; private TodayMenuDataSo _todayMenuDataSo; private TaskCompletionSource _isInitialized = new(); + private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None; private void Awake() { - _slotUi = GetComponent(); + _inventorySlotUi = GetComponent(); } - private async void Start() + public async void Initialize(TodayMenuEventType todayMenuEventType) { + _todayMenuEventType = todayMenuEventType; + _todayMenuDataSo = await AssetManager.LoadAsset(DataConstants.TodayMenuDataSo); _isInitialized.SetResult(true); } @@ -23,25 +34,40 @@ private async void Start() public async void OnInteract() { await _isInitialized.Task; + + switch (_todayMenuEventType) + { + case TodayMenuEventType.Add: + OnAdded(); + break; + case TodayMenuEventType.Remove: + OnRemoved(); + break; + case TodayMenuEventType.None: + default: + throw new ArgumentOutOfRangeException(); + } + } + + private void OnAdded() + { + if (_inventorySlotUi.CanCraft() == false) + { + var evt = GameEvents.RequestShowGlobalMessageEvent; + // TODO : 테스트용 메세지 추후 삭제 및 변경 + evt.NewMessageKey = "today_menu_added_error_message_001"; + evt.FadeDuration = 0.5f; + evt.ShowDuration = 1f; + EventBus.Broadcast(evt); + return; + } - string recipeId = _slotUi.Model.Id; - if (_todayMenuDataSo.Contains(recipeId)) - { - _todayMenuDataSo.RemoveRecipe(recipeId); - _slotUi.ClearMark(); - } - else - { - var recipe = DataManager.Instance.RecipeDataSo.GetDataById(recipeId); - - bool added = recipe.RecipeType switch - { - RecipeType.FoodRecipe => _todayMenuDataSo.TryAddFoodRecipe(recipeId), - RecipeType.DrinkRecipe => _todayMenuDataSo.TryAddDrinkRecipe(recipeId), - _ => false - }; - } + _todayMenuDataSo.TryAddTodayMenu(_inventorySlotUi); + } + private void OnRemoved() + { + _todayMenuDataSo.TryRemoveTodayMenu(_inventorySlotUi); } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuView.cs b/Assets/_DDD/_Scripts/GameUi/New/TodayMenuView.cs index 4926ddd47..811429e69 100644 --- a/Assets/_DDD/_Scripts/GameUi/New/TodayMenuView.cs +++ b/Assets/_DDD/_Scripts/GameUi/New/TodayMenuView.cs @@ -3,117 +3,111 @@ namespace DDD { - public class TodayMenuView : MonoBehaviour, IEventHandler + public class TodayMenuView : MonoBehaviour, IEventHandler, IEventHandler { [SerializeField] private GameObject _slotPrefab; - + [SerializeField] private Transform _todayFoodContent; [SerializeField] private Transform _todayDrinkContent; - - private List _foodSlots; - private List _drinkSlots; + + private List _foodSlots; + private List _drinkSlots; private TodayMenuDataSo _todayMenuDataSo; private async void Start() { - EventBus.Register(this); - + EventBus.Register(this); + EventBus.Register(this); + _todayMenuDataSo = await AssetManager.LoadAsset(DataConstants.TodayMenuDataSo); - + foreach (Transform child in _todayFoodContent) { Destroy(child.gameObject); } int maxFoodCount = _todayMenuDataSo.MaxFoodCount; - _foodSlots = new List(maxFoodCount); + _foodSlots = new List(maxFoodCount); for (int i = 0; i < _todayMenuDataSo.MaxFoodCount; i++) { var go = Instantiate(_slotPrefab, _todayFoodContent); - var slot = go.GetComponent(); - slot.Initialize(null); - slot.SetEmptyFood(); + var slot = go.GetComponent(); + slot.Initialize(null, RecipeType.FoodRecipe); + var todayMenuInteractor = go.GetComponent(); + todayMenuInteractor.Initialize(TodayMenuEventType.Remove); + _foodSlots.Add(slot); } - + foreach (Transform child in _todayDrinkContent) { Destroy(child.gameObject); } - + int maxDrinkCount = _todayMenuDataSo.MaxDrinkCount; - _drinkSlots = new List(maxDrinkCount); + _drinkSlots = new List(maxDrinkCount); for (int i = 0; i < _todayMenuDataSo.MaxDrinkCount; i++) { var go = Instantiate(_slotPrefab, _todayDrinkContent); - var slot = go.GetComponent(); - slot.Initialize(null); - slot.SetEmptyDrink(); + var slot = go.GetComponent(); + slot.Initialize(null, RecipeType.DrinkRecipe); + var todayMenuInteractor = go.GetComponent(); + todayMenuInteractor.Initialize(TodayMenuEventType.Remove); + _drinkSlots.Add(slot); } - - //RefreshView(); + + UpdateView(); } private void OnDestroy() { - EventBus.Unregister(this); + EventBus.Unregister(this); + EventBus.Unregister(this); } - public void Invoke(TodayMenuChangedEvent evt) => RefreshView(); + public void Invoke(TodayMenuAddedEvent evt) + { + UpdateView(); + } - private void RefreshView() + public void Invoke(TodayMenuRemovedEvent evt) + { + UpdateView(); + } + + private void UpdateView() { for (int i = 0; i < _foodSlots.Count; i++) { if (i < _todayMenuDataSo.FoodRecipeIds.Count) { string recipeId = _todayMenuDataSo.FoodRecipeIds[i]; - var recipe = DataManager.Instance.RecipeDataSo.GetDataById(recipeId); - var item = InventoryManager.Instance.GetItemDataByIdOrNull(recipeId); - - var model = new ItemViewModel - { - Id = recipeId, - Icon = DataManager.Instance.GetSprite(recipeId), - ItemType = item.ItemType, - NameKey = DataManager.Instance.FoodDataSo.GetDataById(recipe.ItemKey).NameKey, - DescriptionKey = DataManager.Instance.FoodDataSo.GetDataById(recipe.ItemKey).DescriptionKey - }; + var model = ItemViewModelFactory.CreateByRecipeId(recipeId); _foodSlots[i].Initialize(model); - //_foodSlots[i].SetMark(true); // 등록 상태 마크 + _foodSlots[i].SetActive(true); } else { - //_foodSlots[i].gameObject.SetActive(false); // 또는 Clear() + _foodSlots[i].Initialize(null, RecipeType.FoodRecipe); } } - + for (int i = 0; i < _drinkSlots.Count; i++) { if (i < _todayMenuDataSo.DrinkRecipeIds.Count) { string recipeId = _todayMenuDataSo.DrinkRecipeIds[i]; - var recipe = DataManager.Instance.RecipeDataSo.GetDataById(recipeId); - var item = InventoryManager.Instance.GetItemDataByIdOrNull(recipeId); - - var model = new ItemViewModel - { - Id = recipeId, - Icon = DataManager.Instance.GetSprite(recipeId), - ItemType = item.ItemType, - NameKey = DataManager.Instance.DrinkDataSo.GetDataById(recipe.ItemKey).NameKey, - DescriptionKey = DataManager.Instance.DrinkDataSo.GetDataById(recipe.ItemKey).DescriptionKey - }; + var model = ItemViewModelFactory.CreateByRecipeId(recipeId); _drinkSlots[i].Initialize(model); - //_drinkSlots[i].SetMark(true); + _drinkSlots[i].SetActive(true); } else { - //_drinkSlots[i].gameObject.SetActive(false); + _drinkSlots[i].Initialize(null, RecipeType.DrinkRecipe); } } } diff --git a/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi.cs b/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi.cs index afcd7ad85..f92b738b5 100644 --- a/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi.cs +++ b/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi.cs @@ -15,6 +15,7 @@ public override void Open() { base.Open(); + _ = _inventoryView.Initialize(); _sectionTabs.Initialize(OnSectionTabSelected); _categoryTabs.Initialize(OnCategoryTabSelected); } @@ -69,32 +70,12 @@ private void HandleInteract2() private void OnSectionTabSelected(RestaurantManagementSectionType section) { - // 추후 Menu, Cookware, Worker에 맞춰 다른 콘텐츠 노출 처리 + // TODO : 추후 Menu, Cookware, Worker에 맞춰 다른 콘텐츠 노출 처리 } private void OnCategoryTabSelected(InventoryCategoryType category) { - _inventoryView.ShowItems(itemData => - { - switch (category) - { - case InventoryCategoryType.Food: - case InventoryCategoryType.Drink: - if (itemData.ItemType != ItemType.Recipe) return false; - - RecipeType recipeType = DataManager.Instance.RecipeDataSo.GetDataById(itemData.Id).RecipeType; - return category switch - { - InventoryCategoryType.Food => recipeType == RecipeType.FoodRecipe, - InventoryCategoryType.Drink => recipeType == RecipeType.DrinkRecipe, - _ => false - }; - case InventoryCategoryType.Ingredient: - return itemData.ItemType == ItemType.Ingredient; - default: - return false; - } - }); + _inventoryView.UpdateCategoryView(category); } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/RestaurantController/RestaurantController.cs b/Assets/_DDD/_Scripts/RestaurantController/RestaurantController.cs index 8ae2f2757..a2cfb2194 100644 --- a/Assets/_DDD/_Scripts/RestaurantController/RestaurantController.cs +++ b/Assets/_DDD/_Scripts/RestaurantController/RestaurantController.cs @@ -62,11 +62,13 @@ public async Task OnReadyNewFlow(GameFlowState newFlowState) { CreateRestaurantPlayerSo createRestaurantPlayerSoJob = await AssetManager.LoadAsset(CreateRestaurantPlayerSo); CreateEnvironmentSo createEnvironmentSoJob = await AssetManager.LoadAsset(CreateEnvironmentSo); + TodayMenuDataSo todayMenuDataSo = await AssetManager.LoadAsset(DataConstants.TodayMenuDataSo); var playerHandle = createRestaurantPlayerSoJob.OnReadyNewFlow(newFlowState); var propHandle = createEnvironmentSoJob.OnReadyNewFlow(newFlowState); + var todayMenuHandle = todayMenuDataSo.OnReadyNewFlow(newFlowState); // Combine handles and return it InputManager.Instance.SwitchCurrentActionMap(InputActionMaps.Restaurant); - await Task.WhenAll(playerHandle, propHandle); + await Task.WhenAll(playerHandle, propHandle, todayMenuHandle); } } } diff --git a/ProjectSettings/Packages/com.unity.probuilder/Settings.json b/ProjectSettings/Packages/com.unity.probuilder/Settings.json index 9ee59ba50..b414217a2 100644 --- a/ProjectSettings/Packages/com.unity.probuilder/Settings.json +++ b/ProjectSettings/Packages/com.unity.probuilder/Settings.json @@ -19,12 +19,12 @@ { "type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "key": "about.identifier", - "value": "{\"m_Value\":{\"m_Major\":6,\"m_Minor\":0,\"m_Patch\":5,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}" + "value": "{\"m_Value\":{\"m_Major\":6,\"m_Minor\":0,\"m_Patch\":6,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}" }, { "type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "key": "preferences.version", - "value": "{\"m_Value\":{\"m_Major\":6,\"m_Minor\":0,\"m_Patch\":5,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}" + "value": "{\"m_Value\":{\"m_Major\":6,\"m_Minor\":0,\"m_Patch\":6,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}" }, { "type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",