Add LevelUpHud and UpgradeManager components; implement upgrade selection UI and item management
This commit is contained in:
@@ -180,6 +180,7 @@ namespace Data
|
||||
{
|
||||
Level++;
|
||||
experience -= ExperienceToNextLevel();
|
||||
experience = Math.Min(0, experience);
|
||||
}
|
||||
else if (experience < 0)
|
||||
{
|
||||
|
@@ -62,6 +62,10 @@ namespace Shop
|
||||
shopUI.Show(currentItemChoices, currentWeaponChoices, this);
|
||||
}
|
||||
|
||||
public List<StatModifierItem> DrawRandomItems(int count) => DrawRandomItems(possibleItems, count);
|
||||
|
||||
public List<WeaponItem> DrawRandomWeapons(int count) => DrawRandomItems(possibleWeapons, count);
|
||||
|
||||
private void OpenShop()
|
||||
{
|
||||
OpenShop(GameManager.Instance.CurrentRound);
|
||||
|
@@ -51,6 +51,7 @@ namespace Shop
|
||||
public void MarkAsPurchased()
|
||||
{
|
||||
purchaseButton.interactable = false;
|
||||
purchaseButton.GetComponentInChildren<TextMeshProUGUI>().text = "Purchased";
|
||||
}
|
||||
}
|
||||
}
|
40
Assets/Scripts/Systems/UpgradeManager.cs
Normal file
40
Assets/Scripts/Systems/UpgradeManager.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Inventory;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class UpgradeManager : MonoBehaviour
|
||||
{
|
||||
private bool hasSelectedUpgrade;
|
||||
|
||||
[SerializeField] private InventoryManager inventoryManager;
|
||||
[SerializeField] private LevelUpHud levelUpHud;
|
||||
|
||||
public bool HasSelectedUpgrade => hasSelectedUpgrade;
|
||||
|
||||
public void SetHasSelectedUpgrade(bool value)
|
||||
{
|
||||
hasSelectedUpgrade = value;
|
||||
}
|
||||
|
||||
public void SelectUpgrade(StatModifierItem item)
|
||||
{
|
||||
if (hasSelectedUpgrade) return;
|
||||
|
||||
inventoryManager.EquipItem(item);
|
||||
hasSelectedUpgrade = true;
|
||||
levelUpHud.MarkAsSelected(item);
|
||||
|
||||
}
|
||||
|
||||
public void SelectUpgrade(WeaponItem weapon)
|
||||
{
|
||||
if (hasSelectedUpgrade) return;
|
||||
|
||||
inventoryManager.EquipWeapon(weapon);
|
||||
hasSelectedUpgrade = true;
|
||||
levelUpHud.MarkAsSelected(weapon);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/UpgradeManager.cs.meta
Normal file
3
Assets/Scripts/Systems/UpgradeManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e88a6318368843c3b8e02ccad05b4569
|
||||
timeCreated: 1752334253
|
101
Assets/Scripts/UI/LevelUpHud.cs
Normal file
101
Assets/Scripts/UI/LevelUpHud.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Inventory;
|
||||
using KBCore.Refs;
|
||||
using Shop;
|
||||
using Systems;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class LevelUpHud : MonoBehaviour
|
||||
{
|
||||
private List<UpgradeSlot> currentSlots = new();
|
||||
private List<StatModifierItem> currentItemChoices = new();
|
||||
private List<WeaponItem> currentWeaponChoices = new();
|
||||
|
||||
[SerializeField] private GameObject itemsContainer;
|
||||
[SerializeField] private GameObject upgradeSlotPrefab;
|
||||
[SerializeField] private int itemsCount = 3;
|
||||
[SerializeField] private int weaponsCount = 2;
|
||||
[SerializeField, Scene] private ShopManager shopManager;
|
||||
[SerializeField, Scene] private UpgradeManager upgradeManager;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Hide();
|
||||
GameManager.Instance.Player.attributes.OnLevelUp += OnLevelUp;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GameManager.Instance.Player.attributes.OnLevelUp -= OnLevelUp;
|
||||
}
|
||||
|
||||
private void OnLevelUp()
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
private void Show()
|
||||
{
|
||||
Time.timeScale = 0f;
|
||||
ClearSlots();
|
||||
|
||||
currentItemChoices = shopManager.DrawRandomItems(itemsCount);
|
||||
currentWeaponChoices = shopManager.DrawRandomWeapons(weaponsCount);
|
||||
|
||||
foreach (var item in currentItemChoices)
|
||||
{
|
||||
var slot = Instantiate(upgradeSlotPrefab, itemsContainer.transform);
|
||||
if (slot.TryGetComponent(out UpgradeSlot upgradeSlot))
|
||||
{
|
||||
upgradeSlot.Setup(item, upgradeManager);
|
||||
currentSlots.Add(upgradeSlot);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var weapon in currentWeaponChoices)
|
||||
{
|
||||
var slot = Instantiate(upgradeSlotPrefab, itemsContainer.transform);
|
||||
if (slot.TryGetComponent(out UpgradeSlot upgradeSlot))
|
||||
{
|
||||
upgradeSlot.Setup(weapon, upgradeManager);
|
||||
currentSlots.Add(upgradeSlot);
|
||||
}
|
||||
}
|
||||
|
||||
itemsContainer.SetActive(true);
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
itemsContainer.SetActive(false);
|
||||
ClearSlots();
|
||||
}
|
||||
|
||||
private void ClearSlots()
|
||||
{
|
||||
foreach (Transform child in itemsContainer.transform) Destroy(child.gameObject);
|
||||
|
||||
currentSlots.Clear();
|
||||
currentItemChoices.Clear();
|
||||
currentWeaponChoices.Clear();
|
||||
upgradeManager.SetHasSelectedUpgrade(false);
|
||||
}
|
||||
|
||||
public void MarkAsSelected(ScriptableObject item)
|
||||
{
|
||||
foreach (var slot in currentSlots)
|
||||
{
|
||||
if (slot.MatchesItem(item))
|
||||
{
|
||||
slot.MarkAsSelected();
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/UI/LevelUpHud.cs.meta
Normal file
3
Assets/Scripts/UI/LevelUpHud.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47a2be3e3bc54f28a2b304237375b073
|
||||
timeCreated: 1752333303
|
54
Assets/Scripts/UI/UpgradeSlot.cs
Normal file
54
Assets/Scripts/UI/UpgradeSlot.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Inventory;
|
||||
using Shop;
|
||||
using Systems;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class UpgradeSlot : MonoBehaviour
|
||||
{
|
||||
private UpgradeManager upgradeManager;
|
||||
private ScriptableObject item;
|
||||
|
||||
[SerializeField] private Image icon;
|
||||
[SerializeField] private TextMeshProUGUI nameText;
|
||||
[SerializeField] private TextMeshProUGUI descriptionText;
|
||||
[SerializeField] private Button selectButton;
|
||||
|
||||
public void Setup(StatModifierItem item, UpgradeManager manager)
|
||||
{
|
||||
this.item = item;
|
||||
upgradeManager = manager;
|
||||
|
||||
icon.sprite = item.icon;
|
||||
nameText.text = item.name;
|
||||
descriptionText.text = item.description;
|
||||
|
||||
selectButton.interactable = !upgradeManager.HasSelectedUpgrade;
|
||||
selectButton.onClick.AddListener(() => upgradeManager.SelectUpgrade(item));
|
||||
}
|
||||
|
||||
public void Setup(WeaponItem weapon, UpgradeManager manager)
|
||||
{
|
||||
item = weapon;
|
||||
upgradeManager = manager;
|
||||
|
||||
icon.sprite = weapon.icon;
|
||||
nameText.text = weapon.weaponName;
|
||||
descriptionText.text = weapon.description;
|
||||
|
||||
selectButton.interactable = !upgradeManager.HasSelectedUpgrade;
|
||||
selectButton.onClick.AddListener(() => upgradeManager.SelectUpgrade(weapon));
|
||||
}
|
||||
|
||||
public bool MatchesItem(ScriptableObject item) => this.item == item;
|
||||
|
||||
public void MarkAsSelected()
|
||||
{
|
||||
selectButton.interactable = false;
|
||||
selectButton.GetComponentInChildren<TextMeshProUGUI>().text = "Selected";
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/UI/UpgradeSlot.cs.meta
Normal file
3
Assets/Scripts/UI/UpgradeSlot.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 681d2399c12d499b900169ba083bdc62
|
||||
timeCreated: 1752333873
|
Reference in New Issue
Block a user