Added icon to slot

remotes/checkIfPRContentChanged-1749884192368007736/inventory
cblech 8 months ago
parent 60928c520c
commit 8fdb395ae8

@ -1,12 +1,15 @@
[gd_scene load_steps=8 format=3 uid="uid://cgjc4wurbgimy"] [gd_scene load_steps=11 format=3 uid="uid://cgjc4wurbgimy"]
[ext_resource type="Script" uid="uid://hg7jay2kt441" path="res://scripts/CSharp/Common/Inventory/InventoryUi.cs" id="1_6wusm"] [ext_resource type="Script" uid="uid://hg7jay2kt441" path="res://scripts/CSharp/Common/Inventory/InventoryUi.cs" id="1_6wusm"]
[ext_resource type="Script" uid="uid://b2jhdxcrhtm2d" path="res://scripts/CSharp/Common/Inventory/InventoryTestScript.cs" id="3_exrk4"] [ext_resource type="Script" uid="uid://b2jhdxcrhtm2d" path="res://scripts/CSharp/Common/Inventory/InventoryTestScript.cs" id="3_exrk4"]
[ext_resource type="Texture2D" uid="uid://3ln8aleyxgp1" path="res://art/ui/UI/UI_bag_export_01.png" id="3_vvo7l"] [ext_resource type="Texture2D" uid="uid://3ln8aleyxgp1" path="res://art/ui/UI/UI_bag_export_01.png" id="3_vvo7l"]
[ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/pickaxe.tres" id="4_5fdxq"]
[ext_resource type="Texture2D" uid="uid://dcidjcsqk12p1" path="res://art/ui/UI/UI_bag_export_02.png" id="4_df8i8"] [ext_resource type="Texture2D" uid="uid://dcidjcsqk12p1" path="res://art/ui/UI/UI_bag_export_02.png" id="4_df8i8"]
[ext_resource type="Texture2D" uid="uid://c7wqla0mbu3np" path="res://art/ui/babushka_ui_tmp_inventory_select.png" id="4_tiss4"] [ext_resource type="Texture2D" uid="uid://c7wqla0mbu3np" path="res://art/ui/babushka_ui_tmp_inventory_select.png" id="4_tiss4"]
[ext_resource type="PackedScene" uid="uid://c0kmdjeqkqrwv" path="res://prefabs/UI/Inventory/Slot.tscn" id="5_u7kje"] [ext_resource type="PackedScene" uid="uid://c0kmdjeqkqrwv" path="res://prefabs/UI/Inventory/Slot.tscn" id="5_u7kje"]
[ext_resource type="Resource" uid="uid://blr8tine5m0ma" path="res://resources/items/tomato.tres" id="7_l3npx"]
[ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_vvo7l"]
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="8_nw1un"]
[ext_resource type="Resource" uid="uid://c7viddcd3kywp" path="res://resources/items/axe.tres" id="10_o7h8q"]
[node name="CanvasLayer" type="CanvasLayer"] [node name="CanvasLayer" type="CanvasLayer"]
layer = 90 layer = 90
@ -370,4 +373,4 @@ offset_bottom = 612.0
[node name="InventoryTester" type="Node" parent="Inventory"] [node name="InventoryTester" type="Node" parent="Inventory"]
script = ExtResource("3_exrk4") script = ExtResource("3_exrk4")
_testItemToCreate = ExtResource("4_5fdxq") _testItemsToCreate = Array[Object]([ExtResource("7_l3npx"), ExtResource("7_l3npx"), ExtResource("8_nw1un"), ExtResource("7_vvo7l"), ExtResource("10_o7h8q"), ExtResource("7_l3npx"), ExtResource("8_nw1un"), ExtResource("8_nw1un"), ExtResource("8_nw1un"), ExtResource("8_nw1un"), ExtResource("7_vvo7l")])

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://c0kmdjeqkqrwv"] [gd_scene load_steps=5 format=3 uid="uid://c0kmdjeqkqrwv"]
[ext_resource type="Script" uid="uid://bh6wcyxh1f0cv" path="res://scripts/CSharp/Common/Inventory/SlotUi.cs" id="1_au0l0"] [ext_resource type="Script" uid="uid://bh6wcyxh1f0cv" path="res://scripts/CSharp/Common/Inventory/SlotUi.cs" id="1_au0l0"]
[ext_resource type="Texture2D" uid="uid://0p52bm8b1nrl" path="res://art/ui/UI/inventory_standard.png" id="2_7emux"] [ext_resource type="Texture2D" uid="uid://0p52bm8b1nrl" path="res://art/ui/UI/inventory_standard.png" id="2_7emux"]
[ext_resource type="Texture2D" uid="uid://cfxibry711o16" path="res://art/ui/UI/icons/icon-scythe.png" id="3_n5ryf"]
[sub_resource type="LabelSettings" id="LabelSettings_7emux"] [sub_resource type="LabelSettings" id="LabelSettings_7emux"]
font_size = 15 font_size = 15
@ -15,7 +16,7 @@ offset_right = 100.0
offset_bottom = 100.0 offset_bottom = 100.0
script = ExtResource("1_au0l0") script = ExtResource("1_au0l0")
[node name="TextureRect" type="TextureRect" parent="."] [node name="SlotBackground" type="TextureRect" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -57,4 +58,18 @@ theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "999" text = "999"
horizontal_alignment = 2 horizontal_alignment = 2
[node name="Icon" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 10.0
offset_top = 10.0
offset_right = -10.0
offset_bottom = -10.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("3_n5ryf")
expand_mode = 1
[connection signal="gui_input" from="." to="." method="_on_gui_input"] [connection signal="gui_input" from="." to="." method="_on_gui_input"]

@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://cndd64batns31"] [gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://cndd64batns31"]
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_8k5aa"] [ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_8k5aa"]
[ext_resource type="Texture2D" uid="uid://bh7oo5mypstyp" path="res://art/ui/UI/icons/icon-watercan.png" id="1_roi0v"]
[resource] [resource]
script = ExtResource("1_8k5aa") script = ExtResource("1_8k5aa")
name = "Buck the Bucket" name = "Can"
color = Color(0.336269, 0.489145, 0.825324, 1) color = Color(0.336269, 0.489145, 0.825324, 1)
icon = ExtResource("1_roi0v")
maxStack = 1 maxStack = 1
metadata/_custom_type_script = "uid://cbskymrxs6ksu" metadata/_custom_type_script = "uid://cbskymrxs6ksu"

@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://c5yg3lx756v4v"] [gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://c5yg3lx756v4v"]
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_06nef"] [ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_06nef"]
[ext_resource type="Texture2D" uid="uid://cfxibry711o16" path="res://art/ui/UI/icons/icon-scythe.png" id="1_jd58x"]
[resource] [resource]
script = ExtResource("1_06nef") script = ExtResource("1_06nef")
name = "Your Mom" name = "Hoe"
color = Color(0.751421, 0.329615, 0.570911, 1) color = Color(0.751421, 0.329615, 0.570911, 1)
icon = ExtResource("1_jd58x")
maxStack = 1 maxStack = 1
metadata/_custom_type_script = "uid://cbskymrxs6ksu" metadata/_custom_type_script = "uid://cbskymrxs6ksu"

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://blr8tine5m0ma"]
[ext_resource type="Texture2D" uid="uid://c3wht0nakaki1" path="res://art/ui/UI/icons/icon-fruit-tomatoe.png" id="1_k7rt3"]
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_olvff"]
[resource]
script = ExtResource("1_olvff")
name = "Tomato"
color = Color(0.941176, 0, 0, 1)
icon = ExtResource("1_k7rt3")
maxStack = 20
metadata/_custom_type_script = "uid://cbskymrxs6ksu"

@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://d1uuxp1lp4aro"] [gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://d1uuxp1lp4aro"]
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_dustj"] [ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_dustj"]
[ext_resource type="Texture2D" uid="uid://ce04nexh36uwe" path="res://art/ui/UI/icons/icon-seed-tomatoe.png" id="1_u15c2"]
[resource] [resource]
script = ExtResource("1_dustj") script = ExtResource("1_dustj")
name = "Tomato Seed" name = "Tomato Seed"
color = Color(0.135039, 0.307214, 0.333128, 1) color = Color(0.135039, 0.307214, 0.333128, 1)
icon = ExtResource("1_u15c2")
maxStack = 20 maxStack = 20
metadata/_custom_type_script = "uid://cbskymrxs6ksu" metadata/_custom_type_script = "uid://cbskymrxs6ksu"

