From 828adfd8aff1270b92b000445951f2b44b1acc06 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Mon, 5 Aug 2024 14:24:48 +0200 Subject: [PATCH] moved inventory from player to its own scene and added a visible layout can be opened with E or xbox Y, nintendo X or plays triangle --- assets/textures/book.png | Bin 0 -> 4399 bytes assets/textures/book.png.import | 34 +++++++++ project.godot | 6 ++ scenes/components/item_protoset.tres | 26 +++---- scenes/elements/player.tscn | 8 +- scenes/interfaces/inventory.tscn | 108 +++++++++++++++++++++++++++ scenes/interfaces/pause_menu.tscn | 4 +- scenes/main_level.tscn | 6 +- scripts/inventory.gd | 25 +++++++ 9 files changed, 192 insertions(+), 25 deletions(-) create mode 100644 assets/textures/book.png create mode 100644 assets/textures/book.png.import create mode 100644 scenes/interfaces/inventory.tscn create mode 100644 scripts/inventory.gd diff --git a/assets/textures/book.png b/assets/textures/book.png new file mode 100644 index 0000000000000000000000000000000000000000..c2933df9a31ed1f91f13f547a86833809f8150bb GIT binary patch literal 4399 zcmeHLYitx%6rOEu3xyI2NO?Oh5@>OD9{cF-q)REgrCr*E(g&0T($3D@*$(XPY-gw4 zEr_TE1i=Ro6$n2tA_!JfiG~P1z=AX}h=4|kNC+w@4+}`ek_rrKvLPxWw!8QZ> zgU}clkAl7(n)Gbk?>QK2&mjHJr65j40v?srI=sl^EyHq?Fx{rB*MvA@qA8Qv4u}+E zVJSOHS#jFJ(ll$Kuq15l<}_?9VEzfsu(Ky#%}>{JzbD_T?k3Q0mRznfkIRLJ6Fszjvip`6bIDdCC`0NcrZO z=0`SErDge-OkA8&a3lHX*(07)g>&xJl-FhcaHKx}{P!!)eU!Yq@p z@O|8xlUkEG3(H)c`SP~2Tes{Qns@vg=MztSRC43-j>xJP3f`|{4o@91bx~XEy4-bs z+uNy^S6&?RR(sA($IaCRS&u#W>hOl(s*Q#tOLm^wf4zhM?$;ey zr~ks7j=NWbwYRqXzF^*lM+~Qe7cL&$lfB~bPs6BtU%ixZcGEq}n)1Q1{MY3i%ynR9 z?8NoA550IM4KG@PLQgfjYCkMJdv#LBus?3!>ev=ql|Sx)(%g14X%VDxOscF_tG%Tx zF9%JWAp4Lh77XjVn3o?5bNn)-;y&b;LQZ4Hp-+ssBsh%=tzOC-cA+|{c)5Zqmd~x^ zmoMWTf-!$adR~kLfFM#iJQfUuB5cfQ)NxrDYhu!f>niFpr?DE6%_S=cx0oy@iYSap zjf`uuuK0psueTdM6iKiEe2_6NOwuNb3)3XcjKQAnNK8$#f_?ZXX9Kwpl)lPG|Kpc(=H0k`w7b@>D}$ET%erO0K?~30b{aMRtRVA} zz{ZE7kG4@%F2R`{JYk_6Ho}fXAAxAI&n(goo)^VlP@Ygk>cWLgP_QG)zIF)llQ3ufOVqMu)tfx~9OU1+2;JmURiB12etsNdb z5AkhTjz7(v+y%GyO3ogj=%ESS`4M%Rk-$on|S(-nFZ8L*4Xpm;$oB)f}Y zf-|k`{Ets!FaAdl06pNOU;GZxH9%Lt80eSsKz0q#)h`D6r96;b{~2BBJ=ZA|f?q*V zxGc?XFNNzjmg*}ha>p;ucU^~8!Dw)}cu@rYeK1mM25kF|F(6D+J>J5!p9iH39g@9` zrZl~=YGJkNl7rf>a_qh<_rj-#Wr335aTiohJIUALnbfCa#$TD(dDYX|wzn+%hvAcx z;TdU4DK#zq_Sntr&vp;qlkwNBbH?+jTYZ7;TZ=QMj26Cl<8tXP>CV1|Ypdp~tyz;7 sWDJF8PR_ogMH6PMF+86(W^B6wn<9-qb?)vd%^&6|oa=sPR_!x?11rJNAOHXW literal 0 HcmV?d00001 diff --git a/assets/textures/book.png.import b/assets/textures/book.png.import new file mode 100644 index 0000000..0e76e69 --- /dev/null +++ b/assets/textures/book.png.import @@ -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 diff --git a/project.godot b/project.godot index 9f1b82d..dcc77e3 100644 --- a/project.godot +++ b/project.godot @@ -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] diff --git a/scenes/components/item_protoset.tres b/scenes/components/item_protoset.tres index c3872c9..5011df7 100644 --- a/scenes/components/item_protoset.tres +++ b/scenes/components/item_protoset.tres @@ -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 + } +]" diff --git a/scenes/elements/player.tscn b/scenes/elements/player.tscn index a50959f..c83d6c0 100644 --- a/scenes/elements/player.tscn +++ b/scenes/elements/player.tscn @@ -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 index 0000000..08f856e --- /dev/null +++ b/scenes/interfaces/inventory.tscn @@ -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"] diff --git a/scenes/interfaces/pause_menu.tscn b/scenes/interfaces/pause_menu.tscn index 5b5054c..0aff408 100644 --- a/scenes/interfaces/pause_menu.tscn +++ b/scenes/interfaces/pause_menu.tscn @@ -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 diff --git a/scenes/main_level.tscn b/scenes/main_level.tscn index f5d63c3..831ac97 100644 --- a/scenes/main_level.tscn +++ b/scenes/main_level.tscn @@ -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 index 0000000..7a2457b --- /dev/null +++ b/scripts/inventory.gd @@ -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() -- 2.30.2