diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-15 20:00:47 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-15 20:00:47 -0300 |
| commit | 862b399fa37e6ca692d38177a22ee34860d2251e (patch) | |
| tree | 3c0c80efbe0096c8e8d606ee464b54b55eaa209c /scripts | |
| parent | befb39054656e3242e9408f2afe8c902df471ffa (diff) | |
Menu principal
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Entities/Actions/EscapeAction.cs | 13 | ||||
| -rw-r--r-- | scripts/Entities/Actions/EscapeAction.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/GUI/Details.cs | 34 | ||||
| -rw-r--r-- | scripts/GUI/MainMenu.cs | 46 | ||||
| -rw-r--r-- | scripts/GUI/MainMenu.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/GUI/MessageLog.cs | 17 | ||||
| -rw-r--r-- | scripts/Game.cs | 21 | ||||
| -rw-r--r-- | scripts/GameManager.cs | 59 | ||||
| -rw-r--r-- | scripts/GameManager.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/InputHandling/CastSpellInputHandler.cs | 17 | ||||
| -rw-r--r-- | scripts/InputHandling/GameOverInputHandler.cs | 8 | ||||
| -rw-r--r-- | scripts/InputHandling/InputHandler.cs | 9 | ||||
| -rw-r--r-- | scripts/InputHandling/MainGameInputHandler.cs | 5 | ||||
| -rw-r--r-- | scripts/Utils/MessageLogData.cs | 2 | ||||
| -rw-r--r-- | scripts/Utils/SignalBus.cs | 3 |
15 files changed, 227 insertions, 10 deletions
diff --git a/scripts/Entities/Actions/EscapeAction.cs b/scripts/Entities/Actions/EscapeAction.cs new file mode 100644 index 0000000..cc5d289 --- /dev/null +++ b/scripts/Entities/Actions/EscapeAction.cs @@ -0,0 +1,13 @@ +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Utils; + +namespace TheLegendOfGustav.Entities.Actions; + +public partial class EscapeAction(Actor actor) : Action(actor) +{ + public override bool Perform() + { + SignalBus.Instance.EmitSignal(SignalBus.SignalName.EscapeRequested); + return false; + } +}
\ No newline at end of file diff --git a/scripts/Entities/Actions/EscapeAction.cs.uid b/scripts/Entities/Actions/EscapeAction.cs.uid new file mode 100644 index 0000000..380f369 --- /dev/null +++ b/scripts/Entities/Actions/EscapeAction.cs.uid @@ -0,0 +1 @@ +uid://dtxw6x1naf3oc 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) diff --git a/scripts/Game.cs b/scripts/Game.cs index 5c1b634..3bb1b83 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -33,10 +33,18 @@ public partial class Game : Node private Hud hud; + [Signal] + public delegate void MainMenuRequestedEventHandler(); + + private SignalBus.EscapeRequestedEventHandler escapeLambda; + public override void _Ready() { base._Ready(); + escapeLambda = () => EmitSignal(SignalName.MainMenuRequested); + SignalBus.Instance.EscapeRequested += escapeLambda; + Map = GetNode<Map.Map>("Map"); InputHandler = GetNode<InputHandler>("InputHandler"); @@ -61,6 +69,19 @@ public partial class Game : Node MessageLogData.Instance.AddMessage("Boa sorte!"); } + public override void _Notification(int what) + { + if (what == NotificationPredelete) + { + if (escapeLambda != null) + { + SignalBus.Instance.EscapeRequested -= escapeLambda; + } + } + base._Notification(what); + } + + /// <summary> /// Método executa aproximadamente 60 vezes por segundo. /// </summary> diff --git a/scripts/GameManager.cs b/scripts/GameManager.cs new file mode 100644 index 0000000..8bc8b6b --- /dev/null +++ b/scripts/GameManager.cs @@ -0,0 +1,59 @@ +using Godot; +using GodotPlugins.Game; +using System; +using TheLegendOfGustav.GUI; +using TheLegendOfGustav.Utils; + +namespace TheLegendOfGustav; + +public partial class GameManager : Node +{ + private PackedScene mainMenuScene = GD.Load<PackedScene>("res://scenes/GUI/main_menu.tscn"); + private PackedScene gameScene = GD.Load<PackedScene>("res://scenes/Game.tscn"); + + private Node currentScene; + + public override void _Ready() + { + base._Ready(); + LoadMainMenu(); + } + + private Node SwitchToScene(PackedScene scene) + { + if (currentScene != null && currentScene is Game gaimu) + { + gaimu.MainMenuRequested -= LoadMainMenu; + gaimu.QueueFree(); + gaimu = null; + } else if (currentScene != null && currentScene is MainMenu menu) + { + menu.QueueFree(); + menu.GameRequest -= OnGameRequest; + menu = null; + } + + currentScene?.QueueFree(); + currentScene = scene.Instantiate(); + AddChild(currentScene); + return currentScene; + } + + private void LoadMainMenu() + { + MainMenu menu = (MainMenu)SwitchToScene(mainMenuScene); + menu.GameRequest += OnGameRequest; + } + + private void LoadGame() + { + MessageLogData.Instance.ClearMessages(); + Game game = (Game)SwitchToScene(gameScene); + game.MainMenuRequested += LoadMainMenu; + } + + private void OnGameRequest(bool load) + { + LoadGame(); + } +} diff --git a/scripts/GameManager.cs.uid b/scripts/GameManager.cs.uid new file mode 100644 index 0000000..d1b1098 --- /dev/null +++ b/scripts/GameManager.cs.uid @@ -0,0 +1 @@ +uid://hya6i6i11teo diff --git a/scripts/InputHandling/CastSpellInputHandler.cs b/scripts/InputHandling/CastSpellInputHandler.cs index 1c5d005..904bfab 100644 --- a/scripts/InputHandling/CastSpellInputHandler.cs +++ b/scripts/InputHandling/CastSpellInputHandler.cs @@ -36,12 +36,15 @@ public partial class CastSpellInputHandler : BaseInputHandler [Export] private Map map; + SignalBus.PlayerSpellChooseLocationEventHandler spellLocationLambda; + public override void _Ready() { base._Ready(); + spellLocationLambda = (SpellResource spell) => selectedSpell = spell; // O jogador informa qual feitiço será usado. - SignalBus.Instance.PlayerSpellChooseLocation += (SpellResource spell) => selectedSpell = spell; + SignalBus.Instance.PlayerSpellChooseLocation += spellLocationLambda; } public override void Enter() @@ -90,4 +93,16 @@ public partial class CastSpellInputHandler : BaseInputHandler return action; } + + public override void _Notification(int what) + { + if (what == NotificationPredelete) + { + if (spellLocationLambda != null) + { + SignalBus.Instance.PlayerSpellChooseLocation -= spellLocationLambda; + } + } + base._Notification(what); + } }
\ No newline at end of file diff --git a/scripts/InputHandling/GameOverInputHandler.cs b/scripts/InputHandling/GameOverInputHandler.cs index e11e98a..bfd6d79 100644 --- a/scripts/InputHandling/GameOverInputHandler.cs +++ b/scripts/InputHandling/GameOverInputHandler.cs @@ -1,3 +1,4 @@ +using Godot; using TheLegendOfGustav.Entities.Actions; using TheLegendOfGustav.Entities.Actors; @@ -11,6 +12,11 @@ public partial class GameOverInputHandler : BaseInputHandler // Por enquanto não tem nada. public override Action GetAction(Player player) { - return null; + Action action = null; + if (Input.IsActionJustPressed("quit")) + { + action = new EscapeAction(player); + } + return action; } }
\ No newline at end of file diff --git a/scripts/InputHandling/InputHandler.cs b/scripts/InputHandling/InputHandler.cs index ce265a1..3c39587 100644 --- a/scripts/InputHandling/InputHandler.cs +++ b/scripts/InputHandling/InputHandler.cs @@ -57,6 +57,15 @@ public partial class InputHandler : Node return SelectedInputHandler.GetAction(player); } + public override void _Notification(int what) + { + if (what == NotificationPredelete) + { + SignalBus.Instance.CommandInputHandler -= SetInputHandler; + } + base._Notification(what); + } + /// <summary> /// Define o esquema de controle atual do jogo /// para o estado informado. diff --git a/scripts/InputHandling/MainGameInputHandler.cs b/scripts/InputHandling/MainGameInputHandler.cs index 6a110d7..bbfb9ca 100644 --- a/scripts/InputHandling/MainGameInputHandler.cs +++ b/scripts/InputHandling/MainGameInputHandler.cs @@ -58,6 +58,11 @@ public partial class MainGameInputHandler : BaseInputHandler action = new WaitAction(player); } + if (Input.IsActionJustPressed("quit")) + { + action = new EscapeAction(player); + } + return action; } } diff --git a/scripts/Utils/MessageLogData.cs b/scripts/Utils/MessageLogData.cs index 46d2c3e..ab81fe6 100644 --- a/scripts/Utils/MessageLogData.cs +++ b/scripts/Utils/MessageLogData.cs @@ -40,7 +40,7 @@ public partial class MessageLogData : Node { Message message = Messages[i]; Messages.RemoveAt(i); - message.QueueFree(); + message?.QueueFree(); } } diff --git a/scripts/Utils/SignalBus.cs b/scripts/Utils/SignalBus.cs index bf97c2d..291ffcd 100644 --- a/scripts/Utils/SignalBus.cs +++ b/scripts/Utils/SignalBus.cs @@ -31,6 +31,9 @@ public partial class SignalBus : Node [Signal] public delegate void CommandInputHandlerEventHandler(InputHandlers state); + [Signal] + public delegate void EscapeRequestedEventHandler(); + public override void _Ready() { base._Ready(); |
