[Fix] Code visual
This commit is contained in:
@@ -6,87 +6,86 @@ using YachtDice.Modifiers;
|
||||
|
||||
namespace YachtDice.Shop
|
||||
{
|
||||
|
||||
public sealed class ShopItemView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image iconImage;
|
||||
[SerializeField] private TMP_Text nameText;
|
||||
[SerializeField] private TMP_Text descriptionText;
|
||||
[SerializeField] private TMP_Text priceText;
|
||||
[SerializeField] private TMP_Text rarityText;
|
||||
[SerializeField] private Button buyButton;
|
||||
[SerializeField] private TMP_Text buyButtonText;
|
||||
[SerializeField] private Image background;
|
||||
|
||||
[Header("Rarity Colors")]
|
||||
[SerializeField] private Color commonColor = Color.white;
|
||||
[SerializeField] private Color uncommonColor = new(0.4f, 0.8f, 0.4f);
|
||||
[SerializeField] private Color rareColor = new(0.4f, 0.6f, 1f);
|
||||
[SerializeField] private Color epicColor = new(0.8f, 0.4f, 1f);
|
||||
|
||||
private ModifierData data;
|
||||
|
||||
public event Action<ModifierData> OnBuyClicked;
|
||||
|
||||
private void Awake()
|
||||
public class ShopItemView : MonoBehaviour
|
||||
{
|
||||
if (buyButton != null)
|
||||
buyButton.onClick.AddListener(() => OnBuyClicked?.Invoke(data));
|
||||
}
|
||||
[SerializeField] private Image iconImage;
|
||||
[SerializeField] private TMP_Text nameText;
|
||||
[SerializeField] private TMP_Text descriptionText;
|
||||
[SerializeField] private TMP_Text priceText;
|
||||
[SerializeField] private TMP_Text rarityText;
|
||||
[SerializeField] private Button buyButton;
|
||||
[SerializeField] private TMP_Text buyButtonText;
|
||||
[SerializeField] private Image background;
|
||||
|
||||
public void Setup(ModifierData modifierData, ShopItemState state)
|
||||
{
|
||||
data = modifierData;
|
||||
[Header("Rarity Colors")]
|
||||
[SerializeField] private Color commonColor = Color.white;
|
||||
[SerializeField] private Color uncommonColor = new(0.4f, 0.8f, 0.4f);
|
||||
[SerializeField] private Color rareColor = new(0.4f, 0.6f, 1f);
|
||||
[SerializeField] private Color epicColor = new(0.8f, 0.4f, 1f);
|
||||
|
||||
if (nameText != null) nameText.text = data.DisplayName;
|
||||
if (descriptionText != null) descriptionText.text = data.Description;
|
||||
if (priceText != null) priceText.text = data.ShopPrice.ToString();
|
||||
if (iconImage != null && data.Icon != null) iconImage.sprite = data.Icon;
|
||||
private ModifierData data;
|
||||
|
||||
if (rarityText != null)
|
||||
public event Action<ModifierData> OnBuyClicked;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rarityText.text = data.Rarity.ToString();
|
||||
rarityText.color = GetRarityColor(data.Rarity);
|
||||
if (buyButton != null)
|
||||
buyButton.onClick.AddListener(() => OnBuyClicked?.Invoke(data));
|
||||
}
|
||||
|
||||
SetState(state);
|
||||
}
|
||||
|
||||
public void SetState(ShopItemState state)
|
||||
{
|
||||
if (buyButton == null) return;
|
||||
|
||||
switch (state)
|
||||
public void Setup(ModifierData modifierData, ShopItemState state)
|
||||
{
|
||||
case ShopItemState.Available:
|
||||
buyButton.interactable = true;
|
||||
if (buyButtonText != null) buyButtonText.text = "Buy";
|
||||
break;
|
||||
case ShopItemState.RepurchaseAvailable:
|
||||
buyButton.interactable = true;
|
||||
if (buyButtonText != null) buyButtonText.text = "Buy";
|
||||
break;
|
||||
case ShopItemState.TooExpensive:
|
||||
buyButton.interactable = false;
|
||||
if (buyButtonText != null) buyButtonText.text = "Buy";
|
||||
break;
|
||||
case ShopItemState.Owned:
|
||||
buyButton.interactable = false;
|
||||
if (buyButtonText != null) buyButtonText.text = "Owned";
|
||||
break;
|
||||
data = modifierData;
|
||||
|
||||
if (nameText != null) nameText.text = data.DisplayName;
|
||||
if (descriptionText != null) descriptionText.text = data.Description;
|
||||
if (priceText != null) priceText.text = data.ShopPrice.ToString();
|
||||
if (iconImage != null && data.Icon != null) iconImage.sprite = data.Icon;
|
||||
|
||||
if (rarityText != null)
|
||||
{
|
||||
rarityText.text = data.Rarity.ToString();
|
||||
rarityText.color = GetRarityColor(data.Rarity);
|
||||
}
|
||||
|
||||
SetState(state);
|
||||
}
|
||||
|
||||
public void SetState(ShopItemState state)
|
||||
{
|
||||
if (buyButton == null) return;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ShopItemState.Available:
|
||||
buyButton.interactable = true;
|
||||
if (buyButtonText != null) buyButtonText.text = "Buy";
|
||||
break;
|
||||
case ShopItemState.RepurchaseAvailable:
|
||||
buyButton.interactable = true;
|
||||
if (buyButtonText != null) buyButtonText.text = "Buy";
|
||||
break;
|
||||
case ShopItemState.TooExpensive:
|
||||
buyButton.interactable = false;
|
||||
if (buyButtonText != null) buyButtonText.text = "Buy";
|
||||
break;
|
||||
case ShopItemState.Owned:
|
||||
buyButton.interactable = false;
|
||||
if (buyButtonText != null) buyButtonText.text = "Owned";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetRarityColor(ModifierRarity rarity)
|
||||
{
|
||||
return rarity switch
|
||||
{
|
||||
ModifierRarity.Common => commonColor,
|
||||
ModifierRarity.Uncommon => uncommonColor,
|
||||
ModifierRarity.Rare => rareColor,
|
||||
ModifierRarity.Epic => epicColor,
|
||||
_ => commonColor
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetRarityColor(ModifierRarity rarity)
|
||||
{
|
||||
return rarity switch
|
||||
{
|
||||
ModifierRarity.Common => commonColor,
|
||||
ModifierRarity.Uncommon => uncommonColor,
|
||||
ModifierRarity.Rare => rareColor,
|
||||
ModifierRarity.Epic => epicColor,
|
||||
_ => commonColor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user