mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Fix crash in editor when using up/down keys on empty images list
This commit is contained in:
parent
4a683e024a
commit
f5a16c1c77
|
@ -3987,55 +3987,58 @@ void CEditor::RenderImagesList(CUIRect ToolBox)
|
|||
ToolBox.y += ScrollOffset.y;
|
||||
|
||||
bool ScrollToSelection = false;
|
||||
if(Input()->KeyPress(KEY_DOWN) && m_Dialog == DIALOG_NONE)
|
||||
if(m_Dialog == DIALOG_NONE && !m_Map.m_vpImages.empty())
|
||||
{
|
||||
int OldImage = m_SelectedImage;
|
||||
m_SelectedImage = clamp(m_SelectedImage, 0, (int)m_Map.m_vpImages.size() - 1);
|
||||
for(size_t i = m_SelectedImage + 1; i < m_Map.m_vpImages.size(); i++)
|
||||
if(Input()->KeyPress(KEY_DOWN))
|
||||
{
|
||||
if(m_Map.m_vpImages[i]->m_External == m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
int OldImage = m_SelectedImage;
|
||||
m_SelectedImage = clamp(m_SelectedImage, 0, (int)m_Map.m_vpImages.size() - 1);
|
||||
for(size_t i = m_SelectedImage + 1; i < m_Map.m_vpImages.size(); i++)
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(m_SelectedImage == OldImage && !m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
{
|
||||
for(size_t i = 0; i < m_Map.m_vpImages.size(); i++)
|
||||
{
|
||||
if(m_Map.m_vpImages[i]->m_External)
|
||||
if(m_Map.m_vpImages[i]->m_External == m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ScrollToSelection = OldImage != m_SelectedImage;
|
||||
}
|
||||
if(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE)
|
||||
{
|
||||
int OldImage = m_SelectedImage;
|
||||
m_SelectedImage = clamp(m_SelectedImage, 0, (int)m_Map.m_vpImages.size() - 1);
|
||||
for(int i = m_SelectedImage - 1; i >= 0; i--)
|
||||
{
|
||||
if(m_Map.m_vpImages[i]->m_External == m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
if(m_SelectedImage == OldImage && !m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
break;
|
||||
for(size_t i = 0; i < m_Map.m_vpImages.size(); i++)
|
||||
{
|
||||
if(m_Map.m_vpImages[i]->m_External)
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ScrollToSelection = OldImage != m_SelectedImage;
|
||||
}
|
||||
if(m_SelectedImage == OldImage && m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
else if(Input()->KeyPress(KEY_UP))
|
||||
{
|
||||
for(int i = (int)m_Map.m_vpImages.size() - 1; i >= 0; i--)
|
||||
int OldImage = m_SelectedImage;
|
||||
m_SelectedImage = clamp(m_SelectedImage, 0, (int)m_Map.m_vpImages.size() - 1);
|
||||
for(int i = m_SelectedImage - 1; i >= 0; i--)
|
||||
{
|
||||
if(!m_Map.m_vpImages[i]->m_External)
|
||||
if(m_Map.m_vpImages[i]->m_External == m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(m_SelectedImage == OldImage && m_Map.m_vpImages[m_SelectedImage]->m_External)
|
||||
{
|
||||
for(int i = (int)m_Map.m_vpImages.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if(!m_Map.m_vpImages[i]->m_External)
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ScrollToSelection = OldImage != m_SelectedImage;
|
||||
}
|
||||
ScrollToSelection = OldImage != m_SelectedImage;
|
||||
}
|
||||
|
||||
for(int e = 0; e < 2; e++) // two passes, first embedded, then external
|
||||
|
|
Loading…
Reference in a new issue