ba626acb9b
Replace hardcoded BonusForOnes/MultiplierForSixes with data-driven modifier system supporting 2 scopes (SelectedCategory, AnyCategoryClosed), 4 effect types, durability modes (Permanent, LimitedUses), and configurable targets via ScriptableObject (ModifierData). - Modifier domain: ModifierEnums, ModifierTarget, ModifierData, ModifierRuntime, ModifierEffect (dict-based strategy), ModifierPipeline (4-pass: cat-additive → cat-multiplicative → final-additive → final-multiplicative) - ScoringSystem: replaced old modifier list with ModifierPipeline integration, added OnCategoryConfirmed event - Shop MVC: ShopCatalog (SO), ShopModel, ShopView, ShopItemView, ShopController - Inventory MVC: InventoryModel (activate/deactivate/sell/durability), InventoryView, InventorySlotView, InventoryController - CurrencyBank: editor-adjustable balance with events - Persistence: SaveData + SaveSystem (Newtonsoft JSON + PlayerPrefs) - Editor: ModifierAssetCreator menu item to generate 6 example modifiers + catalog - Tests: 6 test classes covering effects, pipeline, scoring, shop, inventory, save - GameController: wired shop/inventory/save lifecycle - GameInfoView: added currency display, shop/inventory toggle buttons Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
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);
|
|
}
|