diff --git a/.gitignore b/.gitignore index 583e132..d2c1a03 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ # temporary files **/*.tmp **/*.translation -**/*~lock~ \ No newline at end of file +**/*~lock~ + +# override config can be used by developers to override the settings without pushing changes to the repository +override.cfg diff --git a/Babushka.csproj b/Babushka.csproj index e75f04c..70c0d51 100644 --- a/Babushka.csproj +++ b/Babushka.csproj @@ -2,5 +2,6 @@ net8.0 true + enable \ No newline at end of file diff --git a/Babushka.sln.DotSettings b/Babushka.sln.DotSettings new file mode 100644 index 0000000..ed91201 --- /dev/null +++ b/Babushka.sln.DotSettings @@ -0,0 +1,5 @@ + + Godot Signal + [Signal] +public delegate void $SignalName$EventHandler($END$); + suggestVariableName() \ No newline at end of file diff --git a/art/mockups/3d/best_house_blender.blend.import b/art/mockups/3d/best_house_blender.blend.import index 2f414a6..7031f50 100644 --- a/art/mockups/3d/best_house_blender.blend.import +++ b/art/mockups/3d/best_house_blender.blend.import @@ -4,11 +4,12 @@ importer="scene" importer_version=1 type="PackedScene" uid="uid://b3kyrsoobmkhp" -valid=false +path="res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn" [deps] source_file="res://art/mockups/3d/best_house_blender.blend" +dest_files=["res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"] [params] diff --git a/art/ui/UI/UI_bag_export_01.png b/art/ui/UI/UI_bag_export_01.png new file mode 100644 index 0000000..7feb88c Binary files /dev/null and b/art/ui/UI/UI_bag_export_01.png differ diff --git a/art/ui/UI/UI_bag_export_01.png.import b/art/ui/UI/UI_bag_export_01.png.import new file mode 100644 index 0000000..ce691a4 --- /dev/null +++ b/art/ui/UI/UI_bag_export_01.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://3ln8aleyxgp1" +path="res://.godot/imported/UI_bag_export_01.png-849f65e7f0ae9838cbd0b40d7db0adbf.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/ui/UI/UI_bag_export_01.png" +dest_files=["res://.godot/imported/UI_bag_export_01.png-849f65e7f0ae9838cbd0b40d7db0adbf.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/art/ui/UI/UI_bag_export_02.png b/art/ui/UI/UI_bag_export_02.png new file mode 100644 index 0000000..2b7173c Binary files /dev/null and b/art/ui/UI/UI_bag_export_02.png differ diff --git a/art/ui/UI/UI_bag_export_02.png.import b/art/ui/UI/UI_bag_export_02.png.import new file mode 100644 index 0000000..63373f2 --- /dev/null +++ b/art/ui/UI/UI_bag_export_02.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dcidjcsqk12p1" +path="res://.godot/imported/UI_bag_export_02.png-1d79b1aa82b484e614d86097168b3404.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/ui/UI/UI_bag_export_02.png" +dest_files=["res://.godot/imported/UI_bag_export_02.png-1d79b1aa82b484e614d86097168b3404.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/prefabs/UI/Inventory/Inventory.tscn b/prefabs/UI/Inventory/Inventory.tscn index b4a294f..ed884fb 100644 --- a/prefabs/UI/Inventory/Inventory.tscn +++ b/prefabs/UI/Inventory/Inventory.tscn @@ -1,20 +1,32 @@ -[gd_scene load_steps=5 format=3 uid="uid://cgjc4wurbgimy"] +[gd_scene load_steps=8 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://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="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://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"] -[node name="Inventory" type="Control"] +[node name="CanvasLayer" type="CanvasLayer"] +layer = 90 + +[node name="Inventory" type="Control" parent="."] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +offset_left = 174.0 +offset_top = 191.0 +offset_right = 174.0 +offset_bottom = 191.0 grow_horizontal = 2 grow_vertical = 2 +scale = Vector2(0.7, 0.7) script = ExtResource("1_6wusm") +_inventoryOpenedOffset = -700.0 -[node name="SlotsContainer" type="Control" parent="."] +[node name="SlotsContainer" type="Control" parent="Inventory"] custom_minimum_size = Vector2(500, 0) layout_mode = 1 anchors_preset = 13 @@ -24,34 +36,23 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="Slots" type="GridContainer" parent="SlotsContainer"] -custom_minimum_size = Vector2(1000, 200) -layout_mode = 1 -anchors_preset = -1 -anchor_left = 0.5 -anchor_top = 1.0 -anchor_right = 0.5 -anchor_bottom = 1.0 -offset_bottom = 200.0 -grow_horizontal = 2 -grow_vertical = 0 -theme_override_constants/h_separation = 0 -theme_override_constants/v_separation = 0 -columns = 10 - -[node name="SlotSelectContainer" type="Control" parent="SlotsContainer"] -custom_minimum_size = Vector2(1000, 100) +[node name="SlotSelectContainer" type="Control" parent="Inventory/SlotsContainer"] +custom_minimum_size = Vector2(900, 100) layout_mode = 1 anchors_preset = 7 anchor_left = 0.5 anchor_top = 1.0 anchor_right = 0.5 anchor_bottom = 1.0 +offset_left = -450.0 +offset_top = -115.0 +offset_right = 450.0 +offset_bottom = -15.0 grow_horizontal = 2 grow_vertical = 0 -[node name="Selector" type="TextureRect" parent="SlotsContainer/SlotSelectContainer"] -visible = false +[node name="Selector" type="TextureRect" parent="Inventory/SlotsContainer/SlotSelectContainer"] +z_index = 10 custom_minimum_size = Vector2(100, 100) layout_mode = 0 offset_left = 1.0 @@ -60,11 +61,316 @@ offset_bottom = 100.0 texture = ExtResource("4_tiss4") expand_mode = 1 -[node name="InventoryTester" type="Node" parent="."] +[node name="SlotsMover" type="Control" parent="Inventory/SlotsContainer"] +custom_minimum_size = Vector2(900, 610) +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -200.0 +offset_top = -611.0 +offset_right = 200.0 +offset_bottom = -1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="BackgroundContainer" type="Control" parent="Inventory/SlotsContainer/SlotsMover"] +layout_mode = 1 +anchors_preset = 0 +offset_left = 5.0 +offset_top = 384.0 +offset_right = 901.0 +offset_bottom = 1230.0 +mouse_filter = 2 + +[node name="TextureRect" type="TextureRect" parent="Inventory/SlotsContainer/SlotsMover/BackgroundContainer"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -305.0 +offset_right = 303.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +texture = ExtResource("3_vvo7l") +expand_mode = 3 + +[node name="TextureRect2" type="TextureRect" parent="Inventory/SlotsContainer/SlotsMover/BackgroundContainer"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +texture = ExtResource("3_vvo7l") +expand_mode = 3 +flip_h = true + +[node name="TextureRect3" type="TextureRect" parent="Inventory/SlotsContainer/SlotsMover/BackgroundContainer"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +texture = ExtResource("4_df8i8") +expand_mode = 3 +flip_h = true + +[node name="Slots" type="Control" parent="Inventory/SlotsContainer/SlotsMover"] +custom_minimum_size = Vector2(900, 610) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = 496.0 +offset_bottom = 496.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Slot" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 + +[node name="Slot2" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 100.0 +offset_right = 200.0 + +[node name="Slot3" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 201.0 +offset_right = 301.0 + +[node name="Slot4" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 301.0 +offset_right = 401.0 + +[node name="Slot5" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 401.0 +offset_right = 501.0 + +[node name="Slot6" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 501.0 +offset_right = 601.0 + +[node name="Slot7" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 601.0 +offset_right = 701.0 + +[node name="Slot8" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 702.0 +offset_right = 802.0 + +[node name="Slot9" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 802.0 +offset_right = 902.0 + +[node name="Slot10" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 101.0 +offset_top = 212.0 +offset_right = 201.0 +offset_bottom = 312.0 + +[node name="Slot11" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 201.0 +offset_top = 212.0 +offset_right = 301.0 +offset_bottom = 312.0 + +[node name="Slot12" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 301.0 +offset_top = 212.0 +offset_right = 401.0 +offset_bottom = 312.0 + +[node name="Slot13" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 401.0 +offset_top = 212.0 +offset_right = 501.0 +offset_bottom = 312.0 + +[node name="Slot14" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 501.0 +offset_top = 212.0 +offset_right = 601.0 +offset_bottom = 312.0 + +[node name="Slot15" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 602.0 +offset_top = 212.0 +offset_right = 702.0 +offset_bottom = 312.0 + +[node name="Slot16" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 702.0 +offset_top = 212.0 +offset_right = 802.0 +offset_bottom = 312.0 + +[node name="Slot17" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 102.0 +offset_top = 312.0 +offset_right = 202.0 +offset_bottom = 412.0 + +[node name="Slot18" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 202.0 +offset_top = 312.0 +offset_right = 302.0 +offset_bottom = 412.0 + +[node name="Slot19" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 302.0 +offset_top = 312.0 +offset_right = 402.0 +offset_bottom = 412.0 + +[node name="Slot20" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 402.0 +offset_top = 312.0 +offset_right = 502.0 +offset_bottom = 412.0 + +[node name="Slot21" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 502.0 +offset_top = 312.0 +offset_right = 602.0 +offset_bottom = 412.0 + +[node name="Slot22" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 603.0 +offset_top = 312.0 +offset_right = 703.0 +offset_bottom = 412.0 + +[node name="Slot23" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 703.0 +offset_top = 312.0 +offset_right = 803.0 +offset_bottom = 412.0 + +[node name="Slot24" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 102.0 +offset_top = 412.0 +offset_right = 202.0 +offset_bottom = 512.0 + +[node name="Slot25" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 202.0 +offset_top = 412.0 +offset_right = 302.0 +offset_bottom = 512.0 + +[node name="Slot26" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 302.0 +offset_top = 412.0 +offset_right = 402.0 +offset_bottom = 512.0 + +[node name="Slot27" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 402.0 +offset_top = 412.0 +offset_right = 502.0 +offset_bottom = 512.0 + +[node name="Slot28" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 502.0 +offset_top = 412.0 +offset_right = 602.0 +offset_bottom = 512.0 + +[node name="Slot29" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 603.0 +offset_top = 412.0 +offset_right = 703.0 +offset_bottom = 512.0 + +[node name="Slot30" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 703.0 +offset_top = 412.0 +offset_right = 803.0 +offset_bottom = 512.0 + +[node name="Slot31" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 102.0 +offset_top = 512.0 +offset_right = 202.0 +offset_bottom = 612.0 + +[node name="Slot32" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 202.0 +offset_top = 512.0 +offset_right = 302.0 +offset_bottom = 612.0 + +[node name="Slot33" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 302.0 +offset_top = 512.0 +offset_right = 402.0 +offset_bottom = 612.0 + +[node name="Slot34" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 402.0 +offset_top = 512.0 +offset_right = 502.0 +offset_bottom = 612.0 + +[node name="Slot35" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 502.0 +offset_top = 512.0 +offset_right = 602.0 +offset_bottom = 612.0 + +[node name="Slot36" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 603.0 +offset_top = 512.0 +offset_right = 703.0 +offset_bottom = 612.0 + +[node name="Slot37" parent="Inventory/SlotsContainer/SlotsMover/Slots" instance=ExtResource("5_u7kje")] +layout_mode = 1 +offset_left = 703.0 +offset_top = 512.0 +offset_right = 803.0 +offset_bottom = 612.0 + +[node name="InventoryTester" type="Node" parent="Inventory"] script = ExtResource("3_exrk4") _testItemToCreate = ExtResource("4_5fdxq") - -[node name="BabushkaUiTmpInventorySelect" type="Sprite2D" parent="."] -visible = false -position = Vector2(-648, 1020) -texture = ExtResource("4_tiss4") diff --git a/prefabs/UI/Inventory/Slot.tscn b/prefabs/UI/Inventory/Slot.tscn index b4d4948..f5210c8 100644 --- a/prefabs/UI/Inventory/Slot.tscn +++ b/prefabs/UI/Inventory/Slot.tscn @@ -1,7 +1,7 @@ [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://art/ui/babushka_ui_inventory_slot.png" id="2_7emux"] +[ext_resource type="Texture2D" uid="uid://0p52bm8b1nrl" path="res://art/ui/UI/inventory_standard.png" id="2_7emux"] [sub_resource type="LabelSettings" id="LabelSettings_7emux"] font_size = 15 @@ -10,12 +10,9 @@ 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 +anchors_preset = 0 +offset_right = 100.0 +offset_bottom = 100.0 script = ExtResource("1_au0l0") [node name="TextureRect" type="TextureRect" parent="."] @@ -23,6 +20,10 @@ layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +offset_left = 3.0 +offset_top = 3.0 +offset_right = -3.0 +offset_bottom = -3.0 grow_horizontal = 2 grow_vertical = 2 texture = ExtResource("2_7emux") @@ -45,18 +46,15 @@ vertical_alignment = 1 layout_mode = 1 anchors_preset = -1 anchor_left = 1.0 -anchor_top = 1.0 anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -409.0 -offset_top = -329.0 +offset_left = -50.0 +offset_top = 9.0 offset_right = -10.0 -offset_bottom = -10.0 +offset_bottom = 49.0 grow_horizontal = 0 grow_vertical = 0 theme_override_colors/font_color = Color(0, 0, 0, 1) text = "999" horizontal_alignment = 2 -vertical_alignment = 2 [connection signal="gui_input" from="." to="." method="_on_gui_input"] diff --git a/project.godot b/project.godot index c732bba..fe71c10 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Babushka" -run/main_scene="uid://gigb28qk8t12" +run/main_scene="uid://dee2hgv85mdak" config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/icon="uid://b2smanpdo1y5e" @@ -69,6 +69,8 @@ text/autopauses={} [display] window/size/always_on_top=true +window/stretch/mode="viewport" +window/stretch/aspect="keep_height" [dotnet] diff --git a/resources/items/pickaxe.tres b/resources/items/pickaxe.tres index afc788d..31870c8 100644 --- a/resources/items/pickaxe.tres +++ b/resources/items/pickaxe.tres @@ -6,4 +6,5 @@ script = ExtResource("1_07aya") name = "Pick Axe" color = Color(0.589014, 0.823353, 0.998475, 1) +maxStack = 1 metadata/_custom_type_script = "uid://cbskymrxs6ksu" diff --git a/scripts/CSharp/Common/Inventory/InventoryManager.cs b/scripts/CSharp/Common/Inventory/InventoryManager.cs index b191e98..edc8c47 100644 --- a/scripts/CSharp/Common/Inventory/InventoryManager.cs +++ b/scripts/CSharp/Common/Inventory/InventoryManager.cs @@ -1,13 +1,27 @@ -#nullable enable +using System; using Godot; namespace Babushka.scripts.CSharp.Common.Inventory; public partial class InventoryManager : Node { - public static InventoryManager Instance { get; private set; } + [Signal] + public delegate void SlotIndexChangedEventHandler(int newIndex); + + public static InventoryManager Instance { get; private set; } = null!; + public int CurrentSelectedSlotIndex + { + get => _currentSelectedSlotIndex; + set + { + _currentSelectedSlotIndex = value; + EmitSignalSlotIndexChanged(_currentSelectedSlotIndex); + } + } - public InventoryInstance playerInventory; + public InventoryInstance playerInventory = new InventoryInstance(); + + private int _currentSelectedSlotIndex = 0; public override void _EnterTree() { @@ -16,8 +30,7 @@ public partial class InventoryManager : Node public override void _Ready() { - playerInventory = new InventoryInstance(); - playerInventory.SlotAmount = 30; + playerInventory.SlotAmount = 37; } public InventoryActionResult CreateItem( @@ -68,4 +81,14 @@ public partial class InventoryManager : Node { return playerInventory.AddItem(itemInstance); } -} \ No newline at end of file + + public InventorySlot GetCurrentSelectedSlot() + { + if (CurrentSelectedSlotIndex < 0 || CurrentSelectedSlotIndex > 8) + throw new ArgumentOutOfRangeException( + nameof(CurrentSelectedSlotIndex), + "currentInventoryBarIndex must be between 0 and 8 (inclusively)"); + + return playerInventory.Slots[CurrentSelectedSlotIndex]; + } +} diff --git a/scripts/CSharp/Common/Inventory/InventoryUi.cs b/scripts/CSharp/Common/Inventory/InventoryUi.cs index eb92b91..1c06cf9 100644 --- a/scripts/CSharp/Common/Inventory/InventoryUi.cs +++ b/scripts/CSharp/Common/Inventory/InventoryUi.cs @@ -1,28 +1,34 @@ -#nullable enable using Godot; namespace Babushka.scripts.CSharp.Common.Inventory; public partial class InventoryUi : Control { - private GridContainer _slots; + private Control _slots; + private Control _slotsMover; private InventoryInstance _playerInventory; private Control _slotSelect; private int? _slotOnMouse; - private int _selectedSlot = 0; - private bool _inventoryExtended = false; private Tween? _inventoryExtensionTween; + [Export] + private float _inventoryClosedOffset = 0f; + + [Export] + private float _inventoryOpenedOffset = 200f; + public override void _Ready() { GD.Print("Ready inventory ui"); - _slots = GetNode("SlotsContainer/Slots"); + _slots = GetNode("SlotsContainer/SlotsMover/Slots"); + _slotsMover = GetNode("SlotsContainer/SlotsMover"); _playerInventory = InventoryManager.Instance.playerInventory; _slotSelect = GetNode("SlotsContainer/SlotSelectContainer/Selector"); - PopulateSlots(); + //PopulateSlots(); + SubscribeSlots(); SetSlotContent(); SetSlotSelectPosition(); InventoryManager.Instance.playerInventory.InventoryContentsChanged += SetSlotContent; @@ -54,7 +60,7 @@ public partial class InventoryUi : Control private void SetSlotSelectPosition() { - _slotSelect.Position = new Vector2(_selectedSlot * 100, 0); + _slotSelect.Position = new Vector2(InventoryManager.Instance.CurrentSelectedSlotIndex * 100, 0); } private void PopulateSlots() @@ -68,6 +74,17 @@ public partial class InventoryUi : Control _slots.AddChild(slotInstance); } } + + private void SubscribeSlots() + { + for (var index = 0; index < _playerInventory.Slots.Count; index++) + { + var slotInstance = _slots.GetChild(index); + slotInstance.index = index; + slotInstance.Clicked += SlotClicked; + _slots.AddChild(slotInstance); + } + } private void UnsubscribeSlots() { @@ -108,17 +125,17 @@ public partial class InventoryUi : Control if (Input.IsActionJustPressed("ui_inventory_disadvance")) { - _selectedSlot++; - if (_selectedSlot > 9) - _selectedSlot = 0; + InventoryManager.Instance.CurrentSelectedSlotIndex++; + if (InventoryManager.Instance.CurrentSelectedSlotIndex > 8) + InventoryManager.Instance.CurrentSelectedSlotIndex = 0; SetSlotSelectPosition(); } if (Input.IsActionJustPressed("ui_inventory_advance")) { - _selectedSlot--; - if (_selectedSlot < 0) - _selectedSlot = 9; + InventoryManager.Instance.CurrentSelectedSlotIndex--; + if (InventoryManager.Instance.CurrentSelectedSlotIndex < 0) + InventoryManager.Instance.CurrentSelectedSlotIndex = 8; SetSlotSelectPosition(); } } @@ -134,7 +151,7 @@ public partial class InventoryUi : Control _inventoryExtensionTween = GetTree().CreateTween(); _slotSelect.Hide(); _inventoryExtensionTween - .TweenProperty(_slots, "offset_bottom", -100, 0.4) + .TweenProperty(_slotsMover, "offset_bottom", _inventoryOpenedOffset, 0.4) .SetTrans(Tween.TransitionType.Quad) .SetEase(Tween.EaseType.Out); } @@ -144,7 +161,7 @@ public partial class InventoryUi : Control _inventoryExtensionTween = GetTree().CreateTween(); _slotSelect.Show(); _inventoryExtensionTween - .TweenProperty(_slots, "offset_bottom", 200, 0.4) + .TweenProperty(_slotsMover, "offset_bottom", _inventoryClosedOffset, 0.4) .SetTrans(Tween.TransitionType.Quad) .SetEase(Tween.EaseType.Out);