diff --git a/graphics/ui/babushka_ui_inventory_slot.png b/graphics/ui/babushka_ui_inventory_slot.png index 02629a4..eaeb5e1 100644 Binary files a/graphics/ui/babushka_ui_inventory_slot.png and b/graphics/ui/babushka_ui_inventory_slot.png differ diff --git a/graphics/ui/babushka_ui_tmp_inventory_select.afdesign b/graphics/ui/babushka_ui_tmp_inventory_select.afdesign new file mode 100644 index 0000000..4a1b739 Binary files /dev/null and b/graphics/ui/babushka_ui_tmp_inventory_select.afdesign differ diff --git a/graphics/ui/babushka_ui_tmp_inventory_select.afdesign~lock~ b/graphics/ui/babushka_ui_tmp_inventory_select.afdesign~lock~ new file mode 100644 index 0000000..3a7fcfa Binary files /dev/null and b/graphics/ui/babushka_ui_tmp_inventory_select.afdesign~lock~ differ diff --git a/graphics/ui/babushka_ui_tmp_inventory_select.png b/graphics/ui/babushka_ui_tmp_inventory_select.png new file mode 100644 index 0000000..8d30a9e Binary files /dev/null and b/graphics/ui/babushka_ui_tmp_inventory_select.png differ diff --git a/graphics/ui/babushka_ui_tmp_inventory_select.png.import b/graphics/ui/babushka_ui_tmp_inventory_select.png.import new file mode 100644 index 0000000..2a3f0f6 --- /dev/null +++ b/graphics/ui/babushka_ui_tmp_inventory_select.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c7wqla0mbu3np" +path="res://.godot/imported/babushka_ui_tmp_inventory_select.png-b544ba0ded36dd6bd66bd197fb76d424.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/ui/babushka_ui_tmp_inventory_select.png" +dest_files=["res://.godot/imported/babushka_ui_tmp_inventory_select.png-b544ba0ded36dd6bd66bd197fb76d424.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 index ac2ecd1..543ab9d 100644 Binary files a/graphics/ui/untitled.afdesign and b/graphics/ui/untitled.afdesign differ diff --git a/graphics/ui/untitled.afdesign~lock~ b/graphics/ui/untitled.afdesign~lock~ new file mode 100644 index 0000000..2a748b6 Binary files /dev/null and b/graphics/ui/untitled.afdesign~lock~ differ diff --git a/prefabs/UI/Inventory/Inventory.tscn b/prefabs/UI/Inventory/Inventory.tscn index 53f5f9e..8912fac 100644 --- a/prefabs/UI/Inventory/Inventory.tscn +++ b/prefabs/UI/Inventory/Inventory.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://cgjc4wurbgimy"] +[gd_scene load_steps=5 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://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"] +[ext_resource type="Texture2D" uid="uid://c7wqla0mbu3np" path="res://graphics/ui/babushka_ui_tmp_inventory_select.png" id="4_tiss4"] [node name="Inventory" type="Control"] layout_mode = 3 @@ -13,8 +14,18 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_6wusm") -[node name="Slots" type="GridContainer" parent="."] -custom_minimum_size = Vector2(500, 200) +[node name="SlotsContainer" type="Control" parent="."] +custom_minimum_size = Vector2(500, 0) +layout_mode = 1 +anchors_preset = 13 +anchor_left = 0.5 +anchor_right = 0.5 +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 @@ -24,8 +35,29 @@ 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) +layout_mode = 1 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="Selector" type="TextureRect" parent="SlotsContainer/SlotSelectContainer"] +custom_minimum_size = Vector2(100, 100) +layout_mode = 0 +offset_left = 1.0 +offset_right = 101.0 +offset_bottom = 100.0 +texture = ExtResource("4_tiss4") +expand_mode = 1 + [node name="InventoryTester" type="Node" parent="."] script = ExtResource("3_exrk4") _testItemToCreate = ExtResource("4_5fdxq") diff --git a/project.godot b/project.godot index bba5e15..cc39fa4 100644 --- a/project.godot +++ b/project.godot @@ -120,6 +120,16 @@ ui_inventory_open_close={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) ] } +ui_inventory_advance={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null) +] +} +ui_inventory_disadvance={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null) +] +} [internationalization] diff --git a/scripts/CSharp/Common/Inventory/InventoryUi.cs b/scripts/CSharp/Common/Inventory/InventoryUi.cs index 086d8da..f9241be 100644 --- a/scripts/CSharp/Common/Inventory/InventoryUi.cs +++ b/scripts/CSharp/Common/Inventory/InventoryUi.cs @@ -7,19 +7,24 @@ public partial class InventoryUi : Control { private GridContainer _slots; private InventoryInstance _playerInventory; + private Control _slotSelect; private int? _slotOnMouse; + private int _selectedSlot = 0; + private bool _inventoryExtended = false; private Tween? _inventoryExtensionTween; public override void _Ready() { GD.Print("Ready inventory ui"); - _slots = GetNode("Slots"); + _slots = GetNode("SlotsContainer/Slots"); _playerInventory = InventoryManager.Instance.playerInventory; + _slotSelect = GetNode("SlotsContainer/SlotSelectContainer/Selector"); PopulateSlots(); SetSlotContent(); + SetSlotSelectPosition(); } public override void _ExitTree() @@ -40,6 +45,11 @@ public partial class InventoryUi : Control } } + private void SetSlotSelectPosition() + { + _slotSelect.Position = new Vector2(_selectedSlot * 100, 0); + } + private void PopulateSlots() { var slotPackedScene = GD.Load("res://prefabs/UI/Inventory/Slot.tscn"); @@ -64,7 +74,7 @@ public partial class InventoryUi : Control private void SlotClicked(int index) { if (!_inventoryExtended) return; - + GD.Print($"Clicked slot {index}"); if (_slotOnMouse == null) { @@ -86,29 +96,50 @@ public partial class InventoryUi : Control { if (Input.IsActionJustPressed("ui_inventory_open_close")) { - _inventoryExtensionTween?.Kill(); - - _inventoryExtended = !_inventoryExtended; - if (_inventoryExtended) - { - //GD.Print("Open inventory"); - _inventoryExtensionTween = GetTree().CreateTween(); - _inventoryExtensionTween - .TweenProperty(_slots, "offset_bottom", -100, 0.4) - .SetTrans(Tween.TransitionType.Quad) - .SetEase(Tween.EaseType.Out); - } - else - { - //GD.Print("Close inventory"); - _inventoryExtensionTween = GetTree().CreateTween(); - _inventoryExtensionTween - .TweenProperty(_slots, "offset_bottom", 200, 0.4) - .SetTrans(Tween.TransitionType.Quad) - .SetEase(Tween.EaseType.Out); - - _slotOnMouse = null; - } + InputInventoryOpenClose(); + } + if (Input.IsActionJustPressed("ui_inventory_disadvance")) + { + _selectedSlot++; + if (_selectedSlot > 9) + _selectedSlot = 0; + SetSlotSelectPosition(); + } + if(Input.IsActionJustPressed("ui_inventory_advance")) + { + _selectedSlot--; + if (_selectedSlot < 0) + _selectedSlot = 9; + SetSlotSelectPosition(); + } + } + + private void InputInventoryOpenClose() + { + _inventoryExtensionTween?.Kill(); + + _inventoryExtended = !_inventoryExtended; + if (_inventoryExtended) + { + //GD.Print("Open inventory"); + _inventoryExtensionTween = GetTree().CreateTween(); + _slotSelect.Hide(); + _inventoryExtensionTween + .TweenProperty(_slots, "offset_bottom", -100, 0.4) + .SetTrans(Tween.TransitionType.Quad) + .SetEase(Tween.EaseType.Out); + } + else + { + //GD.Print("Close inventory"); + _inventoryExtensionTween = GetTree().CreateTween(); + _slotSelect.Show(); + _inventoryExtensionTween + .TweenProperty(_slots, "offset_bottom", 200, 0.4) + .SetTrans(Tween.TransitionType.Quad) + .SetEase(Tween.EaseType.Out); + + _slotOnMouse = null; } } }