Added icon to slot
This commit is contained in:
@@ -3,15 +3,14 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryTestScript : Node
|
||||
{
|
||||
[Export]
|
||||
private ItemResource _testItemToCreate;
|
||||
[Export(PropertyHint.ArrayType)]
|
||||
private ItemResource[] _testItemsToCreate;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory);
|
||||
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory);
|
||||
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory);
|
||||
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory);
|
||||
GD.Print("Added items");
|
||||
foreach (var itemResource in _testItemsToCreate)
|
||||
{
|
||||
InventoryManager.Instance.CreateItem(itemResource, InventoryManager.Instance.playerInventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public partial class InventoryUi : Control
|
||||
|
||||
[Export]
|
||||
private float _inventoryClosedOffset = 0f;
|
||||
|
||||
|
||||
[Export]
|
||||
private float _inventoryOpenedOffset = 200f;
|
||||
|
||||
@@ -46,15 +46,37 @@ public partial class InventoryUi : Control
|
||||
var inventorySlot = _playerInventory.Slots[i];
|
||||
var uiSlot = _slots.GetChild(i) as SlotUi;
|
||||
|
||||
uiSlot!.nameLabel.Text = inventorySlot.itemInstance?.blueprint.name ?? "";
|
||||
uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings;
|
||||
uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White;
|
||||
if (inventorySlot.itemInstance != null)
|
||||
{
|
||||
var blueprint = inventorySlot.itemInstance.blueprint;
|
||||
var amount = inventorySlot.itemInstance.amount;
|
||||
|
||||
var amountText = inventorySlot.itemInstance != null &&
|
||||
inventorySlot.itemInstance.amount != 1
|
||||
? inventorySlot.itemInstance.amount.ToString()
|
||||
: "";
|
||||
uiSlot!.amountLabel.Text = amountText;
|
||||
if (blueprint.icon != null)
|
||||
{
|
||||
// show icon
|
||||
uiSlot!.nameLabel.Text = "";
|
||||
|
||||
uiSlot.icon.Texture = blueprint.icon;
|
||||
}
|
||||
else
|
||||
{
|
||||
// show name label
|
||||
uiSlot!.nameLabel.Text = inventorySlot.itemInstance.blueprint.name;
|
||||
uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings;
|
||||
uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White;
|
||||
|
||||
uiSlot.icon.Texture = null;
|
||||
}
|
||||
|
||||
// amount
|
||||
uiSlot!.amountLabel.Text = amount != 1 ? amount.ToString() : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
uiSlot!.nameLabel.Text = "";
|
||||
uiSlot!.icon.Texture = null;
|
||||
uiSlot!.amountLabel.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +96,7 @@ public partial class InventoryUi : Control
|
||||
_slots.AddChild(slotInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SubscribeSlots()
|
||||
{
|
||||
for (var index = 0; index < _playerInventory.Slots.Count; index++)
|
||||
@@ -167,4 +189,4 @@ public partial class InventoryUi : Control
|
||||
_slotOnMouse = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ public partial class ItemResource : Resource
|
||||
[Export]
|
||||
public Color color;
|
||||
|
||||
[Export]
|
||||
public Texture2D? icon;
|
||||
|
||||
[Export]
|
||||
public int maxStack;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ public partial class SlotUi : Control
|
||||
public Label nameLabel;
|
||||
public int index;
|
||||
public Label amountLabel;
|
||||
public TextureRect icon;
|
||||
|
||||
[Signal] public delegate void ClickedEventHandler(int index);
|
||||
|
||||
@@ -15,6 +16,7 @@ public partial class SlotUi : Control
|
||||
{
|
||||
nameLabel = GetNode<Label>("NameLabel");
|
||||
amountLabel = GetNode<Label>("AmountLabel");
|
||||
icon = GetNode<TextureRect>("Icon");
|
||||
}
|
||||
|
||||
public void _on_gui_input(InputEvent ev)
|
||||
|
||||
Reference in New Issue
Block a user