From 8a6de193a16db51c821955a2e28951535c04ffbf Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 1 May 2026 19:20:19 +0200 Subject: [PATCH] Added better grid to the map and reworked camera positioning whilst map is open --- Scenes/Game.tscn | 33 ++++++++++++----------- Scripts/Camera3d.cs | 13 --------- Scripts/WorldGeneration/Map.cs | 49 +++++++++++++++++++++++++--------- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index f33d9ab..13a6fb8 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -35,6 +35,9 @@ bg_color = Color(0.36567047, 0.46785766, 0.7000103, 0.5176471) [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2irst"] bg_color = Color(0.30085096, 0.39694247, 0.6216495, 0.5176471) +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bf53h"] +bg_color = Color(0.3106171, 0.31061712, 0.310617, 1) + [node name="Main" type="Node3D" unique_id=234207355] [node name="World" type="Node3D" parent="." unique_id=770208789] @@ -54,7 +57,7 @@ environment = SubResource("Environment_sb48q") [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386] follow_viewport_enabled = true -[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "information", "mainCam", "map", "FPS", "RAM", "options", "uiContent", "menu")] +[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "mainCam", "map", "FPS", "RAM", "options", "uiContent", "menu")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -68,7 +71,6 @@ size_flags_vertical = 3 script = ExtResource("4_fgofq") codingWindow = NodePath("MainUI/Content/CodingWindow") robotList = NodePath("MainUI/Content/RobotList") -information = NodePath("") mainCam = NodePath("../../Camera3D") map = NodePath("MainUI/Content/Map") FPS = NodePath("MainUI/FooterContainer/HBoxContainer/FPS") @@ -255,24 +257,25 @@ theme_override_constants/separation = 10 [node name="Map" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=292881873 node_paths=PackedStringArray("grid")] visible = false layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -20.0 -offset_top = -20.0 -offset_right = 20.0 -offset_bottom = 20.0 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_bf53h") script = ExtResource("8_bf53h") -grid = NodePath("GridContainer") +grid = NodePath("CenterContainer/AspectRatioContainer/GridContainer") -[node name="GridContainer" type="GridContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Map" unique_id=218955579] +[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Map" unique_id=1126051644] layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 + +[node name="AspectRatioContainer" type="AspectRatioContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Map/CenterContainer" unique_id=871200780] +layout_mode = 2 + +[node name="GridContainer" type="GridContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Map/CenterContainer/AspectRatioContainer" unique_id=981768520] +layout_mode = 2 +theme_override_constants/h_separation = 10 +theme_override_constants/v_separation = 10 [node name="Menu" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=370952082] visible = false diff --git a/Scripts/Camera3d.cs b/Scripts/Camera3d.cs index 2787cae..3ea126b 100644 --- a/Scripts/Camera3d.cs +++ b/Scripts/Camera3d.cs @@ -9,7 +9,6 @@ public partial class Camera3d : Camera3D [Export] public float ScrollStrength = 5.0f; private bool isShowingMap = false; - private Vector3 previousPosition; private Vector2 _mouseDelta; @@ -25,18 +24,6 @@ public partial class Camera3d : Camera3D { isShowingMap = !isShowingMap; canMove = !isShowingMap; - if (isShowingMap) - { - previousPosition = Position; - Position = new Vector3(layerSize * tileWidth / 2 - tileWidth / 2, 90 - visibleLayer * 4, layerSize * tileWidth / 2 - tileWidth / 2); - RotationDegrees = new Vector3(-90, 0, 0); - } - else - { - Position = previousPosition; - RotationDegrees = new Vector3(-75, 0, 0); - } - } } diff --git a/Scripts/WorldGeneration/Map.cs b/Scripts/WorldGeneration/Map.cs index 7c55b74..679d681 100644 --- a/Scripts/WorldGeneration/Map.cs +++ b/Scripts/WorldGeneration/Map.cs @@ -7,34 +7,55 @@ public partial class Map : PanelContainer // Called when the node enters the scene tree for the first time. public override void _Ready() { + grid.Columns = GameData.layerSize + 1; } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { - //TODO: This has to be temporary! Drawing each frame is way too expensive. - if (Visible) - { - ShowMap(); - } + } public void ShowMap() { - grid.Columns = GameData.layerSize; - grid.AddThemeConstantOverride("h_separation", (int)(GameData.tileWidth * 2.5f)); - grid.AddThemeConstantOverride("v_separation", (int)(GameData.tileWidth * 2.5f)); foreach (Node node in grid.GetChildren()) { grid.RemoveChild(node); node.QueueFree(); } TextureRect texture; + Label label; Tile[,] tiles = GameData.map[GameData.currentLayer].tiles; - for (int z = 0; z < GameData.layerSize; z++) + int size = GameData.layerSize; + for (int z = -1; z < size; z++) { - for (int x = 0; x < GameData.layerSize; x++) + for (int x = -1; x < size; x++) { + if (z == -1 || x == -1) + { + label = new Label + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + + SizeFlagsHorizontal = SizeFlags.ExpandFill, + SizeFlagsVertical = SizeFlags.ExpandFill + }; + if (z == -1 && x == -1) + { + label.Text = "\u2193 Z | \u2192 X"; + } + else if(z == -1) + { + label.Text = x.ToString(); + } + else + { + label.Text = z.ToString(); + } + grid.AddChild(label); + continue; + } texture = new TextureRect(); if (tiles[x, z].wasVisited) { @@ -44,14 +65,18 @@ public partial class Map : PanelContainer } else { - texture.Texture = GenerateTexture(32, new Color(0,0,0,0)); + texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 0)); } } else { - texture.Texture = GenerateTexture(32, new Color(0,0,0,1)); + texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 1)); } + texture.SizeFlagsHorizontal = SizeFlags.ExpandFill; + texture.SizeFlagsVertical = SizeFlags.ExpandFill; + texture.StretchMode = TextureRect.StretchModeEnum.Scale; + grid.AddChild(texture); }