fcceb0ce45
Generalize the shop from selling only ModifierDefinition to any IShopItem (modifiers + dice). Add purchase condition checks, hover tooltips, and fixed prices. Introduce PlayerModel as a facade over CurrencyBank, InventoryModel, and DiceCollection for centralized state and save/load. New files: - IShopItem interface for purchasable items - ShopCatalog SO (unified catalog for all item types) - ShopTooltipView (description on hover) - PlayerModel (aggregates player state) - DiceCollection (owned dice tracking) - DiceCatalog SO (dice definition registry) - DiceCollectionTests Modified: - ModifierDefinition/DieDefinitionSO implement IShopItem - ShopModel/ShopView/ShopItemView/ShopController use IShopItem - SaveData v3 with OwnedDiceIds - GameController uses PlayerModel for save/load - GameLifetimeScope registers new services Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
114 lines
3.9 KiB
C#
114 lines
3.9 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using YachtDice.Modifiers.Core;
|
|
using YachtDice.Modifiers.Definition;
|
|
|
|
namespace YachtDice.Shop
|
|
{
|
|
public class ShopItemView : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[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 IShopItem data;
|
|
|
|
public event Action<IShopItem> OnBuyClicked;
|
|
public event Action<IShopItem, RectTransform> OnHoverEnter;
|
|
public event Action OnHoverExit;
|
|
|
|
private void Awake()
|
|
{
|
|
if (buyButton != null)
|
|
buyButton.onClick.AddListener(() => OnBuyClicked?.Invoke(data));
|
|
}
|
|
|
|
public void Setup(IShopItem item, ShopItemState state)
|
|
{
|
|
data = item;
|
|
|
|
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)
|
|
{
|
|
if (data is ModifierDefinition mod)
|
|
{
|
|
rarityText.gameObject.SetActive(true);
|
|
rarityText.text = mod.Rarity.ToString();
|
|
rarityText.color = GetRarityColor(mod.Rarity);
|
|
}
|
|
else
|
|
{
|
|
rarityText.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
OnHoverEnter?.Invoke(data, transform as RectTransform);
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
OnHoverExit?.Invoke();
|
|
}
|
|
|
|
private Color GetRarityColor(ModifierRarity rarity)
|
|
{
|
|
return rarity switch
|
|
{
|
|
ModifierRarity.Common => commonColor,
|
|
ModifierRarity.Uncommon => uncommonColor,
|
|
ModifierRarity.Rare => rareColor,
|
|
ModifierRarity.Epic => epicColor,
|
|
_ => commonColor
|
|
};
|
|
}
|
|
}
|
|
}
|