summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project.godot5
-rw-r--r--scenes/GUI/hud.tscn (renamed from scenes/hud.tscn)0
-rw-r--r--scenes/GUI/invetory_menu.tscn36
-rw-r--r--scenes/GUI/item_menu_entry.tscn35
-rw-r--r--scenes/Game.tscn9
-rw-r--r--scripts/GUI/InventoryMenu.cs52
-rw-r--r--scripts/GUI/InventoryMenu.cs.uid1
-rw-r--r--scripts/GUI/ItemMenuEntry.cs41
-rw-r--r--scripts/GUI/ItemMenuEntry.cs.uid1
-rw-r--r--scripts/entities/actions/DropAction.cs13
-rw-r--r--scripts/entities/actions/DropAction.cs.uid1
-rw-r--r--scripts/entities/actions/ItemAction.cs6
-rw-r--r--scripts/entities/actors/Actor.cs2
-rw-r--r--scripts/entities/actors/Inventory.cs4
-rw-r--r--scripts/entities/actors/Player.cs2
-rw-r--r--scripts/entities/items/ConsumableItem.cs8
-rw-r--r--scripts/entities/items/HealingConsumable.cs3
-rw-r--r--scripts/input/InputHandler.cs4
-rw-r--r--scripts/input/InventoryInputHandler.cs65
-rw-r--r--scripts/input/InventoryInputHandler.cs.uid1
-rw-r--r--scripts/input/MainGameInputHandler.cs6
21 files changed, 286 insertions, 9 deletions
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/hud.tscn b/scenes/GUI/hud.tscn
index 034d2d9..034d2d9 100644
--- a/scenes/hud.tscn
+++ b/scenes/GUI/hud.tscn
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/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<PackedScene>("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<VBoxContainer>("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<ItemMenuEntry>();
+
+ 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<TextureRect>("Icon");
+ shortcutLabel = GetNode<Label>("Shortcut");
+ nameLabel = GetNode<Label>("ItemName");
+ activateBtn = GetNode<Button>("ActivateBtn");
+ dropBtn = GetNode<Button>("DropButton");
+
+ activateBtn.Pressed += () => EmitSignal(SignalName.Activate, item);
+ dropBtn.Pressed += () => EmitSignal(SignalName.Drop, item);
+ }
+}
diff --git a/scripts/GUI/ItemMenuEntry.cs.uid b/scripts/GUI/ItemMenuEntry.cs.uid
new file mode 100644
index 0000000..9ebeb06
--- /dev/null
+++ b/scripts/GUI/ItemMenuEntry.cs.uid
@@ -0,0 +1 @@
+uid://bdejwf8qmlii0
diff --git a/scripts/entities/actions/DropAction.cs b/scripts/entities/actions/DropAction.cs
new file mode 100644
index 0000000..e5bd929
--- /dev/null
+++ b/scripts/entities/actions/DropAction.cs
@@ -0,0 +1,13 @@
+using Godot;
+
+public partial class DropAction : ItemAction
+{
+ public DropAction(Player player, ConsumableItem item) : base(player, item)
+ {
+ }
+
+ public override bool Perform() {
+ player.inventory.Drop(item);
+ return true;
+ }
+} \ No newline at end of file
diff --git a/scripts/entities/actions/DropAction.cs.uid b/scripts/entities/actions/DropAction.cs.uid
new file mode 100644
index 0000000..98ed82f
--- /dev/null
+++ b/scripts/entities/actions/DropAction.cs.uid
@@ -0,0 +1 @@
+uid://by48a3a3gbvfa
diff --git a/scripts/entities/actions/ItemAction.cs b/scripts/entities/actions/ItemAction.cs
index 54ff207..d5247df 100644
--- a/scripts/entities/actions/ItemAction.cs
+++ b/scripts/entities/actions/ItemAction.cs
@@ -2,10 +2,12 @@ using Godot;
public partial class ItemAction : Action
{
- private ConsumableItem item;
- public ItemAction(Actor actor, ConsumableItem item) : base(actor)
+ protected ConsumableItem item;
+ protected Player player;
+ public ItemAction(Player player, ConsumableItem item) : base(player)
{
this.item = item;
+ this.player = player;
}
public override bool Perform()
diff --git a/scripts/entities/actors/Actor.cs b/scripts/entities/actors/Actor.cs
index 1717cfa..1cb1f37 100644
--- a/scripts/entities/actors/Actor.cs
+++ b/scripts/entities/actors/Actor.cs
@@ -139,7 +139,7 @@ public partial class Actor : Entity
public int Heal(int amount) {
int neoHp = Hp + amount;
- if (amount > MaxHp) neoHp = MaxHp;
+ if (neoHp > MaxHp) neoHp = MaxHp;
int recovered = neoHp - Hp;
Hp = neoHp;
diff --git a/scripts/entities/actors/Inventory.cs b/scripts/entities/actors/Inventory.cs
index ea9569f..f1cff2a 100644
--- a/scripts/entities/actors/Inventory.cs
+++ b/scripts/entities/actors/Inventory.cs
@@ -32,4 +32,8 @@ public partial class Inventory : Node {
Items.Add(item);
}
+
+ public void RemoveItem(ConsumableItem item) {
+ Items.Remove(item);
+ }
} \ No newline at end of file
diff --git a/scripts/entities/actors/Player.cs b/scripts/entities/actors/Player.cs
index d1c4c7f..71812e8 100644
--- a/scripts/entities/actors/Player.cs
+++ b/scripts/entities/actors/Player.cs
@@ -7,10 +7,12 @@ using System;
[GlobalClass]
public partial class Player : Actor
{
+ private PlayerDefinition definition;
public Inventory inventory;
public Player(Vector2I initialPosition, MapData map, PlayerDefinition definition) : base(initialPosition, map, definition)
{
+ this.definition = definition;
SetDefinition(definition);
}
diff --git a/scripts/entities/items/ConsumableItem.cs b/scripts/entities/items/ConsumableItem.cs
index 8c862da..82fab49 100644
--- a/scripts/entities/items/ConsumableItem.cs
+++ b/scripts/entities/items/ConsumableItem.cs
@@ -15,7 +15,7 @@ public abstract partial class ConsumableItem : Entity
/// </summary>
/// <param name="consumer"></param>
/// <returns></returns>
- public Action GetAction(Actor consumer)
+ public Action GetAction(Player consumer)
{
return new ItemAction(consumer, this);
}
@@ -28,4 +28,10 @@ public abstract partial class ConsumableItem : Entity
/// <param name="action">Ação gerada pelo item.</param>
/// <returns>Se a ação foi realizada ou não.</returns>
public abstract bool Activate(ItemAction action);
+
+ public void ConsumedBy(Player consumer) {
+ Inventory inventory = consumer.inventory;
+ inventory.RemoveItem(this);
+ QueueFree();
+ }
} \ No newline at end of file
diff --git a/scripts/entities/items/HealingConsumable.cs b/scripts/entities/items/HealingConsumable.cs
index 3d8df51..2104693 100644
--- a/scripts/entities/items/HealingConsumable.cs
+++ b/scripts/entities/items/HealingConsumable.cs
@@ -12,7 +12,7 @@ public partial class HealingConsumable : ConsumableItem
public override bool Activate(ItemAction action)
{
- Actor consumer = action.ThisActor;
+ Player consumer = (Player) action.ThisActor;
int intendedAmount = (int)(HealingPercentage / 100 * consumer.MaxHp);
int recovered = consumer.Heal(intendedAmount);
@@ -22,6 +22,7 @@ public partial class HealingConsumable : ConsumableItem
return false;
}
MessageLogData.Instance.AddMessage($"Você consome {DisplayName} e recupera {recovered} de HP");
+ ConsumedBy(consumer);
return true;
}
} \ No newline at end of file
diff --git a/scripts/input/InputHandler.cs b/scripts/input/InputHandler.cs
index 7ee2be1..67f4abf 100644
--- a/scripts/input/InputHandler.cs
+++ b/scripts/input/InputHandler.cs
@@ -5,7 +5,8 @@ public enum InputHandlers
MainGame,
GameOver,
Inspect,
- Pickup
+ Pickup,
+ Inventory
}
/// <summary>
@@ -29,6 +30,7 @@ public partial class InputHandler : Node
inputHandlers.Add(InputHandlers.GameOver, GetNode<GameOverInputHandler>("GameOverInputHandler"));
inputHandlers.Add(InputHandlers.Inspect, GetNode<InspectInputHandler>("InspectInputHandler"));
inputHandlers.Add(InputHandlers.Pickup, GetNode<PickupInputHandler>("PickupInputHandler"));
+ inputHandlers.Add(InputHandlers.Inventory, GetNode<InventoryInputHandler>("InventoryInputHandler"));
SetInputHandler(startingInputHandler);
}
diff --git a/scripts/input/InventoryInputHandler.cs b/scripts/input/InventoryInputHandler.cs
new file mode 100644
index 0000000..98f8576
--- /dev/null
+++ b/scripts/input/InventoryInputHandler.cs
@@ -0,0 +1,65 @@
+using Godot;
+
+public partial class InventoryInputHandler : BaseInputHandler
+{
+ private static readonly PackedScene inventoryScene = GD.Load<PackedScene>("res://scenes/GUI/invetory_menu.tscn");
+
+ private InventoryMenu inventoryMenu;
+
+ ConsumableItem activationItem = null;
+ ConsumableItem dropItem = null;
+
+ [Export]
+ private Map map;
+
+ public override void Enter() {
+ inventoryMenu = inventoryScene.Instantiate<InventoryMenu>();
+ map.Map_Data.Player.AddChild(inventoryMenu);
+ inventoryMenu.Initialize(map.Map_Data.Player.inventory);
+ inventoryMenu.ItemSelected += OnItemActivate;
+ inventoryMenu.ItemDrop += OnItemDrop;
+ }
+
+ public override void Exit() {
+ activationItem = null;
+ dropItem = null;
+ inventoryMenu.QueueFree();
+ }
+
+ public override Action GetAction(Player player)
+ {
+ Action action = null;
+
+ if (activationItem != null) {
+ action = new ItemAction(player, activationItem);
+ Close();
+ }
+
+ if (dropItem != null) {
+ action = new DropAction(player, dropItem);
+ Close();
+ }
+
+ if (Input.IsActionJustPressed("quit")) {
+ Close();
+ }
+
+ return action;
+ }
+
+ private void Close() {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame);
+ }
+
+ private void ActivateItem() {
+
+ }
+
+ private void OnItemActivate(ConsumableItem item) {
+ activationItem = item;
+ }
+
+ private void OnItemDrop(ConsumableItem item) {
+ dropItem = item;
+ }
+} \ No newline at end of file
diff --git a/scripts/input/InventoryInputHandler.cs.uid b/scripts/input/InventoryInputHandler.cs.uid
new file mode 100644
index 0000000..b5d0ed9
--- /dev/null
+++ b/scripts/input/InventoryInputHandler.cs.uid
@@ -0,0 +1 @@
+uid://bjcjktvyrdh10
diff --git a/scripts/input/MainGameInputHandler.cs b/scripts/input/MainGameInputHandler.cs
index 6fb6aac..6bda004 100644
--- a/scripts/input/MainGameInputHandler.cs
+++ b/scripts/input/MainGameInputHandler.cs
@@ -4,7 +4,7 @@ using Godot;
/// Esquema de controles principal do jogo.
/// </summary>
public partial class MainGameInputHandler : BaseInputHandler {
- private readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
+ private static readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
{
{"walk-up", Vector2I.Up},
{"walk-down", Vector2I.Down},
@@ -25,6 +25,10 @@ public partial class MainGameInputHandler : BaseInputHandler {
}
}
+ if (Input.IsActionJustPressed("open-inventory")) {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.Inventory);
+ }
+
if (Input.IsActionJustPressed("pick-item")) {
GetParent<InputHandler>().SetInputHandler(InputHandlers.Pickup);
}