From 853e226dd16b0bddb98ebaf3ded2e67324f0ad21 Mon Sep 17 00:00:00 2001 From: Shush Date: Sat, 14 Jun 2025 19:44:58 +0300 Subject: [PATCH 1/7] Add base nodes and terrain objects to info display --- src/TSMapEditor/Models/MapTile.cs | 37 ++++++++++++++++++++++++++- src/TSMapEditor/UI/TileInfoDisplay.cs | 22 ++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index 166452e71..e63a4a164 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -5,6 +5,7 @@ using TSMapEditor.Models.Enums; using TSMapEditor.Models.MapFormat; using TSMapEditor.Rendering; +using TSMapEditor.UI; namespace TSMapEditor.Models { @@ -254,7 +255,7 @@ public void DoForAllWaypoints(Action action) { action(waypoint); } - } + } public SubCell GetSubCellClosestToPosition(Point2D position, bool onlyOccupiedCells) { @@ -447,6 +448,40 @@ public void ChangeTileIndex(int newTileIndex, byte newSubTileIndex) SubTileIndex = newSubTileIndex; } + public BaseNode GetBaseNode(Map map) + { + foreach (House house in map.Houses) + { + foreach (BaseNode baseNode in house.BaseNodes) + { + var nodeStructureType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName); + + if (nodeStructureType == null) + continue; + + if (baseNode.Position == CoordsToPoint()) + { + return baseNode; + } + + bool baseNodeExistsOnFoundation = false; + nodeStructureType.ArtConfig.DoForFoundationCoords(foundationOffset => + { + Point2D foundationCellCoords = baseNode.Position + foundationOffset; + if (foundationCellCoords == CoordsToPoint()) + baseNodeExistsOnFoundation = true; + }); + + if (baseNodeExistsOnFoundation) + { + return baseNode; + } + } + } + + return null; + } + public Point2D CoordsToPoint() => new Point2D(X, Y); public Point2D GetTileCenter() => new Point2D(Constants.CellSizeX / 2, Constants.CellSizeY / 2); diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 4b52f461f..e0120cb23 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -133,6 +133,8 @@ private void RefreshInfo() MapTile.DoForAllBuildings(structure => AddObjectInformation("Structure: ", structure)); MapTile.DoForAllInfantry(inf => AddObjectInformation("Infantry: ", inf)); MapTile.DoForAllWaypoints(waypoint => AddWaypointInfo(waypoint)); + AddBaseNodeInformation(MapTile.GetBaseNode(map)); + AddTerrainObjectInformation(MapTile.TerrainObject); textRenderer.PrepareTextParts(); @@ -286,5 +288,25 @@ private void AddObjectInformation(string objectTypeLabel, Techno techno) w textRenderer.AddTextPart(new XNATextPart(techno.AttachedTag.Name + " (" + techno.AttachedTag.ID + ")", Constants.UIBoldFont, Color.White)); } } + + private void AddBaseNodeInformation(BaseNode baseNode) + { + if (baseNode == null) + return; + + var nodeBuildingType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName); + + textRenderer.AddTextLine(new XNATextPart("Base Node: ", Constants.UIDefaultFont, Color.Gray)); + textRenderer.AddTextPart(new XNATextPart(nodeBuildingType.Name + " (" + nodeBuildingType.ININame + ")", Constants.UIDefaultFont, Color.White)); + } + + private void AddTerrainObjectInformation(TerrainObject terrainObject) + { + if (terrainObject == null) + return; + + textRenderer.AddTextLine(new XNATextPart("Terrain Object: ", Constants.UIDefaultFont, Color.Gray)); + textRenderer.AddTextPart(new XNATextPart(terrainObject.TerrainType.Name + " (" + terrainObject.TerrainType.ININame + ")", Constants.UIDefaultFont, Color.White)); + } } } From eec84892df91f7c9228e0eab9b5a2ea4a3068861 Mon Sep 17 00:00:00 2001 From: Shush Date: Sat, 14 Jun 2025 19:50:18 +0300 Subject: [PATCH 2/7] Cleanup code --- src/TSMapEditor/Models/MapTile.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index e63a4a164..8c2fa9bdb 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -5,7 +5,6 @@ using TSMapEditor.Models.Enums; using TSMapEditor.Models.MapFormat; using TSMapEditor.Rendering; -using TSMapEditor.UI; namespace TSMapEditor.Models { @@ -255,7 +254,7 @@ public void DoForAllWaypoints(Action action) { action(waypoint); } - } + } public SubCell GetSubCellClosestToPosition(Point2D position, bool onlyOccupiedCells) { From 218c616c6b2d9f866448fc53a32802d6d9be0e73 Mon Sep 17 00:00:00 2001 From: Shush Date: Sat, 14 Jun 2025 20:05:11 +0300 Subject: [PATCH 3/7] Add house owner to base nodes, use string literals --- src/TSMapEditor/UI/TileInfoDisplay.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index e0120cb23..9db1c3db1 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -295,9 +295,13 @@ private void AddBaseNodeInformation(BaseNode baseNode) return; var nodeBuildingType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName); + var house = map.Houses.Find(house => house.BaseNodes.Contains(baseNode)); + + if (nodeBuildingType == null || house == null) + return; textRenderer.AddTextLine(new XNATextPart("Base Node: ", Constants.UIDefaultFont, Color.Gray)); - textRenderer.AddTextPart(new XNATextPart(nodeBuildingType.Name + " (" + nodeBuildingType.ININame + ")", Constants.UIDefaultFont, Color.White)); + textRenderer.AddTextPart(new XNATextPart($"{nodeBuildingType.Name} ({nodeBuildingType.ININame}) ({house.ININame})", Constants.UIDefaultFont, Color.White)); } private void AddTerrainObjectInformation(TerrainObject terrainObject) @@ -306,7 +310,7 @@ private void AddTerrainObjectInformation(TerrainObject terrainObject) return; textRenderer.AddTextLine(new XNATextPart("Terrain Object: ", Constants.UIDefaultFont, Color.Gray)); - textRenderer.AddTextPart(new XNATextPart(terrainObject.TerrainType.Name + " (" + terrainObject.TerrainType.ININame + ")", Constants.UIDefaultFont, Color.White)); + textRenderer.AddTextPart(new XNATextPart($"{terrainObject.TerrainType.Name} (${terrainObject.TerrainType.ININame})", Constants.UIDefaultFont, Color.White)); } } } From 3eb6c9725a2392dcf06357529168d6fa71bed852 Mon Sep 17 00:00:00 2001 From: Shush Date: Fri, 11 Jul 2025 22:24:23 +0300 Subject: [PATCH 4/7] Refactor base node lookup and update UI display Moved base node lookup logic from MapTile to Map for improved encapsulation and efficiency. Updated TileInfoDisplay to use the new Map.GetBaseNode method and improved base node information formatting in the UI. --- src/TSMapEditor/Models/Map.cs | 31 +++++++++++++++++++++++ src/TSMapEditor/Models/MapTile.cs | 36 +-------------------------- src/TSMapEditor/UI/TileInfoDisplay.cs | 6 +++-- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index e03d106ab..6c4796eea 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -2096,5 +2096,36 @@ public void Clear() Tubes = null; GraphicalBaseNodes = null; } + + public BaseNode GetBaseNode(Point2D cellCoords) + { + foreach (var graphicalBaseNode in GraphicalBaseNodes) + { + var nodeBuildingType = graphicalBaseNode.BuildingType; + + if (nodeBuildingType == null) + continue; + + if (graphicalBaseNode.BaseNode.Position == cellCoords) + { + return graphicalBaseNode.BaseNode; + } + + bool baseNodeExistsOnFoundation = false; + nodeBuildingType.ArtConfig.DoForFoundationCoords(foundationOffset => + { + Point2D foundationCellCoords = graphicalBaseNode.BaseNode.Position + foundationOffset; + if (foundationCellCoords == cellCoords) + baseNodeExistsOnFoundation = true; + }); + + if (baseNodeExistsOnFoundation) + { + return graphicalBaseNode.BaseNode; + } + } + + return null; + } } } diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index 8c2fa9bdb..82967b493 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -445,41 +445,7 @@ public void ChangeTileIndex(int newTileIndex, byte newSubTileIndex) TileImage = null; TileIndex = newTileIndex; SubTileIndex = newSubTileIndex; - } - - public BaseNode GetBaseNode(Map map) - { - foreach (House house in map.Houses) - { - foreach (BaseNode baseNode in house.BaseNodes) - { - var nodeStructureType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName); - - if (nodeStructureType == null) - continue; - - if (baseNode.Position == CoordsToPoint()) - { - return baseNode; - } - - bool baseNodeExistsOnFoundation = false; - nodeStructureType.ArtConfig.DoForFoundationCoords(foundationOffset => - { - Point2D foundationCellCoords = baseNode.Position + foundationOffset; - if (foundationCellCoords == CoordsToPoint()) - baseNodeExistsOnFoundation = true; - }); - - if (baseNodeExistsOnFoundation) - { - return baseNode; - } - } - } - - return null; - } + } public Point2D CoordsToPoint() => new Point2D(X, Y); diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 9db1c3db1..09c4c6dc3 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Rampastring.XNAUI; using Rampastring.XNAUI.XNAControls; +using SharpDX.XAPO.Fx; using System; using System.Collections.Generic; using System.Globalization; @@ -133,7 +134,7 @@ private void RefreshInfo() MapTile.DoForAllBuildings(structure => AddObjectInformation("Structure: ", structure)); MapTile.DoForAllInfantry(inf => AddObjectInformation("Infantry: ", inf)); MapTile.DoForAllWaypoints(waypoint => AddWaypointInfo(waypoint)); - AddBaseNodeInformation(MapTile.GetBaseNode(map)); + AddBaseNodeInformation(map.GetBaseNode(MapTile.CoordsToPoint())); AddTerrainObjectInformation(MapTile.TerrainObject); textRenderer.PrepareTextParts(); @@ -301,7 +302,8 @@ private void AddBaseNodeInformation(BaseNode baseNode) return; textRenderer.AddTextLine(new XNATextPart("Base Node: ", Constants.UIDefaultFont, Color.Gray)); - textRenderer.AddTextPart(new XNATextPart($"{nodeBuildingType.Name} ({nodeBuildingType.ININame}) ({house.ININame})", Constants.UIDefaultFont, Color.White)); + textRenderer.AddTextPart(new XNATextPart($"{nodeBuildingType.Name} ({nodeBuildingType.ININame}), Owner:", Constants.UIDefaultFont, Color.White)); + textRenderer.AddTextPart(new XNATextPart(house.ININame, Constants.UIBoldFont, house.XNAColor)); } private void AddTerrainObjectInformation(TerrainObject terrainObject) From b487f2da646af57429cec6bf3964540dc7cbc115 Mon Sep 17 00:00:00 2001 From: Shush Date: Fri, 11 Jul 2025 23:30:34 +0300 Subject: [PATCH 5/7] Support multiple base nodes info per tile Changed Map.GetBaseNode to GetBaseNodes to return a list of base nodes for a given cell coordinate. Updated TileInfoDisplay to handle and display information for multiple base nodes on a tile. --- src/TSMapEditor/Models/Map.cs | 11 +++++++---- src/TSMapEditor/UI/TileInfoDisplay.cs | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 6c4796eea..de02a084e 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -2097,8 +2097,10 @@ public void Clear() GraphicalBaseNodes = null; } - public BaseNode GetBaseNode(Point2D cellCoords) + public List GetBaseNodes(Point2D cellCoords) { + List baseNodes = []; + foreach (var graphicalBaseNode in GraphicalBaseNodes) { var nodeBuildingType = graphicalBaseNode.BuildingType; @@ -2108,7 +2110,8 @@ public BaseNode GetBaseNode(Point2D cellCoords) if (graphicalBaseNode.BaseNode.Position == cellCoords) { - return graphicalBaseNode.BaseNode; + baseNodes.Add(graphicalBaseNode.BaseNode); + continue; } bool baseNodeExistsOnFoundation = false; @@ -2121,11 +2124,11 @@ public BaseNode GetBaseNode(Point2D cellCoords) if (baseNodeExistsOnFoundation) { - return graphicalBaseNode.BaseNode; + baseNodes.Add(graphicalBaseNode.BaseNode); } } - return null; + return baseNodes; } } } diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 09c4c6dc3..2756221ed 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -134,7 +134,7 @@ private void RefreshInfo() MapTile.DoForAllBuildings(structure => AddObjectInformation("Structure: ", structure)); MapTile.DoForAllInfantry(inf => AddObjectInformation("Infantry: ", inf)); MapTile.DoForAllWaypoints(waypoint => AddWaypointInfo(waypoint)); - AddBaseNodeInformation(map.GetBaseNode(MapTile.CoordsToPoint())); + AddBaseNodeInformation(map.GetBaseNodes(MapTile.CoordsToPoint())); AddTerrainObjectInformation(MapTile.TerrainObject); textRenderer.PrepareTextParts(); @@ -290,20 +290,20 @@ private void AddObjectInformation(string objectTypeLabel, Techno techno) w } } - private void AddBaseNodeInformation(BaseNode baseNode) + private void AddBaseNodeInformation(List baseNodes) { - if (baseNode == null) - return; - - var nodeBuildingType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName); - var house = map.Houses.Find(house => house.BaseNodes.Contains(baseNode)); + foreach (var baseNode in baseNodes) + { + var nodeBuildingType = map.Rules.BuildingTypes.Find(bt => bt.ININame == baseNode.StructureTypeName); + var house = map.Houses.Find(house => house.BaseNodes.Contains(baseNode)); - if (nodeBuildingType == null || house == null) - return; + if (nodeBuildingType == null || house == null) + return; - textRenderer.AddTextLine(new XNATextPart("Base Node: ", Constants.UIDefaultFont, Color.Gray)); - textRenderer.AddTextPart(new XNATextPart($"{nodeBuildingType.Name} ({nodeBuildingType.ININame}), Owner:", Constants.UIDefaultFont, Color.White)); - textRenderer.AddTextPart(new XNATextPart(house.ININame, Constants.UIBoldFont, house.XNAColor)); + textRenderer.AddTextLine(new XNATextPart("Base Node: ", Constants.UIDefaultFont, Color.Gray)); + textRenderer.AddTextPart(new XNATextPart($"{nodeBuildingType.Name} ({nodeBuildingType.ININame}), Owner:", Constants.UIDefaultFont, Color.White)); + textRenderer.AddTextPart(new XNATextPart(house.ININame, Constants.UIBoldFont, house.XNAColor)); + } } private void AddTerrainObjectInformation(TerrainObject terrainObject) From 42dfa2ee75138c6e8a840f44a5dbd8bc2f986206 Mon Sep 17 00:00:00 2001 From: Shush Date: Sun, 13 Jul 2025 23:30:54 +0300 Subject: [PATCH 6/7] Revert empty spaces --- src/TSMapEditor/Models/MapTile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index 82967b493..166452e71 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -445,7 +445,7 @@ public void ChangeTileIndex(int newTileIndex, byte newSubTileIndex) TileImage = null; TileIndex = newTileIndex; SubTileIndex = newSubTileIndex; - } + } public Point2D CoordsToPoint() => new Point2D(X, Y); From d258a060c0f1f5c70bca2ed98beff7b17a250a93 Mon Sep 17 00:00:00 2001 From: Shush Date: Thu, 17 Jul 2025 09:46:15 +0300 Subject: [PATCH 7/7] Remove unused import --- src/TSMapEditor/UI/TileInfoDisplay.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 2756221ed..6dfe5a6cc 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Rampastring.XNAUI; using Rampastring.XNAUI.XNAControls; -using SharpDX.XAPO.Fx; using System; using System.Collections.Generic; using System.Globalization;