about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-20 22:53:50 +0100
committeroy <Tom_Adams@web.de>2011-03-20 22:53:50 +0100
commit588a411666de052fd237f9aaa857278ade420b51 (patch)
tree5c934bf0eb635e87db3c2344a3145e9fe17fee47 /src/game
parent8d159ce65a867889db62c4827f25951de33fe106 (diff)
downloadzcatch-588a411666de052fd237f9aaa857278ade420b51.tar.gz
zcatch-588a411666de052fd237f9aaa857278ade420b51.zip
added a popup to create a new folder in the editor's file dialog and show an error if it fails
Diffstat (limited to 'src/game')
-rw-r--r--src/game/editor/ed_editor.cpp21
-rw-r--r--src/game/editor/ed_editor.h3
-rw-r--r--src/game/editor/ed_popups.cpp70
3 files changed, 79 insertions, 15 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp
index 5420b9a2..283ded42 100644
--- a/src/game/editor/ed_editor.cpp
+++ b/src/game/editor/ed_editor.cpp
@@ -2212,8 +2212,9 @@ void CEditor::RenderFileDialog()
 {
 	// GUI coordsys
 	Graphics()->MapScreen(UI()->Screen()->x, UI()->Screen()->y, UI()->Screen()->w, UI()->Screen()->h);
-
 	CUIRect View = *UI()->Screen();
+	float Width = View.w, Height = View.h;
+
 	RenderTools()->DrawUIRect(&View, vec4(0,0,0,0.25f), 0, 0);
 	View.VMargin(150.0f, &View);
 	View.HMargin(50.0f, &View);
@@ -2386,19 +2387,11 @@ void CEditor::RenderFileDialog()
 		ButtonBar.VSplitLeft(70.0f, &Button, &ButtonBar);
 		if(DoButton_Editor(&s_NewFolderButton, "New folder", 0, &Button, 0, 0))
 		{
-			if(*m_aFileDialogFileName)
-			{
-				char aBuf[512];
-				str_format(aBuf, sizeof(aBuf), "%s/%s", m_pFileDialogPath, m_aFileDialogFileName);
-				if(Storage()->CreateFolder(aBuf, IStorage::TYPE_SAVE))
-				{
-					FilelistPopulate(IStorage::TYPE_SAVE);
-					if(m_FilesSelectedIndex >= 0 && !m_FileList[m_FilesSelectedIndex].m_IsDir)
-						str_copy(m_aFileDialogFileName, m_FileList[m_FilesSelectedIndex].m_aFilename, sizeof(m_aFileDialogFileName));
-					else
-						m_aFileDialogFileName[0] = 0;
-				}
-			}
+			m_FileDialogNewFolderName[0] = 0;
+			m_FileDialogErrString[0] = 0;
+			static int s_NewFolderPopupID = 0;
+			UiInvokePopupMenu(&s_NewFolderPopupID, 0, Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, PopupNewFolder);
+			UI()->SetActiveItem(0);
 		}
 	}
 }
diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h
index 61af9249..7e96e5c8 100644
--- a/src/game/editor/ed_editor.h
+++ b/src/game/editor/ed_editor.h
@@ -567,6 +567,8 @@ public:
 	int m_FileDialogFileType;
 	float m_FileDialogScrollValue;
 	int m_FilesSelectedIndex;
