253 lines
6.3 KiB
C#
253 lines
6.3 KiB
C#
using System;
|
|
using BlueWater.Items;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public enum InventorySortingType
|
|
{
|
|
None = 0,
|
|
PriceUp,
|
|
PriceDown,
|
|
TypeUp,
|
|
TypeDown,
|
|
IngredientTypeUp,
|
|
IngredientTypeDown,
|
|
NameUp,
|
|
NameDown,
|
|
AcquisitionTimeUp,
|
|
AcquisitionTimeDown
|
|
}
|
|
|
|
public enum InventoryFilterSortingType
|
|
{
|
|
None = 0,
|
|
Total,
|
|
Ingredient
|
|
}
|
|
|
|
public enum FoodSortingType
|
|
{
|
|
None = 0,
|
|
PriceUp,
|
|
PriceDown,
|
|
CookwareTypeUp,
|
|
CookwareTypeDown,
|
|
TasteUp,
|
|
TasteDown,
|
|
NameUp,
|
|
NameDown
|
|
}
|
|
|
|
public class TycoonItemSlotUi : MonoBehaviour
|
|
{
|
|
[Title("컴포넌트")]
|
|
[SerializeField, Required]
|
|
protected Button Button;
|
|
|
|
[SerializeField, Required]
|
|
protected Image BackgroundImage;
|
|
|
|
[SerializeField, Required]
|
|
protected Image ItemImage;
|
|
|
|
[SerializeField, Required]
|
|
protected TMP_Text QuantityText;
|
|
|
|
[Title("옵션")]
|
|
[SerializeField]
|
|
protected bool IsUsingBackgroundColor;
|
|
|
|
[SerializeField]
|
|
protected bool IsUsingQuantityText;
|
|
|
|
[SerializeField]
|
|
protected bool IsLocked;
|
|
|
|
[SerializeField]
|
|
protected bool IsButtonInteraction;
|
|
|
|
[field: Title("현재 아이템 데이터")]
|
|
[field: SerializeField]
|
|
public ItemSlot ItemSlot { get; protected set; }
|
|
|
|
[field: SerializeField]
|
|
public FoodData FoodData { get; protected set; }
|
|
|
|
protected ItemManager ItemManager;
|
|
protected UnityAction ClickAction;
|
|
|
|
private void Awake()
|
|
{
|
|
ItemManager = ItemManager.Instance;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (IsUsingBackgroundColor)
|
|
{
|
|
UseBackgroundColor();
|
|
}
|
|
else
|
|
{
|
|
DisuseBackgroundColor();
|
|
}
|
|
|
|
if (IsUsingQuantityText)
|
|
{
|
|
UseQuantityText();
|
|
}
|
|
else
|
|
{
|
|
DisuseQuantityText();
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (ClickAction != null)
|
|
{
|
|
Button.onClick.RemoveListener(ClickAction);
|
|
}
|
|
}
|
|
|
|
public void AddButtonClickListener(UnityAction action)
|
|
{
|
|
Button.onClick.AddListener(action);
|
|
}
|
|
|
|
// Background Color
|
|
public void UseBackgroundColor()
|
|
{
|
|
var itemSlotDataSo = ItemManager.ItemSlotDataSo;
|
|
var newColor = Color.white;
|
|
|
|
switch (FoodData.Type)
|
|
{
|
|
case FoodType.None:
|
|
break;
|
|
case FoodType.Skewer:
|
|
newColor = itemSlotDataSo.SkewerPanFood;
|
|
break;
|
|
case FoodType.Soup:
|
|
newColor = itemSlotDataSo.SoupFood;
|
|
break;
|
|
case FoodType.Grill:
|
|
newColor = itemSlotDataSo.GrillFood;
|
|
break;
|
|
case FoodType.Dessert:
|
|
newColor = itemSlotDataSo.DessertFood;
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
BackgroundImage.color = newColor;
|
|
BackgroundImage.enabled = true;
|
|
}
|
|
|
|
public void DisuseBackgroundColor()
|
|
{
|
|
BackgroundImage.enabled = false;
|
|
BackgroundImage.color = Color.white;
|
|
}
|
|
|
|
// Quantity Text
|
|
public void UseQuantityText()
|
|
{
|
|
QuantityText.enabled = true;
|
|
}
|
|
|
|
public void DisuseQuantityText()
|
|
{
|
|
QuantityText.enabled = false;
|
|
}
|
|
|
|
public virtual void SetItemSlot(ItemSlot itemSlot)
|
|
{
|
|
if (IsLocked)
|
|
{
|
|
SetItemImage(ItemManager.ItemSlotDataSo.LockSprite);
|
|
if (IsUsingQuantityText)
|
|
{
|
|
QuantityText.text = null;
|
|
}
|
|
return;
|
|
}
|
|
|
|
ItemSlot = itemSlot;
|
|
ItemManager ??= ItemManager.Instance;
|
|
|
|
if (ItemSlot == null)
|
|
{
|
|
SetItemImage(null);
|
|
QuantityText.text = null;
|
|
}
|
|
else
|
|
{
|
|
SetItemImage(ItemManager.ItemDataSo.GetDataByIdx(ItemSlot.Idx).Sprite);
|
|
QuantityText.text = ItemSlot.Quantity.ToString();
|
|
}
|
|
}
|
|
|
|
public void SetFoodData(FoodData foodData)
|
|
{
|
|
if (IsLocked)
|
|
{
|
|
SetItemImage(ItemManager.ItemSlotDataSo.LockSprite);
|
|
if (IsUsingQuantityText)
|
|
{
|
|
QuantityText.text = null;
|
|
}
|
|
return;
|
|
}
|
|
|
|
FoodData = foodData;
|
|
ItemManager ??= ItemManager.Instance;
|
|
|
|
if (FoodData == null)
|
|
{
|
|
SetItemImage(null);
|
|
if (IsUsingBackgroundColor)
|
|
{
|
|
DisuseBackgroundColor();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SetItemImage(ItemManager.ItemDataSo.GetDataByIdx(FoodData.Idx).Sprite);
|
|
if (IsUsingBackgroundColor)
|
|
{
|
|
UseBackgroundColor();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetItemImage(Sprite sprite)
|
|
{
|
|
ItemImage.sprite = sprite;
|
|
ItemImage.enabled = ItemImage.sprite;
|
|
|
|
if (IsButtonInteraction)
|
|
{
|
|
if (!IsLocked && ItemImage.sprite)
|
|
{
|
|
Button.interactable = true;
|
|
}
|
|
else
|
|
{
|
|
Button.interactable = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool GetIsLocked() => IsLocked;
|
|
public void SetIsLocked(bool value) => IsLocked = value;
|
|
public void ShowUi() => gameObject.SetActive(true);
|
|
public void HideUi() => gameObject.SetActive(false);
|
|
}
|
|
} |