diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Entities/Entity.cs | 2 | ||||
| -rw-r--r-- | scripts/GUI/PlayerName.cs | 24 | ||||
| -rw-r--r-- | scripts/GUI/PlayerName.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Game.cs | 6 | ||||
| -rw-r--r-- | scripts/GameManager.cs | 21 |
5 files changed, 47 insertions, 7 deletions
diff --git a/scripts/Entities/Entity.cs b/scripts/Entities/Entity.cs index 76002b1..5c643db 100644 --- a/scripts/Entities/Entity.cs +++ b/scripts/Entities/Entity.cs @@ -109,7 +109,7 @@ public abstract partial class Entity : Sprite2D, ISaveable public string DisplayName { get => displayName; - protected set + set { displayName = value; } diff --git a/scripts/GUI/PlayerName.cs b/scripts/GUI/PlayerName.cs new file mode 100644 index 0000000..f1f5a00 --- /dev/null +++ b/scripts/GUI/PlayerName.cs @@ -0,0 +1,24 @@ +using Godot; + +namespace TheLegendOfGustav.GUI; +public partial class PlayerName : Control +{ + + private LineEdit nameEdit; + private Button startButton; + [Signal] + public delegate void NewGameRequestEventHandler(string name); + + public override void _Ready() + { + nameEdit = GetNode<LineEdit>("VBoxContainer/thename"); + startButton = GetNode<Button>("VBoxContainer/Button"); + startButton.Pressed += OnClick; + } + + private void OnClick() + { + string name = nameEdit.Text; + EmitSignal(SignalName.NewGameRequest, name); + } +} diff --git a/scripts/GUI/PlayerName.cs.uid b/scripts/GUI/PlayerName.cs.uid new file mode 100644 index 0000000..17f45c4 --- /dev/null +++ b/scripts/GUI/PlayerName.cs.uid @@ -0,0 +1 @@ +uid://cmtn05tqqh0t4 diff --git a/scripts/Game.cs b/scripts/Game.cs index 47102c1..e55b937 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -46,7 +46,7 @@ public partial class Game : Node SignalBus.Instance.EscapeRequested += escapeLambda; } - public void NewGame() + public void NewGame(string name) { map = GetNode<Map.Map>("Map"); @@ -55,6 +55,10 @@ public partial class Game : Node // O jogador é criado pelo jogo. Player player = new Player(Vector2I.Zero, null, playerDefinition); + if (name != "") + { + player.DisplayName = name; + } Camera2D camera = GetNode<Camera2D>("Camera2D"); RemoveChild(camera); player.HealthChanged += (int hp, int maxHp) => hud.OnHealthChanged(hp, maxHp); diff --git a/scripts/GameManager.cs b/scripts/GameManager.cs index a17ae79..5898744 100644 --- a/scripts/GameManager.cs +++ b/scripts/GameManager.cs @@ -1,6 +1,5 @@ +using System.Diagnostics; using Godot; -using GodotPlugins.Game; -using System; using TheLegendOfGustav.GUI; using TheLegendOfGustav.Utils; @@ -10,6 +9,7 @@ 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 PackedScene nameScene = GD.Load<PackedScene>("res://scenes/name_thyself.tscn"); private Node currentScene; @@ -56,19 +56,30 @@ public partial class GameManager : Node } } - private void NewGame() + private void NewGame(string name) { MessageLogData.Instance.ClearMessages(); Game game = (Game)SwitchToScene(gameScene); - game.NewGame(); + game.NewGame(name); game.MainMenuRequested += LoadMainMenu; } + private void SelectName() + { + PlayerName namesc = (PlayerName)SwitchToScene(nameScene); + namesc.NewGameRequest += OnNameSelect; + } + + private void OnNameSelect(string name) + { + NewGame(name); + } + private void OnGameRequest(bool load) { if (!load) { - NewGame(); + SelectName(); } else { |
