using Godot; using System; public partial class Map : PanelContainer { [Export] GridContainer grid; // 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) { } public void ShowMap() { foreach (Node node in grid.GetChildren()) { grid.RemoveChild(node); node.QueueFree(); } TextureRect texture; Label label; Tile[,] tiles = GameData.map[GameData.currentLayer].tiles; int size = GameData.layerSize; for (int z = -1; z < size; z++) { 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) { if (tiles[x, z].containsResource) { texture.Texture = ResourceDistributor.resources[tiles[x, z].resource.name]; } else { texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 0)); } } else { 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); } } } public Texture2D GenerateTexture(int size, Color fillColor) { Image image = Image.CreateEmpty(size, size, false, Image.Format.Rgba8); image.Fill(fillColor); return ImageTexture.CreateFromImage(image); } }