summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/GUI/Details.cs48
-rw-r--r--scripts/GUI/Details.cs.uid1
-rw-r--r--scripts/Utils/SignalBus.cs8
-rw-r--r--scripts/actors/Inspector.cs15
-rw-r--r--scripts/input/InspectInputHandler.cs17
-rw-r--r--scripts/map/MapData.cs32
6 files changed, 105 insertions, 16 deletions
diff --git a/scripts/GUI/Details.cs b/scripts/GUI/Details.cs
new file mode 100644
index 0000000..0e342aa
--- /dev/null
+++ b/scripts/GUI/Details.cs
@@ -0,0 +1,48 @@
+using Godot;
+using System;
+
+public partial class Details : CanvasLayer
+{
+ private static readonly LabelSettings lblSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres");
+ private Map map;
+ private VBoxContainer entityNames;
+ private Godot.Collections.Array<Actor> actors = [];
+
+ private Godot.Collections.Array<Label> actorsLabel = [];
+
+ public override void _Ready()
+ {
+ base._Ready();
+ map = GetParent<Map>();
+ entityNames = GetNode<VBoxContainer>("HBoxContainer/PanelContainer/ScrollContainer/Entities");
+
+ SignalBus.Instance.InspectorMoved += OnInspectorWalk;
+ SignalBus.Instance.EnterInspectionMode += () => Visible = true;
+ SignalBus.Instance.ExitInspectionMode += () => Visible = false;
+ }
+
+ public void OnInspectorWalk(Vector2I pos) {
+ MapData mapData = map.Map_Data;
+ actors = mapData.GetActorsAtPosition(pos);
+ UpdateLabels();
+ }
+
+ private void UpdateLabels() {
+ foreach(Label label in actorsLabel) {
+ label.QueueFree();
+ }
+ actorsLabel.Clear();
+
+ foreach (Actor actor in actors) {
+ Label label = new()
+ {
+ Text = actor.ActorName,
+ LabelSettings = lblSettings
+ };
+
+ actorsLabel.Add(label);
+ entityNames.AddChild(label);
+ }
+ }
+}
+ \ No newline at end of file
diff --git a/scripts/GUI/Details.cs.uid b/scripts/GUI/Details.cs.uid
new file mode 100644
index 0000000..52fcd9c
--- /dev/null
+++ b/scripts/GUI/Details.cs.uid
@@ -0,0 +1 @@
+uid://c5f8urot55re6
diff --git a/scripts/Utils/SignalBus.cs b/scripts/Utils/SignalBus.cs
index f5cb0d2..edeb09b 100644
--- a/scripts/Utils/SignalBus.cs
+++ b/scripts/Utils/SignalBus.cs
@@ -16,4 +16,12 @@ public partial class SignalBus : Node
base._Ready();
Instance = this;
}
+
+ [Signal]
+ public delegate void InspectorMovedEventHandler(Vector2I pos);
+
+ [Signal]
+ public delegate void EnterInspectionModeEventHandler();
+ [Signal]
+ public delegate void ExitInspectionModeEventHandler();
}
diff --git a/scripts/actors/Inspector.cs b/scripts/actors/Inspector.cs
index 0bdab5b..e340543 100644
--- a/scripts/actors/Inspector.cs
+++ b/scripts/actors/Inspector.cs
@@ -5,8 +5,6 @@ using Godot;
/// </summary>
public partial class Inspector : Sprite2D
{
- private static readonly Texture2D texture = GD.Load<Texture2D>("res://assets/sprites/inspector.png");
-
private Vector2I gridPosition = Vector2I.Zero;
/// <summary>
/// Posição do inspetor no espaço. Diferentemente de Position, GridPosition tem como formato
@@ -22,11 +20,13 @@ public partial class Inspector : Sprite2D
get => gridPosition;
}
- public Inspector(Vector2I initialPosition)
- {
- GridPosition = initialPosition;
- Centered = false;
- Texture = texture;
+ public override void _Ready() {
+ base._Ready();
+ Camera2D camera = GetNode<Camera2D>("Camera2D");
+ camera.Enabled = true;
+ camera.MakeCurrent();
+
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.InspectorMoved, GridPosition);
}
/// <summary>
@@ -35,5 +35,6 @@ public partial class Inspector : Sprite2D
/// <param name="offset"></param>
public void Walk(Vector2I offset) {
GridPosition += offset;
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.InspectorMoved, GridPosition);
}
} \ No newline at end of file
diff --git a/scripts/input/InspectInputHandler.cs b/scripts/input/InspectInputHandler.cs
index 60c10e4..ad76c62 100644
--- a/scripts/input/InspectInputHandler.cs
+++ b/scripts/input/InspectInputHandler.cs
@@ -5,6 +5,8 @@ using Godot;
/// </summary>
public partial class InspectInputHandler : BaseInputHandler
{
+ private static readonly PackedScene InspectorScene = GD.Load<PackedScene>("res://scenes/Inspector.tscn");
+
private readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
{
{"walk-up", Vector2I.Up},
@@ -25,21 +27,18 @@ public partial class InspectInputHandler : BaseInputHandler
private Inspector inspector;
public override void Enter() {
- inspector = new(map.Map_Data.Player.GridPosition)
- {
- ZIndex = 4
- };
- // Copiamos a câmera do jogador com todas as suas configurações
- Camera2D camera = (Camera2D) map.Map_Data.Player.GetNode<Camera2D>("Camera2D").Duplicate();
- inspector.AddChild(camera);
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.EnterInspectionMode);
+ inspector = InspectorScene.Instantiate<Inspector>();
+
+ inspector.GridPosition = map.Map_Data.Player.GridPosition;
map.AddChild(inspector);
- camera.Enabled = true;
- camera.MakeCurrent();
}
public override void Exit() {
inspector.QueueFree();
+
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.ExitInspectionMode);
}
public override Action GetAction(Player player)
{
diff --git a/scripts/map/MapData.cs b/scripts/map/MapData.cs
index 3b03de8..de0ddf0 100644
--- a/scripts/map/MapData.cs
+++ b/scripts/map/MapData.cs
@@ -198,6 +198,38 @@ public partial class MapData : RefCounted
}
/// <summary>
+ /// Obtém todos os atores na posição especificada.
+ /// É possível haver mais de um ator na mesma posição se um deles for morto.
+ /// </summary>
+ /// <param name="pos">Vetor posição</param>
+ /// <returns>Lista com todos os atores na posição especificada.</returns>
+ public Godot.Collections.Array<Actor> GetActorsAtPosition(Vector2I pos) {
+ Godot.Collections.Array<Actor> ZOfZero = [];
+ Godot.Collections.Array<Actor> ZOfOne = [];
+ Godot.Collections.Array<Actor> ZOfTwo = [];
+
+ // Pego todos os atores
+ foreach (Actor actor in Actors) {
+ if (actor.GridPosition == pos) {
+ switch (actor.ZIndex) {
+ case 0:
+ ZOfZero.Add(actor);
+ break;
+ case 1:
+ ZOfOne.Add(actor);
+ break;
+ case 2:
+ ZOfTwo.Add(actor);
+ break;
+ }
+ }
+ }
+
+ // Retorno os atores ordenados por ZIndex.
+ return ZOfZero + ZOfOne + ZOfTwo;
+ }
+
+ /// <summary>
/// Verifica se é possível caminhar na coordenada especificada.
/// Este método será removido.
/// </summary>