Added open close inventory
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
[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://6def3c0mcnoq" path="res://prefabs/UI/Inventory/Slots.cs" id="2_5fdxq"]
|
||||||
[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"]
|
||||||
|
|
||||||
@@ -16,17 +17,16 @@ script = ExtResource("1_6wusm")
|
|||||||
[node name="Slots" type="GridContainer" parent="."]
|
[node name="Slots" type="GridContainer" parent="."]
|
||||||
custom_minimum_size = Vector2(500, 200)
|
custom_minimum_size = Vector2(500, 200)
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = -1
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_top = 0.5
|
anchor_top = 1.0
|
||||||
anchor_right = 0.5
|
anchor_right = 0.5
|
||||||
anchor_bottom = 0.5
|
anchor_bottom = 1.0
|
||||||
offset_left = -335.0
|
|
||||||
offset_right = 341.0
|
|
||||||
offset_bottom = 200.0
|
offset_bottom = 200.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 0
|
||||||
columns = 10
|
columns = 10
|
||||||
|
script = ExtResource("2_5fdxq")
|
||||||
|
|
||||||
[node name="InventoryTester" type="Node" parent="."]
|
[node name="InventoryTester" type="Node" parent="."]
|
||||||
script = ExtResource("3_exrk4")
|
script = ExtResource("3_exrk4")
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public partial class Slots : GridContainer
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://6def3c0mcnoq
|
||||||
@@ -115,6 +115,11 @@ interact={
|
|||||||
"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_open_close={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"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)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[internationalization]
|
[internationalization]
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
@@ -9,6 +10,9 @@ public partial class InventoryUi : Control
|
|||||||
|
|
||||||
private int? _slotOnMouse;
|
private int? _slotOnMouse;
|
||||||
|
|
||||||
|
private bool _inventoryExtended = false;
|
||||||
|
private Tween? _inventoryExtensionTween;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
GD.Print("Ready inventory ui");
|
GD.Print("Ready inventory ui");
|
||||||
@@ -59,9 +63,12 @@ public partial class InventoryUi : Control
|
|||||||
|
|
||||||
private void SlotClicked(int index)
|
private void SlotClicked(int index)
|
||||||
{
|
{
|
||||||
|
if (!_inventoryExtended) return;
|
||||||
|
|
||||||
GD.Print($"Clicked slot {index}");
|
GD.Print($"Clicked slot {index}");
|
||||||
if (_slotOnMouse == null)
|
if (_slotOnMouse == null)
|
||||||
{
|
{
|
||||||
|
if (_playerInventory.Slots[index].IsEmpty()) return;
|
||||||
_slotOnMouse = index;
|
_slotOnMouse = index;
|
||||||
GD.Print($"Slot on mouse: {_slotOnMouse}");
|
GD.Print($"Slot on mouse: {_slotOnMouse}");
|
||||||
}
|
}
|
||||||
@@ -74,4 +81,34 @@ public partial class InventoryUi : Control
|
|||||||
SetSlotContent();
|
SetSlotContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user