Added slot select

pull/3/head
cblech 9 months ago
parent 77591425cb
commit daa53e4aef

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@ -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

Binary file not shown.

@ -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://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="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="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"] [node name="Inventory" type="Control"]
layout_mode = 3 layout_mode = 3
@ -13,8 +14,18 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("1_6wusm") script = ExtResource("1_6wusm")
[node name="Slots" type="GridContainer" parent="."] [node name="SlotsContainer" type="Control" parent="."]
custom_minimum_size = Vector2(500, 200) 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 layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.5 anchor_left = 0.5
@ -24,8 +35,29 @@ anchor_bottom = 1.0
offset_bottom = 200.0 offset_bottom = 200.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 0 grow_vertical = 0
theme_override_constants/h_separation = 0
theme_override_constants/v_separation = 0
columns = 10 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="."] [node name="InventoryTester" type="Node" parent="."]
script = ExtResource("3_exrk4") script = ExtResource("3_exrk4")
_testItemToCreate = ExtResource("4_5fdxq") _testItemToCreate = ExtResource("4_5fdxq")

@ -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) "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] [internationalization]

@ -7,19 +7,24 @@ public partial class InventoryUi : Control
{ {
private GridContainer _slots; private GridContainer _slots;
private InventoryInstance _playerInventory; private InventoryInstance _playerInventory;
private Control _slotSelect;
private int? _slotOnMouse; private int? _slotOnMouse;
private int _selectedSlot = 0;
private bool _inventoryExtended = false; private bool _inventoryExtended = false;
private Tween? _inventoryExtensionTween; private Tween? _inventoryExtensionTween;
public override void _Ready() public override void _Ready()
{ {
GD.Print("Ready inventory ui"); GD.Print("Ready inventory ui");
_slots = GetNode<GridContainer>("Slots"); _slots = GetNode<GridContainer>("SlotsContainer/Slots");
_playerInventory = InventoryManager.Instance.playerInventory; _playerInventory = InventoryManager.Instance.playerInventory;
_slotSelect = GetNode<Control>("SlotsContainer/SlotSelectContainer/Selector");
PopulateSlots(); PopulateSlots();
SetSlotContent(); SetSlotContent();
SetSlotSelectPosition();
} }
public override void _ExitTree() 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() private void PopulateSlots()
{ {
var slotPackedScene = GD.Load<PackedScene>("res://prefabs/UI/Inventory/Slot.tscn"); var slotPackedScene = GD.Load<PackedScene>("res://prefabs/UI/Inventory/Slot.tscn");
@ -64,7 +74,7 @@ public partial class InventoryUi : Control
private void SlotClicked(int index) private void SlotClicked(int index)
{ {
if (!_inventoryExtended) return; if (!_inventoryExtended) return;
GD.Print($"Clicked slot {index}"); GD.Print($"Clicked slot {index}");
if (_slotOnMouse == null) if (_slotOnMouse == null)
{ {
@ -86,29 +96,50 @@ public partial class InventoryUi : Control
{ {
if (Input.IsActionJustPressed("ui_inventory_open_close")) if (Input.IsActionJustPressed("ui_inventory_open_close"))
{ {
_inventoryExtensionTween?.Kill(); InputInventoryOpenClose();
}
_inventoryExtended = !_inventoryExtended; if (Input.IsActionJustPressed("ui_inventory_disadvance"))
if (_inventoryExtended) {
{ _selectedSlot++;
//GD.Print("Open inventory"); if (_selectedSlot > 9)
_inventoryExtensionTween = GetTree().CreateTween(); _selectedSlot = 0;
_inventoryExtensionTween SetSlotSelectPosition();
.TweenProperty(_slots, "offset_bottom", -100, 0.4) }
.SetTrans(Tween.TransitionType.Quad) if(Input.IsActionJustPressed("ui_inventory_advance"))
.SetEase(Tween.EaseType.Out); {
} _selectedSlot--;
else if (_selectedSlot < 0)
{ _selectedSlot = 9;
//GD.Print("Close inventory"); SetSlotSelectPosition();
_inventoryExtensionTween = GetTree().CreateTween(); }
_inventoryExtensionTween }
.TweenProperty(_slots, "offset_bottom", 200, 0.4)
.SetTrans(Tween.TransitionType.Quad) private void InputInventoryOpenClose()
.SetEase(Tween.EaseType.Out); {
_inventoryExtensionTween?.Kill();
_slotOnMouse = null;
} _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;
} }
} }
} }

Loading…
Cancel
Save