From f2920ea5d85ea54a8000fdf6b6f8ccba36ebfdfb Mon Sep 17 00:00:00 2001 From: xalduin Date: Wed, 2 Jun 2010 04:49:35 +0800 Subject: [PATCH] Sort by map name when opening map When opening a map, the list of map names is now sorted alphabetically. --- src/game/editor/ed_editor.cpp | 36 +++++++++++++++++------------------ src/game/editor/ed_editor.h | 2 ++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 480a68277..b2b3e1ca8 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -1,7 +1,8 @@ // copyright (c) 2007 magnus auvinen, see licence.txt for more info #include - +#include +#include #include #include @@ -1885,21 +1886,21 @@ static char gs_FileDialogFileName[512] = {0}; static char gs_aFileDialogPath[512] = {0}; static char gs_aFileDialogCompleteFilename[512] = {0}; static int gs_FilesNum = 0; +static sorted_array gs_FileList; int g_FilesStartAt = 0; int g_FilesCur = 0; int g_FilesStopAt = 999; -struct CListDirInfo -{ - CUIRect *m_pRect; - CEditor *m_pEditor; -}; - static void EditorListdirCallback(const char *pName, int IsDir, void *pUser) { if(pName[0] == '.' || IsDir) // skip this shit! return; + gs_FileList.add(string(pName)); +} + +void CEditor::AddFileDialogEntry(const char *pName, CUIRect *pView) +{ if(g_FilesCur > gs_FilesNum) gs_FilesNum = g_FilesCur; @@ -1907,14 +1908,12 @@ static void EditorListdirCallback(const char *pName, int IsDir, void *pUser) if(g_FilesCur-1 < g_FilesStartAt || g_FilesCur > g_FilesStopAt) return; - CListDirInfo *pInfo = (CListDirInfo *)pUser; - CUIRect *pView = pInfo->m_pRect; CUIRect Button; pView->HSplitTop(15.0f, &Button, pView); pView->HSplitTop(2.0f, 0, pView); //char buf[512]; - if(pInfo->m_pEditor->DoButton_File((void*)(10+(int)Button.y), pName, 0, &Button, 0, 0)) + if(DoButton_File((void*)(10+(int)Button.y), pName, 0, &Button, 0, 0)) { str_copy(gs_FileDialogFileName, pName, sizeof(gs_FileDialogFileName)); @@ -1922,11 +1921,11 @@ static void EditorListdirCallback(const char *pName, int IsDir, void *pUser) str_append(gs_aFileDialogCompleteFilename, gs_aFileDialogPath, sizeof(gs_aFileDialogCompleteFilename)); str_append(gs_aFileDialogCompleteFilename, gs_FileDialogFileName, sizeof(gs_aFileDialogCompleteFilename)); - if(pInfo->m_pEditor->Input()->MouseDoubleClick()) + if(Input()->MouseDoubleClick()) { if(gs_pfnFileDialogFunc) - gs_pfnFileDialogFunc(gs_aFileDialogCompleteFilename, pInfo->m_pEditor); - pInfo->m_pEditor->m_Dialog = DIALOG_NONE; + gs_pfnFileDialogFunc(gs_aFileDialogCompleteFilename, this); + m_Dialog = DIALOG_NONE; } } } @@ -1997,13 +1996,12 @@ void CEditor::RenderFileDialog() // set clipping UI()->ClipEnable(&View); - // the list - CListDirInfo Info; - Info.m_pRect = &View; - Info.m_pEditor = this; - // TODO: lazy ass coding, should store the interface pointer somewere - Kernel()->RequestInterface()->ListDirectory(gs_FileDialogDirTypes, gs_aFileDialogPath, EditorListdirCallback, &Info); + Kernel()->RequestInterface()->ListDirectory(gs_FileDialogDirTypes, gs_aFileDialogPath, EditorListdirCallback, 0); + + for(int i = 0; i < gs_FileList.size(); i++) + AddFileDialogEntry(gs_FileList[i].cstr(), &View); + gs_FileList.clear(); // disable clipping again UI()->ClipDisable(); diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index 1730fb0a3..d027c1622 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -606,6 +606,8 @@ public: void RenderMenubar(CUIRect Menubar); void RenderFileDialog(); + + void AddFileDialogEntry(const char *pName, CUIRect *pView); }; // make sure to inline this function