Files
YachtDice/Assets/Scripts/Shop/ShopView.cs
T
horooko bee20fd1f8 [Refactor] Add folder-based namespaces to all C# scripts
Wrap all 39 scripts and 6 test files in namespaces matching their folder
structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace
using directives where types are referenced across modules. Set rootNamespace
in both .asmdef files (YachtDice, YachtDice.Tests).

Namespace mapping:
- YachtDice.Dice — Dice, DiceRoller
- YachtDice.Economy — CurrencyBank
- YachtDice.Game — GameManager, DiceManager, DebugGameInput
- YachtDice.Inventory — InventoryController/Model/SlotView/View
- YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target
- YachtDice.Persistence — SaveData, SaveSystem
- YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory
- YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View
- YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView
- YachtDice.Editor — ModifierAssetCreator
- YachtDice.Tests — all test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:06:57 +07:00

83 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using YachtDice.Modifiers;
namespace YachtDice.Shop
{
public sealed class ShopView : MonoBehaviour
{
[SerializeField] private Transform itemContainer;
[SerializeField] private ShopItemView itemPrefab;
[SerializeField] private TMP_Text currencyText;
[SerializeField] private Button closeButton;
private readonly List<ShopItemView> spawnedItems = new();
public event Action<ModifierData> OnBuyClicked;
private void Awake()
{
if (closeButton != null)
closeButton.onClick.AddListener(Hide);
}
private void OnDestroy()
{
if (closeButton != null)
closeButton.onClick.RemoveListener(Hide);
}
public void Show() => gameObject.SetActive(true);
public void Hide() => gameObject.SetActive(false);
public bool IsVisible => gameObject.activeSelf;
public void Populate(IReadOnlyList<ModifierData> catalog, ShopModel model)
{
ClearItems();
for (int i = 0; i < catalog.Count; i++)
{
var data = catalog[i];
if (data == null) continue;
var item = Instantiate(itemPrefab, itemContainer);
var state = model.GetItemState(data);
item.Setup(data, state);
item.OnBuyClicked += HandleBuy;
spawnedItems.Add(item);
}
}
public void RefreshStates(IReadOnlyList<ModifierData> catalog, ShopModel model)
{
for (int i = 0; i < spawnedItems.Count && i < catalog.Count; i++)
{
var state = model.GetItemState(catalog[i]);
spawnedItems[i].SetState(state);
}
}
public void UpdateCurrencyDisplay(int currency)
{
if (currencyText != null)
currencyText.text = currency.ToString();
}
private void ClearItems()
{
for (int i = 0; i < spawnedItems.Count; i++)
{
spawnedItems[i].OnBuyClicked -= HandleBuy;
Destroy(spawnedItems[i].gameObject);
}
spawnedItems.Clear();
}
private void HandleBuy(ModifierData data) => OnBuyClicked?.Invoke(data);
}
}