Added better grid to the map and reworked camera positioning whilst map is open

This commit is contained in:
=
2026-05-01 19:20:19 +02:00
parent 75818c22d5
commit 8a6de193a1
3 changed files with 55 additions and 40 deletions
-13
View File
@@ -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);
}
}
}
+37 -12
View File
@@ -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);
}