ProjectDDD/Assets/_DDD/_Scripts/GameUi/New/ItemSlotUi.cs

89 lines
2.7 KiB
C#
Raw Normal View History

2025-07-25 07:58:53 +00:00
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; }
2025-07-27 19:32:41 +00:00
public void Initialize(ItemViewModel model, RecipeType recipeType = RecipeType.None)
2025-07-25 07:58:53 +00:00
{
Model = model;
2025-07-27 19:32:41 +00:00
_button.onClick.RemoveAllListeners();
2025-07-25 07:58:53 +00:00
_button.onClick.AddListener(() =>
{
RestaurantEvents.ItemSlotSelectedEvent.Model = Model;
EventBus.Broadcast(RestaurantEvents.ItemSlotSelectedEvent);
});
if (model != null)
{
_icon.sprite = model.Icon;
2025-07-27 19:32:41 +00:00
_countText.text = model.Count.ToString();
EnableCountText();
2025-07-25 07:58:53 +00:00
_button.interactable = true;
}
else
{
2025-07-27 19:32:41 +00:00
if (recipeType == RecipeType.FoodRecipe)
{
SetEmptyFood();
}
else if (recipeType == RecipeType.DrinkRecipe)
{
SetEmptyDrink();
}
EnableMarkImage();
2025-07-25 07:58:53 +00:00
_button.interactable = false;
}
}
2025-07-27 19:32:41 +00:00
public bool CanCraft()
2025-07-25 07:58:53 +00:00
{
2025-07-27 19:32:41 +00:00
return Model.Count > 0;
}
public void EnableCountText()
{
_countText.gameObject.SetActive(true);
_markImage.gameObject.SetActive(false);
2025-07-25 07:58:53 +00:00
}
2025-07-27 19:32:41 +00:00
public void EnableMarkImage()
2025-07-25 07:58:53 +00:00
{
2025-07-27 19:32:41 +00:00
// TODO : 추후에 현재 등록된 요리도구와 매칭되는지 체크
2025-07-25 07:58:53 +00:00
//_markImage.sprite = registered ? _checkSprite : _xSprite;
_countText.gameObject.SetActive(false);
_markImage.gameObject.SetActive(true);
}
public void SetEmptyFood()
{
_icon.sprite = _emptyFoodSprite;
_markImage.gameObject.SetActive(false);
2025-07-27 19:32:41 +00:00
_button.interactable = false;
2025-07-25 07:58:53 +00:00
}
public void SetEmptyDrink()
{
_icon.sprite = _emptyDrinkSprite;
_markImage.gameObject.SetActive(false);
2025-07-27 19:32:41 +00:00
_button.interactable = false;
2025-07-25 07:58:53 +00:00
}
2025-07-27 19:32:41 +00:00
public void SetActive(bool value) => gameObject.SetActive(value);
2025-07-25 07:58:53 +00:00
}
}