Added missing Symbol to the game, Improved move and explore logic, added map refresh for tiles.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class Map : PanelContainer
|
||||
{
|
||||
[Export] GridContainer grid;
|
||||
private HashSet<Tile> handledTiles = new HashSet<Tile>();
|
||||
private Dictionary<Tile, TextureRect> textureMap = new Dictionary<Tile, TextureRect>();
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -76,6 +79,15 @@ public partial class Map : PanelContainer
|
||||
texture.TooltipText = "Not explored";
|
||||
}
|
||||
|
||||
|
||||
textureMap[tiles[x, z]] = texture;
|
||||
|
||||
if (!handledTiles.Contains(tiles[x, z]))
|
||||
{
|
||||
tiles[x, z].OnTileVisited += OnTileVisited;
|
||||
handledTiles.Add(tiles[x, z]);
|
||||
}
|
||||
|
||||
texture.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
texture.SizeFlagsVertical = SizeFlags.ExpandFill;
|
||||
texture.StretchMode = TextureRect.StretchModeEnum.Scale;
|
||||
@@ -86,6 +98,35 @@ public partial class Map : PanelContainer
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTileVisited(object sender, EventArgs e)
|
||||
{
|
||||
Tile tile = sender as Tile;
|
||||
|
||||
if (tile == null)
|
||||
return;
|
||||
|
||||
if (textureMap.TryGetValue(tile, out TextureRect texture))
|
||||
{
|
||||
UpdateMap(tile, texture);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMap(Tile tile, TextureRect texture)
|
||||
{
|
||||
if (!IsInstanceValid(texture)) return;
|
||||
|
||||
if (tile.containsResource)
|
||||
{
|
||||
texture.Texture = ResourceDistributor.resources[tile.resource.name];
|
||||
texture.TooltipText = tile.resource.item.GetReadableName() + $"\r(X: {tile.GridPosition.X},Y: {GameData.currentLayer},Z: {tile.GridPosition.Y})";
|
||||
}
|
||||
else
|
||||
{
|
||||
texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 0));
|
||||
texture.TooltipText = "";
|
||||
}
|
||||
}
|
||||
|
||||
public Texture2D GenerateTexture(int size, Color fillColor)
|
||||
{
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public partial class Tile
|
||||
public bool containsLight, containsDecoration, containsResource;
|
||||
public GameResource resource;
|
||||
public bool wasVisited;
|
||||
public event EventHandler OnTileVisited;
|
||||
|
||||
|
||||
public void SetMeshes(Dictionary<string, MeshInstance3D> tileMeshes)
|
||||
@@ -138,4 +139,10 @@ public partial class Tile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void VisitTile()
|
||||
{
|
||||
wasVisited = true;
|
||||
OnTileVisited?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user