+	char m_FileDialogNewFolderName[64];
+	char m_FileDialogErrString[64];
 
 	struct CFilelistItem
 	{
@@ -655,6 +657,7 @@ public:
 	static int PopupLayer(CEditor *pEditor, CUIRect View);
 	static int PopupQuad(CEditor *pEditor, CUIRect View);
 	static int PopupPoint(CEditor *pEditor, CUIRect View);
+	static int PopupNewFolder(CEditor *pEditor, CUIRect View);
 	static int PopupSelectImage(CEditor *pEditor, CUIRect View);
 	static int PopupSelectGametileOp(CEditor *pEditor, CUIRect View);
 	static int PopupImage(CEditor *pEditor, CUIRect View);
diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp
index d504bee6..dc239cc9 100644
--- a/src/game/editor/ed_popups.cpp
+++ b/src/game/editor/ed_popups.cpp
@@ -4,9 +4,9 @@
 #include <engine/graphics.h>
 #include <engine/input.h>
 #include <engine/keys.h>
+#include <engine/storage.h>
 #include "ed_editor.h"
 
-#include <game/localization.h>
 
 // popup menu handling
 static struct
@@ -445,6 +445,74 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View)
 	return 0;	
 }
 
+int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View)
+{
+	CUIRect Label, ButtonBar, Origin = View;
+
+	// title
+	View.HSplitTop(10.0f, 0, &View);
+	View.HSplitTop(30.0f, &Label, &View);
+	pEditor->UI()->DoLabel(&Label, "Create new folder", 20.0f, 0);
+
+	View.HSplitBottom(10.0f, &View, 0);
+	View.HSplitBottom(20.0f, &View, &ButtonBar);	
+
+	if(pEditor->m_FileDialogErrString[0] == 0)
+	{
+		// interaction box
+		View.HSplitBottom(40.0f, &View, 0);
+		View.VMargin(40.0f, &View);
+		View.HSplitBottom(20.0f, &View, &Label);
+		static int s_FolderBox = 0;
+		pEditor->DoEditBox(&s_FolderBox, &Label, pEditor->m_FileDialogNewFolderName, sizeof(pEditor->m_FileDialogNewFolderName), 15.0f);
+		View.HSplitBottom(20.0f, &View, &Label);
+		pEditor->UI()->DoLabel(&Label, "Name:", 10.0f, -1);
+
+		// button bar
+		ButtonBar.VSplitLeft(30.0f, 0, &ButtonBar);
+		ButtonBar.VSplitLeft(110.0f, &Label, &ButtonBar);
+		static int s_CreateButton = 0;
+		if(pEditor->DoButton_Editor(&s_CreateButton, "Create", 0, &Label, 0, 0))
+		{
+			// create the folder
+			if(*pEditor->m_FileDialogNewFolderName)
+			{
+				char aBuf[512];
+				str_format(aBuf, sizeof(aBuf), "%s/%s", pEditor->m_pFileDialogPath, pEditor->m_FileDialogNewFolderName);
+				if(pEditor->Storage()->CreateFolder(aBuf, IStorage::TYPE_SAVE))
+				{
+					pEditor->FilelistPopulate(IStorage::TYPE_SAVE);
+					return 1;
+				}
+				else
+					str_copy(pEditor->m_FileDialogErrString, "Unable to create the folder", sizeof(pEditor->m_FileDialogErrString));
+			}	
+		}
+		ButtonBar.VSplitRight(30.0f, &ButtonBar, 0);
+		ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label);
+		static int s_AbortButton = 0;
+		if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0))
+			return 1;
+	}
+	else
+	{
+		// error text
+		View.HSplitTop(30.0f, 0, &View);
+		View.VMargin(40.0f, &View);
+		View.HSplitTop(20.0f, &Label, &View);
+		pEditor->UI()->DoLabel(&Label, "Error:", 10.0f, -1);
+		View.HSplitTop(20.0f, &Label, &View);
+		pEditor->UI()->DoLabel(&Label, "Unable to create the folder", 10.0f, -1, View.w);
+
+		// button
+		ButtonBar.VMargin(ButtonBar.w/2.0f-55.0f, &ButtonBar);
+		static int s_CreateButton = 0;
+		if(pEditor->DoButton_Editor(&s_CreateButton, "Ok", 0, &ButtonBar, 0, 0))
+			return 1;
+	}
+
+	return 0;	
+}
 
 
 static int g_SelectImageSelected = -100;