moved inventory from player to its own scene and added a visible layout
authorEduardo <[email protected]>
Mon, 5 Aug 2024 12:24:48 +0000 (14:24 +0200)
committerEduardo <[email protected]>
Mon, 5 Aug 2024 12:24:48 +0000 (14:24 +0200)
can be opened with E or xbox Y, nintendo X or plays triangle

assets/textures/book.png [new file with mode: 0644]
assets/textures/book.png.import [new file with mode: 0644]
project.godot
scenes/components/item_protoset.tres
scenes/elements/player.tscn
scenes/interfaces/inventory.tscn [new file with mode: 0644]
scenes/interfaces/pause_menu.tscn
scenes/main_level.tscn
scripts/inventory.gd [new file with mode: 0644]

diff --git a/assets/textures/book.png b/assets/textures/book.png
new file mode 100644 (file)
index 0000000..c2933df
Binary files /dev/null and b/assets/textures/book.png differ
diff --git a/assets/textures/book.png.import b/assets/textures/book.png.import
new file mode 100644 (file)
index 0000000..0e76e69
--- /dev/null
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://xao42kc77tw"
+path="res://.godot/imported/book.png-61f3e8b263a8d68f3575797d785df077.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/book.png"
+dest_files=["res://.godot/imported/book.png-61f3e8b263a8d68f3575797d785df077.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
index 9f1b82d5a9e7e4ee97030dec702b76124919c20c..dcc77e3c937dca116415ca6b67cc5de17f4ced74 100644 (file)
@@ -67,6 +67,12 @@ ui_menu={
 , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
 ]
 }
+ui_inventory={
+"deadzone": 0.5,
+"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
+, 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)
+]
+}
 
 [rendering]
 
index c3872c9cda76902740f802ff0382ea0091647db0..5011df7e29f213d19efec771058e821d73f51c6b 100644 (file)
@@ -5,18 +5,14 @@
 [resource]
 script = ExtResource("1_gt6d6")
 json_data = "[
-       {
-               \"id\": \"base_item\",
-               \"name\": \"Base Item\",
-               \"description\": \"An example item used as a base to create other items.\",
-               
-               \"_comment\": \"Stack Based Inventory\",
-               \"stack_size\": 10,
-               \"weight\": 1.0,
-               
-               \"_comment\": \"Grid Based Inventory\",
-               \"width\": 2,
-               \"height\": 2,
-       }
-]
-"
+    {
+        \"_comment\": \"Grid Based Inventory\",
+        \"description\": \"An example item used as a base to create other items.\",
+        \"height\": 2,
+        \"id\": \"base_item\",
+        \"name\": \"Base Item\",
+        \"stack_size\": 10,
+        \"weight\": 1,
+        \"width\": 2
+    }
+]"
index a50959f1ec04852f938d4c8460fb48c9c2e6e590..c83d6c062d9f622e4646f9d8dfdadcd2f2d547d3 100644 (file)
@@ -1,9 +1,7 @@
-[gd_scene load_steps=6 format=3 uid="uid://k76535tjepm3"]
+[gd_scene load_steps=4 format=3 uid="uid://k76535tjepm3"]
 
 [ext_resource type="Script" path="res://scripts/player.gd" id="1_1webx"]
 [ext_resource type="SpriteFrames" uid="uid://dum0mxk5oajvu" path="res://assets/animations/player_animation.tres" id="1_qf5ok"]
