bee20fd1f8
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>
80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using YachtDice.Modifiers;
|
|
|
|
namespace YachtDice.Inventory
|
|
{
|
|
|
|
public sealed class InventoryView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform slotContainer;
|
|
[SerializeField] private InventorySlotView slotPrefab;
|
|
[SerializeField] private TMP_Text slotCountText;
|
|
[SerializeField] private Button closeButton;
|
|
|
|
private readonly List<InventorySlotView> spawnedSlots = new();
|
|
|
|
public event Action<ModifierRuntime> OnActivateClicked;
|
|
public event Action<ModifierRuntime> OnDeactivateClicked;
|
|
public event Action<ModifierRuntime> OnSellClicked;
|
|
|
|
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 Refresh(IReadOnlyList<ModifierRuntime> owned, int maxSlots)
|
|
{
|
|
ClearSlots();
|
|
|
|
int activeCount = 0;
|
|
|
|
for (int i = 0; i < owned.Count; i++)
|
|
{
|
|
var runtime = owned[i];
|
|
if (runtime.IsActive) activeCount++;
|
|
|
|
var slot = Instantiate(slotPrefab, slotContainer);
|
|
slot.Setup(runtime, activeCount <= maxSlots);
|
|
slot.OnActivateClicked += HandleActivate;
|
|
slot.OnDeactivateClicked += HandleDeactivate;
|
|
slot.OnSellClicked += HandleSell;
|
|
spawnedSlots.Add(slot);
|
|
}
|
|
|
|
if (slotCountText != null)
|
|
slotCountText.text = $"{activeCount}/{maxSlots}";
|
|
}
|
|
|
|
private void ClearSlots()
|
|
{
|
|
for (int i = 0; i < spawnedSlots.Count; i++)
|
|
{
|
|
spawnedSlots[i].OnActivateClicked -= HandleActivate;
|
|
spawnedSlots[i].OnDeactivateClicked -= HandleDeactivate;
|
|
spawnedSlots[i].OnSellClicked -= HandleSell;
|
|
Destroy(spawnedSlots[i].gameObject);
|
|
}
|
|
spawnedSlots.Clear();
|
|
}
|
|
|
|
private void HandleActivate(ModifierRuntime runtime) => OnActivateClicked?.Invoke(runtime);
|
|
private void HandleDeactivate(ModifierRuntime runtime) => OnDeactivateClicked?.Invoke(runtime);
|
|
private void HandleSell(ModifierRuntime runtime) => OnSellClicked?.Invoke(runtime);
|
|
}
|
|
}
|