summaryrefslogtreecommitdiff
path: root/scripts/GUI
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-09 19:09:34 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-09 19:09:34 -0300
commitc6bbb834f7758027c0df338f1520f34fad3befea (patch)
tree1818cd23c24be16fbe19b16dd0a510874d440d83 /scripts/GUI
parentf1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (diff)
Organização
Diffstat (limited to 'scripts/GUI')
-rw-r--r--scripts/GUI/Details.cs43
-rw-r--r--scripts/GUI/Hud.cs17
-rw-r--r--scripts/GUI/InventoryMenu.cs47
-rw-r--r--scripts/GUI/ItemMenuEntry.cs61
-rw-r--r--scripts/GUI/Message.cs45
-rw-r--r--scripts/GUI/MessageLog.cs12
6 files changed, 138 insertions, 87 deletions
diff --git a/scripts/GUI/Details.cs b/scripts/GUI/Details.cs
index 814d2ac..3c64427 100644
--- a/scripts/GUI/Details.cs
+++ b/scripts/GUI/Details.cs
@@ -1,48 +1,57 @@
using Godot;
-using System;
+using TheLegendOfGustav.Entities;
+using TheLegendOfGustav.Map;
+using TheLegendOfGustav.Utils;
+
+namespace TheLegendOfGustav.GUI;
public partial class Details : CanvasLayer
{
private static readonly LabelSettings lblSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres");
- private Map map;
- private VBoxContainer entityNames;
- private Godot.Collections.Array<Entity> entities = [];
+
+ private Map.Map Map { get; set; }
+ private VBoxContainer EntityNames { get; set; }
+ private Godot.Collections.Array<Entity> Entities { get; set; } = [];
- private Godot.Collections.Array<Label> actorsLabel = [];
+ private Godot.Collections.Array<Label> ActorsLabel { get; set; } = [];
public override void _Ready()
{
base._Ready();
- map = GetParent<Map>();
- entityNames = GetNode<VBoxContainer>("HBoxContainer/PanelContainer/ScrollContainer/Entities");
+ Map = GetParent<Map.Map>();
+ EntityNames = GetNode<VBoxContainer>("HBoxContainer/PanelContainer/ScrollContainer/Entities");
SignalBus.Instance.InspectorMoved += OnInspectorWalk;
SignalBus.Instance.EnterInspectionMode += () => Visible = true;
SignalBus.Instance.ExitInspectionMode += () => Visible = false;
}
- public void OnInspectorWalk(Vector2I pos) {
- MapData mapData = map.Map_Data;
- entities = mapData.GetEntitiesAtPosition(pos);
+ public void OnInspectorWalk(Vector2I pos)
+ {
+ MapData mapData = Map.MapData;
+ Entities = mapData.GetEntitiesAtPosition(pos);
UpdateLabels();
}
- private void UpdateLabels() {
- foreach(Label label in actorsLabel) {
+ private void UpdateLabels()
+ {
+ foreach (Label label in ActorsLabel)
+ {
label.QueueFree();
}
- actorsLabel.Clear();
- foreach (Entity entity in entities) {
+ ActorsLabel.Clear();
+
+ foreach (Entity entity in Entities)
+ {
Label label = new()
{
Text = entity.DisplayName,
LabelSettings = lblSettings
};
- actorsLabel.Add(label);
- entityNames.AddChild(label);
+ ActorsLabel.Add(label);
+ EntityNames.AddChild(label);
}
}
}
- \ No newline at end of file
diff --git a/scripts/GUI/Hud.cs b/scripts/GUI/Hud.cs
index 614fa5e..1149728 100644
--- a/scripts/GUI/Hud.cs
+++ b/scripts/GUI/Hud.cs
@@ -1,17 +1,20 @@
using Godot;
-using System;
+
+namespace TheLegendOfGustav.GUI;
public partial class Hud : Node
{
- private TextureProgressBar hpBar;
+ private TextureProgressBar HpBar { get; set; }
- public override void _Ready() {
+ public override void _Ready()
+ {
base._Ready();
- hpBar = GetNode<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar");
+ HpBar = GetNode<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar");
}
- public void OnHealthChanged(int hp, int maxHp) {
- hpBar.Value = hp;
- hpBar.MaxValue = maxHp;
+ public void OnHealthChanged(int hp, int maxHp)
+ {
+ HpBar.Value = hp;
+ HpBar.MaxValue = maxHp;
}
}
diff --git a/scripts/GUI/InventoryMenu.cs b/scripts/GUI/InventoryMenu.cs
index bfb1795..5bac62b 100644
--- a/scripts/GUI/InventoryMenu.cs
+++ b/scripts/GUI/InventoryMenu.cs
@@ -1,52 +1,63 @@
using Godot;
-using System;
+using TheLegendOfGustav.Entities.Items;
+using TheLegendOfGustav.Entities.Actors;
+
+namespace TheLegendOfGustav.GUI;
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;
+ private VBoxContainer ItemsNode { get; set; }
- public override void _Ready() {
+ public override void _Ready()
+ {
base._Ready();
- itemsNode = GetNode<VBoxContainer>("CenterContainer/PanelContainer/VBoxContainer/Items");
+ ItemsNode = GetNode<VBoxContainer>("CenterContainer/PanelContainer/VBoxContainer/Items");
Hide();
}
- public void OnActivate(ConsumableItem item) {
+ public void OnActivate(ConsumableItem item)
+ {
EmitSignal(SignalName.ItemSelected, item);
}
-
- public void OnDrop(ConsumableItem item) {
+
+ public void OnDrop(ConsumableItem item)
+ {
EmitSignal(SignalName.ItemDrop, item);
}
- private void RegisterItem(int index, ConsumableItem item) {
+ public void Initialize(Inventory inventory)
+ {
+ for (int i = 0; i < inventory.Items.Count; i++)
+ {
+ RegisterItem(i, inventory.Items[i]);
+ }
+
+ Show();
+ }
+
+ private void RegisterItem(int index, ConsumableItem item)
+ {
char? shortcut = null;
// Só terá atalho para as letras do alfabeto.
- if (index < 26) {
+ if (index < 26)
+ {
shortcut = (char)('a' + index);
}
ItemMenuEntry itemEntry = itemMenuEntryScene.Instantiate<ItemMenuEntry>();
- itemsNode.AddChild(itemEntry);
+ 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/ItemMenuEntry.cs b/scripts/GUI/ItemMenuEntry.cs
index 449c97b..7ee3fcd 100644
--- a/scripts/GUI/ItemMenuEntry.cs
+++ b/scripts/GUI/ItemMenuEntry.cs
@@ -1,41 +1,48 @@
using Godot;
+using TheLegendOfGustav.Entities.Items;
+
+namespace TheLegendOfGustav.GUI;
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 delegate void DropEventHandler(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;
- }
+ private TextureRect Icon { get; set; }
+ private Label ShortcutLabel { get; set; }
+ private Label NameLabel { get; set; }
+ private Button ActivateBtn { get; set; }
+ private Button DropBtn { get; set; }
+ private ConsumableItem Item { get; set; }
- public override void _Ready() {
+ 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");
+ 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);
+ ActivateBtn.Pressed += () => EmitSignal(SignalName.Activate, Item);
+ DropBtn.Pressed += () => EmitSignal(SignalName.Drop, Item);
+ }
+
+ public void Initialize(ConsumableItem item, char? shortcut)
+ {
+ Item = item;
+ NameLabel.Text = item.DisplayName;
+ if (shortcut != null)
+ {
+ ShortcutLabel.Text = $"{shortcut}";
+ }
+ else
+ {
+ ShortcutLabel.Text = "";
+ }
+ Icon.Texture = item.Texture;
}
}
diff --git a/scripts/GUI/Message.cs b/scripts/GUI/Message.cs
index b0472ee..11f3532 100644
--- a/scripts/GUI/Message.cs
+++ b/scripts/GUI/Message.cs
@@ -1,32 +1,49 @@
using Godot;
+namespace TheLegendOfGustav.GUI;
+
public partial class Message : Label
{
- private static LabelSettings baseSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres");
+ private static readonly LabelSettings baseSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres");
+
private string plainText;
- public string PlainText { get => plainText; }
private int count = 1;
- public int Count {
+
+ public Message(string text)
+ {
+ PlainText = text;
+ Text = text;
+ LabelSettings = (LabelSettings)baseSettings.Duplicate();
+ AutowrapMode = TextServer.AutowrapMode.WordSmart;
+ }
+
+ public string PlainText
+ {
+ get => plainText;
+ private set
+ {
+ plainText = value;
+ }
+ }
+ public int Count
+ {
get => count;
- set {
+ set
+ {
count = value;
Text = FullText;
}
}
- public string FullText {
- get {
- if (count > 1) {
+ public string FullText
+ {
+ get
+ {
+ if (count > 1)
+ {
return $"{plainText} ({count})";
}
return plainText;
}
}
-
- public Message(string text) {
- plainText = text;
- Text = text;
- LabelSettings = (LabelSettings) baseSettings.Duplicate();
- AutowrapMode = TextServer.AutowrapMode.WordSmart;
- }
}
diff --git a/scripts/GUI/MessageLog.cs b/scripts/GUI/MessageLog.cs
index d481b19..1fc59b6 100644
--- a/scripts/GUI/MessageLog.cs
+++ b/scripts/GUI/MessageLog.cs
@@ -1,24 +1,28 @@
using Godot;
-using System;
using System.Threading.Tasks;
+using TheLegendOfGustav.Utils;
+
+namespace TheLegendOfGustav.GUI;
public partial class MessageLog : ScrollContainer
{
- private VBoxContainer MessageList;
+ private VBoxContainer MessageList { get; set; }
public override void _Ready()
{
base._Ready();
MessageList = GetNode<VBoxContainer>("MessageList");
- foreach (Message msg in MessageLogData.Instance.Messages) {
+ foreach (Message msg in MessageLogData.Instance.Messages)
+ {
_ = AddMessageAsync(msg);
}
MessageLogData.Instance.messageSent += async (Message msg) => await AddMessageAsync(msg);
}
- private async Task AddMessageAsync(Message message) {
+ private async Task AddMessageAsync(Message message)
+ {
MessageList.AddChild(message);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
EnsureControlVisible(message);