From bf51eefdbcc03948c56cbf40f7ae156f64662380 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 29 Aug 2025 14:51:49 -0500 Subject: [PATCH] show better changesite for floodfill/terrain frill/item place --- src/scenedit/scen.undo.cpp | 18 +++++++++++++++++- src/scenedit/scen.undo.hpp | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/scenedit/scen.undo.cpp b/src/scenedit/scen.undo.cpp index 3d0ec7ec..261d9ae4 100644 --- a/src/scenedit/scen.undo.cpp +++ b/src/scenedit/scen.undo.cpp @@ -291,7 +291,7 @@ aPlaceEraseItem::aPlaceEraseItem(std::string name, bool place, size_t index, cTo {} aPlaceEraseItem::aPlaceEraseItem(std::string name, bool place, item_changes_t items) - : cTerrainAction(name, items.begin()->second.loc, !place) + : cTerrainAction(name, closest_to_view(items), !place) , items(items) {} @@ -1249,3 +1249,19 @@ bool aCreateAreaRect::redo_me() { area->area_desc[which] = rect; return true; } + +location closest_to_view(stroke_ter_changes_t changes) { + std::vector locs; + for(auto& it : changes){ + locs.push_back(it.first); + } + return closest_point(locs, loc(cen_x, cen_y)); +} + +location closest_to_view(item_changes_t changes) { + std::vector locs; + for(auto& it : changes){ + locs.push_back(it.second.loc); + } + return closest_point(locs, loc(cen_x, cen_y)); +} \ No newline at end of file diff --git a/src/scenedit/scen.undo.hpp b/src/scenedit/scen.undo.hpp index fbf79214..0f21d284 100644 --- a/src/scenedit/scen.undo.hpp +++ b/src/scenedit/scen.undo.hpp @@ -45,6 +45,9 @@ typedef std::map outdoor_sections_t; typedef std::map,loc_compare> clear_field_stroke_t; typedef std::set field_stroke_t; +location closest_to_view(stroke_ter_changes_t changes); +location closest_to_view(item_changes_t changes); + // Action that modified something in town or outdoor terrain, so we should show the modified area when undoing or redoing class cTerrainAction : public cAction { public: @@ -100,7 +103,7 @@ public: class aDrawTerrain : public cTerrainAction { public: aDrawTerrain(std::string name, stroke_ter_changes_t stroke_changes) : - cTerrainAction(name, stroke_changes.begin()->first), // Use arbitrary changed tile as site of change + cTerrainAction(name, closest_to_view(stroke_changes)), changes(stroke_changes) {} bool undo_me() override; bool redo_me() override;