Skip to content

Commit 853e226

Browse files
committed
Add base nodes and terrain objects to info display
1 parent 9b65580 commit 853e226

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/TSMapEditor/Models/MapTile.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using TSMapEditor.Models.Enums;
66
using TSMapEditor.Models.MapFormat;
77
using TSMapEditor.Rendering;
8+
using TSMapEditor.UI;
89

910
namespace TSMapEditor.Models
1011
{
@@ -254,7 +255,7 @@ public void DoForAllWaypoints(Action<Waypoint> action)
254255
{
255256
action(waypoint);
256257
}
257-
}
258+
}
258259

259260
public SubCell GetSubCellClosestToPosition(Point2D position, bool onlyOccupiedCells)
260261
{
@@ -447,6 +448,40 @@ public void ChangeTileIndex(int newTileIndex, byte newSubTileIndex)
447448
SubTileIndex = newSubTileIndex;
448449
}
449450

451+
public BaseNode GetBaseNode(Map map)
452+
{
453+
foreach (House house in map.Houses)
454+
{
455+
foreach (BaseNode baseNode in house.BaseNodes)
456+
{
457+
var nodeStructureType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName);
458+
459+
if (nodeStructureType == null)
460+
continue;
461+
462+
if (baseNode.Position == CoordsToPoint())
463+
{
464+
return baseNode;
465+
}
466+
467+
bool baseNodeExistsOnFoundation = false;
468+
nodeStructureType.ArtConfig.DoForFoundationCoords(foundationOffset =>
469+
{
470+
Point2D foundationCellCoords = baseNode.Position + foundationOffset;
471+
if (foundationCellCoords == CoordsToPoint())
472+
baseNodeExistsOnFoundation = true;
473+
});
474+
475+
if (baseNodeExistsOnFoundation)
476+
{
477+
return baseNode;
478+
}
479+
}
480+
}
481+
482+
return null;
483+
}
484+
450485
public Point2D CoordsToPoint() => new Point2D(X, Y);
451486

452487
public Point2D GetTileCenter() => new Point2D(Constants.CellSizeX / 2, Constants.CellSizeY / 2);

src/TSMapEditor/UI/TileInfoDisplay.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ private void RefreshInfo()
133133
MapTile.DoForAllBuildings(structure => AddObjectInformation("Structure: ", structure));
134134
MapTile.DoForAllInfantry(inf => AddObjectInformation("Infantry: ", inf));
135135
MapTile.DoForAllWaypoints(waypoint => AddWaypointInfo(waypoint));
136+
AddBaseNodeInformation(MapTile.GetBaseNode(map));
137+
AddTerrainObjectInformation(MapTile.TerrainObject);
136138

137139
textRenderer.PrepareTextParts();
138140

@@ -286,5 +288,25 @@ private void AddObjectInformation<T>(string objectTypeLabel, Techno<T> techno) w
286288
textRenderer.AddTextPart(new XNATextPart(techno.AttachedTag.Name + " (" + techno.AttachedTag.ID + ")", Constants.UIBoldFont, Color.White));
287289
}
288290
}
291+
292+
private void AddBaseNodeInformation(BaseNode baseNode)
293+
{
294+
if (baseNode == null)
295+
return;
296+
297+
var nodeBuildingType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName);
298+
299+
textRenderer.AddTextLine(new XNATextPart("Base Node: ", Constants.UIDefaultFont, Color.Gray));
300+
textRenderer.AddTextPart(new XNATextPart(nodeBuildingType.Name + " (" + nodeBuildingType.ININame + ")", Constants.UIDefaultFont, Color.White));
301+
}
302+
303+
private void AddTerrainObjectInformation(TerrainObject terrainObject)
304+
{
305+
if (terrainObject == null)
306+
return;
307+
308+
textRenderer.AddTextLine(new XNATextPart("Terrain Object: ", Constants.UIDefaultFont, Color.Gray));
309+
textRenderer.AddTextPart(new XNATextPart(terrainObject.TerrainType.Name + " (" + terrainObject.TerrainType.ININame + ")", Constants.UIDefaultFont, Color.White));
310+
}
289311
}
290312
}

0 commit comments

Comments
 (0)