summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/bg.pngbin0 -> 998257 bytes
-rw-r--r--assets/bg.png.import34
-rw-r--r--project.godot2
-rw-r--r--scenes/GUI/main_menu.tscn91
-rw-r--r--scenes/Game.tscn3
-rw-r--r--scenes/game_manager.tscn6
-rw-r--r--scripts/Entities/Actions/EscapeAction.cs13
-rw-r--r--scripts/Entities/Actions/EscapeAction.cs.uid1
-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
-rw-r--r--scripts/Game.cs21
-rw-r--r--scripts/GameManager.cs59
-rw-r--r--scripts/GameManager.cs.uid1
-rw-r--r--scripts/InputHandling/CastSpellInputHandler.cs17
-rw-r--r--scripts/InputHandling/GameOverInputHandler.cs8
-rw-r--r--scripts/InputHandling/InputHandler.cs9
-rw-r--r--scripts/InputHandling/MainGameInputHandler.cs5
-rw-r--r--scripts/Utils/MessageLogData.cs2
-rw-r--r--scripts/Utils/SignalBus.cs3
21 files changed, 361 insertions, 12 deletions
diff --git a/assets/bg.png b/assets/bg.png
new file mode 100644
index 0000000..6729cf4
--- /dev/null
+++ b/assets/bg.png
Binary files differ
diff --git a/assets/bg.png.import b/assets/bg.png.import
new file mode 100644
index 0000000..1975e68
--- /dev/null
+++ b/assets/bg.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bxjwbucke02gl"
+path="res://.godot/imported/bg.png-23a59c2e9cba2223a50fa3fe41b70b25.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/bg.png"
+dest_files=["res://.godot/imported/bg.png-23a59c2e9cba2223a50fa3fe41b70b25.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/project.godot b/project.godot
index ccb3ac6..ad54fc4 100644
--- a/project.godot
+++ b/project.godot
@@ -12,7 +12,7 @@ config_version=5
config/name="projeto-fantasia"
config/tags=PackedStringArray("based")
-run/main_scene="uid://u5h6iqyi8wd0"
+run/main_scene="uid://cqrq8cosoge7i"
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
config/icon="res://icon.svg"
diff --git a/scenes/GUI/main_menu.tscn b/scenes/GUI/main_menu.tscn
new file mode 100644
index 0000000..2794830
--- /dev/null
+++ b/scenes/GUI/main_menu.tscn
@@ -0,0 +1,91 @@
+[gd_scene load_steps=10 format=3 uid="uid://cppjdsdfkkxtm"]
+
+[ext_resource type="Script" uid="uid://dx0fxht2oadb6" path="res://scripts/GUI/MainMenu.cs" id="1_b4h60"]
+[ext_resource type="Texture2D" uid="uid://bxjwbucke02gl" path="res://assets/bg.png" id="1_tbt31"]
+
+[sub_resource type="LabelSettings" id="LabelSettings_b4h60"]
+font_size = 32
+
+[sub_resource type="InputEventKey" id="InputEventKey_tbt31"]
+device = -1
+keycode = 78
+unicode = 110
+
+[sub_resource type="Shortcut" id="Shortcut_b4h60"]
+events = [SubResource("InputEventKey_tbt31")]
+
+[sub_resource type="InputEventKey" id="InputEventKey_kebck"]
+device = -1
+keycode = 67
+unicode = 99
+
+[sub_resource type="Shortcut" id="Shortcut_1ei6q"]
+events = [SubResource("InputEventKey_kebck")]
+
+[sub_resource type="InputEventKey" id="InputEventKey_xm7ak"]
+device = -1
+keycode = 83
+unicode = 115
+
+[sub_resource type="Shortcut" id="Shortcut_h03jd"]
+events = [SubResource("InputEventKey_xm7ak")]
+
+[node name="MainMenu" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1_b4h60")
+
+[node name="Background" type="TextureRect" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+texture = ExtResource("1_tbt31")
+stretch_mode = 6
+
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+
+[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
+layout_mode = 2
+size_flags_vertical = 3
+
+[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/CenterContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="VBoxContainer/CenterContainer/VBoxContainer"]
+layout_mode = 2
+text = "The Legend of Gustav"
+label_settings = SubResource("LabelSettings_b4h60")
+
+[node name="neogame" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"]
+layout_mode = 2
+shortcut = SubResource("Shortcut_b4h60")
+shortcut_feedback = false
+text = "[N] Novo jogo"
+
+[node name="continue" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"]
+layout_mode = 2
+shortcut = SubResource("Shortcut_1ei6q")
+shortcut_feedback = false
+text = "[C] Continuar"
+
+[node name="quit" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"]
+layout_mode = 2
+shortcut = SubResource("Shortcut_h03jd")
+text = "[S] Sair"
+
+[node name="Label" type="Label" parent="VBoxContainer"]
+layout_mode = 2
+text = "Não temo a morte, temo o tempo."
diff --git a/scenes/Game.tscn b/scenes/Game.tscn
index 96ba3c0..e53783b 100644
--- a/scenes/Game.tscn
+++ b/scenes/Game.tscn
@@ -33,8 +33,9 @@ script = ExtResource("5_s0nni")
[node name="Entities" type="Node2D" parent="Map"]
-[node name="InspectDetails" parent="Map" instance=ExtResource("5_qy1jj")]
+[node name="InspectDetails" parent="Map" node_paths=PackedStringArray("map") instance=ExtResource("5_qy1jj")]
visible = false
+map = NodePath("..")
[node name="InputHandler" type="Node" parent="."]
script = ExtResource("3_s0nni")
diff --git a/scenes/game_manager.tscn b/scenes/game_manager.tscn
new file mode 100644
index 0000000..db916d5
--- /dev/null
+++ b/scenes/game_manager.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://cqrq8cosoge7i"]
+
+[ext_resource type="Script" uid="uid://hya6i6i11teo" path="res://scripts/GameManager.cs" id="1_hwd4i"]
+
+[node name="GameManager" type="Node"]
+script = ExtResource("1_hwd4i")
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();