Added icon to slot
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user