From 1e6c7e7f4e4f8e8018b46958b06378d8acee9cae Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 15 Apr 2025 16:51:13 +0200 Subject: [PATCH] Draw room connections --- Scripts/Controllers/RogueliteRoomManager.cs | 2 + Scripts/UI/Minimap.cs | 45 +++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Scripts/Controllers/RogueliteRoomManager.cs b/Scripts/Controllers/RogueliteRoomManager.cs index bce3332a..44065eae 100644 --- a/Scripts/Controllers/RogueliteRoomManager.cs +++ b/Scripts/Controllers/RogueliteRoomManager.cs @@ -74,6 +74,8 @@ public partial class RogueliteRoomManager : Node2D private List _mainPath = new(); private List _connections = new(); + + public List Connections => _connections; private void GenerateStraightLineDungeon() { diff --git a/Scripts/UI/Minimap.cs b/Scripts/UI/Minimap.cs index 8a50be4d..3d2fe006 100644 --- a/Scripts/UI/Minimap.cs +++ b/Scripts/UI/Minimap.cs @@ -14,6 +14,8 @@ public partial class Minimap : CanvasLayer private List SpawnedRooms => RoomManager.SpawnedRooms; + private List Connections => RoomManager.Connections; + [Export] public int CellSize { get; private set; } = 16; [Export] public Vector2 Padding { get; private set; } = new Vector2(20, 20); @@ -89,6 +91,49 @@ public partial class Minimap : CanvasLayer RenderingServer.CanvasItemAddRect(_canvasItemRid, new Rect2(drawPos, drawSize), color); } + + DrawRoomConnections( Connections, min, offset); + } + + private void DrawRoomConnections(List connections, Vector2I minGrid, Vector2 baseOffset) + { + foreach (var connection in connections) + { + // Skip if either room is missing + if (!RoomGrid.ContainsKey(connection.From) || !RoomGrid.ContainsKey(connection.To)) + continue; + + // // Calculate center positions of each room + // Vector2 from = baseOffset + ((connection.From - minGrid) * (CellSize + (int)Separation)) + new Vector2(CellSize / 2f, CellSize / 2f); + // Vector2 to = baseOffset + ((connection.To - minGrid) * (CellSize + (int)Separation)) + new Vector2(CellSize / 2f, Separation / 2f); + + // Get relative positions of the two rooms + Vector2 fromPos = baseOffset + ((connection.From - minGrid) * (CellSize + (int)Separation)); + Vector2 toPos = baseOffset + ((connection.To - minGrid) * (CellSize + (int)Separation)); + + // Determine direction between rooms (assumes adjacent rooms only) + Vector2 delta = (toPos - fromPos).Normalized(); + + // Midpoint between rooms, where the gap is + Vector2 gapCenter = (fromPos + toPos) * 0.5f + new Vector2(CellSize / 2f, CellSize / 2f); + + // Calculate endpoints of the connection line (centered in gap) + Vector2 halfGap = delta * (Separation / 2f); + Vector2 lineStart = gapCenter - halfGap; + Vector2 lineEnd = gapCenter + halfGap; + + // Pick color based on type + Color color = Colors.White; + if (connection.IsSecret) + color = Colors.Purple; + else if (connection.IsLocked) + color = Colors.Orange; + + float thickness = 1f; + + // Draw the line + RenderingServer.CanvasItemAddLine(_canvasItemRid, lineStart, lineEnd, color, thickness); + } } private Color GetColorForRoomType(RoomType type)