diff options
| author | xalduin <xalduin@gmail.com> | 2010-06-02 12:12:32 -0400 |
|---|---|---|
| committer | xalduin <xalduin@gmail.com> | 2010-06-02 12:12:32 -0400 |
| commit | a99cbfc74238136723a83913b809479267e3dfa2 (patch) | |
| tree | 41f72c6c9aeaffc6ae3a9d852664e1a1b6c24489 /src/game | |
| parent | fee651735fd7a29cfbec6b13ea9efdecc0ccb688 (diff) | |
| download | zcatch-a99cbfc74238136723a83913b809479267e3dfa2.tar.gz zcatch-a99cbfc74238136723a83913b809479267e3dfa2.zip | |
Image sorting working, less hackish
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/editor/ed_editor.cpp | 68 | ||||
| -rw-r--r-- | src/game/editor/ed_editor.h | 1 |
2 files changed, 67 insertions, 2 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index b2b3e1ca..df40c48a 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -554,8 +554,24 @@ CQuad *CEditor::GetSelectedQuad() return 0; } -static void CallbackOpenMap(const char *pFileName, void *pUser) { if(((CEditor*)pUser)->Load(pFileName)) str_copy(((CEditor*)pUser)->m_aFileName, pFileName, 512); } -static void CallbackAppendMap(const char *pFileName, void *pUser) { if(((CEditor*)pUser)->Append(pFileName)) ((CEditor*)pUser)->m_aFileName[0] = 0; } +static void CallbackOpenMap(const char *pFileName, void *pUser) +{ + CEditor *pEditor = (CEditor*)pUser; + if(pEditor->Load(pFileName)) + { + str_copy(pEditor->m_aFileName, pFileName, 512); + pEditor->SortImages(); + } +} +static void CallbackAppendMap(const char *pFileName, void *pUser) +{ + CEditor *pEditor = (CEditor*)pUser; + if(pEditor->Append(pFileName)) + { + pEditor->m_aFileName[0] = 0; + pEditor->SortImages(); + } +} static void CallbackSaveMap(const char *pFileName, void *pUser){ if(((CEditor*)pUser)->Save(pFileName)) str_copy(((CEditor*)pUser)->m_aFileName, pFileName, 512); } void CEditor::DoToolbar(CUIRect ToolBar) @@ -1725,6 +1741,7 @@ void CEditor::ReplaceImage(const char *pFileName, void *pUser) *pImg = ImgInfo; ExtractName(pFileName, pImg->m_aName); pImg->m_TexId = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + pEditor->SortImages(); } void CEditor::AddImage(const char *pFileName, void *pUser) @@ -1747,6 +1764,7 @@ void CEditor::AddImage(const char *pFileName, void *pUser) } pEditor->m_Map.m_lImages.add(pImg); + pEditor->SortImages(); } @@ -1809,9 +1827,55 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View) return 0; } +static int CompareImageName(const void *pObject1, const void *pObject2) +{ + CEditorImage *pImage1 = *(CEditorImage**)pObject1; + CEditorImage *pImage2 = *(CEditorImage**)pObject2; + + return str_comp(pImage1->m_aName, pImage2->m_aName); +} + +static int *gs_pSortedIndex = 0; +static void ModifySortedIndex(int *pIndex) +{ + if(*pIndex > -1) + *pIndex = gs_pSortedIndex[*pIndex]; +} + +void CEditor::SortImages() +{ + bool Sorted = true; + for(int i = 1; i < m_Map.m_lImages.size(); i++) + if( str_comp(m_Map.m_lImages[i]->m_aName, m_Map.m_lImages[i-1]->m_aName) < 0 ) + { + Sorted = false; + break; + } + + if(!Sorted) + { + array<CEditorImage*> lTemp = array<CEditorImage*>(m_Map.m_lImages); + gs_pSortedIndex = new int[lTemp.size()]; + + qsort(m_Map.m_lImages.base_ptr(), m_Map.m_lImages.size(), sizeof(CEditorImage*), CompareImageName); + + for(int OldIndex = 0; OldIndex < lTemp.size(); OldIndex++) + for(int NewIndex = 0; NewIndex < m_Map.m_lImages.size(); NewIndex++) + if(lTemp[OldIndex] == m_Map.m_lImages[NewIndex]) + gs_pSortedIndex[OldIndex] = NewIndex; + + m_Map.ModifyImageIndex(ModifySortedIndex); + + delete [] gs_pSortedIndex; + gs_pSortedIndex = 0; + } +} + void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) { + SortImages(); + for(int e = 0; e < 2; e++) // two passes, first embedded, then external { CUIRect Slot; diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index d027c162..a7d742a8 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -608,6 +608,7 @@ public: void RenderFileDialog(); void AddFileDialogEntry(const char *pName, CUIRect *pView); + void SortImages(); }; // make sure to inline this function |