mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
added a popup to create a new folder in the editor's file dialog and show an error if it fails
This commit is contained in:
parent
8d159ce65a
commit
588a411666
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue