using TMPro; using UnityEngine; using UnityEngine.UI; namespace DDD { public class ItemSlotUi : MonoBehaviour, IInventorySlotUi { [SerializeField] private Button _button; [SerializeField] private Image _icon; [SerializeField] private TextMeshProUGUI _countText; [SerializeField] private Image _markImage; [SerializeField] private Sprite _checkSprite; [SerializeField] private Sprite _xSprite; [SerializeField] private Sprite _emptyFoodSprite; [SerializeField] private Sprite _emptyDrinkSprite; public ItemViewModel Model { get; private set; } public void Initialize(ItemViewModel model, RecipeType recipeType = RecipeType.None) { Model = model; _button.onClick.RemoveAllListeners(); _button.onClick.AddListener(() => { RestaurantEvents.ItemSlotSelectedEvent.Model = Model; EventBus.Broadcast(RestaurantEvents.ItemSlotSelectedEvent); }); if (Model != null) { SetIcon(); _countText.text = model.Count.ToString(); EnableCountText(); _button.interactable = true; } else { if (recipeType == RecipeType.FoodRecipe) { SetEmptyFood(); } else if (recipeType == RecipeType.DrinkRecipe) { SetEmptyDrink(); } _countText.gameObject.SetActive(false); _button.interactable = false; } } public bool CanCraft() { return Model.Count > 0; } 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 SetIcon() { string iconKey = null; if (Model.ItemType == ItemType.Recipe) { if (Model.RecipeType == RecipeType.FoodRecipe) { iconKey = DataManager.Instance.FoodDataSo.GetDataById(Model.GetItemKey).SpriteKey; } else if (Model.RecipeType == RecipeType.DrinkRecipe) { iconKey = DataManager.Instance.DrinkDataSo.GetDataById(Model.GetItemKey).SpriteKey; } } else if (Model.ItemType == ItemType.Ingredient) { iconKey = DataManager.Instance.IngredientDataSo.GetDataById(Model.Id).SpriteKey; } _icon.sprite = DataManager.Instance.GetSprite(iconKey); } 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); } }