From f1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 8 Sep 2025 22:10:45 -0300 Subject: inventário acessivel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 5 ++ scenes/GUI/hud.tscn | 88 +++++++++++++++++++++++++++++ scenes/GUI/invetory_menu.tscn | 36 ++++++++++++ scenes/GUI/item_menu_entry.tscn | 35 ++++++++++++ scenes/Game.tscn | 9 ++- scenes/hud.tscn | 88 ----------------------------- scripts/GUI/InventoryMenu.cs | 52 +++++++++++++++++ scripts/GUI/InventoryMenu.cs.uid | 1 + scripts/GUI/ItemMenuEntry.cs | 41 ++++++++++++++ scripts/GUI/ItemMenuEntry.cs.uid | 1 + scripts/entities/actions/DropAction.cs | 13 +++++ scripts/entities/actions/DropAction.cs.uid | 1 + scripts/entities/actions/ItemAction.cs | 6 +- scripts/entities/actors/Actor.cs | 2 +- scripts/entities/actors/Inventory.cs | 4 ++ scripts/entities/actors/Player.cs | 2 + scripts/entities/items/ConsumableItem.cs | 8 ++- scripts/entities/items/HealingConsumable.cs | 3 +- scripts/input/InputHandler.cs | 4 +- scripts/input/InventoryInputHandler.cs | 65 +++++++++++++++++++++ scripts/input/InventoryInputHandler.cs.uid | 1 + scripts/input/MainGameInputHandler.cs | 6 +- 22 files changed, 374 insertions(+), 97 deletions(-) create mode 100644 scenes/GUI/hud.tscn create mode 100644 scenes/GUI/invetory_menu.tscn create mode 100644 scenes/GUI/item_menu_entry.tscn delete mode 100644 scenes/hud.tscn create mode 100644 scripts/GUI/InventoryMenu.cs create mode 100644 scripts/GUI/InventoryMenu.cs.uid create mode 100644 scripts/GUI/ItemMenuEntry.cs create mode 100644 scripts/GUI/ItemMenuEntry.cs.uid create mode 100644 scripts/entities/actions/DropAction.cs create mode 100644 scripts/entities/actions/DropAction.cs.uid create mode 100644 scripts/input/InventoryInputHandler.cs create mode 100644 scripts/input/InventoryInputHandler.cs.uid diff --git a/project.godot b/project.godot index fa6d1ed..5d0052e 100644 --- a/project.godot +++ b/project.godot @@ -104,6 +104,11 @@ pick-item={ "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":59,"physical_keycode":0,"key_label":0,"unicode":59,"location":0,"echo":false,"script":null) ] } +open-inventory={ +"deadzone": 0.2, +"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":73,"physical_keycode":0,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) +] +} [rendering] diff --git a/scenes/GUI/hud.tscn b/scenes/GUI/hud.tscn new file mode 100644 index 0000000..034d2d9 --- /dev/null +++ b/scenes/GUI/hud.tscn @@ -0,0 +1,88 @@ +[gd_scene load_steps=9 format=3 uid="uid://b4h4xyr1g8o50"] + +[ext_resource type="Script" uid="uid://br7w3abe0boqb" path="res://scripts/GUI/Hud.cs" id="1_gdt2y"] +[ext_resource type="Texture2D" uid="uid://cbqd3s1065am6" path="res://assets/sprites/inter-face/HP/HealthBarUnder2.png" id="2_p7vwb"] +[ext_resource type="Texture2D" uid="uid://c1cktg2arnphx" path="res://assets/sprites/inter-face/HP/HealthBarOverlay2.png" id="3_ktti3"] +[ext_resource type="Texture2D" uid="uid://sgqb6ccdbt4h" path="res://assets/sprites/inter-face/MP/ManaBarUnder2.png" id="4_8dubc"] +[ext_resource type="Texture2D" uid="uid://do06pptudsqdp" path="res://assets/sprites/inter-face/HP/HealthBar2.png" id="4_cgfq5"] +[ext_resource type="Texture2D" uid="uid://b2msd7khjxtat" path="res://assets/sprites/inter-face/MP/ManaBarOverlay.png" id="5_p7vwb"] +[ext_resource type="Texture2D" uid="uid://b1rotmrfynpau" path="res://assets/sprites/inter-face/MP/ManaBar.png" id="6_ktti3"] +[ext_resource type="Script" uid="uid://0al5sptrm0fn" path="res://scripts/GUI/MessageLog.cs" id="8_hd3ao"] + +[node name="HUD" type="CanvasLayer"] +script = ExtResource("1_gdt2y") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +size_flags_stretch_ratio = 5.0 + +[node name="InfoBar" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 0 + +[node name="Stats" type="PanelContainer" parent="VBoxContainer/InfoBar"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/InfoBar/Stats"] +layout_mode = 2 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_top = 5 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 5 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/InfoBar/Stats/MarginContainer"] +layout_mode = 2 + +[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +ratio = 5.0 + +[node name="HPbar" type="TextureProgressBar" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer"] +custom_minimum_size = Vector2(50, 10) +layout_mode = 2 +size_flags_horizontal = 3 +value = 100.0 +nine_patch_stretch = true +texture_under = ExtResource("2_p7vwb") +texture_over = ExtResource("3_ktti3") +texture_progress = ExtResource("4_cgfq5") + +[node name="AspectRatioContainer2" type="AspectRatioContainer" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +ratio = 5.0 + +[node name="MPbar" type="TextureProgressBar" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer2"] +custom_minimum_size = Vector2(50, 10) +layout_mode = 2 +size_flags_horizontal = 3 +value = 100.0 +nine_patch_stretch = true +texture_under = ExtResource("4_8dubc") +texture_over = ExtResource("5_p7vwb") +texture_progress = ExtResource("6_ktti3") + +[node name="MessagelogContainer" type="PanelContainer" parent="VBoxContainer/InfoBar"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 2.0 + +[node name="MessageLog" type="ScrollContainer" parent="VBoxContainer/InfoBar/MessagelogContainer"] +layout_mode = 2 +script = ExtResource("8_hd3ao") + +[node name="MessageList" type="VBoxContainer" parent="VBoxContainer/InfoBar/MessagelogContainer/MessageLog"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 0 diff --git a/scenes/GUI/invetory_menu.tscn b/scenes/GUI/invetory_menu.tscn new file mode 100644 index 0000000..9f36186 --- /dev/null +++ b/scenes/GUI/invetory_menu.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=3 format=3 uid="uid://cnfa8cijjtc05"] + +[ext_resource type="Script" uid="uid://dukpdkyy365y4" path="res://scripts/GUI/InventoryMenu.cs" id="1_elppw"] + +[sub_resource type="LabelSettings" id="LabelSettings_mo078"] +font_size = 32 + +[node name="InvetoryMenu" type="CanvasLayer"] +layer = 2 +script = ExtResource("1_elppw") + +[node name="CenterContainer" type="CenterContainer" parent="."] +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="VBoxContainer" type="VBoxContainer" parent="CenterContainer/PanelContainer"] +layout_mode = 2 + +[node name="Title" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer"] +layout_mode = 2 +text = "Inventário" +label_settings = SubResource("LabelSettings_mo078") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HSeparator" type="HSeparator" parent="CenterContainer/PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="Items" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer"] +layout_mode = 2 diff --git a/scenes/GUI/item_menu_entry.tscn b/scenes/GUI/item_menu_entry.tscn new file mode 100644 index 0000000..64692cb --- /dev/null +++ b/scenes/GUI/item_menu_entry.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=3 format=3 uid="uid://c511reen3sdq"] + +[ext_resource type="Script" uid="uid://bdejwf8qmlii0" path="res://scripts/GUI/ItemMenuEntry.cs" id="1_jbgv3"] +[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/actors/player.png" id="2_boylf"] + +[node name="ItemMenuEntry" type="HBoxContainer"] +offset_right = 8.0 +offset_bottom = 8.0 +size_flags_horizontal = 3 +script = ExtResource("1_jbgv3") + +[node name="Icon" type="TextureRect" parent="."] +layout_mode = 2 +texture = ExtResource("2_boylf") +expand_mode = 3 + +[node name="Shortcut" type="Label" parent="."] +layout_mode = 2 +text = "Atalho" + +[node name="VSeparator" type="VSeparator" parent="."] +layout_mode = 2 + +[node name="ItemName" type="Label" parent="."] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Nome" + +[node name="ActivateBtn" type="Button" parent="."] +layout_mode = 2 +text = "Usar" + +[node name="DropButton" type="Button" parent="."] +layout_mode = 2 +text = "Descartar" diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 2a59777..4cb5231 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://u5h6iqyi8wd0"] +[gd_scene load_steps=13 format=3 uid="uid://u5h6iqyi8wd0"] [ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"] [ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/input/MainGameInputHandler.cs" id="3_400sg"] @@ -9,8 +9,9 @@ [ext_resource type="Script" uid="uid://bamlnrj5bm1rd" path="res://scripts/input/InspectInputHandler.cs" id="5_g4kob"] [ext_resource type="PackedScene" uid="uid://bryqrafavmwj4" path="res://scenes/Details.tscn" id="5_qy1jj"] [ext_resource type="Script" uid="uid://bereyrj1s46y5" path="res://scripts/map/FieldOfView.cs" id="5_s0nni"] -[ext_resource type="PackedScene" uid="uid://b4h4xyr1g8o50" path="res://scenes/hud.tscn" id="6_aug50"] +[ext_resource type="PackedScene" uid="uid://b4h4xyr1g8o50" path="res://scenes/GUI/hud.tscn" id="6_aug50"] [ext_resource type="Script" uid="uid://dspqgdxg5jji0" path="res://scripts/input/PickupInputHandler.cs" id="10_3xj3m"] +[ext_resource type="Script" uid="uid://bjcjktvyrdh10" path="res://scripts/input/InventoryInputHandler.cs" id="11_mcffj"] [node name="Game" type="Node"] script = ExtResource("1_cpr0p") @@ -50,6 +51,10 @@ map = NodePath("../../Map") [node name="PickupInputHandler" type="Node" parent="InputHandler"] script = ExtResource("10_3xj3m") +[node name="InventoryInputHandler" type="Node" parent="InputHandler" node_paths=PackedStringArray("map")] +script = ExtResource("11_mcffj") +map = NodePath("../../Map") + [node name="Camera2D" type="Camera2D" parent="."] offset = Vector2(8, 8) zoom = Vector2(2, 2) diff --git a/scenes/hud.tscn b/scenes/hud.tscn deleted file mode 100644 index 034d2d9..0000000 --- a/scenes/hud.tscn +++ /dev/null @@ -1,88 +0,0 @@ -[gd_scene load_steps=9 format=3 uid="uid://b4h4xyr1g8o50"] - -[ext_resource type="Script" uid="uid://br7w3abe0boqb" path="res://scripts/GUI/Hud.cs" id="1_gdt2y"] -[ext_resource type="Texture2D" uid="uid://cbqd3s1065am6" path="res://assets/sprites/inter-face/HP/HealthBarUnder2.png" id="2_p7vwb"] -[ext_resource type="Texture2D" uid="uid://c1cktg2arnphx" path="res://assets/sprites/inter-face/HP/HealthBarOverlay2.png" id="3_ktti3"] -[ext_resource type="Texture2D" uid="uid://sgqb6ccdbt4h" path="res://assets/sprites/inter-face/MP/ManaBarUnder2.png" id="4_8dubc"] -[ext_resource type="Texture2D" uid="uid://do06pptudsqdp" path="res://assets/sprites/inter-face/HP/HealthBar2.png" id="4_cgfq5"] -[ext_resource type="Texture2D" uid="uid://b2msd7khjxtat" path="res://assets/sprites/inter-face/MP/ManaBarOverlay.png" id="5_p7vwb"] -[ext_resource type="Texture2D" uid="uid://b1rotmrfynpau" path="res://assets/sprites/inter-face/MP/ManaBar.png" id="6_ktti3"] -[ext_resource type="Script" uid="uid://0al5sptrm0fn" path="res://scripts/GUI/MessageLog.cs" id="8_hd3ao"] - -[node name="HUD" type="CanvasLayer"] -script = ExtResource("1_gdt2y") - -[node name="VBoxContainer" type="VBoxContainer" parent="."] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -size_flags_stretch_ratio = 5.0 - -[node name="InfoBar" type="HBoxContainer" parent="VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -theme_override_constants/separation = 0 - -[node name="Stats" type="PanelContainer" parent="VBoxContainer/InfoBar"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/InfoBar/Stats"] -layout_mode = 2 -theme_override_constants/margin_left = 5 -theme_override_constants/margin_top = 5 -theme_override_constants/margin_right = 5 -theme_override_constants/margin_bottom = 5 - -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/InfoBar/Stats/MarginContainer"] -layout_mode = 2 - -[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -ratio = 5.0 - -[node name="HPbar" type="TextureProgressBar" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer"] -custom_minimum_size = Vector2(50, 10) -layout_mode = 2 -size_flags_horizontal = 3 -value = 100.0 -nine_patch_stretch = true -texture_under = ExtResource("2_p7vwb") -texture_over = ExtResource("3_ktti3") -texture_progress = ExtResource("4_cgfq5") - -[node name="AspectRatioContainer2" type="AspectRatioContainer" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -ratio = 5.0 - -[node name="MPbar" type="TextureProgressBar" parent="VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer2"] -custom_minimum_size = Vector2(50, 10) -layout_mode = 2 -size_flags_horizontal = 3 -value = 100.0 -nine_patch_stretch = true -texture_under = ExtResource("4_8dubc") -texture_over = ExtResource("5_p7vwb") -texture_progress = ExtResource("6_ktti3") - -[node name="MessagelogContainer" type="PanelContainer" parent="VBoxContainer/InfoBar"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_stretch_ratio = 2.0 - -[node name="MessageLog" type="ScrollContainer" parent="VBoxContainer/InfoBar/MessagelogContainer"] -layout_mode = 2 -script = ExtResource("8_hd3ao") - -[node name="MessageList" type="VBoxContainer" parent="VBoxContainer/InfoBar/MessagelogContainer/MessageLog"] -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_constants/separation = 0 diff --git a/scripts/GUI/InventoryMenu.cs b/scripts/GUI/InventoryMenu.cs new file mode 100644 index 0000000..bfb1795 --- /dev/null +++ b/scripts/GUI/InventoryMenu.cs @@ -0,0 +1,52 @@ +using Godot; +using System; + +public partial class InventoryMenu : CanvasLayer +{ + private static readonly PackedScene itemMenuEntryScene = GD.Load("res://scenes/GUI/item_menu_entry.tscn"); + [Signal] + public delegate void ItemSelectedEventHandler(ConsumableItem item); + [Signal] + public delegate void ItemDropEventHandler(ConsumableItem item); + + private VBoxContainer itemsNode; + + public override void _Ready() { + base._Ready(); + + itemsNode = GetNode("CenterContainer/PanelContainer/VBoxContainer/Items"); + Hide(); + } + + public void OnActivate(ConsumableItem item) { + EmitSignal(SignalName.ItemSelected, item); + } + + public void OnDrop(ConsumableItem item) { + EmitSignal(SignalName.ItemDrop, item); + } + + private void RegisterItem(int index, ConsumableItem item) { + char? shortcut = null; + + // Só terá atalho para as letras do alfabeto. + if (index < 26) { + shortcut = (char)('a' + index); + } + + ItemMenuEntry itemEntry = itemMenuEntryScene.Instantiate(); + + itemsNode.AddChild(itemEntry); + itemEntry.Initialize(item, shortcut); + itemEntry.Activate += OnActivate; + itemEntry.Drop += OnDrop; + } + + public void Initialize(Inventory inventory) { + for (int i = 0; i < inventory.Items.Count; i++) { + RegisterItem(i, inventory.Items[i]); + } + + Show(); + } +} diff --git a/scripts/GUI/InventoryMenu.cs.uid b/scripts/GUI/InventoryMenu.cs.uid new file mode 100644 index 0000000..594b644 --- /dev/null +++ b/scripts/GUI/InventoryMenu.cs.uid @@ -0,0 +1 @@ +uid://dukpdkyy365y4 diff --git a/scripts/GUI/ItemMenuEntry.cs b/scripts/GUI/ItemMenuEntry.cs new file mode 100644 index 0000000..449c97b --- /dev/null +++ b/scripts/GUI/ItemMenuEntry.cs @@ -0,0 +1,41 @@ +using Godot; + +public partial class ItemMenuEntry : HBoxContainer +{ + private TextureRect icon; + private Label shortcutLabel; + private Label nameLabel; + private Button activateBtn; + private Button dropBtn; + + [Signal] + public delegate void ActivateEventHandler(ConsumableItem Item); + + [Signal] + public delegate void DropEventHandler(ConsumableItem item); + + private ConsumableItem item; + + public void Initialize(ConsumableItem item, char? shortcut) { + this.item = item; + nameLabel.Text = item.DisplayName; + if (shortcut != null) { + shortcutLabel.Text = $"{shortcut}"; + } else { + shortcutLabel.Text = ""; + } + icon.Texture = item.Texture; + } + + public override void _Ready() { + base._Ready(); + icon = GetNode("Icon"); + shortcutLabel = GetNode