-[ext_resource type="Script" path="res://addons/gloot/core/inventory_stacked.gd" id="3_kcm8a"]
-[ext_resource type="Resource" uid="uid://djhhxwo6oave4" path="res://scenes/components/item_protoset.tres" id="4_oy0ny"]
 
 [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_geqid"]
 radius = 6.0
@@ -21,7 +19,3 @@ position = Vector2(0, -8)
 sprite_frames = ExtResource("1_qf5ok")
 animation = &"idle"
 frame_progress = 0.577081
-
-[node name="InventoryStacked" type="Node" parent="."]
-script = ExtResource("3_kcm8a")
-item_protoset = ExtResource("4_oy0ny")
diff --git a/scenes/interfaces/inventory.tscn b/scenes/interfaces/inventory.tscn
new file mode 100644 (file)
index 0000000..08f856e
--- /dev/null
@@ -0,0 +1,108 @@
+[gd_scene load_steps=10 format=3 uid="uid://cjvtoi20cy8wi"]
+
+[ext_resource type="Script" path="res://scripts/inventory.gd" id="1_8uk8r"]
+[ext_resource type="Script" path="res://addons/gloot/core/inventory_grid_stacked.gd" id="2_yqb3t"]
+[ext_resource type="Script" path="res://addons/gloot/core/item_protoset.gd" id="3_76oh0"]
+[ext_resource type="Script" path="res://addons/gloot/core/inventory_item.gd" id="4_dbq78"]
+[ext_resource type="Texture2D" uid="uid://caxlr5o014d0h" path="res://assets/ui/button_square_depth_line.png" id="4_pbytw"]
+[ext_resource type="Theme" uid="uid://c6osikflt1uy1" path="res://assets/resources/ui_theme.tres" id="6_em7re"]
+[ext_resource type="Script" path="res://addons/gloot/ui/ctrl_inventory_grid.gd" id="7_v7tk4"]
+
+[sub_resource type="Resource" id="Resource_g1a6x"]
+script = ExtResource("3_76oh0")
+json_data = "[
+    {
+        \"_comment\": \"Grid Based Inventory\",
+        \"description\": \"An example item used as a base to create other items.\",
+        \"height\": 2,
+        \"id\": \"base_item\",
+        \"image\": \"res://assets/textures/book.png\",
+        \"name\": \"Base Item\",
+        \"stack_size\": 10,
+        \"weight\": 1,
+        \"width\": 2
+    }
+]"
+
+[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_cujr1"]
+size = Vector2(30, 30)
+
+[node name="InventoryMenu" type="Control"]
+process_mode = 2
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1_8uk8r")
+
+[node name="InventoryGridStacked" type="Node" parent="."]
+script = ExtResource("2_yqb3t")
+size = Vector2i(5, 5)
+item_protoset = SubResource("Resource_g1a6x")
+
+[node name="_Node_80111" type="Node" parent="InventoryGridStacked"]
+script = ExtResource("4_dbq78")
+protoset = SubResource("Resource_g1a6x")
+prototype_id = "base_item"
+
+[node name="CenterContainer" type="CenterContainer" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+
+[node name="PanelContainer" type="PanelContainer" parent="CenterContainer"]
+layout_mode = 2
+
+[node name="NinePatchRect" type="NinePatchRect" parent="CenterContainer/PanelContainer"]
+modulate = Color(0.831856, 0.844692, 0.906161, 1)
+custom_minimum_size = Vector2(100, 100)
+layout_mode = 2
+texture = ExtResource("4_pbytw")
+patch_margin_left = 15
+patch_margin_top = 15
+patch_margin_right = 15
+patch_margin_bottom = 25
+
+[node name="MarginContainer" type="MarginContainer" parent="CenterContainer/PanelContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 50
+theme_override_constants/margin_top = 20
+theme_override_constants/margin_right = 50
+theme_override_constants/margin_bottom = 35
+
+[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer"]
+layout_mode = 2
+
+[node name="Row1Container" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
+layout_mode = 2
+alignment = 1
+
+[node name="CtrlInventoryGrid" type="Control" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Row1Container"]
+custom_minimum_size = Vector2(100, 100)
+layout_mode = 2
+script = ExtResource("7_v7tk4")
+inventory_path = NodePath("../../../../../../InventoryGridStacked")
+default_item_texture = SubResource("PlaceholderTexture2D_cujr1")
+
+[node name="MarginContainer" type="MarginContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_top = 20
+
+[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/MarginContainer"]
+layout_mode = 2
+alignment = 2
+
+[node name="ReturnButton" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer"]
+modulate = Color(0.901197, 0.823165, 0.861526, 1)
+custom_minimum_size = Vector2(150, 0)
+layout_mode = 2
+theme = ExtResource("6_em7re")
+text = "Return"
+
+[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
+[connection signal="pressed" from="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer/ReturnButton" to="." method="_on_return_button_pressed"]
index 5b5054ce6ec3f004f2aed320b7394b664c9b29a6..0aff4088eebbfd93470f4a14ff7f2b4c57362626 100644 (file)
@@ -3,7 +3,7 @@
 [ext_resource type="Script" path="res://scripts/pause_menu.gd" id="1_aq3as"]
 [ext_resource type="Script" path="res://addons/label_font_auto_sizer/label_auto_sizer.gd" id="2_j81qh"]
 
-[sub_resource type="LabelSettings" id="LabelSettings_0w75j"]
+[sub_resource type="LabelSettings" id="LabelSettings_3vmtb"]
 font_size = 50
 
 [node name="PauseMenu" type="Control"]
@@ -33,7 +33,7 @@ custom_minimum_size = Vector2(250, 100)
 layout_mode = 2
 theme_override_font_sizes/font_size = 16
 text = "Pause"
-label_settings = SubResource("LabelSettings_0w75j")
+label_settings = SubResource("LabelSettings_3vmtb")
 horizontal_alignment = 1
 vertical_alignment = 1
 autowrap_mode = 3
index f5d63c368a8196f2f0b4e4b285c1f64f4fb9c10c..831ac979496efa1fd6ed07d3f763e6df9ae18500 100644 (file)
@@ -1,10 +1,11 @@
-[gd_scene load_steps=8 format=4 uid="uid://ds1fjw3marbia"]
+[gd_scene load_steps=9 format=4 uid="uid://ds1fjw3marbia"]
 
 [ext_resource type="PackedScene" uid="uid://k76535tjepm3" path="res://scenes/elements/player.tscn" id="1_6iuf6"]
 [ext_resource type="Script" path="res://scripts/main_level.gd" id="1_fdviv"]
 [ext_resource type="Texture2D" uid="uid://bj3fteudhyal6" path="res://assets/textures/Overworld.png" id="1_pt2os"]
 [ext_resource type="PackedScene" uid="uid://da1uex028xkv1" path="res://scenes/elements/door_scene_manager.tscn" id="1_qqjfh"]
 [ext_resource type="PackedScene" uid="uid://d11oo2pxcah1g" path="res://scenes/interfaces/pause_menu.tscn" id="2_4k3ic"]
+[ext_resource type="PackedScene" uid="uid://cjvtoi20cy8wi" path="res://scenes/interfaces/inventory.tscn" id="6_a0ayx"]
 
 [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_n0o3p"]
 texture = ExtResource("1_pt2os")
@@ -1665,3 +1666,6 @@ offset_left = -288.0
 offset_top = -162.0
 offset_right = 288.0
 offset_bottom = 162.0
+
+[node name="InventoryMenu" parent="Player/Camera2D" instance=ExtResource("6_a0ayx")]
+process_mode = 3
diff --git a/scripts/inventory.gd b/scripts/inventory.gd
new file mode 100644 (file)
index 0000000..7a2457b
--- /dev/null
@@ -0,0 +1,25 @@
+extends Control
+
+
+var inventory_open: bool = false
+var save_menu: Node
+
+
+func _ready():
+       visible = inventory_open
+
+
+func _process(_delta):
+       if Input.is_action_just_pressed("ui_inventory"):
+               open_inventory()
+               print("open inventory (", inventory_open, ")")
+
+
+func open_inventory():
+       inventory_open = !inventory_open
+       visible = inventory_open
+       get_tree().paused = inventory_open
+
+
+func _on_return_button_pressed():
+       open_inventory()