From 4d35f63174a8304ad2b4c1178f1fe10e3f84ae14 Mon Sep 17 00:00:00 2001 From: xalduin Date: Tue, 1 Jun 2010 21:36:10 -0400 Subject: [PATCH] Images are now sorted in the editor --- src/game/editor/ed_editor.cpp | 40 +++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 0a5c22d3e..76fd10962 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -1820,7 +1820,33 @@ static int CompareImageName(const void *Object1, const void *Object2) 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 lImages = array(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 { @@ -1831,19 +1857,19 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) else 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) || - (!e && m_Map.m_lImages[i]->m_External)) + if((e && !lImages[i]->m_External) || + (!e && lImages[i]->m_External)) { continue; } 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); - 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")) { m_SelectedImage = i; @@ -1864,7 +1890,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) r.w = r.h; else 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()->QuadsBegin(); IGraphics::CQuadItem QuadItem(r.x, r.y, r.w, r.h);