about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxalduin <xalduin@gmail.com>2010-06-02 04:49:35 +0800
committerMagnus Auvinen <magnus.auvinen@gmail.com>2010-06-02 05:11:12 +0800
commitf2920ea5d85ea54a8000fdf6b6f8ccba36ebfdfb (patch)
treeaef51e5774bd7abfa72e15ba2962b986e6e1b95b
parent61fdee33679dc50fd119f32a3b9590f57332b015 (diff)
downloadzcatch-f2920ea5d85ea54a8000fdf6b6f8ccba36ebfdfb.tar.gz
zcatch-f2920ea5d85ea54a8000fdf6b6f8ccba36ebfdfb.zip
Sort by map name when opening map
When opening a map, the list of map names is now sorted alphabetically.
-rw-r--r--src/game/editor/ed_editor.cpp36
-rw-r--r--src/game/editor/ed_editor.h2
2 files changed, 19 insertions, 19 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp
index 480a6827..b2b3e1ca 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 <base/system.h>
-
+#include <base/tl/sorted_array.h>
+#include <base/tl/string.h>
 
 #include <engine/shared/datafile.h>
 #include <engine/shared/config.h>
@@ -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<string> 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<IStorage>()->ListDirectory(gs_FileDialogDirTypes, gs_aFileDialogPath, EditorListdirCallback, &Info);
+	Kernel()->RequestInterface<IStorage>()->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 1730fb0a..d027c162 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