71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
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()
|
|
{
|
|
}
|
|
|
|
// 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;
|
|
Tile[,] tiles = GameData.map[GameData.currentLayer].tiles;
|
|
for (int z = 0; z < GameData.layerSize; z++)
|
|
{
|
|
for (int x = 0; x < GameData.layerSize; x++)
|
|
{
|
|
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));
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|