Select previous layer after deletion

This commit is contained in:
ChillerDragon 2024-09-18 20:38:11 +08:00
parent e5fffb0ab8
commit 6a2afb6f60
3 changed files with 56 additions and 40 deletions

View file

@ -738,6 +738,54 @@ std::pair<int, int> CEditor::EnvGetSelectedTimeAndValue() const
return std::pair<int, int>{CurrentTime, CurrentValue};
}
void CEditor::SelectNextLayer()
{
int CurrentLayer = 0;
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = maximum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);
if(m_vSelectedLayers[0] < (int)m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1)
{
SelectLayer(m_vSelectedLayers[0] + 1);
}
else
{
for(size_t Group = m_SelectedGroup + 1; Group < m_Map.m_vpGroups.size(); Group++)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(0, Group);
break;
}
}
}
}
void CEditor::SelectPreviousLayer()
{
int CurrentLayer = std::numeric_limits<int>::max();
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = minimum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);
if(m_vSelectedLayers[0] > 0)
{
SelectLayer(m_vSelectedLayers[0] - 1);
}
else
{
for(int Group = m_SelectedGroup - 1; Group >= 0; Group--)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(m_Map.m_vpGroups[Group]->m_vpLayers.size() - 1, Group);
break;
}
}
}
}
bool CEditor::CallbackOpenMap(const char *pFileName, int StorageType, void *pUser)
{
CEditor *pEditor = (CEditor *)pUser;
@ -4195,26 +4243,7 @@ void CEditor::RenderLayers(CUIRect LayersBox)
}
else
{
int CurrentLayer = 0;
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = maximum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);
if(m_vSelectedLayers[0] < (int)m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1)
{
SelectLayer(m_vSelectedLayers[0] + 1);
}
else
{
for(size_t Group = m_SelectedGroup + 1; Group < m_Map.m_vpGroups.size(); Group++)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(0, Group);
break;
}
}
}
SelectNextLayer();
}
s_ScrollToSelectionNext = true;
}
@ -4227,27 +4256,9 @@ void CEditor::RenderLayers(CUIRect LayersBox)
}
else
{
int CurrentLayer = std::numeric_limits<int>::max();
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = minimum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);
if(m_vSelectedLayers[0] > 0)
{
SelectLayer(m_vSelectedLayers[0] - 1);
}
else
{
for(int Group = m_SelectedGroup - 1; Group >= 0; Group--)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(m_Map.m_vpGroups[Group]->m_vpLayers.size() - 1, Group);
break;
}
}
}
SelectPreviousLayer();
}
s_ScrollToSelectionNext = true;
}

View file

@ -324,6 +324,9 @@ public:
const CMapView *MapView() const { return &m_MapView; }
CLayerSelector *LayerSelector() { return &m_LayerSelector; }
void SelectNextLayer();
void SelectPreviousLayer();
void FillGameTiles(EGameTileOp FillTile) const;
bool CanFillGameTiles() const;
void AddQuadOrSound();

View file

@ -157,4 +157,6 @@ void CEditor::DeleteSelectedLayer()
if(pCurrentLayer == m_Map.m_pTuneLayer)
m_Map.m_pTuneLayer = nullptr;
m_Map.m_vpGroups[m_SelectedGroup]->DeleteLayer(m_vSelectedLayers[0]);
SelectPreviousLayer();
}