[Fix] Code visual
This commit is contained in:
@@ -7,76 +7,75 @@ 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()
|
||||
public class ShopView : MonoBehaviour
|
||||
{
|
||||
if (closeButton != null)
|
||||
closeButton.onClick.AddListener(Hide);
|
||||
}
|
||||
[SerializeField] private Transform itemContainer;
|
||||
[SerializeField] private ShopItemView itemPrefab;
|
||||
[SerializeField] private TMP_Text currencyText;
|
||||
[SerializeField] private Button closeButton;
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (closeButton != null)
|
||||
closeButton.onClick.RemoveListener(Hide);
|
||||
}
|
||||
private readonly List<ShopItemView> spawnedItems = new();
|
||||
|
||||
public void Show() => gameObject.SetActive(true);
|
||||
public void Hide() => gameObject.SetActive(false);
|
||||
public bool IsVisible => gameObject.activeSelf;
|
||||
public event Action<ModifierData> OnBuyClicked;
|
||||
|
||||
public void Populate(IReadOnlyList<ModifierData> catalog, ShopModel model)
|
||||
{
|
||||
ClearItems();
|
||||
|
||||
for (int i = 0; i < catalog.Count; i++)
|
||||
private void Awake()
|
||||
{
|
||||
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);
|
||||
if (closeButton != null)
|
||||
closeButton.onClick.AddListener(Hide);
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshStates(IReadOnlyList<ModifierData> catalog, ShopModel model)
|
||||
{
|
||||
for (int i = 0; i < spawnedItems.Count && i < catalog.Count; i++)
|
||||
private void OnDestroy()
|
||||
{
|
||||
var state = model.GetItemState(catalog[i]);
|
||||
spawnedItems[i].SetState(state);
|
||||
if (closeButton != null)
|
||||
closeButton.onClick.RemoveListener(Hide);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCurrencyDisplay(int currency)
|
||||
{
|
||||
if (currencyText != null)
|
||||
currencyText.text = currency.ToString();
|
||||
}
|
||||
public void Show() => gameObject.SetActive(true);
|
||||
public void Hide() => gameObject.SetActive(false);
|
||||
public bool IsVisible => gameObject.activeSelf;
|
||||
|
||||
private void ClearItems()
|
||||
{
|
||||
for (int i = 0; i < spawnedItems.Count; i++)
|
||||
public void Populate(IReadOnlyList<ModifierData> catalog, ShopModel model)
|
||||
{
|
||||
spawnedItems[i].OnBuyClicked -= HandleBuy;
|
||||
Destroy(spawnedItems[i].gameObject);
|
||||
}
|
||||
spawnedItems.Clear();
|
||||
}
|
||||
ClearItems();
|
||||
|
||||
private void HandleBuy(ModifierData data) => OnBuyClicked?.Invoke(data);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user