// using System; // using System.Collections.Generic; // using BlueWater.Items; // using Sirenix.OdinInspector; // using TMPro; // using UnityEngine; // using UnityEngine.UI; // // namespace BlueWater.Uis // { // public class CookUi : MonoBehaviour // { // [Title("컴포넌트")] // [SerializeField, Required] // private Image _selectedFoodImage; // // [SerializeField, Required] // private TMP_Text _selectedFoodName; // // [SerializeField, Required] // private TMP_Text _selectedFoodTasteText; // // [SerializeField, Required] // private TMP_Dropdown _finishedFoodSortDropdown; // // [SerializeField, Required] // private Button _cookButton; // // [SerializeField, Required] // private TMP_Text _cookText; // // [Title("프리팹 생성 위치")] // [SerializeField, Required] // private Transform _finishedFoodSlotLocation; // // [SerializeField, Required] // private Transform _ingredientFoodSlotLocation; // // [Title("프리팹")] // [SerializeField, Required] // private TycoonItemSlotUi _finishedFoodSlotUi; // // [SerializeField, Required] // private IngredientItemSlotUi _ingredientItemSlotUi; // // private List _finishedFoodSlotUis; // private List _highIngredientSlotUis; // private List _normalIngredientSlotUis; // // private DataManager _dataManager; // private ItemManager _itemManager; // private DailyFoodMenuUi _dailyFoodMenuUi; // private FoodData _selectedFoodData; // private bool _isEnoughIngredient; // // private void Awake() // { // Initialize(); // InventorySynchronization(); // SelectFinishedFood(null); // } // // private void Start() // { // //TycoonEvents.OnFoodRecipeAcquired += AddFoodRecipe; // _dataManager.Inventory.OnChangeItemSlot += OnInventoryChange; // } // // private void OnDestroy() // { // //TycoonEvents.OnFoodRecipeAcquired -= AddFoodRecipe; // _dataManager.Inventory.OnChangeItemSlot -= OnInventoryChange; // } // // private void Initialize() // { // _dataManager = DataManager.Instance; // _itemManager = ItemManager.Instance; // _dailyFoodMenuUi = TycoonUiManager.Instance.TycoonManagementUi.CookMenuUi.DailyFoodMenuUi; // // _finishedFoodSlotUis = new List(); // foreach (Transform element in _finishedFoodSlotLocation) // { // Destroy(element.gameObject); // } // // _highIngredientSlotUis = new List(5); // _normalIngredientSlotUis = new List(5); // foreach (Transform element in _ingredientFoodSlotLocation) // { // Destroy(element.gameObject); // } // // for (var i = 0; i < 10; i++) // { // var newItemSlot = Instantiate(_ingredientItemSlotUi, _ingredientFoodSlotLocation).GetComponent(); // // if (i < 5) // { // _highIngredientSlotUis.Add(newItemSlot); // _highIngredientSlotUis[i].SetIsLocked(true); // } // else // { // _normalIngredientSlotUis.Add(newItemSlot); // } // newItemSlot.SetItemSlot(null); // } // // CheckCookable(); // } // // private void InventorySynchronization() // { // foreach (var element in _dataManager.TycoonData.FoodRecipes) // { // var newItemSlot = Instantiate(_finishedFoodSlotUi, _finishedFoodSlotLocation).GetComponent(); // var foodData = _itemManager.FoodDataSo.GetDataByIdx(element); // newItemSlot.SetFoodData(foodData); // _finishedFoodSlotUis.Add(newItemSlot); // newItemSlot.AddButtonClickListener(() => SelectFinishedFood(foodData)); // } // } // // private void AddFoodRecipe(string idx) // { // var foodData = _itemManager.FoodDataSo.GetDataByIdx(idx); // var newItemSlot = Instantiate(_finishedFoodSlotUi, _finishedFoodSlotLocation).GetComponent(); // newItemSlot.SetFoodData(foodData); // _finishedFoodSlotUis.Add(newItemSlot); // newItemSlot.AddButtonClickListener(() => SelectFinishedFood(foodData)); // } // // private void OnInventoryChange(ItemSlot itemSlot, bool isAdded) // { // UpdateIngredientSlots(); // } // // private void UpdateIngredientSlots() // { // if (_selectedFoodData == null) return; // // SetIngredient(_selectedFoodData); // } // // private void SelectFinishedFood(FoodData foodData) // { // if (foodData == null) // { // _selectedFoodImage.enabled = false; // _selectedFoodImage.sprite = null; // _selectedFoodName.text = null; // _selectedFoodTasteText.text = null; // SetIngredient(null); // } // else // { // _selectedFoodData = foodData; // _selectedFoodImage.sprite = _itemManager.ItemDataSo.GetDataByIdx(_selectedFoodData.Idx).Sprite; // _selectedFoodName.text = _selectedFoodData.Name; // _selectedFoodTasteText.text = _selectedFoodData.TasteToString(); // _selectedFoodImage.enabled = true; // SetIngredient(_selectedFoodData); // } // } // // private void SetIngredient(FoodData foodData) // { // if (foodData == null) // { // for (var i = 0; i < 5; i++) // { // _normalIngredientSlotUis[i].SetItemSlot(null); // } // CheckCookable(); // return; // } // // var ingredients = foodData.GetValidIngredients(); // var ingredientCount = ingredients.Count; // for (var i = 0; i < 5; i++) // { // if (i < ingredientCount) // { // _normalIngredientSlotUis[i].SetItemSlot(new ItemSlot(ingredients[i].Idx, ingredients[i].Quantity)); // } // else // { // _normalIngredientSlotUis[i].SetItemSlot(null); // } // } // // CheckCookable(); // } // // public void CheckCookable() // { // if (_selectedFoodData == null || string.IsNullOrEmpty(_selectedFoodData.Idx)) // { // _cookButton.interactable = false; // _cookText.color = _cookButton.colors.disabledColor; // return; // } // // if (!_dailyFoodMenuUi.IsEmptyDailyFoodMenu(_selectedFoodData)) // { // _cookButton.interactable = false; // _cookText.color = _cookButton.colors.disabledColor; // return; // } // // var ingredientCount = _selectedFoodData.GetValidIngredients().Count; // for (var i = 0; i < ingredientCount; i++) // { // if (_normalIngredientSlotUis[i].IsEnoughIngredient) continue; // // _cookButton.interactable = false; // _cookText.color = _cookButton.colors.disabledColor; // return; // } // // _cookButton.interactable = true; // _cookText.color = Color.black; // } // // public void Cook() // { // foreach (var element in _selectedFoodData.GetValidIngredients()) // { // var itemSlot = _dataManager.Inventory.GetItemByIdx(element.Idx); // _dataManager.Inventory.RemoveItem(itemSlot, element.Quantity); // } // // _dailyFoodMenuUi.AddDailyFoodMenu(_selectedFoodData); // CheckCookable(); // } // // public void SortButton() // { // if (_finishedFoodSortDropdown.value == 0) return; // // SortItemSlotUi((FoodSortingType)_finishedFoodSortDropdown.value); // // _finishedFoodSortDropdown.value = 0; // } // // private void SortItemSlotUi(FoodSortingType sortingType) // { // switch (sortingType) // { // case FoodSortingType.None: // return; // case FoodSortingType.PriceUp: // _finishedFoodSlotUis.Sort((x, y) => // _itemManager.ItemDataSo.GetDataByIdx(x.FoodData.Idx).Price. // CompareTo(_itemManager.ItemDataSo.GetDataByIdx(y.FoodData.Idx).Price)); // break; // case FoodSortingType.PriceDown: // _finishedFoodSlotUis.Sort((x, y) => // _itemManager.ItemDataSo.GetDataByIdx(y.FoodData.Idx).Price. // CompareTo(_itemManager.ItemDataSo.GetDataByIdx(x.FoodData.Idx).Price)); // break; // case FoodSortingType.CookwareTypeUp: // _finishedFoodSlotUis.Sort((x, y) => // x.FoodData.Type. // CompareTo(y.FoodData.Type)); // break; // case FoodSortingType.CookwareTypeDown: // _finishedFoodSlotUis.Sort((x, y) => // y.FoodData.Type. // CompareTo(x.FoodData.Type)); // break; // case FoodSortingType.TasteUp: // _finishedFoodSlotUis.Sort((x, y) => // x.FoodData.Taste. // CompareTo(y.FoodData.Taste)); // break; // case FoodSortingType.TasteDown: // _finishedFoodSlotUis.Sort((x, y) => // y.FoodData.Taste. // CompareTo(x.FoodData.Taste)); // break; // case FoodSortingType.NameUp: // _finishedFoodSlotUis.Sort((x, y) => // string.Compare(x.FoodData.Name, y.FoodData.Name, StringComparison.Ordinal)); // break; // case FoodSortingType.NameDown: // _finishedFoodSlotUis.Sort((x, y) => // string.Compare(y.FoodData.Name, x.FoodData.Name, StringComparison.Ordinal)); // break; // default: // throw new ArgumentOutOfRangeException(); // } // // for (var i = 0; i < _finishedFoodSlotUis.Count; i++) // { // _finishedFoodSlotUis[i].transform.SetSiblingIndex(i); // } // } // // public void TycoonClosed() // { // SelectFinishedFood(null); // } // } // }