summaryrefslogtreecommitdiff
path: root/scripts/GUI
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-15 20:00:47 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-15 20:00:47 -0300
commit862b399fa37e6ca692d38177a22ee34860d2251e (patch)
tree3c0c80efbe0096c8e8d606ee464b54b55eaa209c /scripts/GUI
parentbefb39054656e3242e9408f2afe8c902df471ffa (diff)
Menu principal
Diffstat (limited to 'scripts/GUI')
-rw-r--r--scripts/GUI/Details.cs34
-rw-r--r--scripts/GUI/MainMenu.cs46
-rw-r--r--scripts/GUI/MainMenu.cs.uid1
-rw-r--r--scripts/GUI/MessageLog.cs17
4 files changed, 91 insertions, 7 deletions
diff --git a/scripts/GUI/Details.cs b/scripts/GUI/Details.cs
index 3c64427..3ead3a9 100644
--- a/scripts/GUI/Details.cs
+++ b/scripts/GUI/Details.cs
@@ -8,31 +8,53 @@ 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 Map { get; set; }
+
+ [Export]
+ private Map.Map map;
private VBoxContainer EntityNames { get; set; }
private Godot.Collections.Array<Entity> Entities { get; set; } = [];
private Godot.Collections.Array<Label> ActorsLabel { get; set; } = [];
+ private SignalBus.EnterInspectionModeEventHandler enterLambda;
+ private SignalBus.ExitInspectionModeEventHandler exitLambda;
+
public override void _Ready()
{
base._Ready();
- Map = GetParent<Map.Map>();
EntityNames = GetNode<VBoxContainer>("HBoxContainer/PanelContainer/ScrollContainer/Entities");
+ enterLambda = () => Visible = true;
+ exitLambda = () => Visible = false;
SignalBus.Instance.InspectorMoved += OnInspectorWalk;
- SignalBus.Instance.EnterInspectionMode += () => Visible = true;
- SignalBus.Instance.ExitInspectionMode += () => Visible = false;
+ SignalBus.Instance.EnterInspectionMode += enterLambda;
+ SignalBus.Instance.ExitInspectionMode += exitLambda;
}
public void OnInspectorWalk(Vector2I pos)
{
- MapData mapData = Map.MapData;
+ MapData mapData = map.MapData;
Entities = mapData.GetEntitiesAtPosition(pos);
UpdateLabels();
}
+ public override void _Notification(int what)
+ {
+ if (what == NotificationPredelete)
+ {
+ SignalBus.Instance.InspectorMoved -= OnInspectorWalk;
+ if (enterLambda != null)
+ {
+ SignalBus.Instance.EnterInspectionMode -= enterLambda;
+ }
+ if (exitLambda != null)
+ {
+ SignalBus.Instance.ExitInspectionMode -= exitLambda;
+ }
+ }
+ base._Notification(what);
+ }
+
private void UpdateLabels()
{
foreach (Label label in ActorsLabel)
diff --git a/scripts/GUI/MainMenu.cs b/scripts/GUI/MainMenu.cs
new file mode 100644
index 0000000..4d89b36
--- /dev/null
+++ b/scripts/GUI/MainMenu.cs
@@ -0,0 +1,46 @@
+using Godot;
+
+namespace TheLegendOfGustav.GUI;
+
+public partial class MainMenu : Control
+{
+ private Button NewGameButton;
+ private Button LoadGameButton;
+ private Button QuitButton;
+
+ [Signal]
+ public delegate void GameRequestEventHandler(bool load);
+
+ public override void _Ready()
+ {
+ base._Ready();
+
+ NewGameButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/neogame");
+ LoadGameButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/continue");
+ QuitButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/quit");
+
+ NewGameButton.Pressed += OnNewGameButtonPressed;
+ LoadGameButton.Pressed += OnLoadGameButtonPressed;
+ QuitButton.Pressed += OnQuitButtonPressed;
+
+ NewGameButton.GrabFocus();
+ bool hasSaveFile = FileAccess.FileExists("user://save.dat");
+ LoadGameButton.Disabled = !hasSaveFile;
+ }
+
+ private void OnNewGameButtonPressed()
+ {
+ GD.Print("Signal EMIT!");
+ EmitSignal(SignalName.GameRequest, false);
+ }
+
+ private void OnLoadGameButtonPressed()
+ {
+ EmitSignal(SignalName.GameRequest, true);
+ }
+
+ private void OnQuitButtonPressed()
+ {
+ GetTree().Quit();
+ }
+}
diff --git a/scripts/GUI/MainMenu.cs.uid b/scripts/GUI/MainMenu.cs.uid
new file mode 100644
index 0000000..6bd82a6
--- /dev/null
+++ b/scripts/GUI/MainMenu.cs.uid
@@ -0,0 +1 @@
+uid://dx0fxht2oadb6
diff --git a/scripts/GUI/MessageLog.cs b/scripts/GUI/MessageLog.cs
index 1fc59b6..c83879a 100644
--- a/scripts/GUI/MessageLog.cs
+++ b/scripts/GUI/MessageLog.cs
@@ -8,6 +8,7 @@ public partial class MessageLog : ScrollContainer
{
private VBoxContainer MessageList { get; set; }
+ private MessageLogData.messageSentEventHandler joinSignal;
public override void _Ready()
{
base._Ready();
@@ -18,7 +19,21 @@ public partial class MessageLog : ScrollContainer
_ = AddMessageAsync(msg);
}
- MessageLogData.Instance.messageSent += async (Message msg) => await AddMessageAsync(msg);
+ joinSignal = async (Message msg) => await AddMessageAsync(msg);
+
+ MessageLogData.Instance.messageSent += joinSignal;
+ }
+
+ public override void _Notification(int what)
+ {
+ if (what == NotificationPredelete)
+ {
+ if (joinSignal != null)
+ {
+ MessageLogData.Instance.messageSent -= joinSignal;
+ }
+ }
+ base._Notification(what);
}
private async Task AddMessageAsync(Message message)