mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Editor: made "Clean up game tiles" undoable
This commit is contained in:
parent
a2c8869025
commit
af51fcccbb
|
@ -476,24 +476,24 @@ void CEditorActionBulk::Redo()
|
|||
|
||||
// ---------
|
||||
|
||||
CEditorActionAutoMap::CEditorActionAutoMap(CEditor *pEditor, int GroupIndex, int LayerIndex, const EditorTileStateChangeHistory<STileStateChange> &Changes) :
|
||||
CEditorActionTileChanges::CEditorActionTileChanges(CEditor *pEditor, int GroupIndex, int LayerIndex, const char *pAction, const EditorTileStateChangeHistory<STileStateChange> &Changes) :
|
||||
CEditorActionLayerBase(pEditor, GroupIndex, LayerIndex), m_Changes(Changes)
|
||||
{
|
||||
ComputeInfos();
|
||||
str_format(m_aDisplayText, sizeof(m_aDisplayText), "Auto map (x%d)", m_TotalChanges);
|
||||
str_format(m_aDisplayText, sizeof(m_aDisplayText), "%s (x%d)", pAction, m_TotalChanges);
|
||||
}
|
||||
|
||||
void CEditorActionAutoMap::Undo()
|
||||
void CEditorActionTileChanges::Undo()
|
||||
{
|
||||
Apply(true);
|
||||
}
|
||||
|
||||
void CEditorActionAutoMap::Redo()
|
||||
void CEditorActionTileChanges::Redo()
|
||||
{
|
||||
Apply(false);
|
||||
}
|
||||
|
||||
void CEditorActionAutoMap::Apply(bool Undo)
|
||||
void CEditorActionTileChanges::Apply(bool Undo)
|
||||
{
|
||||
auto &Map = m_pEditor->m_Map;
|
||||
std::shared_ptr<CLayerTiles> pLayerTiles = std::static_pointer_cast<CLayerTiles>(m_pLayer);
|
||||
|
@ -512,7 +512,7 @@ void CEditorActionAutoMap::Apply(bool Undo)
|
|||
Map.OnModify();
|
||||
}
|
||||
|
||||
void CEditorActionAutoMap::ComputeInfos()
|
||||
void CEditorActionTileChanges::ComputeInfos()
|
||||
{
|
||||
m_TotalChanges = 0;
|
||||
for(auto &Line : m_Changes)
|
||||
|
|
|
@ -155,10 +155,10 @@ private:
|
|||
|
||||
//
|
||||
|
||||
class CEditorActionAutoMap : public CEditorActionLayerBase
|
||||
class CEditorActionTileChanges : public CEditorActionLayerBase
|
||||
{
|
||||
public:
|
||||
CEditorActionAutoMap(CEditor *pEditor, int GroupIndex, int LayerIndex, const EditorTileStateChangeHistory<STileStateChange> &Changes);
|
||||
CEditorActionTileChanges(CEditor *pEditor, int GroupIndex, int LayerIndex, const char *pAction, const EditorTileStateChangeHistory<STileStateChange> &Changes);
|
||||
|
||||
void Undo() override;
|
||||
void Redo() override;
|
||||
|
|
|
@ -924,7 +924,7 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
|
|||
if(!m_TilesHistory.empty()) // Sometimes pressing that button causes the automap to run so we should be able to undo that
|
||||
{
|
||||
// record undo
|
||||
m_pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionAutoMap>(m_pEditor, m_pEditor->m_SelectedGroup, m_pEditor->m_vSelectedLayers[0], m_TilesHistory));
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -935,7 +935,7 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
|
|||
{
|
||||
m_pEditor->m_Map.m_vpImages[m_Image]->m_AutoMapper.Proceed(this, m_AutoMapperConfig, m_Seed);
|
||||
// record undo
|
||||
m_pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionAutoMap>(m_pEditor, m_pEditor->m_SelectedGroup, m_pEditor->m_vSelectedLayers[0], m_TilesHistory));
|
||||
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();
|
||||
return CUI::POPUP_CLOSE_CURRENT;
|
||||
}
|
||||
|
|
|
@ -405,10 +405,14 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
|
|||
{
|
||||
// gather all tile layers
|
||||
std::vector<std::shared_ptr<CLayerTiles>> vpLayers;
|
||||
for(auto &pLayer : pEditor->m_Map.m_pGameGroup->m_vpLayers)
|
||||
int GameLayerIndex;
|
||||
for(int LayerIndex = 0; LayerIndex < (int)pEditor->m_Map.m_pGameGroup->m_vpLayers.size(); LayerIndex++)
|
||||
{
|
||||
auto &pLayer = pEditor->m_Map.m_pGameGroup->m_vpLayers.at(LayerIndex);
|
||||
if(pLayer != pEditor->m_Map.m_pGameLayer && pLayer->m_Type == LAYERTYPE_TILES)
|
||||
vpLayers.push_back(std::static_pointer_cast<CLayerTiles>(pLayer));
|
||||
else if(pLayer == pEditor->m_Map.m_pGameLayer)
|
||||
GameLayerIndex = LayerIndex;
|
||||
}
|
||||
|
||||
// search for unneeded game tiles
|
||||
|
@ -430,14 +434,23 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
|
|||
}
|
||||
}
|
||||
|
||||
if(!Found)
|
||||
CTile Tile = pGameLayer->GetTile(x, y);
|
||||
if(!Found && Tile.m_Index != TILE_AIR)
|
||||
{
|
||||
pGameLayer->m_pTiles[y * pGameLayer->m_Width + x].m_Index = TILE_AIR;
|
||||
Tile.m_Index = TILE_AIR;
|
||||
pGameLayer->SetTile(x, y, Tile);
|
||||
pEditor->m_Map.OnModify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!pGameLayer->m_TilesHistory.empty())
|
||||
{
|
||||
// record undo
|
||||
pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionTileChanges>(pEditor, pEditor->m_SelectedGroup, GameLayerIndex, "Clean up game tiles", pGameLayer->m_TilesHistory));
|
||||
pGameLayer->ClearHistory();
|
||||
}
|
||||
|
||||
return CUI::POPUP_CLOSE_CURRENT;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue