working on charging system

This commit is contained in:
2025-07-30 08:26:07 +02:00
parent 61a42bdf10
commit 407454555f
13 changed files with 544 additions and 497 deletions

View File

@@ -19,7 +19,6 @@ namespace RebootReality.jelycho.Player.HUD {
public VisualElement Root;
public VisualElement Slot;
public VisualElement Icon;
public Label QuantityLabel;
}
readonly List<InventorySlot> m_InventorySlots = new List<InventorySlot>();
@@ -43,13 +42,11 @@ namespace RebootReality.jelycho.Player.HUD {
InventorySlot slot = new InventorySlot {
Root = slotRoot,
Slot = slotRoot.Q<VisualElement>("player-hud__inventory-slot"),
Icon = slotRoot.Q<VisualElement>("player-hud__inventory-slot-icon"),
QuantityLabel = slotRoot.Q<Label>("player-hud__inventory-slot-quantity"),
Icon = slotRoot.Q<VisualElement>("player-hud__inventory-slot-icon")
};
Assert.IsNotNull(slot.Root, "Slot root cannot be null");
Assert.IsNotNull(slot.Slot, "Slot element cannot be null");
Assert.IsNotNull(slot.Icon, "Slot icon cannot be null");
Assert.IsNotNull(slot.QuantityLabel, "Slot quantity label cannot be null");
m_InventorySlots.Add(slot);
OnSlotUpdated(i);
@@ -86,25 +83,15 @@ namespace RebootReality.jelycho.Player.HUD {
s_Logger.Error($"Invalid slot index: {slotIndex}. Inventory has {m_InventorySlots.Count} slots.");
return;
}
int quantity = m_Inventory.GetQuantity(slotIndex);
if (quantity <= 0) {
m_InventorySlots[slotIndex].QuantityLabel.style.display = DisplayStyle.None;
ItemActor itemActor = m_Inventory.GetItem(slotIndex);
if (itemActor == null) {
m_InventorySlots[slotIndex].Icon.style.backgroundImage = null;
m_InventorySlots[slotIndex].Icon.style.display = DisplayStyle.None;
} else {
m_InventorySlots[slotIndex].QuantityLabel.style.display = DisplayStyle.Flex;
m_InventorySlots[slotIndex].QuantityLabel.text = quantity.ToString();
ItemActor itemActor = m_Inventory.GetFirstItem(slotIndex);
if (itemActor != null) {
m_InventorySlots[slotIndex].Icon.style.backgroundImage = new StyleBackground(itemActor.Config.icon);
m_InventorySlots[slotIndex].Icon.style.display = DisplayStyle.Flex;
} else {
m_InventorySlots[slotIndex].Icon.style.backgroundImage = null;
m_InventorySlots[slotIndex].Icon.style.display = DisplayStyle.None;
}
m_InventorySlots[slotIndex].Icon.style.backgroundImage = new StyleBackground(itemActor.Config.icon);
m_InventorySlots[slotIndex].Icon.style.display = DisplayStyle.Flex;
}
}
}