mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 00:57:14 +08:00
57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
|
|
using Base;
|
||
|
|
using Entity;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
namespace UI
|
||
|
|
{
|
||
|
|
public class ShopUI : FullScreenUI
|
||
|
|
{
|
||
|
|
public Transform cardsParent;
|
||
|
|
|
||
|
|
public ShopCardUI[] cardPrefabs;
|
||
|
|
|
||
|
|
public Button refreshButton;
|
||
|
|
|
||
|
|
public override void Show()
|
||
|
|
{
|
||
|
|
base.Show();
|
||
|
|
if (Program.Instance.FocusedEntity is Character character)
|
||
|
|
{
|
||
|
|
var cost = Configs.ConfigManager.Instance.GetValue<int>("OpenShopCost");
|
||
|
|
refreshButton.interactable = character.Coin.Quantity >= cost;
|
||
|
|
}
|
||
|
|
if (cardsParent.childCount <= 1)
|
||
|
|
{
|
||
|
|
Refresh();
|
||
|
|
}
|
||
|
|
// Refresh();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Refresh(int count = 3)
|
||
|
|
{
|
||
|
|
ClearCards();
|
||
|
|
if (cardPrefabs == null || cardPrefabs.Length == 0)
|
||
|
|
return;
|
||
|
|
for (var i = 0; i < count; i++)
|
||
|
|
{
|
||
|
|
var index = Random.Range(0, cardPrefabs.Length);
|
||
|
|
var card = cardPrefabs[index];
|
||
|
|
var newCard = Instantiate(card, cardsParent);
|
||
|
|
newCard.shopUI = this;
|
||
|
|
newCard.Init();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public void ClearCards()
|
||
|
|
{
|
||
|
|
foreach (Transform card in cardsParent) Destroy(card.gameObject);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnHide()
|
||
|
|
{
|
||
|
|
UIInputControl.Instance.Hide(this);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|