From 1c479ad534ad07c50d3796f0be7fc518818cde48 Mon Sep 17 00:00:00 2001 From: Nayiem Willems Date: Thu, 9 Jul 2026 13:26:44 -0700 Subject: [PATCH] Run cursor action pre-draw logic before capturing the object under the cursor Since the MapUI/MapView split, the object under the cursor has been passed to the renderer by value before the active cursor action's PreMapDraw ran, but placement previews assign the object-under-cursor property inside PreMapDraw. The property was then reset on the next update, so range indicators never showed while placing buildings such as pillboxes. Invoke PreMapDraw before passing the object to the renderer. --- src/TSMapEditor/Rendering/MapView.cs | 7 +++---- src/TSMapEditor/UI/MapUI.cs | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index ffd182284..f4997ddc9 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -1614,10 +1614,9 @@ private static void DrawArrow(Vector2 start, Vector2 end, public void Draw(bool isActive, TechnoBase technoUnderCursor, MapTile tileUnderCursor, CursorAction cursorAction) { - if (isActive && tileUnderCursor != null && cursorAction != null) - { - cursorAction.PreMapDraw(tileUnderCursor.CoordsToPoint()); - } + // Note: the cursor action's PreMapDraw is invoked by MapUI.Draw before this method, + // so that TechnoUnderCursor assignments made by placement previews are + // visible to DrawPerFrameTransparentElements below. if (mapInvalidated || cameraMoved) { diff --git a/src/TSMapEditor/UI/MapUI.cs b/src/TSMapEditor/UI/MapUI.cs index 0eee76419..05dce647b 100644 --- a/src/TSMapEditor/UI/MapUI.cs +++ b/src/TSMapEditor/UI/MapUI.cs @@ -742,6 +742,12 @@ public void DeleteObjectFromCell(Point2D cellCoords) public override void Draw(GameTime gameTime) { + // Run the cursor action's pre-map-draw logic before passing TechnoUnderCursor + // to the renderer, so that placement previews (which assign TechnoUnderCursor) + // get their range indicators drawn during placement. + if (IsActive && tileUnderCursor != null && CursorAction != null) + CursorAction.PreMapDraw(tileUnderCursor.CoordsToPoint()); + mapView.Draw(IsActive, TechnoUnderCursor, tileUnderCursor, CursorAction); mapView.DrawOnTileUnderCursor(tileUnderCursor, CursorAction, isDraggingObject,