@ -3,15 +3,14 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
public partial class InventoryTestScript : Node public partial class InventoryTestScript : Node
{ {
[Export] [Export(PropertyHint.ArrayType)]
private ItemResource _testItemToCreate; private ItemResource[] _testItemsToCreate;
public override void _Ready() public override void _Ready()
{ {
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory); foreach (var itemResource in _testItemsToCreate)
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory); {
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory); InventoryManager.Instance.CreateItem(itemResource, InventoryManager.Instance.playerInventory);
InventoryManager.Instance.CreateItem(_testItemToCreate, InventoryManager.Instance.playerInventory); }
GD.Print("Added items");
} }
} }

@ -16,7 +16,7 @@ public partial class InventoryUi : Control
[Export] [Export]
private float _inventoryClosedOffset = 0f; private float _inventoryClosedOffset = 0f;
[Export] [Export]
private float _inventoryOpenedOffset = 200f; private float _inventoryOpenedOffset = 200f;
@ -46,15 +46,37 @@ public partial class InventoryUi : Control
var inventorySlot = _playerInventory.Slots[i]; var inventorySlot = _playerInventory.Slots[i];
var uiSlot = _slots.GetChild(i) as SlotUi; var uiSlot = _slots.GetChild(i) as SlotUi;
uiSlot!.nameLabel.Text = inventorySlot.itemInstance?.blueprint.name ?? ""; if (inventorySlot.itemInstance != null)
uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings; {
uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White; var blueprint = inventorySlot.itemInstance.blueprint;
var amount = inventorySlot.itemInstance.amount;
var amountText = inventorySlot.itemInstance != null &&
inventorySlot.itemInstance.amount != 1 if (blueprint.icon != null)
? inventorySlot.itemInstance.amount.ToString() {
: ""; // show icon
uiSlot!.amountLabel.Text = amountText; 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); _slots.AddChild(slotInstance);
} }
} }
private void SubscribeSlots() private void SubscribeSlots()
{ {
for (var index = 0; index < _playerInventory.Slots.Count; index++) for (var index = 0; index < _playerInventory.Slots.Count; index++)
@ -167,4 +189,4 @@ public partial class InventoryUi : Control
_slotOnMouse = null; _slotOnMouse = null;
} }
} }
} }

@ -10,6 +10,9 @@ public partial class ItemResource : Resource
[Export] [Export]
public Color color; public Color color;
[Export]
public Texture2D? icon;
[Export] [Export]
public int maxStack; public int maxStack;

@ -8,6 +8,7 @@ public partial class SlotUi : Control
public Label nameLabel; public Label nameLabel;
public int index; public int index;
public Label amountLabel; public Label amountLabel;
public TextureRect icon;
[Signal] public delegate void ClickedEventHandler(int index); [Signal] public delegate void ClickedEventHandler(int index);
@ -15,6 +16,7 @@ public partial class SlotUi : Control
{ {
nameLabel = GetNode<Label>("NameLabel"); nameLabel = GetNode<Label>("NameLabel");
amountLabel = GetNode<Label>("AmountLabel"); amountLabel = GetNode<Label>("AmountLabel");
icon = GetNode<TextureRect>("Icon");
} }
public void _on_gui_input(InputEvent ev) public void _on_gui_input(InputEvent ev)

Loading…
Cancel
Save