mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Images are now sorted in the editor
This commit is contained in:
parent
7454cec57e
commit
4d35f63174
|
@ -1820,7 +1820,33 @@ static int CompareImageName(const void *Object1, const void *Object2)
|
||||||
|
|
||||||
void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
||||||
{
|
{
|
||||||
qsort(m_Map.m_lImages.base_ptr(), m_Map.m_lImages.size(), sizeof(CEditorImage*), CompareImageName);
|
array<CEditorImage*> lImages = array<CEditorImage*>(m_Map.m_lImages);
|
||||||
|
int aIndexes[lImages.size()];
|
||||||
|
|
||||||
|
bool Sorted = true;
|
||||||
|
for(int i = 1; i < lImages.size(); i++)
|
||||||
|
if( str_comp(lImages[i]->m_aName, lImages[i-1]->m_aName) < 0 )
|
||||||
|
{
|
||||||
|
Sorted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Sorted)
|
||||||
|
{
|
||||||
|
qsort(lImages.base_ptr(), lImages.size(), sizeof(CEditorImage*), CompareImageName);
|
||||||
|
|
||||||
|
// lImages now contains a sorted version of m_Map.m_lImages
|
||||||
|
// Now updating aIndex such that
|
||||||
|
// aIndex[SortedIndexOf_lImages] = UnsortedIndexOf_m_Map.m_lImages
|
||||||
|
|
||||||
|
for(int NewRef = 0; NewRef < lImages.size(); NewRef++)
|
||||||
|
for(int OldRef = 0; OldRef < m_Map.m_lImages.size(); OldRef++)
|
||||||
|
if( m_Map.m_lImages[OldRef] == lImages[NewRef] )
|
||||||
|
{
|
||||||
|
aIndexes[NewRef] = OldRef;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(int e = 0; e < 2; e++) // two passes, first embedded, then external
|
for(int e = 0; e < 2; e++) // two passes, first embedded, then external
|
||||||
{
|
{
|
||||||
|
@ -1831,19 +1857,19 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
||||||
else
|
else
|
||||||
UI()->DoLabel(&Slot, "External", 12.0f, 0);
|
UI()->DoLabel(&Slot, "External", 12.0f, 0);
|
||||||
|
|
||||||
for(int i = 0; i < m_Map.m_lImages.size(); i++)
|
for(int i = 0; i < lImages.size(); i++)
|
||||||
{
|
{
|
||||||
if((e && !m_Map.m_lImages[i]->m_External) ||
|
if((e && !lImages[i]->m_External) ||
|
||||||
(!e && m_Map.m_lImages[i]->m_External))
|
(!e && lImages[i]->m_External))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char aBuf[128];
|
char aBuf[128];
|
||||||
str_copy(aBuf, m_Map.m_lImages[i]->m_aName, sizeof(aBuf));
|
str_copy(aBuf, lImages[i]->m_aName, sizeof(aBuf));
|
||||||
ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
|
ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
|
||||||
|
|
||||||
if(int Result = DoButton_Editor(&m_Map.m_lImages[i], aBuf, m_SelectedImage == i, &Slot,
|
if(int Result = DoButton_Editor(&m_Map.m_lImages[aIndexes[i]], aBuf, m_SelectedImage == i, &Slot,
|
||||||
BUTTON_CONTEXT, "Select image"))
|
BUTTON_CONTEXT, "Select image"))
|
||||||
{
|
{
|
||||||
m_SelectedImage = i;
|
m_SelectedImage = i;
|
||||||
|
@ -1864,7 +1890,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
||||||
r.w = r.h;
|
r.w = r.h;
|
||||||
else
|
else
|
||||||
r.h = r.w;
|
r.h = r.w;
|
||||||
Graphics()->TextureSet(m_Map.m_lImages[i]->m_TexId);
|
Graphics()->TextureSet(m_Map.m_lImages[aIndexes[i]]->m_TexId);
|
||||||
Graphics()->BlendNormal();
|
Graphics()->BlendNormal();
|
||||||
Graphics()->QuadsBegin();
|
Graphics()->QuadsBegin();
|
||||||
IGraphics::CQuadItem QuadItem(r.x, r.y, r.w, r.h);
|
IGraphics::CQuadItem QuadItem(r.x, r.y, r.w, r.h);
|
||||||
|
|
Loading…
Reference in a new issue