Skip to content

Commit 804dd49

Browse files
authored
Merge pull request #419 from C7-Game/pcen/use-tilemaps-grid-view
[4.x] TileMap: Grid View
2 parents 8e35041 + 8a052c8 commit 804dd49

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ data_*/
2020

2121
# Below here are ignores imported from Puppeteer's project
2222
sav/
23-
*.png
2423
*.pcx
2524
*.flc
2625
*.mp4

C7/Art/grid.png

756 Bytes
Loading

C7/Game.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private void processActions() {
453453
}
454454

455455
if (Input.IsActionJustPressed(C7Action.ToggleGrid)) {
456-
mapView.showGrid = !mapView.showGrid;
456+
mapView.toggleGrid();
457457
}
458458

459459
if (Input.IsActionJustPressed(C7Action.Escape) && !this.inUnitGoToMode) {

C7/Map/MapView.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ public partial class MapView : Node2D {
1919
public int worldEdgeLeft {get; private set;}
2020
private int width;
2121
private int height;
22-
public bool showGrid {
23-
get => showGrid;
24-
set {
25-
showGrid = value;
26-
}
27-
}
22+
private bool showGrid = false;
23+
private void setShowGrid(bool value) {
24+
bool update = showGrid != value;
25+
showGrid = value;
26+
if (update) {
27+
updateGridLayer();
28+
}
29+
}
30+
public void toggleGrid() {
31+
setShowGrid(!showGrid);
32+
}
2833
private Game game;
34+
private GameData data;
2935
private GameMap gameMap;
3036

3137
public override void _Draw() {
@@ -119,8 +125,9 @@ private Vector2I stackedCoords(Tile tile) {
119125
}
120126

121127
public MapView(Game game, GameData data) {
128+
this.data = data;
122129
this.game = game;
123-
gameMap = data.map;
130+
this.gameMap = data.map;
124131
width = gameMap.numTilesWide / 2;
125132
height = gameMap.numTilesTall;
126133
initializeTileMap();
@@ -441,5 +448,15 @@ public void updateTile(Tile tile) {
441448

442449
updateBuildingLayer(tile);
443450
}
451+
452+
private void updateGridLayer() {
453+
if (showGrid) {
454+
foreach (Tile tile in data.map.tiles) {
455+
setCell(Layer.Grid, Atlas.Grid, tile, Vector2I.Zero);
456+
}
457+
} else {
458+
tilemap.ClearLayer(Layer.Grid.Index());
459+
}
460+
}
444461
}
445462
}

C7/Map/TileSetLoader.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum Layer {
1313
Resource,
1414
TerrainYield,
1515
Building,
16+
Grid,
1617
Invalid,
1718
};
1819

@@ -44,6 +45,7 @@ public enum Atlas {
4445
TerrainYield,
4546
TerrainBuilding,
4647
GoodyHut,
48+
Grid,
4749
Invalid,
4850
}
4951

@@ -68,7 +70,7 @@ public AtlasLoader(string p, int w, int h, Vector2I rs, int y = 0) {
6870
height = h;
6971
regionSize = rs;
7072
textureOrigin = new Vector2I(0, y);
71-
source = new TileSetAtlasSource{
73+
source = new TileSetAtlasSource {
7274
Texture = Util.LoadTextureFromPCX(path),
7375
TextureRegionSize = regionSize,
7476
};
@@ -140,7 +142,7 @@ protected override void load() {
140142
}
141143

142144
class MarshAtlasLoader : AtlasLoader {
143-
public MarshAtlasLoader(string p, Vector2I rs) : base(p, -1, -1, rs, 12) {}
145+
public MarshAtlasLoader(string p, Vector2I rs) : base(p, -1, -1, rs, 12) { }
144146

145147
protected override void load() {
146148
// TODO: incomplete
@@ -217,6 +219,13 @@ public static TileSet LoadCiv3TileSet() {
217219
tileset.AddSource(source, atlas.Index());
218220
}
219221

222+
TileSetAtlasSource gridSource = new TileSetAtlasSource{
223+
Texture = Util.LoadTextureFromC7JPG("Art/grid.png"),
224+
TextureRegionSize = tileSize,
225+
};
226+
gridSource.CreateTile(Vector2I.Zero);
227+
tileset.AddSource(gridSource, Atlas.Grid.Index());
228+
220229
return tileset;
221230
}
222231
}

0 commit comments

Comments
 (0)