diff options
| -rw-r--r-- | scenes/name_thyself.tscn | 49 | ||||
| -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 |
6 files changed, 96 insertions, 7 deletions
diff --git a/scenes/name_thyself.tscn b/scenes/name_thyself.tscn new file mode 100644 index 0000000..215c9b7 --- /dev/null +++ b/scenes/name_thyself.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=3 format=3 uid="uid://baio67tv5ifph"] + +[ext_resource type="Texture2D" uid="uid://bxjwbucke02gl" path="res://assets/bg.png" id="1_c644k"] +[ext_resource type="Script" uid="uid://cmtn05tqqh0t4" path="res://scripts/GUI/PlayerName.cs" id="1_jhpgh"] + +[node name="NameThyself" 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_jhpgh") + +[node name="TextureRect" 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_c644k") +expand_mode = 3 + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -54.0 +offset_top = -29.0 +offset_right = 54.0 +offset_bottom = 29.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Label" type="Label" parent="VBoxContainer"] +layout_mode = 2 +text = "Quem é você?" + +[node name="thename" type="LineEdit" parent="VBoxContainer"] +layout_mode = 2 +placeholder_text = "Player" + +[node name="Button" type="Button" parent="VBoxContainer"] +layout_mode = 2 +text = "Iniciar" 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 { |
