diff --git a/.idea/.idea.Babushka/.idea/.name b/.idea/.idea.Babushka/.idea/.name new file mode 100644 index 0000000..4ba9019 --- /dev/null +++ b/.idea/.idea.Babushka/.idea/.name @@ -0,0 +1 @@ +Babushka \ No newline at end of file diff --git a/graphics/ui/babushka_ui_inventory_slot.png b/graphics/ui/babushka_ui_inventory_slot.png new file mode 100644 index 0000000..02629a4 Binary files /dev/null and b/graphics/ui/babushka_ui_inventory_slot.png differ diff --git a/graphics/ui/babushka_ui_inventory_slot.png.import b/graphics/ui/babushka_ui_inventory_slot.png.import new file mode 100644 index 0000000..88eda78 --- /dev/null +++ b/graphics/ui/babushka_ui_inventory_slot.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c2dbd0q02x2h" +path="res://.godot/imported/babushka_ui_inventory_slot.png-cd1973aa1d3922af7e3271aeaf56cc88.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/ui/babushka_ui_inventory_slot.png" +dest_files=["res://.godot/imported/babushka_ui_inventory_slot.png-cd1973aa1d3922af7e3271aeaf56cc88.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/graphics/ui/untitled.afdesign b/graphics/ui/untitled.afdesign new file mode 100644 index 0000000..ac2ecd1 Binary files /dev/null and b/graphics/ui/untitled.afdesign differ diff --git a/prefabs/UI/Inventory/Inventory.tscn b/prefabs/UI/Inventory/Inventory.tscn index 24645b2..15356f4 100644 --- a/prefabs/UI/Inventory/Inventory.tscn +++ b/prefabs/UI/Inventory/Inventory.tscn @@ -1,8 +1,33 @@ -[gd_scene load_steps=2 format=3 uid="uid://cgjc4wurbgimy"] +[gd_scene load_steps=4 format=3 uid="uid://cgjc4wurbgimy"] -[ext_resource type="Script" uid="uid://b7vlkecrn0t5c" path="res://scripts/CSharp/Common/Inventory/InventoryUI.cs" id="1_6wusm"] +[ext_resource type="Script" uid="uid://b7vlkecrn0t5c" 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="Resource" uid="uid://datee0flk1e84" path="res://resources/items/pickaxe.tres" id="4_5fdxq"] [node name="Inventory" type="Control"] layout_mode = 3 -anchors_preset = 0 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1_6wusm") + +[node name="Slots" type="GridContainer" parent="."] +custom_minimum_size = Vector2(500, 200) +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -335.0 +offset_right = 341.0 +offset_bottom = 200.0 +grow_horizontal = 2 +grow_vertical = 2 +columns = 10 + +[node name="InventoryTester" type="Node" parent="."] +script = ExtResource("3_exrk4") +_testItemToCreate = ExtResource("4_5fdxq") diff --git a/prefabs/UI/Inventory/Slot.tscn b/prefabs/UI/Inventory/Slot.tscn new file mode 100644 index 0000000..8e7c2ac --- /dev/null +++ b/prefabs/UI/Inventory/Slot.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=4 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="Texture2D" uid="uid://c2dbd0q02x2h" path="res://graphics/ui/babushka_ui_inventory_slot.png" id="2_7emux"] + +[sub_resource type="LabelSettings" id="LabelSettings_7emux"] +font_size = 15 +font_color = Color(0.203922, 1, 1, 1) + +[node name="Slot" type="Control"] +custom_minimum_size = Vector2(100, 100) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_bottom = 2.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_au0l0") + +[node name="TextureRect" type="TextureRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("2_7emux") +expand_mode = 1 +stretch_mode = 5 + +[node name="NameLabel" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "asdf" +label_settings = SubResource("LabelSettings_7emux") +horizontal_alignment = 1 +vertical_alignment = 1 + +[connection signal="gui_input" from="." to="." method="_on_gui_input"] diff --git a/project.godot b/project.godot index e955fed..d163539 100644 --- a/project.godot +++ b/project.godot @@ -66,10 +66,6 @@ translation/id_counter=22 translation/locales=["de", "en"] text/autopauses={} -[display] - -window/size/always_on_top=true - [dotnet] project/assembly_name="Babushka" diff --git a/resources/items/pickaxe.tres b/resources/items/pickaxe.tres index 185e49e..afc788d 100644 --- a/resources/items/pickaxe.tres +++ b/resources/items/pickaxe.tres @@ -5,5 +5,5 @@ [resource] script = ExtResource("1_07aya") name = "Pick Axe" -color = Color(0.226361, 0.573832, 0.480633, 1) +color = Color(0.589014, 0.823353, 0.998475, 1) metadata/_custom_type_script = "uid://cbskymrxs6ksu" diff --git a/scripts/CSharp/Common/Inventory/InventoryActionResult.cs.uid b/scripts/CSharp/Common/Inventory/InventoryActionResult.cs.uid new file mode 100644 index 0000000..71d5ef2 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventoryActionResult.cs.uid @@ -0,0 +1 @@ +uid://bxre8ecfx3xx diff --git a/scripts/CSharp/Common/Inventory/InventoryManager.cs b/scripts/CSharp/Common/Inventory/InventoryManager.cs index 61c209d..cd024aa 100644 --- a/scripts/CSharp/Common/Inventory/InventoryManager.cs +++ b/scripts/CSharp/Common/Inventory/InventoryManager.cs @@ -5,7 +5,7 @@ namespace Babushka.scripts.CSharp.Common.Inventory; public partial class InventoryManager : Node { - public InventoryManager Instance { get; private set; } + public static InventoryManager Instance { get; private set; } public InventoryInstance playerInventory; diff --git a/scripts/CSharp/Common/Inventory/InventorySlot.cs.uid b/scripts/CSharp/Common/Inventory/InventorySlot.cs.uid new file mode 100644 index 0000000..d910764 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventorySlot.cs.uid @@ -0,0 +1 @@ +uid://rxaoggm0qxgm diff --git a/scripts/CSharp/Common/Inventory/InventoryTestScript.cs b/scripts/CSharp/Common/Inventory/InventoryTestScript.cs new file mode 100644 index 0000000..a19a049 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventoryTestScript.cs @@ -0,0 +1,17 @@ +using Godot; +namespace Babushka.scripts.CSharp.Common.Inventory; + +public partial class InventoryTestScript : Node +{ + [Export] + private ItemResource _testItemToCreate; + + 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"); + } +} diff --git a/scripts/CSharp/Common/Inventory/InventoryTestScript.cs.uid b/scripts/CSharp/Common/Inventory/InventoryTestScript.cs.uid new file mode 100644 index 0000000..21116fc --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventoryTestScript.cs.uid @@ -0,0 +1 @@ +uid://b2jhdxcrhtm2d diff --git a/scripts/CSharp/Common/Inventory/InventoryUI.cs b/scripts/CSharp/Common/Inventory/InventoryUI.cs deleted file mode 100644 index 1851f2d..0000000 --- a/scripts/CSharp/Common/Inventory/InventoryUI.cs +++ /dev/null @@ -1,6 +0,0 @@ -using Godot; -using System; - -public partial class InventoryUI : Control -{ -} diff --git a/scripts/CSharp/Common/Inventory/InventoryUi.cs b/scripts/CSharp/Common/Inventory/InventoryUi.cs new file mode 100644 index 0000000..2774d11 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/InventoryUi.cs @@ -0,0 +1,77 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.Inventory; + +public partial class InventoryUi : Control +{ + private GridContainer _slots; + private InventoryInstance _playerInventory; + + private int? _slotOnMouse; + + public override void _Ready() + { + GD.Print("Ready inventory ui"); + _slots = GetNode("Slots"); + _playerInventory = InventoryManager.Instance.playerInventory; + PopulateSlots(); + SetSlotContent(); + } + + public override void _ExitTree() + { + UnsubscribeSlots(); + } + + private void SetSlotContent() + { + for (var i = 0; i < _playerInventory.Slots.Count; i++) + { + 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; + } + } + + private void PopulateSlots() + { + var slotPackedScene = GD.Load("res://prefabs/UI/Inventory/Slot.tscn"); + for (var index = 0; index < _playerInventory.Slots.Count; index++) + { + var slotInstance = slotPackedScene.Instantiate(); + slotInstance.index = index; + slotInstance.Clicked += SlotClicked; + _slots.AddChild(slotInstance); + } + } + + private void UnsubscribeSlots() + { + for (var index = 0; index < _playerInventory.Slots.Count; index++) + { + var slotInstance = _slots.GetChild(index) as SlotUi; + slotInstance!.Clicked -= SlotClicked; + } + } + + private void SlotClicked(int index) + { + GD.Print($"Clicked slot {index}"); + if (_slotOnMouse == null) + { + _slotOnMouse = index; + GD.Print($"Slot on mouse: {_slotOnMouse}"); + } + else + { + var sourceSlot = _slotOnMouse.Value; + var destinationSlot = index; + InventoryManager.Instance.MoveItem(_playerInventory, sourceSlot, _playerInventory, destinationSlot); + _slotOnMouse = null; + SetSlotContent(); + } + } +} diff --git a/scripts/CSharp/Common/Inventory/ItemInstance.cs.uid b/scripts/CSharp/Common/Inventory/ItemInstance.cs.uid new file mode 100644 index 0000000..3a0fb36 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/ItemInstance.cs.uid @@ -0,0 +1 @@ +uid://be54lnb6gg81f diff --git a/scripts/CSharp/Common/Inventory/SlotUi.cs b/scripts/CSharp/Common/Inventory/SlotUi.cs new file mode 100644 index 0000000..2c174b2 --- /dev/null +++ b/scripts/CSharp/Common/Inventory/SlotUi.cs @@ -0,0 +1,27 @@ +using Godot; +using System; + +namespace Babushka.scripts.CSharp.Common.Inventory; + +public partial class SlotUi : Control +{ + public Label nameLabel; + public int index; + + [Signal] public delegate void ClickedEventHandler(int index); + + public override void _EnterTree() + { + nameLabel = GetNode