OK so I’m currently cleaning up a few bugs, and one bug that’s really really annoying me, is the Quiver Slot UI. For some reason, it may or may not update in the QuiverSlotUI.cs slot, and it’s driving me crazy as of why. For context, here’s the ‘QuiverSlotUI.cs’ script:
using System;
using GameDevTV.Core.UI.Dragging;
using GameDevTV.Inventories;
using RPG.Inventories;
using TMPro;
using UnityEngine;
namespace GameDevTV.UI.Inventories {
public class QuiverSlotUI : MonoBehaviour, IItemHolder, IDragContainer<InventoryItem> {
[SerializeField] InventoryItemIcon icon = null;
[SerializeField] private GameObject itemCounter;
[SerializeField] private TextMeshProUGUI number;
private Quiver quiver;
private void Awake()
{
quiver = Inventory.GetPlayerInventory().GetComponent<Quiver>();
quiver.quiverUpdated += RedrawUI;
}
void RedrawUI()
{
icon.SetItem(GetItem());
itemCounter.SetActive(GetNumber() > 0);
number.text = $"{GetNumber()}";
}
public InventoryItem GetItem()
{
return quiver.GetItem();
}
public int GetNumber()
{
return quiver.GetAmount();
}
public void RemoveItems(int number)
{
quiver.RemoveAmmunition(number);
}
public int MaxAcceptable(InventoryItem item) // Part of the 'IDragContainer<InventoryItem>' Interface
{
if (item is AmmunitionItem ammunitionItem)
{
return Int32.MaxValue;
}
return 0;
}
public void AddItems(InventoryItem item, int number) // Part of the 'IDragContainer<InventoryItem>' Interface
{
// This inherited function from the drag and drop system checks if
// the item we are dragging and dropping to our Quiver slot is the same as the
// item that already exists. If so, just add the numbers up (stackable items). If not, replace
if (item is AmmunitionItem ammunitionItem) {
if (object.ReferenceEquals(ammunitionItem, quiver.GetItem())) {
quiver.AddAmmunition(ammunitionItem, number + quiver.GetAmount());
}
else quiver.AddAmmunition(ammunitionItem, number);
}
}
public void TryHandleRightClick(Inventory inventory) {
if (GetItem() is AmmunitionItem ammunitionItem) {
AmmunitionItem equippedAmmunition = quiver.GetItem();
if (inventory.HasSpaceFor(equippedAmmunition)) {
inventory.AddToFirstEmptySlot(equippedAmmunition, GetNumber());
quiver.RemoveAmmunition();
}
}
}
}
}
I also went to ‘InventorySlotUI.cs’ and tried calling the ‘Quiver.TriggerUpdated()’ function (basically invoke the Quiver Updated function), where it should be invoked:
else if (item is AmmunitionItem ammunitionItem && inventory.GetGameObject().TryGetComponent(out Quiver quiver))
{
// If there is a "Quiver" Equipment slot, and what we clicked on is a Rangers' arrow,
// then we shall transfer the arrow to the dedicated slot
Debug.Log($"{ammunitionItem} is ammo, transferring to {quiver}");
TransferToQuiver(ammunitionItem, quiver, number);
quiver.TriggerUpdated();
}
But still, it does not 100% get (visually) updated when I open my Equipment tab. Sometimes (Most of the time) a Re-equipment will be necessary
Any idea how to fix this? It’s a minor bug, but it’s quite annoying tbh
(I also have to mention that this slot is a stacked slot. In other words, it accepts stacked items (and it’s the only one in my game of that kind), if that makes a difference)
There’s a similar problem with the amount of money in my player’s purse, but I will get to that another day. For now, I want to fix this one first
Edit 1: Apparently I just learned that for that event to be called, the ‘Equipment’ Window slot has to be opened at least one when the game starts. I want to end this curse - for every other slot in the equipments tab, this is not a problem at all (the problem isn’t with the ‘RedrawUI()’ function. It’s with whoever is calling that function, somehow not recognizing it when it’s first clicked when the game is open again!).