Call FlagModified only when property can affect automapper (fixes #7959)

Handle more cases for undoing auto automap
This commit is contained in:
Corantin H 2024-02-10 11:22:39 +01:00
parent a7bbcf00a6
commit 93120b83cf
4 changed files with 41 additions and 2 deletions

View file

@ -88,3 +88,8 @@ void CEditorHistory::EndBulk(const char *pDisplay)
m_vpBulkActions.clear();
}
void CEditorHistory::EndBulk(int DisplayToUse)
{
EndBulk((DisplayToUse < 0 || DisplayToUse >= (int)m_vpBulkActions.size()) ? nullptr : m_vpBulkActions[DisplayToUse]->DisplayText());
}

View file

@ -32,6 +32,7 @@ public:
void BeginBulk();
void EndBulk(const char *pDisplay = nullptr);
void EndBulk(int DisplayToUse);
CEditor *m_pEditor;
std::deque<std::shared_ptr<IEditorAction>> m_vpUndoActions;

View file

@ -976,6 +976,7 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
static CLayerTilesPropTracker s_Tracker(m_pEditor);
s_Tracker.Begin(this, Prop, State);
m_pEditor->m_EditorHistory.BeginBulk();
if(Prop == ETilesProp::PROP_WIDTH && NewVal > 1)
{
@ -1064,12 +1065,25 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
m_AutoMapperConfig = -1;
}
if(Prop != ETilesProp::PROP_NONE && Prop != ETilesProp::PROP_SHIFT_BY)
s_Tracker.End(Prop, State);
// Check if modified property could have an effect on automapper
if(HasAutomapEffect(Prop))
{
FlagModified(0, 0, m_Width, m_Height);
// Record undo if automapper was ran
if(m_AutoAutoMap && !m_TilesHistory.empty())
{
m_pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionTileChanges>(m_pEditor, m_pEditor->m_SelectedGroup, m_pEditor->m_vSelectedLayers[0], "Auto map", m_TilesHistory));
ClearHistory();
}
}
s_Tracker.End(Prop, State);
// End undo bulk, taking the first action display as the displayed text in the history
// This is usually the resulting text of the edit layer tiles prop action
// Since we may also squeeze a tile changes action, we want both to appear as one, thus using a bulk
m_pEditor->m_EditorHistory.EndBulk(0);
return CUI::POPUP_KEEP_OPEN;
}
@ -1275,3 +1289,20 @@ void CLayerTiles::ShowPreventUnusedTilesWarning()
m_pEditor->m_PreventUnusedTilesWasWarned = true;
}
}
bool CLayerTiles::HasAutomapEffect(ETilesProp Prop)
{
switch(Prop)
{
case ETilesProp::PROP_WIDTH:
case ETilesProp::PROP_HEIGHT:
case ETilesProp::PROP_SHIFT:
case ETilesProp::PROP_IMAGE:
case ETilesProp::PROP_AUTOMAPPER:
case ETilesProp::PROP_SEED:
return true;
default:
return false;
}
return false;
}

View file

@ -185,6 +185,8 @@ public:
EditorTileStateChangeHistory<STileStateChange> m_TilesHistory;
inline virtual void ClearHistory() { m_TilesHistory.clear(); }
static bool HasAutomapEffect(ETilesProp Prop);
protected:
void RecordStateChange(int x, int y, CTile Previous, CTile Tile);