diff options
| -rw-r--r-- | assets/definitions/details_label_settings.tres | 4 | ||||
| -rw-r--r-- | scenes/Details.tscn | 28 | ||||
| -rw-r--r-- | scenes/Game.tscn | 6 | ||||
| -rw-r--r-- | scenes/Inspector.tscn | 13 | ||||
| -rw-r--r-- | scripts/GUI/Details.cs | 48 | ||||
| -rw-r--r-- | scripts/GUI/Details.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Utils/SignalBus.cs | 8 | ||||
| -rw-r--r-- | scripts/actors/Inspector.cs | 15 | ||||
| -rw-r--r-- | scripts/input/InspectInputHandler.cs | 17 | ||||
| -rw-r--r-- | scripts/map/MapData.cs | 32 |
10 files changed, 155 insertions, 17 deletions
diff --git a/assets/definitions/details_label_settings.tres b/assets/definitions/details_label_settings.tres new file mode 100644 index 0000000..e3bff56 --- /dev/null +++ b/assets/definitions/details_label_settings.tres @@ -0,0 +1,4 @@ +[gd_resource type="LabelSettings" format=3 uid="uid://3nh470qx26gy"] + +[resource] +line_spacing = 0.0 diff --git a/scenes/Details.tscn b/scenes/Details.tscn new file mode 100644 index 0000000..65df792 --- /dev/null +++ b/scenes/Details.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=2 format=3 uid="uid://bryqrafavmwj4"] + +[ext_resource type="Script" uid="uid://c5f8urot55re6" path="res://scripts/GUI/Details.cs" id="1_5ml16"] + +[node name="InspectDetails" type="CanvasLayer"] +script = ExtResource("1_5ml16") + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="AspectRatioContainer" type="AspectRatioContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 3.0 + +[node name="PanelContainer" type="PanelContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer/PanelContainer"] +layout_mode = 2 + +[node name="Entities" type="VBoxContainer" parent="HBoxContainer/PanelContainer/ScrollContainer"] +layout_mode = 2 diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 7f7eff0..54a0729 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://u5h6iqyi8wd0"] +[gd_scene load_steps=11 format=3 uid="uid://u5h6iqyi8wd0"] [ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"] [ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/input/MainGameInputHandler.cs" id="3_400sg"] @@ -7,6 +7,7 @@ [ext_resource type="Script" uid="uid://dwyr067lwqcsj" path="res://scripts/map/DungeonGenerator.cs" id="4_78awf"] [ext_resource type="Script" uid="uid://ogqlb3purl6n" path="res://scripts/input/GameOverInputHandler.cs" id="4_g4kob"] [ext_resource type="Script" uid="uid://bamlnrj5bm1rd" path="res://scripts/input/InspectInputHandler.cs" id="5_g4kob"] +[ext_resource type="PackedScene" uid="uid://bryqrafavmwj4" path="res://scenes/Details.tscn" id="5_qy1jj"] [ext_resource type="Script" uid="uid://bereyrj1s46y5" path="res://scripts/map/FieldOfView.cs" id="5_s0nni"] [ext_resource type="PackedScene" uid="uid://b4h4xyr1g8o50" path="res://scenes/hud.tscn" id="6_aug50"] @@ -29,6 +30,9 @@ script = ExtResource("5_s0nni") [node name="Actors" type="Node2D" parent="Map"] +[node name="InspectDetails" parent="Map" instance=ExtResource("5_qy1jj")] +visible = false + [node name="InputHandler" type="Node" parent="."] script = ExtResource("3_s0nni") diff --git a/scenes/Inspector.tscn b/scenes/Inspector.tscn new file mode 100644 index 0000000..886b41c --- /dev/null +++ b/scenes/Inspector.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=3 format=3 uid="uid://dyythuxaio6j4"] + +[ext_resource type="Texture2D" uid="uid://cjjxf4rbj8gku" path="res://assets/sprites/inspector.png" id="1_psyxb"] +[ext_resource type="Script" uid="uid://dxsrtu4b3pi08" path="res://scripts/actors/Inspector.cs" id="2_g62u7"] + +[node name="Sprite2D" type="Sprite2D"] +texture = ExtResource("1_psyxb") +centered = false +script = ExtResource("2_g62u7") + +[node name="Camera2D" type="Camera2D" parent="."] +offset = Vector2(8, 8) +zoom = Vector2(2, 2) 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> |
