From 29857162de6c72780924dd5ccef1b53305e81f76 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 9 Aug 2023 00:25:56 +0300 Subject: [PATCH 01/15] Waypoints are now stored in a List to allow for multiple waypoints in a cell --- src/TSMapEditor/Initialization/MapLoader.cs | 10 +++--- src/TSMapEditor/Models/Map.cs | 31 ++++++++++--------- src/TSMapEditor/Models/MapTile.cs | 5 ++- .../Classes/PlaceWaypointMutation.cs | 2 +- src/TSMapEditor/Rendering/MapView.cs | 4 +-- .../PlaceWaypointCursorAction.cs | 3 -- src/TSMapEditor/UI/TileInfoDisplay.cs | 5 +-- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index e507a6cc..b8367577 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -674,11 +674,11 @@ public static void ReadWaypoints(IMap map, IniFile mapIni) continue; } - if (mapCell.Waypoint != null) - { - AddMapLoadError($"Cell at {waypoint.Position} has multiple waypoints placed on it. Skipping adding waypoint #{waypoint.Identifier} there."); - continue; - } + //if (mapCell.Waypoint != null) + //{ + // AddMapLoadError($"Cell at {waypoint.Position} has multiple waypoints placed on it. Skipping adding waypoint #{waypoint.Identifier} there."); + // continue; + //} map.AddWaypoint(waypoint); } diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 261e35de..6eb476fb 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -597,31 +597,34 @@ public void AddWaypoint(Waypoint waypoint) { Waypoints.Add(waypoint); var cell = GetTile(waypoint.Position.X, waypoint.Position.Y); - if (cell.Waypoint != null) - { - throw new InvalidOperationException($"Cell at {cell.CoordsToPoint()} already has a waypoint, skipping adding waypoint {waypoint.Identifier}"); - } + //if (cell.Waypoint != null) + //{ + // throw new InvalidOperationException($"Cell at {cell.CoordsToPoint()} already has a waypoint, skipping adding waypoint {waypoint.Identifier}"); + //} - cell.Waypoint = waypoint; + cell.Waypoints.Add(waypoint); } public void RemoveWaypoint(Waypoint waypoint) { var tile = GetTile(waypoint.Position); - if (tile.Waypoint == waypoint) + if (tile.Waypoints.Contains(waypoint)) { Waypoints.Remove(waypoint); - tile.Waypoint = null; + tile.Waypoints.Remove(waypoint); } } - public void RemoveWaypointFrom(Point2D cellCoords) + public void RemoveWaypointsFrom(Point2D cellCoords) { var tile = GetTile(cellCoords); - if (tile.Waypoint != null) + if (tile.Waypoints.Count > 0) { - Waypoints.Remove(tile.Waypoint); - tile.Waypoint = null; + foreach (var waypoint in tile.Waypoints) + { + Waypoints.Remove(waypoint); + } + tile.Waypoints.Clear(); } } @@ -954,7 +957,7 @@ public bool CanPlaceObjectAt(IMovable movable, Point2D newCoords, bool considerS MapTile cell = GetTile(newCoords); if (movable.WhatAmI() == RTTIType.Waypoint) - return cell.Waypoint == null; + return true; return cell.CanAddObject((GameObject)movable); } @@ -1004,9 +1007,9 @@ public void DeleteObjectFromCell(Point2D cellCoords) return; } - if (tile.Waypoint != null) + if (tile.Waypoints.Count > 0) { - RemoveWaypoint(tile.Waypoint); + RemoveWaypointsFrom(tile.CoordsToPoint()); return; } } diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index 1d846fc5..aac6e7b8 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -33,8 +33,7 @@ public MapTile(byte[] data) : base(data) { } public Overlay Overlay { get; set; } public Smudge Smudge { get; set; } - - public Waypoint Waypoint { get; set; } + public List Waypoints { get; set; } = new(); public CellTag CellTag { get; set; } @@ -210,7 +209,7 @@ public bool ContainsObject(AbstractObject abstractObject) case RTTIType.Smudge: return Smudge == abstractObject; case RTTIType.Waypoint: - return Waypoint == abstractObject; + return Waypoints.Contains((Waypoint)abstractObject); } return false; diff --git a/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs index f348ba4a..557295f1 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs @@ -26,7 +26,7 @@ public override void Perform() public override void Undo() { - MutationTarget.Map.RemoveWaypointFrom(cellCoords); + MutationTarget.Map.RemoveWaypointsFrom(cellCoords); MutationTarget.AddRefreshPoint(cellCoords, 1); } } diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index da8ae62d..d4f4b463 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -1076,9 +1076,9 @@ public override void OnMouseMove() isDraggingObject = true; } } - else if (tileUnderCursor.Waypoint != null) + else if (tileUnderCursor.Waypoints.Count > 0) { - draggedOrRotatedObject = tileUnderCursor.Waypoint; + draggedOrRotatedObject = tileUnderCursor.Waypoints[0]; isDraggingObject = true; } } diff --git a/src/TSMapEditor/UI/CursorActions/PlaceWaypointCursorAction.cs b/src/TSMapEditor/UI/CursorActions/PlaceWaypointCursorAction.cs index 001b8fee..26be3c71 100644 --- a/src/TSMapEditor/UI/CursorActions/PlaceWaypointCursorAction.cs +++ b/src/TSMapEditor/UI/CursorActions/PlaceWaypointCursorAction.cs @@ -18,9 +18,6 @@ public PlaceWaypointCursorAction(ICursorActionTarget cursorActionTarget) : base( public override void LeftClick(Point2D cellCoords) { - if (CursorActionTarget.Map.GetTile(cellCoords).Waypoint != null) - return; - PlaceWaypointWindow.Open(cellCoords); } diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 967dace6..347c0562 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -140,9 +140,10 @@ private void RefreshInfo() AddObjectInformation("Infantry: ", MapTile.Infantry[i]); } - if (MapTile.Waypoint != null) + if (MapTile.Waypoints.Count > 0) { - AddWaypointInfo(MapTile.Waypoint); + foreach (var waypoint in MapTile.Waypoints) + AddWaypointInfo(waypoint); } textRenderer.PrepareTextParts(); From 9f0049b5b0a33f001789919d6e9879477e3de52e Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 9 Aug 2023 01:36:48 +0300 Subject: [PATCH 02/15] Buildings are now stored in a list to allow for multiple buildings in a tile --- src/TSMapEditor/Initialization/MapLoader.cs | 22 ++++---- src/TSMapEditor/Models/Map.cs | 37 +++++++------- src/TSMapEditor/Models/MapTile.cs | 24 +++++---- .../Mutations/Classes/PasteTerrainMutation.cs | 8 +-- .../Classes/PlaceBuildingMutation.cs | 4 +- src/TSMapEditor/Rendering/MapView.cs | 11 ++-- .../CursorActions/BuildingPlacementAction.cs | 50 ++++++++++--------- .../CursorActions/CopyTerrainCursorAction.cs | 7 ++- .../ManageBaseNodesCursorAction.cs | 12 ++--- src/TSMapEditor/UI/TileInfoDisplay.cs | 13 +++-- 10 files changed, 102 insertions(+), 86 deletions(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index b8367577..ef899633 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -350,10 +350,11 @@ void CheckFoundationCell(Point2D cellCoords) return; } - if (tile.Structure != null) + if (tile.Structures.Count > 0) { - isClear = false; - AddMapLoadError($"Building {buildingType.ININame} exists on a cell ({cellCoords}) that already has another building ({tile.Structure.ObjectType.ININame}). Skipping adding it to map."); + //isClear = false; + //AddMapLoadError($"Building {buildingType.ININame} exists on a cell ({cellCoords}) that already has another building ({tile.Structure.ObjectType.ININame}). Skipping adding it to map."); + Logger.Log($"NOTE: Building {buildingType.ININame} exists on the cell {cellCoords} that already has other buildings."); } } @@ -366,7 +367,7 @@ void CheckFoundationCell(Point2D cellCoords) buildingType.ArtConfig.DoForFoundationCoordsOrOrigin(offset => { var tile = map.GetTile(building.Position + offset); - tile.Structure = building; + tile.Structures.Add(building); }); } } @@ -673,12 +674,13 @@ public static void ReadWaypoints(IMap map, IniFile mapIni) AddMapLoadError($"Waypoint {waypoint.Identifier} at {waypoint.Position} is not within the valid map area."); continue; } - - //if (mapCell.Waypoint != null) - //{ - // AddMapLoadError($"Cell at {waypoint.Position} has multiple waypoints placed on it. Skipping adding waypoint #{waypoint.Identifier} there."); - // continue; - //} + + if (mapCell.Waypoints.Count > 0) + { + //AddMapLoadError($"Cell at {waypoint.Position} has multiple waypoints placed on it. Skipping adding waypoint #{waypoint.Identifier} there."); + Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists on the cell {waypoint.Position} that already has other waypoints."); + continue; + } map.AddWaypoint(waypoint); } diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 6eb476fb..3c7a91b9 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -597,10 +597,11 @@ public void AddWaypoint(Waypoint waypoint) { Waypoints.Add(waypoint); var cell = GetTile(waypoint.Position.X, waypoint.Position.Y); - //if (cell.Waypoint != null) - //{ - // throw new InvalidOperationException($"Cell at {cell.CoordsToPoint()} already has a waypoint, skipping adding waypoint {waypoint.Identifier}"); - //} + if (cell.Waypoints.Count > 0) + { + //throw new InvalidOperationException($"Cell at {cell.CoordsToPoint()} already has a waypoint, skipping adding waypoint {waypoint.Identifier}"); + Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists on the cell {cell.CoordsToPoint()} that already has other waypoints."); + } cell.Waypoints.Add(waypoint); } @@ -750,26 +751,26 @@ public void PlaceBuilding(Structure structure) if (cell == null) return; - if (cell.Structure != null) - throw new InvalidOperationException("Cannot place a structure on a cell that already has a structure!"); + //if (cell.Structure != null) + // throw new InvalidOperationException("Cannot place a structure on a cell that already has a structure!"); - cell.Structure = structure; + cell.Structures.Add(structure); }); if (structure.ObjectType.ArtConfig.Foundation.Width == 0 && structure.ObjectType.ArtConfig.Foundation.Height == 0) { - GetTile(structure.Position).Structure = structure; + GetTile(structure.Position).Structures.Add(structure); } Structures.Add(structure); } - public void RemoveBuilding(Point2D cellCoords) + public void RemoveBuildingsFrom(Point2D cellCoords) { var cell = GetTile(cellCoords); - if (cell.Structure != null) - RemoveBuilding(cell.Structure); + if (cell.Structures.Count > 0) + cell.Structures.Clear(); } public void RemoveBuilding(Structure structure) @@ -780,13 +781,13 @@ public void RemoveBuilding(Structure structure) if (cell == null) return; - if (cell.Structure == structure) - cell.Structure = null; + if (cell.Structures.Contains(structure)) + cell.Structures.Remove(structure); }); if (structure.ObjectType.ArtConfig.Foundation.Width == 0 && structure.ObjectType.ArtConfig.Foundation.Height == 0) { - GetTile(structure.Position).Structure = null; + GetTile(structure.Position).Structures.Remove(structure); } Structures.Remove(structure); @@ -947,8 +948,8 @@ public bool CanPlaceObjectAt(IMovable movable, Point2D newCoords, bool considerS if (foundationCell == null) return; - if (foundationCell.Structure != null && (considerSelf || foundationCell.Structure != movable)) - canPlace = false; + //if (foundationCell.Structure != null && foundationCell.Structure != movable) + // canPlace = false; }); if (!canPlace) @@ -989,9 +990,9 @@ public void DeleteObjectFromCell(Point2D cellCoords) return; } - if (tile.Structure != null) + if (tile.Structures.Count > 0) { - RemoveBuilding(tile.Structure); + RemoveBuildingsFrom(tile.CoordsToPoint()); return; } diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index aac6e7b8..6fb6ad3a 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -23,6 +23,7 @@ public MapTile(byte[] data) : base(data) { } /// public TileImage TileImage { get; set; } public TerrainObject TerrainObject { get; set; } + public List Structures { get; set; } = new List(); public Structure Structure { get; set; } public Unit Vehicle { get; set; } public Aircraft Aircraft { get; set; } @@ -33,7 +34,7 @@ public MapTile(byte[] data) : base(data) { } public Overlay Overlay { get; set; } public Smudge Smudge { get; set; } - public List Waypoints { get; set; } = new(); + public List Waypoints { get; set; } = new List(); public CellTag CellTag { get; set; } @@ -67,8 +68,8 @@ public void ShiftPosition(int x, int y) public void AddObjectsToList(List objects) { - if (Structure != null) - objects.Add(Structure); + if (Structures.Count > 0) + objects.AddRange(Structures); if (Vehicle != null) objects.Add(Vehicle); @@ -120,7 +121,7 @@ public Infantry GetFirstInfantry() public bool HasTechno() { - return Structure != null || Vehicle != null || Aircraft != null || Array.Exists(Infantry, inf => inf != null); + return Structures.Count > 0 || Vehicle != null || Aircraft != null || Array.Exists(Infantry, inf => inf != null); } public bool HasTechnoThatPassesCheck(Predicate predicate) @@ -130,8 +131,11 @@ public bool HasTechnoThatPassesCheck(Predicate predicate) public TechnoBase GetFirstTechnoThatPassesCheck(Predicate predicate) { - if (Structure != null && predicate(Structure)) - return Structure; + foreach (var structure in Structures) + { + if (predicate(structure)) + return structure; + } if (Vehicle != null && predicate(Vehicle)) return Vehicle; @@ -144,8 +148,8 @@ public TechnoBase GetFirstTechnoThatPassesCheck(Predicate predicate) public TechnoBase GetTechno() { - if (Structure != null) - return Structure; + if (Structures.Count > 0) + return Structures[0]; if (Vehicle != null) return Vehicle; @@ -178,7 +182,7 @@ public bool CanAddObject(GameObject gameObject) case RTTIType.Aircraft: return Aircraft == null; case RTTIType.Building: - return Structure == null || Structure == gameObject; + return true; case RTTIType.Unit: return Vehicle == null; case RTTIType.Infantry: @@ -199,7 +203,7 @@ public bool ContainsObject(AbstractObject abstractObject) case RTTIType.Terrain: return TerrainObject == abstractObject; case RTTIType.Building: - return Structure == abstractObject; + return Structures.Contains((Structure)abstractObject); case RTTIType.Unit: return Vehicle == abstractObject; case RTTIType.Infantry: diff --git a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs index 7714e2c0..63beb57b 100644 --- a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs @@ -657,8 +657,8 @@ public override void Perform() if (cell == null) continue; - if (cell.Structure != null) - continue; + //if (cell.Structure != null) + // continue; var buildingType = MutationTarget.Map.Rules.BuildingTypes.Find(tt => tt.ININame == copiedStructureEntry.ObjectTypeName); if (buildingType == null) @@ -670,7 +670,7 @@ public override void Perform() Point2D foundationCellCoords = foundationPoint + cellCoords; MapTile foundationCell = MutationTarget.Map.GetTile(foundationCellCoords); - if (foundationCell == null || foundationCell.Structure != null) + if (foundationCell == null)// || foundationCell.Structure != null) isFoundationClear = false; }); @@ -774,7 +774,7 @@ public override void Undo() foreach (Point2D cellCoords in structureCells) { - MutationTarget.Map.RemoveBuilding(cellCoords); + MutationTarget.Map.RemoveBuildingsFrom(cellCoords); } foreach (var infantryInfo in infantryLocations) diff --git a/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs index 0c12ee35..541b34e0 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs @@ -26,8 +26,8 @@ public override void Perform() { var cell = MutationTarget.Map.GetTileOrFail(cellCoords); - if (cell.Structure != null) - throw new InvalidOperationException(nameof(PlaceBuildingMutation) + ": the cell already has a building!"); + //if (cell.Structure != null) + // throw new InvalidOperationException(nameof(PlaceBuildingMutation) + ": the cell already has a building!"); var structure = new Structure(buildingType); structure.Owner = MutationTarget.ObjectOwner; diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index d4f4b463..a86c7aaf 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -558,8 +558,11 @@ public void DrawTerrainTileAndRegisterObjects(MapTile tile) if (tile.Overlay != null && tile.Overlay.OverlayType != null) gameObjectsToRender.Add(tile.Overlay); - if (tile.Structure != null && tile.Structure.Position == tile.CoordsToPoint()) - gameObjectsToRender.Add(tile.Structure); + foreach (var structure in tile.Structures) + { + if (structure.Position == tile.CoordsToPoint()) + gameObjectsToRender.Add(structure); + } tile.DoForAllInfantry(i => gameObjectsToRender.Add(i)); @@ -1121,8 +1124,8 @@ private void HandleDoubleClick() { if (tileUnderCursor != null && CursorAction == null) { - if (tileUnderCursor.Structure != null) - windowController.StructureOptionsWindow.Open(tileUnderCursor.Structure); + if (tileUnderCursor.Structures.Count > 0) + windowController.StructureOptionsWindow.Open(tileUnderCursor.Structures[0]); if (tileUnderCursor.Vehicle != null) windowController.VehicleOptionsWindow.Open(tileUnderCursor.Vehicle); diff --git a/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs index 9017648b..6e54a347 100644 --- a/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs @@ -48,33 +48,37 @@ public override void PreMapDraw(Point2D cellCoords) structure.Position = cellCoords; var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Structure != null) - return; - - bool foundationAreaHasStructure = false; - structure.ObjectType.ArtConfig.DoForFoundationCoordsOrOrigin(offset => - { - var cell = CursorActionTarget.Map.GetTile(cellCoords + offset); - - if (cell != null && cell.Structure != null) - foundationAreaHasStructure = true; - }); - - if (!foundationAreaHasStructure) - { - tile.Structure = structure; - CursorActionTarget.TechnoUnderCursor = structure; - CursorActionTarget.AddRefreshPoint(cellCoords, 10); - } + tile.Structures.Add(structure); + CursorActionTarget.TechnoUnderCursor = structure; + CursorActionTarget.AddRefreshPoint(cellCoords, 10); + + //if (tile.Structure != null) + // return; + + //bool foundationAreaHasStructure = false; + //structure.ObjectType.ArtConfig.DoForFoundationCoords(offset => + //{ + // var cell = CursorActionTarget.Map.GetTile(cellCoords + offset); + + // if (cell != null && cell.Structure != null) + // foundationAreaHasStructure = true; + //}); + + //if (!foundationAreaHasStructure) + //{ + // tile.Structure = structure; + // CursorActionTarget.TechnoUnderCursor = structure; + // CursorActionTarget.AddRefreshPoint(cellCoords, 10); + //} } public override void PostMapDraw(Point2D cellCoords) { // Clear preview data var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Structure == structure) + if (tile.Structures.Contains(structure)) { - tile.Structure = null; + tile.Structures.Remove(structure); CursorActionTarget.TechnoUnderCursor = null; CursorActionTarget.AddRefreshPoint(cellCoords, 10); } @@ -86,14 +90,14 @@ public override void LeftDown(Point2D cellCoords) throw new InvalidOperationException(nameof(BuildingType) + " cannot be null"); var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Structure != null) - return; + //if (tile.Structure != null) + // return; bool foundationInvalid = false; structure.ObjectType.ArtConfig.DoForFoundationCoords(offset => { var cell = CursorActionTarget.Map.GetTile(cellCoords + offset); - if (cell == null || cell.Structure != null) + if (cell == null)// || cell.Structure != null) foundationInvalid = true; }); diff --git a/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs b/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs index 85466017..986e1164 100644 --- a/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs +++ b/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs @@ -79,8 +79,11 @@ public override void LeftClick(Point2D cellCoords) if ((EntryTypes & CopiedEntryType.Structure) == CopiedEntryType.Structure) { - if (cell.Structure != null && cell.Structure.Position == new Point2D(x, y)) - copiedMapData.CopiedMapEntries.Add(new CopiedStructureEntry(offset, cell.Structure.ObjectType.ININame, cell.Structure.Owner.ININame, cell.Structure.HP, 0, cell.Structure.Facing, string.Empty)); + foreach (var structure in cell.Structures) + { + if (structure.Position == new Point2D(x, y)) + copiedMapData.CopiedMapEntries.Add(new CopiedStructureEntry(offset, structure.ObjectType.ININame, structure.Owner.ININame, structure.HP, 0, structure.Facing, string.Empty)); + } } if ((EntryTypes & CopiedEntryType.Infantry) == CopiedEntryType.Infantry) diff --git a/src/TSMapEditor/UI/CursorActions/ManageBaseNodesCursorAction.cs b/src/TSMapEditor/UI/CursorActions/ManageBaseNodesCursorAction.cs index 4a6c479a..4ed9b026 100644 --- a/src/TSMapEditor/UI/CursorActions/ManageBaseNodesCursorAction.cs +++ b/src/TSMapEditor/UI/CursorActions/ManageBaseNodesCursorAction.cs @@ -68,10 +68,10 @@ private void CreateBaseNode(Point2D cellCoords) { var mapCell = CursorActionTarget.Map.GetTile(cellCoords); - if (mapCell.Structure == null) + if (mapCell.Structures.Count == 0) return; - var structureType = mapCell.Structure.ObjectType; + var structureType = mapCell.Structures[0].ObjectType; var cellCoordsToCheck = new List(); if (structureType.ArtConfig.Foundation.Width == 0 || structureType.ArtConfig.Foundation.Height == 0) cellCoordsToCheck.Add(cellCoords); @@ -80,11 +80,11 @@ private void CreateBaseNode(Point2D cellCoords) { for (int x = 0; x < structureType.ArtConfig.Foundation.Width; x++) { - cellCoordsToCheck.Add(mapCell.Structure.Position + new Point2D(x, y)); + cellCoordsToCheck.Add(mapCell.Structures[0].Position + new Point2D(x, y)); } } - House owner = mapCell.Structure.Owner; + House owner = mapCell.Structures[0].Owner; bool overlappingNodes = false; @@ -126,7 +126,7 @@ private void CreateBaseNode(Point2D cellCoords) if (!overlappingNodes) { // All OK, create the base node - var baseNode = new BaseNode(structureType.ININame, mapCell.Structure.Position); + var baseNode = new BaseNode(structureType.ININame, mapCell.Structures[0].Position); owner.BaseNodes.Add(baseNode); CursorActionTarget.Map.RegisterBaseNode(owner, baseNode); } @@ -134,7 +134,7 @@ private void CreateBaseNode(Point2D cellCoords) // If the user is holding Shift, then also delete the building if (CursorActionTarget.WindowManager.Keyboard.IsShiftHeldDown()) { - CursorActionTarget.Map.RemoveBuilding(cellCoords); + CursorActionTarget.Map.RemoveBuildingsFrom(cellCoords); } CursorActionTarget.AddRefreshPoint(cellCoords); diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 347c0562..5559eb5f 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -129,9 +129,9 @@ private void RefreshInfo() AddObjectInformation("Vehicle: ", MapTile.Vehicle); } - if (MapTile.Structure != null) - { - AddObjectInformation("Structure: ", MapTile.Structure); + foreach (var structure in MapTile.Structures) + { + AddObjectInformation("Structure: ", structure); } for (int i = 0; i < MapTile.Infantry.Length; i++) @@ -140,12 +140,11 @@ private void RefreshInfo() AddObjectInformation("Infantry: ", MapTile.Infantry[i]); } - if (MapTile.Waypoints.Count > 0) + foreach (var waypoint in MapTile.Waypoints) { - foreach (var waypoint in MapTile.Waypoints) - AddWaypointInfo(waypoint); + AddWaypointInfo(waypoint); } - + textRenderer.PrepareTextParts(); Height = textRenderer.Bottom + Constants.UIEmptyBottomSpace; From 752e824497bede6b4ff06788e2eb538eded2b8bf Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 9 Aug 2023 02:24:10 +0300 Subject: [PATCH 03/15] Units in a cell are now a List --- src/TSMapEditor/Initialization/MapLoader.cs | 2 +- src/TSMapEditor/Models/Map.cs | 23 ++++--- src/TSMapEditor/Models/MapTile.cs | 68 +++++++++++++------ .../Mutations/Classes/PasteTerrainMutation.cs | 6 +- .../Mutations/Classes/PlaceVehicleMutation.cs | 9 +-- src/TSMapEditor/Rendering/MapView.cs | 15 ++-- src/TSMapEditor/Rendering/Refresh.cs | 4 +- .../CursorActions/CopyTerrainCursorAction.cs | 7 +- .../CursorActions/SetFollowerCursorAction.cs | 8 +-- .../UI/CursorActions/UnitPlacementAction.cs | 24 ++++--- src/TSMapEditor/UI/TileInfoDisplay.cs | 24 ++----- 11 files changed, 105 insertions(+), 85 deletions(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index ef899633..5578f6d7 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -486,7 +486,7 @@ public static void ReadUnits(IMap map, IniFile mapIni) map.Units.Add(unit); var tile = map.GetTile(x, y); if (tile != null) - tile.Vehicle = unit; + tile.Vehicles.Add(unit); } // Process follow IDs diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 3c7a91b9..1cfd7331 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -770,7 +770,7 @@ public void RemoveBuildingsFrom(Point2D cellCoords) var cell = GetTile(cellCoords); if (cell.Structures.Count > 0) - cell.Structures.Clear(); + cell.DoForAllBuildings(structure => RemoveBuilding(structure)); } public void RemoveBuilding(Structure structure) @@ -803,23 +803,26 @@ public void MoveBuilding(Structure structure, Point2D newCoords) public void PlaceUnit(Unit unit) { var cell = GetTile(unit.Position); - if (cell.Vehicle != null) - throw new InvalidOperationException("Cannot place a vehicle on a cell that already has a vehicle!"); + //if (cell.Vehicle != null) + // throw new InvalidOperationException("Cannot place a vehicle on a cell that already has a vehicle!"); - cell.Vehicle = unit; + cell.Vehicles.Add(unit); Units.Add(unit); } public void RemoveUnit(Unit unit) { - RemoveUnit(unit.Position); + var cell = GetTile(unit.Position); + Units.Remove(unit); + cell.Vehicles.Remove(unit); } - public void RemoveUnit(Point2D cellCoords) + public void RemoveUnitsFrom(Point2D cellCoords) { var cell = GetTile(cellCoords); - Units.Remove(cell.Vehicle); - cell.Vehicle = null; + cell.DoForAllVehicles(unit => Units.Remove(unit)); + + cell.Vehicles.Clear(); } public void MoveUnit(Unit unit, Point2D newCoords) @@ -984,9 +987,9 @@ public void DeleteObjectFromCell(Point2D cellCoords) return; } - if (tile.Vehicle != null) + if (tile.Vehicles.Count > 0) { - RemoveUnit(tile.Vehicle); + RemoveUnitsFrom(tile.CoordsToPoint()); return; } diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index 6fb6ad3a..e7c407b8 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -24,8 +24,9 @@ public MapTile(byte[] data) : base(data) { } public TileImage TileImage { get; set; } public TerrainObject TerrainObject { get; set; } public List Structures { get; set; } = new List(); - public Structure Structure { get; set; } + public List Vehicles { get; set; } = new List(); public Unit Vehicle { get; set; } + public List Aircrafts { get; set; } = new List(); public Aircraft Aircraft { get; set; } public Infantry[] Infantry { get; set; } = new Infantry[SubCellCount]; public TileImage PreviewTileImage { get; set; } @@ -71,8 +72,8 @@ public void AddObjectsToList(List objects) if (Structures.Count > 0) objects.AddRange(Structures); - if (Vehicle != null) - objects.Add(Vehicle); + if (Structures.Count > 0) + objects.AddRange(Vehicles); } public void AddInfantry(Infantry infantry) @@ -89,6 +90,38 @@ public void DoForAllInfantry(Action action) } } + public void DoForAllVehicles(Action action) + { + foreach (var unit in Vehicles) + { + action(unit); + } + } + + public void DoForAllAircraft(Action action) + { + foreach (var aircraft in Aircrafts) + { + action(aircraft); + } + } + + public void DoForAllBuildings(Action action) + { + foreach (var structure in Structures) + { + action(structure); + } + } + + public void DoForAllWaypoints(Action action) + { + foreach (var waypoint in Waypoints) + { + action(waypoint); + } + } + public SubCell GetFreeSubCellSpot() { if (GetInfantryFromSubCellSpot(SubCell.Bottom) == null) @@ -121,7 +154,7 @@ public Infantry GetFirstInfantry() public bool HasTechno() { - return Structures.Count > 0 || Vehicle != null || Aircraft != null || Array.Exists(Infantry, inf => inf != null); + return Structures.Count > 0 || Vehicles.Count > 0 || Aircrafts.Count > 0 || Array.Exists(Infantry, inf => inf != null); } public bool HasTechnoThatPassesCheck(Predicate predicate) @@ -131,17 +164,14 @@ public bool HasTechnoThatPassesCheck(Predicate predicate) public TechnoBase GetFirstTechnoThatPassesCheck(Predicate predicate) { - foreach (var structure in Structures) - { - if (predicate(structure)) - return structure; - } + var structure = Structures.Find(predicate); + if (structure != null) return structure; - if (Vehicle != null && predicate(Vehicle)) - return Vehicle; + var unit = Vehicles.Find(predicate); + if (unit != null) return unit; - if (Aircraft != null && predicate(Aircraft)) - return Aircraft; + var aircraft = Aircrafts.Find(predicate); + if (aircraft != null) return aircraft; return Array.Find(Infantry, inf => inf != null && predicate(inf)); } @@ -151,11 +181,11 @@ public TechnoBase GetTechno() if (Structures.Count > 0) return Structures[0]; - if (Vehicle != null) - return Vehicle; + if (Vehicles.Count > 0) + return Vehicles[0]; - if (Aircraft != null) - return Aircraft; + if (Aircrafts.Count > 0) + return Aircrafts[0]; return Array.Find(Infantry, inf => inf != null); } @@ -184,7 +214,7 @@ public bool CanAddObject(GameObject gameObject) case RTTIType.Building: return true; case RTTIType.Unit: - return Vehicle == null; + return true; case RTTIType.Infantry: return GetFreeSubCellSpot() != SubCell.None; case RTTIType.Terrain: @@ -205,7 +235,7 @@ public bool ContainsObject(AbstractObject abstractObject) case RTTIType.Building: return Structures.Contains((Structure)abstractObject); case RTTIType.Unit: - return Vehicle == abstractObject; + return Vehicles.Contains((Unit)abstractObject); case RTTIType.Infantry: return Array.Exists(Infantry, inf => inf == abstractObject); case RTTIType.Overlay: diff --git a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs index 63beb57b..22d3ff48 100644 --- a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs @@ -616,8 +616,8 @@ public override void Perform() if (cell == null) continue; - if (cell.Vehicle != null) - continue; + //if (cell.Vehicle != null) + // continue; var unitType = MutationTarget.Map.Rules.UnitTypes.Find(tt => tt.ININame == copiedVehicleEntry.ObjectTypeName); if (unitType == null) @@ -769,7 +769,7 @@ public override void Undo() foreach (Point2D cellCoords in vehicleCells) { - MutationTarget.Map.RemoveUnit(cellCoords); + MutationTarget.Map.RemoveUnitsFrom(cellCoords); } foreach (Point2D cellCoords in structureCells) diff --git a/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs index a934505c..41e6558b 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs @@ -18,15 +18,16 @@ public PlaceVehicleMutation(IMutationTarget mutationTarget, UnitType unitType, P private readonly UnitType unitType; private readonly Point2D cellCoords; + private Unit unit; public override void Perform() { var cell = MutationTarget.Map.GetTileOrFail(cellCoords); - if (cell.Vehicle != null) - throw new InvalidOperationException(nameof(PlaceVehicleMutation) + ": the cell already has a vehicle!"); + //if (cell.Vehicle != null) + // throw new InvalidOperationException(nameof(PlaceVehicleMutation) + ": the cell already has a vehicle!"); - var unit = new Unit(unitType); + unit = new Unit(unitType); unit.Owner = MutationTarget.ObjectOwner; unit.Position = cellCoords; MutationTarget.Map.PlaceUnit(unit); @@ -36,7 +37,7 @@ public override void Perform() public override void Undo() { var cell = MutationTarget.Map.GetTile(cellCoords); - MutationTarget.Map.RemoveUnit(cell.Vehicle); + MutationTarget.Map.RemoveUnit(unit); MutationTarget.AddRefreshPoint(cellCoords); } } diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index a86c7aaf..8b98eeb9 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -558,19 +558,18 @@ public void DrawTerrainTileAndRegisterObjects(MapTile tile) if (tile.Overlay != null && tile.Overlay.OverlayType != null) gameObjectsToRender.Add(tile.Overlay); - foreach (var structure in tile.Structures) + tile.DoForAllBuildings(i => { - if (structure.Position == tile.CoordsToPoint()) - gameObjectsToRender.Add(structure); - } + if (i.Position == tile.CoordsToPoint()) + gameObjectsToRender.Add(i); + }); tile.DoForAllInfantry(i => gameObjectsToRender.Add(i)); if (tile.Aircraft != null) gameObjectsToRender.Add(tile.Aircraft); - if (tile.Vehicle != null) - gameObjectsToRender.Add(tile.Vehicle); + tile.DoForAllVehicles(i => gameObjectsToRender.Add(i)); if (tile.TerrainObject != null) gameObjectsToRender.Add(tile.TerrainObject); @@ -1127,8 +1126,8 @@ private void HandleDoubleClick() if (tileUnderCursor.Structures.Count > 0) windowController.StructureOptionsWindow.Open(tileUnderCursor.Structures[0]); - if (tileUnderCursor.Vehicle != null) - windowController.VehicleOptionsWindow.Open(tileUnderCursor.Vehicle); + if (tileUnderCursor.Vehicles.Count > 0) + windowController.VehicleOptionsWindow.Open(tileUnderCursor.Vehicles[0]); Infantry infantry = tileUnderCursor.GetFirstInfantry(); if (infantry != null) diff --git a/src/TSMapEditor/Rendering/Refresh.cs b/src/TSMapEditor/Rendering/Refresh.cs index dfe45817..61fccd69 100644 --- a/src/TSMapEditor/Rendering/Refresh.cs +++ b/src/TSMapEditor/Rendering/Refresh.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.Win32; using TSMapEditor.GameMath; using TSMapEditor.Models; @@ -112,8 +113,7 @@ private void RedrawTile(MapTile mapTile) // } mapTile.DoForAllInfantry(inf => RedrawFromObject(inf)); - if (mapTile.Vehicle != null) - RedrawFromObject(mapTile.Vehicle); + mapTile.DoForAllVehicles(unit => RedrawFromObject(unit)); if (mapTile.Aircraft != null) RedrawFromObject(mapTile.Aircraft); if (mapTile.TerrainObject != null) diff --git a/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs b/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs index 986e1164..71955e78 100644 --- a/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs +++ b/src/TSMapEditor/UI/CursorActions/CopyTerrainCursorAction.cs @@ -73,17 +73,16 @@ public override void LeftClick(Point2D cellCoords) if ((EntryTypes & CopiedEntryType.Vehicle) == CopiedEntryType.Vehicle) { - if (cell.Vehicle != null) - copiedMapData.CopiedMapEntries.Add(new CopiedVehicleEntry(offset, cell.Vehicle.ObjectType.ININame, cell.Vehicle.Owner.ININame, cell.Vehicle.HP, cell.Vehicle.Veterancy, cell.Vehicle.Facing, cell.Vehicle.Mission)); + cell.DoForAllVehicles(unit => copiedMapData.CopiedMapEntries.Add(new CopiedVehicleEntry(offset, unit.ObjectType.ININame, unit.Owner.ININame, unit.HP, unit.Veterancy, unit.Facing, unit.Mission))); } if ((EntryTypes & CopiedEntryType.Structure) == CopiedEntryType.Structure) { - foreach (var structure in cell.Structures) + cell.DoForAllBuildings(structure => { if (structure.Position == new Point2D(x, y)) copiedMapData.CopiedMapEntries.Add(new CopiedStructureEntry(offset, structure.ObjectType.ININame, structure.Owner.ININame, structure.HP, 0, structure.Facing, string.Empty)); - } + }); } if ((EntryTypes & CopiedEntryType.Infantry) == CopiedEntryType.Infantry) diff --git a/src/TSMapEditor/UI/CursorActions/SetFollowerCursorAction.cs b/src/TSMapEditor/UI/CursorActions/SetFollowerCursorAction.cs index c3bf5588..4d4cbced 100644 --- a/src/TSMapEditor/UI/CursorActions/SetFollowerCursorAction.cs +++ b/src/TSMapEditor/UI/CursorActions/SetFollowerCursorAction.cs @@ -40,7 +40,7 @@ public override void DrawPreview(Point2D cellCoords, Point2D cameraTopLeftPoint) Color color = Color.Gray; var cell = Map.GetTile(cellCoords); - if (cell != null && cell.Vehicle != null && cell.Vehicle != UnitToFollow) + if (cell != null && cell.Vehicles.Count > 0 && cell.Vehicles[0] != UnitToFollow) color = Color.Yellow; var rect = new Rectangle(x - Constants.UIEmptySideSpace, @@ -73,13 +73,13 @@ public override void LeftClick(Point2D cellCoords) if (cell == null) return; - if (cell.Vehicle == null) + if (cell.Vehicles.Count == 0) return; - if (cell.Vehicle == UnitToFollow) + if (cell.Vehicles[0] == UnitToFollow) return; - PerformMutation(new SetFollowerMutation(MutationTarget, UnitToFollow, cell.Vehicle)); + PerformMutation(new SetFollowerMutation(MutationTarget, UnitToFollow, cell.Vehicles[0])); ExitAction(); } diff --git a/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs index 57ac5337..a8a203fa 100644 --- a/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs @@ -48,21 +48,25 @@ public override void PreMapDraw(Point2D cellCoords) unit.Position = cellCoords; var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Vehicle == null) - { - tile.Vehicle = unit; - CursorActionTarget.TechnoUnderCursor = unit; - CursorActionTarget.AddRefreshPoint(cellCoords); - } + tile.Vehicles.Add(unit); + CursorActionTarget.TechnoUnderCursor = unit; + CursorActionTarget.AddRefreshPoint(cellCoords); + + //if (tile.Vehicle == null) + //{ + // tile.Vehicle = unit; + // CursorActionTarget.TechnoUnderCursor = unit; + // CursorActionTarget.AddRefreshPoint(cellCoords); + //} } public override void PostMapDraw(Point2D cellCoords) { // Clear preview data var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Vehicle == unit) + if (tile.Vehicles.Contains(unit)) { - tile.Vehicle = null; + tile.Vehicles.Remove(unit); CursorActionTarget.TechnoUnderCursor = null; CursorActionTarget.AddRefreshPoint(cellCoords); } @@ -74,8 +78,8 @@ public override void LeftDown(Point2D cellPoint) throw new InvalidOperationException(nameof(UnitType) + " cannot be null"); var tile = CursorActionTarget.Map.GetTile(cellPoint); - if (tile.Vehicle != null) - return; + //if (tile.Vehicle != null) + // return; var mutation = new PlaceVehicleMutation(CursorActionTarget.MutationTarget, UnitType, cellPoint); CursorActionTarget.MutationManager.PerformMutation(mutation); diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 5559eb5f..28234992 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -124,27 +124,11 @@ private void RefreshInfo() AddObjectInformation("Aircraft: ", MapTile.Aircraft); } - if (MapTile.Vehicle != null) - { - AddObjectInformation("Vehicle: ", MapTile.Vehicle); - } - - foreach (var structure in MapTile.Structures) - { - AddObjectInformation("Structure: ", structure); - } - - for (int i = 0; i < MapTile.Infantry.Length; i++) - { - if (MapTile.Infantry[i] != null) - AddObjectInformation("Infantry: ", MapTile.Infantry[i]); - } + MapTile.DoForAllVehicles(unit => AddObjectInformation("Vehicle: ", unit)); + MapTile.DoForAllBuildings(structure => AddObjectInformation("Structure: ", structure)); + MapTile.DoForAllInfantry(inf => AddObjectInformation("Infantry: ", inf)); + MapTile.DoForAllWaypoints(waypoint => AddWaypointInfo(waypoint)); - foreach (var waypoint in MapTile.Waypoints) - { - AddWaypointInfo(waypoint); - } - textRenderer.PrepareTextParts(); Height = textRenderer.Bottom + Constants.UIEmptyBottomSpace; From 389944afb0ef6d6b9e2014f65337e546827a4206 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 9 Aug 2023 02:49:03 +0300 Subject: [PATCH 04/15] Aircraft are now stored in a List in a cell --- src/TSMapEditor/Initialization/MapLoader.cs | 6 ++--- src/TSMapEditor/Models/Map.cs | 23 ++++++++++-------- src/TSMapEditor/Models/MapTile.cs | 18 +++++++------- .../Classes/PlaceAircraftMutation.cs | 9 +++---- src/TSMapEditor/Rendering/MapView.cs | 15 +++++------- src/TSMapEditor/Rendering/Refresh.cs | 3 +-- .../CursorActions/AircraftPlacementAction.cs | 24 +++++++++++-------- src/TSMapEditor/UI/TileInfoDisplay.cs | 6 +---- 8 files changed, 51 insertions(+), 53 deletions(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index 5578f6d7..6e77777e 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -354,7 +354,7 @@ void CheckFoundationCell(Point2D cellCoords) { //isClear = false; //AddMapLoadError($"Building {buildingType.ININame} exists on a cell ({cellCoords}) that already has another building ({tile.Structure.ObjectType.ININame}). Skipping adding it to map."); - Logger.Log($"NOTE: Building {buildingType.ININame} exists on the cell {cellCoords} that already has other buildings."); + Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell {cellCoords} that already has other buildings."); } } @@ -425,7 +425,7 @@ public static void ReadAircraft(IMap map, IniFile mapIni) map.Aircraft.Add(aircraft); var tile = map.GetTile(x, y); if (tile != null) - tile.Aircraft = aircraft; + tile.Aircraft.Add(aircraft); } } @@ -678,7 +678,7 @@ public static void ReadWaypoints(IMap map, IniFile mapIni) if (mapCell.Waypoints.Count > 0) { //AddMapLoadError($"Cell at {waypoint.Position} has multiple waypoints placed on it. Skipping adding waypoint #{waypoint.Identifier} there."); - Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists on the cell {waypoint.Position} that already has other waypoints."); + Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell {waypoint.Position} that already has other waypoints."); continue; } diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 1cfd7331..c8ed275a 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -600,7 +600,7 @@ public void AddWaypoint(Waypoint waypoint) if (cell.Waypoints.Count > 0) { //throw new InvalidOperationException($"Cell at {cell.CoordsToPoint()} already has a waypoint, skipping adding waypoint {waypoint.Identifier}"); - Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists on the cell {cell.CoordsToPoint()} that already has other waypoints."); + Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell {cell.CoordsToPoint()} that already has other waypoints."); } cell.Waypoints.Add(waypoint); @@ -870,23 +870,26 @@ public void MoveInfantry(Infantry infantry, Point2D newCoords) public void PlaceAircraft(Aircraft aircraft) { var cell = GetTile(aircraft.Position); - if (cell.Aircraft != null) - throw new InvalidOperationException("Cannot place an aircraft on a cell that already has an aircraft!"); + //if (cell.Aircraft != null) + // throw new InvalidOperationException("Cannot place an aircraft on a cell that already has an aircraft!"); - cell.Aircraft = aircraft; + cell.Aircraft.Add(aircraft); Aircraft.Add(aircraft); } public void RemoveAircraft(Aircraft aircraft) { - RemoveAircraft(aircraft.Position); + var cell = GetTile(aircraft.Position); + cell.Aircraft.Remove(aircraft); + Aircraft.Remove(aircraft); } - public void RemoveAircraft(Point2D cellCoords) + public void RemoveAircraftFrom(Point2D cellCoords) { var cell = GetTile(cellCoords); - Aircraft.Remove(cell.Aircraft); - cell.Aircraft = null; + cell.DoForAllAircraft(aircraft => Aircraft.Remove(aircraft)); + + cell.Aircraft.Clear(); } public void MoveAircraft(Aircraft aircraft, Point2D newCoords) @@ -981,9 +984,9 @@ public void DeleteObjectFromCell(Point2D cellCoords) } } - if (tile.Aircraft != null) + if (tile.Aircraft.Count > 0) { - RemoveAircraft(tile.Aircraft); + RemoveAircraftFrom(tile.CoordsToPoint()); return; } diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index e7c407b8..eed14020 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -25,9 +25,7 @@ public MapTile(byte[] data) : base(data) { } public TerrainObject TerrainObject { get; set; } public List Structures { get; set; } = new List(); public List Vehicles { get; set; } = new List(); - public Unit Vehicle { get; set; } - public List Aircrafts { get; set; } = new List(); - public Aircraft Aircraft { get; set; } + public List Aircraft { get; set; } = new List(); public Infantry[] Infantry { get; set; } = new Infantry[SubCellCount]; public TileImage PreviewTileImage { get; set; } public int PreviewSubTileIndex { get; set; } @@ -100,7 +98,7 @@ public void DoForAllVehicles(Action action) public void DoForAllAircraft(Action action) { - foreach (var aircraft in Aircrafts) + foreach (var aircraft in Aircraft) { action(aircraft); } @@ -154,7 +152,7 @@ public Infantry GetFirstInfantry() public bool HasTechno() { - return Structures.Count > 0 || Vehicles.Count > 0 || Aircrafts.Count > 0 || Array.Exists(Infantry, inf => inf != null); + return Structures.Count > 0 || Vehicles.Count > 0 || Aircraft.Count > 0 || Array.Exists(Infantry, inf => inf != null); } public bool HasTechnoThatPassesCheck(Predicate predicate) @@ -170,7 +168,7 @@ public TechnoBase GetFirstTechnoThatPassesCheck(Predicate predicate) var unit = Vehicles.Find(predicate); if (unit != null) return unit; - var aircraft = Aircrafts.Find(predicate); + var aircraft = Aircraft.Find(predicate); if (aircraft != null) return aircraft; return Array.Find(Infantry, inf => inf != null && predicate(inf)); @@ -184,8 +182,8 @@ public TechnoBase GetTechno() if (Vehicles.Count > 0) return Vehicles[0]; - if (Aircrafts.Count > 0) - return Aircrafts[0]; + if (Aircraft.Count > 0) + return Aircraft[0]; return Array.Find(Infantry, inf => inf != null); } @@ -210,7 +208,7 @@ public bool CanAddObject(GameObject gameObject) switch (gameObject.WhatAmI()) { case RTTIType.Aircraft: - return Aircraft == null; + return true; case RTTIType.Building: return true; case RTTIType.Unit: @@ -229,7 +227,7 @@ public bool ContainsObject(AbstractObject abstractObject) switch (abstractObject.WhatAmI()) { case RTTIType.Aircraft: - return Aircraft == abstractObject; + return Aircraft.Contains((Aircraft)abstractObject); case RTTIType.Terrain: return TerrainObject == abstractObject; case RTTIType.Building: diff --git a/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs index 72755d83..bf817b26 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs @@ -18,6 +18,7 @@ public PlaceAircraftMutation(IMutationTarget mutationTarget, AircraftType aircra private readonly AircraftType aircraftType; private readonly Point2D cellCoords; + private Aircraft aircraft; public override void Perform() { @@ -25,10 +26,10 @@ public override void Perform() if (cell == null) return; - if (cell.Aircraft != null) - throw new InvalidOperationException(nameof(PlaceAircraftMutation) + ": the cell already has an aircraft!"); + //if (cell.Aircraft != null) + // throw new InvalidOperationException(nameof(PlaceAircraftMutation) + ": the cell already has an aircraft!"); - var aircraft = new Aircraft(aircraftType); + aircraft = new Aircraft(aircraftType); aircraft.Owner = MutationTarget.ObjectOwner; aircraft.Position = cellCoords; MutationTarget.Map.PlaceAircraft(aircraft); @@ -38,7 +39,7 @@ public override void Perform() public override void Undo() { var cell = MutationTarget.Map.GetTile(cellCoords); - MutationTarget.Map.RemoveAircraft(cell.Aircraft); + MutationTarget.Map.RemoveAircraft(aircraft); MutationTarget.AddRefreshPoint(cellCoords); } } diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index 8b98eeb9..82642238 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -558,18 +558,15 @@ public void DrawTerrainTileAndRegisterObjects(MapTile tile) if (tile.Overlay != null && tile.Overlay.OverlayType != null) gameObjectsToRender.Add(tile.Overlay); - tile.DoForAllBuildings(i => + tile.DoForAllBuildings(structure => { - if (i.Position == tile.CoordsToPoint()) - gameObjectsToRender.Add(i); + if (structure.Position == tile.CoordsToPoint()) + gameObjectsToRender.Add(structure); }); - tile.DoForAllInfantry(i => gameObjectsToRender.Add(i)); - - if (tile.Aircraft != null) - gameObjectsToRender.Add(tile.Aircraft); - - tile.DoForAllVehicles(i => gameObjectsToRender.Add(i)); + tile.DoForAllInfantry(inf => gameObjectsToRender.Add(inf)); + tile.DoForAllAircraft(aircraft => gameObjectsToRender.Add(aircraft)); + tile.DoForAllVehicles(unit => gameObjectsToRender.Add(unit)); if (tile.TerrainObject != null) gameObjectsToRender.Add(tile.TerrainObject); diff --git a/src/TSMapEditor/Rendering/Refresh.cs b/src/TSMapEditor/Rendering/Refresh.cs index 61fccd69..2bf4c811 100644 --- a/src/TSMapEditor/Rendering/Refresh.cs +++ b/src/TSMapEditor/Rendering/Refresh.cs @@ -114,8 +114,7 @@ private void RedrawTile(MapTile mapTile) mapTile.DoForAllInfantry(inf => RedrawFromObject(inf)); mapTile.DoForAllVehicles(unit => RedrawFromObject(unit)); - if (mapTile.Aircraft != null) - RedrawFromObject(mapTile.Aircraft); + mapTile.DoForAllAircraft(aircraft => RedrawFromObject(aircraft)); if (mapTile.TerrainObject != null) RedrawFromObject(mapTile.TerrainObject); diff --git a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs index 2e5e39b9..d9bf37de 100644 --- a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs @@ -45,21 +45,25 @@ public override void PreMapDraw(Point2D cellCoords) aircraft.Position = cellCoords; var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Aircraft == null) - { - tile.Aircraft = aircraft; - CursorActionTarget.TechnoUnderCursor = aircraft; - CursorActionTarget.AddRefreshPoint(cellCoords); - } + tile.Aircraft.Add(aircraft); + CursorActionTarget.TechnoUnderCursor = aircraft; + CursorActionTarget.AddRefreshPoint(cellCoords); + //if (tile.Aircraft == null) + //{ + // tile.Aircraft = aircraft; + // CursorActionTarget.TechnoUnderCursor = aircraft; + // CursorActionTarget.AddRefreshPoint(cellCoords); + //} + } public override void PostMapDraw(Point2D cellCoords) { // Clear preview data var tile = CursorActionTarget.Map.GetTile(cellCoords); - if (tile.Aircraft == aircraft) + if (tile.Aircraft.Contains(aircraft)) { - tile.Aircraft = null; + tile.Aircraft.Remove(aircraft); CursorActionTarget.TechnoUnderCursor = null; CursorActionTarget.AddRefreshPoint(cellCoords); } @@ -71,8 +75,8 @@ public override void LeftDown(Point2D cellPoint) throw new InvalidOperationException(nameof(AircraftType) + " cannot be null"); var tile = CursorActionTarget.Map.GetTile(cellPoint); - if (tile.Aircraft != null) - return; + //if (tile.Aircraft != null) + // return; var mutation = new PlaceAircraftMutation(CursorActionTarget.MutationTarget, AircraftType, cellPoint); CursorActionTarget.MutationManager.PerformMutation(mutation); diff --git a/src/TSMapEditor/UI/TileInfoDisplay.cs b/src/TSMapEditor/UI/TileInfoDisplay.cs index 28234992..83ec43a1 100644 --- a/src/TSMapEditor/UI/TileInfoDisplay.cs +++ b/src/TSMapEditor/UI/TileInfoDisplay.cs @@ -119,11 +119,7 @@ private void RefreshInfo() Constants.UIDefaultFont, baseTextColor)); } - if (MapTile.Aircraft != null) - { - AddObjectInformation("Aircraft: ", MapTile.Aircraft); - } - + MapTile.DoForAllAircraft(aircraft => AddObjectInformation("Aircraft: ", aircraft)); MapTile.DoForAllVehicles(unit => AddObjectInformation("Vehicle: ", unit)); MapTile.DoForAllBuildings(structure => AddObjectInformation("Structure: ", structure)); MapTile.DoForAllInfantry(inf => AddObjectInformation("Infantry: ", inf)); From 3c32bcb9c01da76d2bf11592ede1a8d5f82e231b Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 9 Aug 2023 05:57:28 +0300 Subject: [PATCH 05/15] Fixed undo removing all waypoints from cell --- src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs index 557295f1..b4f4a985 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceWaypointMutation.cs @@ -17,16 +17,18 @@ public PlaceWaypointMutation(IMutationTarget mutationTarget, Point2D cellCoords, private readonly Point2D cellCoords; private readonly int waypointNumber; + private Waypoint waypoint; public override void Perform() { - MutationTarget.Map.AddWaypoint(new Waypoint() { Identifier = waypointNumber, Position = cellCoords }); + waypoint = new Waypoint() { Identifier = waypointNumber, Position = cellCoords }; + MutationTarget.Map.AddWaypoint(waypoint); MutationTarget.AddRefreshPoint(cellCoords, 1); } public override void Undo() { - MutationTarget.Map.RemoveWaypointsFrom(cellCoords); + MutationTarget.Map.RemoveWaypoint(waypoint); MutationTarget.AddRefreshPoint(cellCoords, 1); } } From a12c6e7a59959a684cb00c8d5fec77af9fefa41d Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sun, 13 Aug 2023 01:47:13 +0300 Subject: [PATCH 06/15] Added object overlap key, Alt by default. Placing new objects doesn't consider it yet. --- src/TSMapEditor/Initialization/MapLoader.cs | 3 --- src/TSMapEditor/Models/Map.cs | 26 ++++++------------- src/TSMapEditor/Models/MapTile.cs | 19 +++++++++++--- .../Mutations/Classes/CloneObjectMutation.cs | 6 ++--- src/TSMapEditor/Rendering/MapView.cs | 8 +++--- src/TSMapEditor/UI/KeyboardCommands.cs | 2 ++ 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index 6e77777e..c4b230b4 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -352,8 +352,6 @@ void CheckFoundationCell(Point2D cellCoords) if (tile.Structures.Count > 0) { - //isClear = false; - //AddMapLoadError($"Building {buildingType.ININame} exists on a cell ({cellCoords}) that already has another building ({tile.Structure.ObjectType.ININame}). Skipping adding it to map."); Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell {cellCoords} that already has other buildings."); } } @@ -677,7 +675,6 @@ public static void ReadWaypoints(IMap map, IniFile mapIni) if (mapCell.Waypoints.Count > 0) { - //AddMapLoadError($"Cell at {waypoint.Position} has multiple waypoints placed on it. Skipping adding waypoint #{waypoint.Identifier} there."); Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell {waypoint.Position} that already has other waypoints."); continue; } diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index c8ed275a..36e68fe7 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -6,10 +6,10 @@ using System.IO; using System.Linq; using TSMapEditor.CCEngine; +using TSMapEditor.Extensions; using TSMapEditor.GameMath; using TSMapEditor.Initialization; using TSMapEditor.Rendering; -using TSMapEditor.Extensions; namespace TSMapEditor.Models { @@ -751,9 +751,6 @@ public void PlaceBuilding(Structure structure) if (cell == null) return; - //if (cell.Structure != null) - // throw new InvalidOperationException("Cannot place a structure on a cell that already has a structure!"); - cell.Structures.Add(structure); }); @@ -803,8 +800,6 @@ public void MoveBuilding(Structure structure, Point2D newCoords) public void PlaceUnit(Unit unit) { var cell = GetTile(unit.Position); - //if (cell.Vehicle != null) - // throw new InvalidOperationException("Cannot place a vehicle on a cell that already has a vehicle!"); cell.Vehicles.Add(unit); Units.Add(unit); @@ -870,8 +865,6 @@ public void MoveInfantry(Infantry infantry, Point2D newCoords) public void PlaceAircraft(Aircraft aircraft) { var cell = GetTile(aircraft.Position); - //if (cell.Aircraft != null) - // throw new InvalidOperationException("Cannot place an aircraft on a cell that already has an aircraft!"); cell.Aircraft.Add(aircraft); Aircraft.Add(aircraft); @@ -940,9 +933,10 @@ public void MoveWaypoint(Waypoint waypoint, Point2D newCoords) /// /// The object to move. /// The new coordinates of the object. - /// Determines whether the object itself can be considered as blocking placement of the object. + /// Determines whether the object itself can be considered as blocking placement of the object. + /// Determines whether multiple objects of the same type should be allowed to exist in the same cell. /// True if the object can be moved, otherwise false. - public bool CanPlaceObjectAt(IMovable movable, Point2D newCoords, bool considerSelf) + public bool CanPlaceObjectAt(IMovable movable, Point2D newCoords, bool blocksSelf, bool overlapObjects) { if (movable.WhatAmI() == RTTIType.Building) { @@ -954,19 +948,15 @@ public bool CanPlaceObjectAt(IMovable movable, Point2D newCoords, bool considerS if (foundationCell == null) return; - //if (foundationCell.Structure != null && foundationCell.Structure != movable) - // canPlace = false; + if (!foundationCell.CanAddObject((GameObject)movable, blocksSelf, overlapObjects)) + canPlace = false; }); - if (!canPlace) - return false; + return canPlace; } MapTile cell = GetTile(newCoords); - if (movable.WhatAmI() == RTTIType.Waypoint) - return true; - - return cell.CanAddObject((GameObject)movable); + return cell.CanAddObject((GameObject)movable, blocksSelf, overlapObjects); } public void DeleteObjectFromCell(Point2D cellCoords) diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index eed14020..f8a8e72a 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.CodeAnalysis.CSharp.Syntax; using TSMapEditor.GameMath; using TSMapEditor.Models.MapFormat; using TSMapEditor.Rendering; @@ -203,20 +204,30 @@ public GameObject GetObject() /// /// Determines whether a specific game object can be assigned to this tile. /// - public bool CanAddObject(GameObject gameObject) + public bool CanAddObject(GameObject gameObject, bool blocksSelf, bool overlapObjects) { switch (gameObject.WhatAmI()) { - case RTTIType.Aircraft: - return true; case RTTIType.Building: + { + bool multipleStructuresExist = Structures.Count > 1; + bool anotherExists = Structures.Count == 1 && !Structures.Contains((Structure)gameObject); + bool clone = Structures.Count == 1 && Structures.Contains((Structure)gameObject) && blocksSelf; + + if ((multipleStructuresExist || anotherExists || clone) && !overlapObjects) + return false; return true; + } case RTTIType.Unit: - return true; + return Vehicles.Count == 0 || overlapObjects; + case RTTIType.Aircraft: + return Aircraft.Count == 0 || overlapObjects; case RTTIType.Infantry: return GetFreeSubCellSpot() != SubCell.None; case RTTIType.Terrain: return TerrainObject == null; + case RTTIType.Waypoint: + return true; } return false; diff --git a/src/TSMapEditor/Mutations/Classes/CloneObjectMutation.cs b/src/TSMapEditor/Mutations/Classes/CloneObjectMutation.cs index dcc12c92..05f64c0d 100644 --- a/src/TSMapEditor/Mutations/Classes/CloneObjectMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/CloneObjectMutation.cs @@ -67,13 +67,13 @@ public override void Undo() switch (objectToClone.WhatAmI()) { case RTTIType.Aircraft: - Map.RemoveAircraft(clonePosition); + Map.RemoveAircraft((Aircraft)placedClone); break; case RTTIType.Building: - Map.RemoveBuilding(clonePosition); + Map.RemoveBuilding((Structure)placedClone); break; case RTTIType.Unit: - Map.RemoveUnit(clonePosition); + Map.RemoveUnit((Unit)placedClone); break; case RTTIType.Infantry: Map.RemoveInfantry((Infantry)placedClone); diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index 82642238..53e892e7 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -993,15 +993,16 @@ public override void OnMouseOnControl() { // If the clone modifier is held down, attempt cloning the object. // Otherwise, move the dragged object. + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(Keyboard); if (KeyboardCommands.Instance.CloneObject.AreKeysOrModifiersDown(Keyboard)) { - if (Map.CanPlaceObjectAt(draggedOrRotatedObject, tileUnderCursor.CoordsToPoint(), true)) + if (Map.CanPlaceObjectAt(draggedOrRotatedObject, tileUnderCursor.CoordsToPoint(), true, overlapObjects)) { var mutation = new CloneObjectMutation(MutationTarget, draggedOrRotatedObject, tileUnderCursor.CoordsToPoint()); MutationManager.PerformMutation(mutation); } } - else if (Map.CanPlaceObjectAt(draggedOrRotatedObject, tileUnderCursor.CoordsToPoint(), false)) + else if (Map.CanPlaceObjectAt(draggedOrRotatedObject, tileUnderCursor.CoordsToPoint(), false, overlapObjects)) { var mutation = new MoveObjectMutation(MutationTarget, draggedOrRotatedObject, tileUnderCursor.CoordsToPoint()); MutationManager.PerformMutation(mutation); @@ -1239,9 +1240,10 @@ private void DrawOnTileUnderCursor() if (isDraggingObject) { bool isCloning = KeyboardCommands.Instance.CloneObject.AreKeysOrModifiersDown(Keyboard); + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(Keyboard); Color lineColor = isCloning ? new Color(0, 255, 255) : Color.White; - if (!Map.CanPlaceObjectAt(draggedOrRotatedObject, tileUnderCursor.CoordsToPoint(), isCloning)) + if (!Map.CanPlaceObjectAt(draggedOrRotatedObject, tileUnderCursor.CoordsToPoint(), isCloning, overlapObjects)) lineColor = Color.Red; Point2D cameraAndCellCenterOffset = new Point2D(-Camera.TopLeftPoint.X + Constants.CellSizeX / 2, diff --git a/src/TSMapEditor/UI/KeyboardCommands.cs b/src/TSMapEditor/UI/KeyboardCommands.cs index 871a703b..fc2eda04 100644 --- a/src/TSMapEditor/UI/KeyboardCommands.cs +++ b/src/TSMapEditor/UI/KeyboardCommands.cs @@ -35,6 +35,7 @@ public KeyboardCommands() PlaceTerrainBelow, FillTerrain, CloneObject, + OverlapObjects, ViewMegamap, GenerateTerrain, ConfigureTerrainGenerator, @@ -109,6 +110,7 @@ public void WriteToSettings() public KeyboardCommand PlaceTerrainBelow { get; } = new KeyboardCommand("PlaceTerrainBelow", "Place Terrain Below Cursor", new KeyboardCommandInput(Keys.None, KeyboardModifiers.Alt), true); public KeyboardCommand FillTerrain { get; } = new KeyboardCommand("FillTerrain", "Fill Terrain (1x1 tiles only)", new KeyboardCommandInput(Keys.None, KeyboardModifiers.Ctrl), true); public KeyboardCommand CloneObject { get; } = new KeyboardCommand("CloneObject", "Clone Object (Modifier)", new KeyboardCommandInput(Keys.None, KeyboardModifiers.Shift), true); + public KeyboardCommand OverlapObjects { get; } = new KeyboardCommand("OverlapObjects", "Overlap Objects (Modifier)", new KeyboardCommandInput(Keys.None, KeyboardModifiers.Alt), true); public KeyboardCommand ViewMegamap { get; } = new KeyboardCommand("ViewMegamap", "View Megamap", new KeyboardCommandInput(Keys.F12, KeyboardModifiers.None)); public KeyboardCommand GenerateTerrain { get; } = new KeyboardCommand("GenerateTerrain", "Generate Terrain", new KeyboardCommandInput(Keys.G, KeyboardModifiers.Ctrl)); public KeyboardCommand ConfigureTerrainGenerator { get; } = new KeyboardCommand("ConfigureTerrainGenerator", "Configure Terrain Generator", new KeyboardCommandInput(Keys.G, KeyboardModifiers.Alt)); From 57bf6609eb61ec8b2680667b971e24e6b378517b Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sun, 13 Aug 2023 02:56:26 +0300 Subject: [PATCH 07/15] Placing new objects now also respects the hotkey --- .../CursorActions/AircraftPlacementAction.cs | 50 +++++++++------ .../CursorActions/BuildingPlacementAction.cs | 61 ++++++++----------- .../CursorActions/InfantryPlacementAction.cs | 22 +++---- .../OverlayCollectionPlacementAction.cs | 6 +- .../CursorActions/OverlayPlacementAction.cs | 8 +-- .../TerrainObjectCollectionPlacementAction.cs | 8 +-- .../TerrainObjectPlacementAction.cs | 14 ++--- .../UI/CursorActions/UnitPlacementAction.cs | 51 +++++++++------- .../UI/Sidebar/AircraftListPanel.cs | 2 +- .../UI/Sidebar/BuildingListPanel.cs | 2 +- src/TSMapEditor/UI/Sidebar/UnitListPanel.cs | 2 +- 11 files changed, 116 insertions(+), 110 deletions(-) diff --git a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs index d9bf37de..ce5cac29 100644 --- a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs @@ -1,4 +1,5 @@ using System; +using Rampastring.XNAUI.Input; using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Mutations.Classes; @@ -8,32 +9,35 @@ namespace TSMapEditor.UI.CursorActions { public class AircraftPlacementAction : CursorAction { - public AircraftPlacementAction(ICursorActionTarget cursorActionTarget) : base(cursorActionTarget) + public AircraftPlacementAction(ICursorActionTarget cursorActionTarget, RKeyboard keyboard) : base(cursorActionTarget) { + this.keyboard = keyboard; } public override string GetName() => "Place Aircraft"; private Aircraft aircraft; - private AircraftType _aircraftType; + private AircraftType aircraftType; + + private readonly RKeyboard keyboard; public AircraftType AircraftType { - get => _aircraftType; + get => aircraftType; set { - if (_aircraftType != value) + if (aircraftType != value) { - _aircraftType = value; + aircraftType = value; - if (_aircraftType == null) + if (aircraftType == null) { aircraft = null; } else { - aircraft = new Aircraft(_aircraftType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + aircraft = new Aircraft(aircraftType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } @@ -44,16 +48,18 @@ public override void PreMapDraw(Point2D cellCoords) // Assign preview data aircraft.Position = cellCoords; + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); + + bool canPlace = Map.CanPlaceObjectAt(aircraft, cellCoords, false, + overlapObjects); + + if (!canPlace) + return; + var tile = CursorActionTarget.Map.GetTile(cellCoords); tile.Aircraft.Add(aircraft); CursorActionTarget.TechnoUnderCursor = aircraft; CursorActionTarget.AddRefreshPoint(cellCoords); - //if (tile.Aircraft == null) - //{ - // tile.Aircraft = aircraft; - // CursorActionTarget.TechnoUnderCursor = aircraft; - // CursorActionTarget.AddRefreshPoint(cellCoords); - //} } @@ -69,22 +75,26 @@ public override void PostMapDraw(Point2D cellCoords) } } - public override void LeftDown(Point2D cellPoint) + public override void LeftDown(Point2D cellCoords) { if (AircraftType == null) throw new InvalidOperationException(nameof(AircraftType) + " cannot be null"); - var tile = CursorActionTarget.Map.GetTile(cellPoint); - //if (tile.Aircraft != null) - // return; + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); + + bool canPlace = Map.CanPlaceObjectAt(aircraft, cellCoords, false, + overlapObjects); + + if (!canPlace) + return; - var mutation = new PlaceAircraftMutation(CursorActionTarget.MutationTarget, AircraftType, cellPoint); + var mutation = new PlaceAircraftMutation(CursorActionTarget.MutationTarget, AircraftType, cellCoords); CursorActionTarget.MutationManager.PerformMutation(mutation); } - public override void LeftClick(Point2D cellPoint) + public override void LeftClick(Point2D cellCoords) { - LeftDown(cellPoint); + LeftDown(cellCoords); } } } diff --git a/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs index 6e54a347..aec65c72 100644 --- a/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs @@ -1,4 +1,6 @@ using System; +using Rampastring.XNAUI.Input; +using Rampastring.XNAUI.XNAControls; using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Mutations.Classes; @@ -11,32 +13,35 @@ namespace TSMapEditor.UI.CursorActions /// public class BuildingPlacementAction : CursorAction { - public BuildingPlacementAction(ICursorActionTarget cursorActionTarget) : base(cursorActionTarget) + public BuildingPlacementAction(ICursorActionTarget cursorActionTarget, RKeyboard keyboard) : base(cursorActionTarget) { + this.keyboard = keyboard; } public override string GetName() => "Place Building"; private Structure structure; - private BuildingType _buildingType; + private BuildingType buildingType; + + private readonly RKeyboard keyboard; public BuildingType BuildingType { - get => _buildingType; + get => buildingType; set { - if (_buildingType != value) + if (buildingType != value) { - _buildingType = value; + buildingType = value; - if (_buildingType == null) + if (buildingType == null) { structure = null; } else { - structure = new Structure(_buildingType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + structure = new Structure(buildingType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } @@ -47,29 +52,18 @@ public override void PreMapDraw(Point2D cellCoords) // Assign preview data structure.Position = cellCoords; + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); + + bool canPlace = Map.CanPlaceObjectAt(structure, cellCoords, false, + overlapObjects); + + if (!canPlace) + return; + var tile = CursorActionTarget.Map.GetTile(cellCoords); tile.Structures.Add(structure); CursorActionTarget.TechnoUnderCursor = structure; CursorActionTarget.AddRefreshPoint(cellCoords, 10); - - //if (tile.Structure != null) - // return; - - //bool foundationAreaHasStructure = false; - //structure.ObjectType.ArtConfig.DoForFoundationCoords(offset => - //{ - // var cell = CursorActionTarget.Map.GetTile(cellCoords + offset); - - // if (cell != null && cell.Structure != null) - // foundationAreaHasStructure = true; - //}); - - //if (!foundationAreaHasStructure) - //{ - // tile.Structure = structure; - // CursorActionTarget.TechnoUnderCursor = structure; - // CursorActionTarget.AddRefreshPoint(cellCoords, 10); - //} } public override void PostMapDraw(Point2D cellCoords) @@ -89,19 +83,12 @@ public override void LeftDown(Point2D cellCoords) if (BuildingType == null) throw new InvalidOperationException(nameof(BuildingType) + " cannot be null"); - var tile = CursorActionTarget.Map.GetTile(cellCoords); - //if (tile.Structure != null) - // return; + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); - bool foundationInvalid = false; - structure.ObjectType.ArtConfig.DoForFoundationCoords(offset => - { - var cell = CursorActionTarget.Map.GetTile(cellCoords + offset); - if (cell == null)// || cell.Structure != null) - foundationInvalid = true; - }); + bool canPlace = Map.CanPlaceObjectAt(structure, cellCoords, false, + overlapObjects); - if (foundationInvalid) + if (!canPlace) return; var mutation = new PlaceBuildingMutation(CursorActionTarget.MutationTarget, BuildingType, cellCoords); diff --git a/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs index 5f3e85e2..c3a9bdeb 100644 --- a/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs @@ -19,25 +19,25 @@ public InfantryPlacementAction(ICursorActionTarget cursorActionTarget) : base(cu private Infantry infantry; - private InfantryType _infantryType; + private InfantryType infantryType; public InfantryType InfantryType { - get => _infantryType; + get => infantryType; set { - if (_infantryType != value) + if (infantryType != value) { - _infantryType = value; + infantryType = value; - if (_infantryType == null) + if (infantryType == null) { infantry = null; } else { - infantry = new Infantry(_infantryType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + infantry = new Infantry(infantryType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } @@ -73,23 +73,23 @@ public override void PostMapDraw(Point2D cellCoords) } } - public override void LeftDown(Point2D cellPoint) + public override void LeftDown(Point2D cellCoords) { if (InfantryType == null) throw new InvalidOperationException(nameof(InfantryType) + " cannot be null"); - var tile = CursorActionTarget.Map.GetTile(cellPoint); + var tile = CursorActionTarget.Map.GetTile(cellCoords); SubCell freeSubCell = tile.GetFreeSubCellSpot(); if (freeSubCell == SubCell.None) return; - var mutation = new PlaceInfantryMutation(CursorActionTarget.MutationTarget, InfantryType, cellPoint, freeSubCell); + var mutation = new PlaceInfantryMutation(CursorActionTarget.MutationTarget, InfantryType, cellCoords, freeSubCell); CursorActionTarget.MutationManager.PerformMutation(mutation); } - public override void LeftClick(Point2D cellPoint) + public override void LeftClick(Point2D cellCoords) { - LeftDown(cellPoint); + LeftDown(cellCoords); } } } diff --git a/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs index 56c9252b..7e82cfa0 100644 --- a/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs @@ -15,10 +15,10 @@ public OverlayCollectionPlacementAction(ICursorActionTarget cursorActionTarget) public override string GetName() => "Place Overlay Collection"; - private OverlayCollection _overlayCollection; + private OverlayCollection overlayCollection; public OverlayCollection OverlayCollection { - get => _overlayCollection; + get => overlayCollection; set { if (value.Entries.Length == 0) @@ -26,7 +26,7 @@ public OverlayCollection OverlayCollection throw new InvalidOperationException($"Overlay collection {value.Name} has no overlay entries!"); } - _overlayCollection = value; + overlayCollection = value; } } diff --git a/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs index 9f790cac..36d6e50b 100644 --- a/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs @@ -20,15 +20,15 @@ public OverlayPlacementAction(ICursorActionTarget cursorActionTarget) : base(cur public event EventHandler OverlayTypeChanged; - private OverlayType _overlayType; + private OverlayType overlayType; public OverlayType OverlayType { - get => _overlayType; + get => overlayType; set { - if (_overlayType != value) + if (overlayType != value) { - _overlayType = value; + overlayType = value; OverlayTypeChanged?.Invoke(this, EventArgs.Empty); } } diff --git a/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs index 18274c2f..6620be11 100644 --- a/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs @@ -15,10 +15,10 @@ public TerrainObjectCollectionPlacementAction(ICursorActionTarget cursorActionTa public override string GetName() => "Place TerrainObject Collection"; private TerrainObject terrainObject; - private TerrainObjectCollection _terrainObjectCollection; + private TerrainObjectCollection terrainObjectCollection; public TerrainObjectCollection TerrainObjectCollection { - get => _terrainObjectCollection; + get => terrainObjectCollection; set { if (value.Entries.Length == 0) @@ -26,8 +26,8 @@ public TerrainObjectCollection TerrainObjectCollection throw new InvalidOperationException($"Terrain object collection {value.Name} has no terrain object entries!"); } - _terrainObjectCollection = value; - terrainObject = new TerrainObject(_terrainObjectCollection.Entries[0].TerrainType); + terrainObjectCollection = value; + terrainObject = new TerrainObject(terrainObjectCollection.Entries[0].TerrainType); } } diff --git a/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs index b18ce89c..2c144ae1 100644 --- a/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs @@ -19,24 +19,24 @@ public TerrainObjectPlacementAction(ICursorActionTarget cursorActionTarget) : ba private TerrainObject terrainObject; - private TerrainType _terrainType; + private TerrainType terrainType; public TerrainType TerrainType { - get => _terrainType; + get => terrainType; set { - if (_terrainType != value) + if (terrainType != value) { - _terrainType = value; + terrainType = value; - if (_terrainType == null) + if (terrainType == null) { terrainObject = null; } else { - terrainObject = new TerrainObject(_terrainType); + terrainObject = new TerrainObject(terrainType); } } } @@ -67,7 +67,7 @@ public override void PostMapDraw(Point2D cellCoords) public override void LeftDown(Point2D cellCoords) { - if (_terrainType == null) + if (terrainType == null) throw new InvalidOperationException(nameof(TerrainType) + " cannot be null"); var cell = CursorActionTarget.Map.GetTile(cellCoords); diff --git a/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs index a8a203fa..571a1401 100644 --- a/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs @@ -1,4 +1,5 @@ using System; +using Rampastring.XNAUI.Input; using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Mutations.Classes; @@ -11,32 +12,35 @@ namespace TSMapEditor.UI.CursorActions /// class UnitPlacementAction : CursorAction { - public UnitPlacementAction(ICursorActionTarget cursorActionTarget) : base(cursorActionTarget) + public UnitPlacementAction(ICursorActionTarget cursorActionTarget, RKeyboard keyboard) : base(cursorActionTarget) { + this.keyboard = keyboard; } public override string GetName() => "Place Vehicle"; private Unit unit; - private UnitType _unitType; + private UnitType unitType; + + private readonly RKeyboard keyboard; public UnitType UnitType { - get => _unitType; + get => unitType; set { - if (_unitType != value) + if (unitType != value) { - _unitType = value; + unitType = value; - if (_unitType == null) + if (unitType == null) { unit = null; } else { - unit = new Unit(_unitType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + unit = new Unit(unitType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } @@ -47,17 +51,18 @@ public override void PreMapDraw(Point2D cellCoords) // Assign preview data unit.Position = cellCoords; + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); + + bool canPlace = Map.CanPlaceObjectAt(unit, cellCoords, false, + overlapObjects); + + if (!canPlace) + return; + var tile = CursorActionTarget.Map.GetTile(cellCoords); tile.Vehicles.Add(unit); CursorActionTarget.TechnoUnderCursor = unit; CursorActionTarget.AddRefreshPoint(cellCoords); - - //if (tile.Vehicle == null) - //{ - // tile.Vehicle = unit; - // CursorActionTarget.TechnoUnderCursor = unit; - // CursorActionTarget.AddRefreshPoint(cellCoords); - //} } public override void PostMapDraw(Point2D cellCoords) @@ -72,22 +77,26 @@ public override void PostMapDraw(Point2D cellCoords) } } - public override void LeftDown(Point2D cellPoint) + public override void LeftDown(Point2D cellCoords) { if (UnitType == null) throw new InvalidOperationException(nameof(UnitType) + " cannot be null"); - var tile = CursorActionTarget.Map.GetTile(cellPoint); - //if (tile.Vehicle != null) - // return; + bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); + + bool canPlace = Map.CanPlaceObjectAt(unit, cellCoords, false, + overlapObjects); + + if (!canPlace) + return; - var mutation = new PlaceVehicleMutation(CursorActionTarget.MutationTarget, UnitType, cellPoint); + var mutation = new PlaceVehicleMutation(CursorActionTarget.MutationTarget, UnitType, cellCoords); CursorActionTarget.MutationManager.PerformMutation(mutation); } - public override void LeftClick(Point2D cellPoint) + public override void LeftClick(Point2D cellCoords) { - LeftDown(cellPoint); + LeftDown(cellCoords); } } } diff --git a/src/TSMapEditor/UI/Sidebar/AircraftListPanel.cs b/src/TSMapEditor/UI/Sidebar/AircraftListPanel.cs index 819a8ee5..ca5c379f 100644 --- a/src/TSMapEditor/UI/Sidebar/AircraftListPanel.cs +++ b/src/TSMapEditor/UI/Sidebar/AircraftListPanel.cs @@ -15,7 +15,7 @@ public AircraftListPanel(WindowManager windowManager, EditorState editorState, Map map, TheaterGraphics theaterGraphics, ICursorActionTarget cursorActionTarget) : base(windowManager, editorState, map, theaterGraphics) { - aircraftPlacementAction = new AircraftPlacementAction(cursorActionTarget); + aircraftPlacementAction = new AircraftPlacementAction(cursorActionTarget, Keyboard); aircraftPlacementAction.ActionExited += AircraftPlacementAction_ActionExited; } diff --git a/src/TSMapEditor/UI/Sidebar/BuildingListPanel.cs b/src/TSMapEditor/UI/Sidebar/BuildingListPanel.cs index becc1336..5d5da6f0 100644 --- a/src/TSMapEditor/UI/Sidebar/BuildingListPanel.cs +++ b/src/TSMapEditor/UI/Sidebar/BuildingListPanel.cs @@ -11,7 +11,7 @@ public BuildingListPanel(WindowManager windowManager, EditorState editorState, Map map, TheaterGraphics theaterGraphics, ICursorActionTarget cursorActionTarget) : base(windowManager, editorState, map, theaterGraphics) { - buildingPlacementAction = new BuildingPlacementAction(cursorActionTarget); + buildingPlacementAction = new BuildingPlacementAction(cursorActionTarget, Keyboard); buildingPlacementAction.ActionExited += BuildingPlacementAction_ActionExited; } diff --git a/src/TSMapEditor/UI/Sidebar/UnitListPanel.cs b/src/TSMapEditor/UI/Sidebar/UnitListPanel.cs index dadd8d4d..3eba30d0 100644 --- a/src/TSMapEditor/UI/Sidebar/UnitListPanel.cs +++ b/src/TSMapEditor/UI/Sidebar/UnitListPanel.cs @@ -13,7 +13,7 @@ public class UnitListPanel : ObjectListPanel { public UnitListPanel(WindowManager windowManager, EditorState editorState, Map map, TheaterGraphics theaterGraphics, ICursorActionTarget cursorActionTarget, bool isNaval) : base(windowManager, editorState, map, theaterGraphics) { - unitPlacementAction = new UnitPlacementAction(cursorActionTarget); + unitPlacementAction = new UnitPlacementAction(cursorActionTarget, Keyboard); unitPlacementAction.ActionExited += UnitPlacementAction_ActionExited; this.isNaval = isNaval; From 86138ab389a2487ff8bfb07bbeca9fc76657968c Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sun, 13 Aug 2023 03:39:58 +0300 Subject: [PATCH 08/15] Terrain copy tool now also respects the key --- .../Mutations/Classes/PasteTerrainMutation.cs | 82 +++++++++++++------ .../Classes/PlaceBuildingMutation.cs | 3 - .../CursorActions/PasteTerrainCursorAction.cs | 10 ++- src/TSMapEditor/UI/UIManager.cs | 2 +- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs index 22d3ff48..d3615b16 100644 --- a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs @@ -448,10 +448,11 @@ public void Deserialize(byte[] bytes) /// public class PasteTerrainMutation : Mutation { - public PasteTerrainMutation(IMutationTarget mutationTarget, CopiedMapData copiedMapData, Point2D origin) : base(mutationTarget) + public PasteTerrainMutation(IMutationTarget mutationTarget, CopiedMapData copiedMapData, Point2D origin, bool allowOverlap) : base(mutationTarget) { this.copiedMapData = copiedMapData; this.origin = origin; + this.allowOverlap = allowOverlap; } private struct PlacedInfantryInfo @@ -468,6 +469,7 @@ public PlacedInfantryInfo(Point2D coords, SubCell subCell) private readonly CopiedMapData copiedMapData; private readonly Point2D origin; + private readonly bool allowOverlap; private OriginalCellTerrainData[] terrainUndoData; private OriginalOverlayInfo[] overlayUndoData; @@ -477,6 +479,8 @@ public PlacedInfantryInfo(Point2D coords, SubCell subCell) private Point2D[] structureCells; private PlacedInfantryInfo[] infantryLocations; + private List placedObjects = new List(); + private void AddRefresh() { if (copiedMapData.CopiedMapEntries.Count > 10) @@ -616,8 +620,19 @@ public override void Perform() if (cell == null) continue; - //if (cell.Vehicle != null) - // continue; + if (cell.Vehicles.Count > 0 && !allowOverlap) + { + bool foreignUnitExists = false; + foreach (var vehicle in cell.Vehicles) + if (!placedObjects.Contains(vehicle)) + { + foreignUnitExists = true; + break; + } + + if (foreignUnitExists) + continue; + } var unitType = MutationTarget.Map.Rules.UnitTypes.Find(tt => tt.ININame == copiedVehicleEntry.ObjectTypeName); if (unitType == null) @@ -627,15 +642,18 @@ public override void Perform() if (owner == null) continue; - MutationTarget.Map.PlaceUnit(new Unit(unitType) - { - Position = cellCoords, - Owner = owner, - HP = copiedVehicleEntry.HP, + var unit = new Unit(unitType) + { + Position = cellCoords, + Owner = owner, + HP = copiedVehicleEntry.HP, Veterancy = copiedVehicleEntry.Veterancy, - Facing = copiedVehicleEntry.Facing, - Mission = copiedVehicleEntry.Mission - }); + Facing = copiedVehicleEntry.Facing, + Mission = copiedVehicleEntry.Mission + }; + + MutationTarget.Map.PlaceUnit(unit); + placedObjects.Add(unit); vehicleCells.Add(cellCoords); } @@ -657,31 +675,43 @@ public override void Perform() if (cell == null) continue; - //if (cell.Structure != null) - // continue; - var buildingType = MutationTarget.Map.Rules.BuildingTypes.Find(tt => tt.ININame == copiedStructureEntry.ObjectTypeName); if (buildingType == null) continue; - bool isFoundationClear = true; - buildingType.ArtConfig.DoForFoundationCoords(foundationPoint => + if (cell.Structures.Count > 0 && !allowOverlap) { - Point2D foundationCellCoords = foundationPoint + cellCoords; - MapTile foundationCell = MutationTarget.Map.GetTile(foundationCellCoords); - - if (foundationCell == null)// || foundationCell.Structure != null) - isFoundationClear = false; - }); - - if (!isFoundationClear) - continue; + bool isFoundationClear = true; + buildingType.ArtConfig.DoForFoundationCoords(offset => + { + Point2D foundationCellCoords = offset + cellCoords; + MapTile foundationCell = MutationTarget.Map.GetTile(foundationCellCoords); + + foreach (var building in foundationCell.Structures) + if (!placedObjects.Contains(building)) + { + isFoundationClear = false; + break; + } + }); + + if (!isFoundationClear) + continue; + } House owner = MutationTarget.Map.GetHouses().Find(h => h.ININame == copiedStructureEntry.OwnerHouseName); if (owner == null) continue; - MutationTarget.Map.PlaceBuilding(new Structure(buildingType) { Position = cellCoords, Owner = owner, HP = copiedStructureEntry.HP, Facing = copiedStructureEntry.Facing }); + var building = new Structure(buildingType) + { + Position = cellCoords, Owner = owner, HP = copiedStructureEntry.HP, + Facing = copiedStructureEntry.Facing + }; + + MutationTarget.Map.PlaceBuilding(building); + placedObjects.Add(building); + structureCells.Add(cellCoords); } diff --git a/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs index 541b34e0..117c22d9 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs @@ -26,9 +26,6 @@ public override void Perform() { var cell = MutationTarget.Map.GetTileOrFail(cellCoords); - //if (cell.Structure != null) - // throw new InvalidOperationException(nameof(PlaceBuildingMutation) + ": the cell already has a building!"); - var structure = new Structure(buildingType); structure.Owner = MutationTarget.ObjectOwner; structure.Position = cellCoords; diff --git a/src/TSMapEditor/UI/CursorActions/PasteTerrainCursorAction.cs b/src/TSMapEditor/UI/CursorActions/PasteTerrainCursorAction.cs index 73ba5085..7c051c4b 100644 --- a/src/TSMapEditor/UI/CursorActions/PasteTerrainCursorAction.cs +++ b/src/TSMapEditor/UI/CursorActions/PasteTerrainCursorAction.cs @@ -1,6 +1,7 @@ using Rampastring.Tools; using System; using System.Collections.Generic; +using Rampastring.XNAUI.Input; using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Mutations.Classes; @@ -13,8 +14,9 @@ namespace TSMapEditor.UI.CursorActions /// public class PasteTerrainCursorAction : CursorAction { - public PasteTerrainCursorAction(ICursorActionTarget cursorActionTarget) : base(cursorActionTarget) + public PasteTerrainCursorAction(ICursorActionTarget cursorActionTarget, RKeyboard keyboard) : base(cursorActionTarget) { + this.keyboard = keyboard; } public override string GetName() => "Paste Copied Terrain"; @@ -38,6 +40,8 @@ public OriginalOverlayInfo(Point2D cellCoords, OverlayType overlayType, int fram private List originalOverlay = new List(); + private RKeyboard keyboard; + public override void OnActionEnter() { base.OnActionEnter(); @@ -147,7 +151,9 @@ public override void LeftClick(Point2D cellCoords) if (CursorActionTarget.Map.GetTile(cellCoords) == null) return; - var mutation = new PasteTerrainMutation(CursorActionTarget.MutationTarget, copiedMapData, cellCoords); + bool allowOverlap = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); + + var mutation = new PasteTerrainMutation(CursorActionTarget.MutationTarget, copiedMapData, cellCoords, allowOverlap); CursorActionTarget.MutationManager.PerformMutation(mutation); } } diff --git a/src/TSMapEditor/UI/UIManager.cs b/src/TSMapEditor/UI/UIManager.cs index 787a5b80..fbd999a0 100644 --- a/src/TSMapEditor/UI/UIManager.cs +++ b/src/TSMapEditor/UI/UIManager.cs @@ -151,7 +151,7 @@ public override void Initialize() overlayPlacementAction.OverlayTypeChanged += OverlayPlacementAction_OverlayTypeChanged; copyTerrainCursorAction = new CopyTerrainCursorAction(mapView); - pasteTerrainCursorAction = new PasteTerrainCursorAction(mapView); + pasteTerrainCursorAction = new PasteTerrainCursorAction(mapView, Keyboard); InitAutoSaveAndSaveNotifications(); From 32e46a33d81212162eb631e5b8f6f2c707e63031 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sun, 13 Aug 2023 03:44:33 +0300 Subject: [PATCH 09/15] Update Map.cs --- src/TSMapEditor/Models/Map.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 36e68fe7..31cdb737 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -599,7 +599,6 @@ public void AddWaypoint(Waypoint waypoint) var cell = GetTile(waypoint.Position.X, waypoint.Position.Y); if (cell.Waypoints.Count > 0) { - //throw new InvalidOperationException($"Cell at {cell.CoordsToPoint()} already has a waypoint, skipping adding waypoint {waypoint.Identifier}"); Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell {cell.CoordsToPoint()} that already has other waypoints."); } From 216ed4109fdf4eddaeeb5bc612d615daf91804e0 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sun, 13 Aug 2023 03:46:05 +0300 Subject: [PATCH 10/15] Update MapTile.cs --- 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 f8a8e72a..f3d8a27f 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -214,7 +214,7 @@ public bool CanAddObject(GameObject gameObject, bool blocksSelf, bool overlapObj bool anotherExists = Structures.Count == 1 && !Structures.Contains((Structure)gameObject); bool clone = Structures.Count == 1 && Structures.Contains((Structure)gameObject) && blocksSelf; - if ((multipleStructuresExist || anotherExists || clone) && !overlapObjects) + if ((multipleStructuresExist || anotherExists || clone) && !overlapObjects) return false; return true; } From 818ff616d404cea1bd31892df0683b210597d80c Mon Sep 17 00:00:00 2001 From: ZivDero Date: Sun, 13 Aug 2023 10:05:47 +0300 Subject: [PATCH 11/15] Minor cleanup --- src/TSMapEditor/Models/MapTile.cs | 1 - src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs | 6 +----- src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs | 3 +-- src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs | 6 +----- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index f3d8a27f..900f1858 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Microsoft.CodeAnalysis.CSharp.Syntax; using TSMapEditor.GameMath; using TSMapEditor.Models.MapFormat; using TSMapEditor.Rendering; diff --git a/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs index bf817b26..3084ef75 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceAircraftMutation.cs @@ -1,5 +1,4 @@ -using System; -using TSMapEditor.GameMath; +using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Rendering; @@ -26,9 +25,6 @@ public override void Perform() if (cell == null) return; - //if (cell.Aircraft != null) - // throw new InvalidOperationException(nameof(PlaceAircraftMutation) + ": the cell already has an aircraft!"); - aircraft = new Aircraft(aircraftType); aircraft.Owner = MutationTarget.ObjectOwner; aircraft.Position = cellCoords; diff --git a/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs index 117c22d9..0bc44fcc 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceBuildingMutation.cs @@ -1,5 +1,4 @@ -using System; -using TSMapEditor.GameMath; +using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Rendering; diff --git a/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs b/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs index 41e6558b..856ce045 100644 --- a/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PlaceVehicleMutation.cs @@ -1,5 +1,4 @@ -using System; -using TSMapEditor.GameMath; +using TSMapEditor.GameMath; using TSMapEditor.Models; using TSMapEditor.Rendering; @@ -24,9 +23,6 @@ public override void Perform() { var cell = MutationTarget.Map.GetTileOrFail(cellCoords); - //if (cell.Vehicle != null) - // throw new InvalidOperationException(nameof(PlaceVehicleMutation) + ": the cell already has a vehicle!"); - unit = new Unit(unitType); unit.Owner = MutationTarget.ObjectOwner; unit.Position = cellCoords; From 62160dca89efa445add52d5af0f2a556380e7223 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 16 Aug 2023 19:23:31 +0300 Subject: [PATCH 12/15] Minor fixes --- src/TSMapEditor/Initialization/MapLoader.cs | 11 ++++++----- src/TSMapEditor/Models/Map.cs | 8 ++++---- src/TSMapEditor/Models/MapTile.cs | 2 +- .../Mutations/Classes/PasteTerrainMutation.cs | 4 ++++ .../UI/CursorActions/AircraftPlacementAction.cs | 13 ++++++------- .../CursorActions/TerrainObjectPlacementAction.cs | 14 +++++++------- .../UI/CursorActions/UnitPlacementAction.cs | 12 ++++++------ 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index c4b230b4..589f20b0 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Text; using TSMapEditor.GameMath; using TSMapEditor.Models; @@ -352,7 +353,7 @@ void CheckFoundationCell(Point2D cellCoords) if (tile.Structures.Count > 0) { - Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell {cellCoords} that already has other buildings."); + Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell at {cellCoords} that already has other buildings: {string.Join(", ", tile.Structures.Select(s => s.ObjectType.ININame))}"); } } @@ -666,16 +667,16 @@ public static void ReadWaypoints(IMap map, IniFile mapIni) continue; } - var mapCell = map.GetTile(waypoint.Position.X, waypoint.Position.Y); - if (mapCell == null) + var tile = map.GetTile(waypoint.Position.X, waypoint.Position.Y); + if (tile == null) { AddMapLoadError($"Waypoint {waypoint.Identifier} at {waypoint.Position} is not within the valid map area."); continue; } - if (mapCell.Waypoints.Count > 0) + if (tile.Waypoints.Count > 0) { - Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell {waypoint.Position} that already has other waypoints."); + Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell at {waypoint.Position} that already contains other waypoints: {string.Join(", ", tile.Waypoints.Select(s => s.Identifier))}"); continue; } diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 31cdb737..601b4702 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -596,13 +596,13 @@ public void PlaceTerrainTileAt(ITileImage tile, Point2D cellCoords) public void AddWaypoint(Waypoint waypoint) { Waypoints.Add(waypoint); - var cell = GetTile(waypoint.Position.X, waypoint.Position.Y); - if (cell.Waypoints.Count > 0) + var tile = GetTile(waypoint.Position.X, waypoint.Position.Y); + if (tile.Waypoints.Count > 0) { - Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell {cell.CoordsToPoint()} that already has other waypoints."); + Logger.Log($"NOTE: Waypoint {waypoint.Identifier} exists in the cell at {waypoint.Position} that already contains other waypoints: {string.Join(", ", tile.Waypoints.Select(s => s.Identifier))}"); } - cell.Waypoints.Add(waypoint); + tile.Waypoints.Add(waypoint); } public void RemoveWaypoint(Waypoint waypoint) diff --git a/src/TSMapEditor/Models/MapTile.cs b/src/TSMapEditor/Models/MapTile.cs index 900f1858..ec9af5fc 100644 --- a/src/TSMapEditor/Models/MapTile.cs +++ b/src/TSMapEditor/Models/MapTile.cs @@ -70,7 +70,7 @@ public void AddObjectsToList(List objects) if (Structures.Count > 0) objects.AddRange(Structures); - if (Structures.Count > 0) + if (Vehicles.Count > 0) objects.AddRange(Vehicles); } diff --git a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs index d3615b16..b47628cb 100644 --- a/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs +++ b/src/TSMapEditor/Mutations/Classes/PasteTerrainMutation.cs @@ -624,11 +624,13 @@ public override void Perform() { bool foreignUnitExists = false; foreach (var vehicle in cell.Vehicles) + { if (!placedObjects.Contains(vehicle)) { foreignUnitExists = true; break; } + } if (foreignUnitExists) continue; @@ -688,11 +690,13 @@ public override void Perform() MapTile foundationCell = MutationTarget.Map.GetTile(foundationCellCoords); foreach (var building in foundationCell.Structures) + { if (!placedObjects.Contains(building)) { isFoundationClear = false; break; } + } }); if (!isFoundationClear) diff --git a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs index ce5cac29..c8fecf3b 100644 --- a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs @@ -18,26 +18,26 @@ public AircraftPlacementAction(ICursorActionTarget cursorActionTarget, RKeyboard private Aircraft aircraft; - private AircraftType aircraftType; + private AircraftType _aircraftType; private readonly RKeyboard keyboard; public AircraftType AircraftType { - get => aircraftType; + get => _aircraftType; set { - if (aircraftType != value) + if (_aircraftType != value) { - aircraftType = value; + _aircraftType = value; - if (aircraftType == null) + if (_aircraftType == null) { aircraft = null; } else { - aircraft = new Aircraft(aircraftType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + aircraft = new Aircraft(_aircraftType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } @@ -60,7 +60,6 @@ public override void PreMapDraw(Point2D cellCoords) tile.Aircraft.Add(aircraft); CursorActionTarget.TechnoUnderCursor = aircraft; CursorActionTarget.AddRefreshPoint(cellCoords); - } public override void PostMapDraw(Point2D cellCoords) diff --git a/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs index 2c144ae1..b18ce89c 100644 --- a/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/TerrainObjectPlacementAction.cs @@ -19,24 +19,24 @@ public TerrainObjectPlacementAction(ICursorActionTarget cursorActionTarget) : ba private TerrainObject terrainObject; - private TerrainType terrainType; + private TerrainType _terrainType; public TerrainType TerrainType { - get => terrainType; + get => _terrainType; set { - if (terrainType != value) + if (_terrainType != value) { - terrainType = value; + _terrainType = value; - if (terrainType == null) + if (_terrainType == null) { terrainObject = null; } else { - terrainObject = new TerrainObject(terrainType); + terrainObject = new TerrainObject(_terrainType); } } } @@ -67,7 +67,7 @@ public override void PostMapDraw(Point2D cellCoords) public override void LeftDown(Point2D cellCoords) { - if (terrainType == null) + if (_terrainType == null) throw new InvalidOperationException(nameof(TerrainType) + " cannot be null"); var cell = CursorActionTarget.Map.GetTile(cellCoords); diff --git a/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs index 571a1401..c8ce9e04 100644 --- a/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/UnitPlacementAction.cs @@ -21,26 +21,26 @@ public UnitPlacementAction(ICursorActionTarget cursorActionTarget, RKeyboard key private Unit unit; - private UnitType unitType; + private UnitType _unitType; private readonly RKeyboard keyboard; public UnitType UnitType { - get => unitType; + get => _unitType; set { - if (unitType != value) + if (_unitType != value) { - unitType = value; + _unitType = value; - if (unitType == null) + if (_unitType == null) { unit = null; } else { - unit = new Unit(unitType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + unit = new Unit(_unitType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } From 80602cf9418208c8bb8c8bd774c0f20926299b8a Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 16 Aug 2023 19:26:51 +0300 Subject: [PATCH 13/15] Changed one word in debug comment --- src/TSMapEditor/Initialization/MapLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TSMapEditor/Initialization/MapLoader.cs b/src/TSMapEditor/Initialization/MapLoader.cs index 589f20b0..fe6aa3e8 100644 --- a/src/TSMapEditor/Initialization/MapLoader.cs +++ b/src/TSMapEditor/Initialization/MapLoader.cs @@ -353,7 +353,7 @@ void CheckFoundationCell(Point2D cellCoords) if (tile.Structures.Count > 0) { - Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell at {cellCoords} that already has other buildings: {string.Join(", ", tile.Structures.Select(s => s.ObjectType.ININame))}"); + Logger.Log($"NOTE: Building {buildingType.ININame} exists in the cell at {cellCoords} that already contains other buildings: {string.Join(", ", tile.Structures.Select(s => s.ObjectType.ININame))}"); } } From 447f5d0e1453e7f2173d7dd2d8b577aac2cc0c00 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 16 Aug 2023 20:23:56 +0300 Subject: [PATCH 14/15] More underscore removal reverted --- .../UI/CursorActions/BuildingPlacementAction.cs | 12 ++++++------ .../UI/CursorActions/InfantryPlacementAction.cs | 12 ++++++------ .../OverlayCollectionPlacementAction.cs | 6 +++--- .../UI/CursorActions/OverlayPlacementAction.cs | 8 ++++---- .../TerrainObjectCollectionPlacementAction.cs | 8 ++++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs index aec65c72..4b2babbf 100644 --- a/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/BuildingPlacementAction.cs @@ -22,26 +22,26 @@ public BuildingPlacementAction(ICursorActionTarget cursorActionTarget, RKeyboard private Structure structure; - private BuildingType buildingType; + private BuildingType _buildingType; private readonly RKeyboard keyboard; public BuildingType BuildingType { - get => buildingType; + get => _buildingType; set { - if (buildingType != value) + if (_buildingType != value) { - buildingType = value; + _buildingType = value; - if (buildingType == null) + if (_buildingType == null) { structure = null; } else { - structure = new Structure(buildingType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + structure = new Structure(_buildingType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } diff --git a/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs index c3a9bdeb..64ec8098 100644 --- a/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/InfantryPlacementAction.cs @@ -19,25 +19,25 @@ public InfantryPlacementAction(ICursorActionTarget cursorActionTarget) : base(cu private Infantry infantry; - private InfantryType infantryType; + private InfantryType _infantryType; public InfantryType InfantryType { - get => infantryType; + get => _infantryType; set { - if (infantryType != value) + if (_infantryType != value) { - infantryType = value; + _infantryType = value; - if (infantryType == null) + if (_infantryType == null) { infantry = null; } else { - infantry = new Infantry(infantryType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; + infantry = new Infantry(_infantryType) { Owner = CursorActionTarget.MutationTarget.ObjectOwner }; } } } diff --git a/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs index 7e82cfa0..56c9252b 100644 --- a/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/OverlayCollectionPlacementAction.cs @@ -15,10 +15,10 @@ public OverlayCollectionPlacementAction(ICursorActionTarget cursorActionTarget) public override string GetName() => "Place Overlay Collection"; - private OverlayCollection overlayCollection; + private OverlayCollection _overlayCollection; public OverlayCollection OverlayCollection { - get => overlayCollection; + get => _overlayCollection; set { if (value.Entries.Length == 0) @@ -26,7 +26,7 @@ public OverlayCollection OverlayCollection throw new InvalidOperationException($"Overlay collection {value.Name} has no overlay entries!"); } - overlayCollection = value; + _overlayCollection = value; } } diff --git a/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs index 36d6e50b..9f790cac 100644 --- a/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/OverlayPlacementAction.cs @@ -20,15 +20,15 @@ public OverlayPlacementAction(ICursorActionTarget cursorActionTarget) : base(cur public event EventHandler OverlayTypeChanged; - private OverlayType overlayType; + private OverlayType _overlayType; public OverlayType OverlayType { - get => overlayType; + get => _overlayType; set { - if (overlayType != value) + if (_overlayType != value) { - overlayType = value; + _overlayType = value; OverlayTypeChanged?.Invoke(this, EventArgs.Empty); } } diff --git a/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs index 6620be11..18274c2f 100644 --- a/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/TerrainObjectCollectionPlacementAction.cs @@ -15,10 +15,10 @@ public TerrainObjectCollectionPlacementAction(ICursorActionTarget cursorActionTa public override string GetName() => "Place TerrainObject Collection"; private TerrainObject terrainObject; - private TerrainObjectCollection terrainObjectCollection; + private TerrainObjectCollection _terrainObjectCollection; public TerrainObjectCollection TerrainObjectCollection { - get => terrainObjectCollection; + get => _terrainObjectCollection; set { if (value.Entries.Length == 0) @@ -26,8 +26,8 @@ public TerrainObjectCollection TerrainObjectCollection throw new InvalidOperationException($"Terrain object collection {value.Name} has no terrain object entries!"); } - terrainObjectCollection = value; - terrainObject = new TerrainObject(terrainObjectCollection.Entries[0].TerrainType); + _terrainObjectCollection = value; + terrainObject = new TerrainObject(_terrainObjectCollection.Entries[0].TerrainType); } } From a6e5b230fe5ac0fdb7c90dbfaa5e63141b0d0838 Mon Sep 17 00:00:00 2001 From: ZivDero Date: Wed, 16 Aug 2023 20:35:50 +0300 Subject: [PATCH 15/15] Minor stylistic change --- src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs index c8fecf3b..7ff1f02d 100644 --- a/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs +++ b/src/TSMapEditor/UI/CursorActions/AircraftPlacementAction.cs @@ -50,8 +50,7 @@ public override void PreMapDraw(Point2D cellCoords) bool overlapObjects = KeyboardCommands.Instance.OverlapObjects.AreKeysOrModifiersDown(keyboard); - bool canPlace = Map.CanPlaceObjectAt(aircraft, cellCoords, false, - overlapObjects); + bool canPlace = Map.CanPlaceObjectAt(aircraft, cellCoords, false, overlapObjects); if (!canPlace) return;