aboutsummaryrefslogtreecommitdiff
path: root/src/guiMainMenu.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-03-26 02:19:41 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-03-26 08:37:15 +0300
commit405347769a2f8c73aead3bc2b64fdc4d81763921 (patch)
tree65ab3580caa279407436c0b5ed97b8a329d4f537 /src/guiMainMenu.cpp
parent5b31d32da8b1dc8b5e60b495bdfc20a563487cc7 (diff)
downloadminetest-405347769a2f8c73aead3bc2b64fdc4d81763921.tar.gz
minetest-405347769a2f8c73aead3bc2b64fdc4d81763921.tar.bz2
minetest-405347769a2f8c73aead3bc2b64fdc4d81763921.zip
New world removal GUI code
Diffstat (limited to 'src/guiMainMenu.cpp')
-rw-r--r--src/guiMainMenu.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp
index 647903521..ca0481e35 100644
--- a/src/guiMainMenu.cpp
+++ b/src/guiMainMenu.cpp
@@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gettext.h"
#include "utility.h"
#include "tile.h" // getTexturePath
+#include "filesys.h"
struct CreateWorldDestMainMenu : public CreateWorldDest
{
@@ -53,18 +54,21 @@ struct CreateWorldDestMainMenu : public CreateWorldDest
struct ConfirmDestDeleteWorld : public ConfirmDest
{
- ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu):
+ ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu,
+ const std::vector<std::string> &paths):
m_spec(spec),
- m_menu(menu)
+ m_menu(menu),
+ m_paths(paths)
{}
void answer(bool answer)
{
if(answer == false)
return;
- m_menu->deleteWorld(m_spec);
+ m_menu->deleteWorld(m_paths);
}
WorldSpec m_spec;
GUIMainMenu *m_menu;
+ std::vector<std::string> m_paths;
};
enum
@@ -819,12 +823,25 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
)->drop();
} else {
WorldSpec spec = m_data->worlds[cur.selected_world];
+ // Get files and directories involved
+ std::vector<std::string> paths;
+ paths.push_back(spec.path);
+ fs::GetRecursiveSubPaths(spec.path, paths);
+ // Launch confirmation dialog
ConfirmDestDeleteWorld *dest = new
- ConfirmDestDeleteWorld(spec, this);
+ ConfirmDestDeleteWorld(spec, this, paths);
+ std::wstring text = wgettext("Delete world");
+ text += L" \"";
+ text += narrow_to_wide(spec.name);
+ text += L"\"?\n\n";
+ text += wgettext("Files to be deleted");
+ text += L":\n";
+ for(u32 i=0; i<paths.size(); i++){
+ if(i == 3){ text += L"..."; break; }
+ text += narrow_to_wide(paths[i]) + L"\n";
+ }
(new GUIConfirmMenu(env, parent, -1, menumgr, dest,
- (std::wstring(wgettext("Delete world "))
- +L"\""+narrow_to_wide(spec.name)+L"\"?").c_str()
- ))->drop();
+ text.c_str()))->drop();
}
return true;
}
@@ -889,12 +906,18 @@ void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
quitMenu();
}
-void GUIMainMenu::deleteWorld(WorldSpec spec)
+void GUIMainMenu::deleteWorld(const std::vector<std::string> &paths)
{
- if(!spec.isValid())
- return;
+ // Delete files
+ bool did = fs::DeletePaths(paths);
+ if(!did){
+ GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
+ -1, menumgr, wgettext("Failed to delete all world files"));
+ menu->drop();
+ }
+ // Quit menu to refresh it
acceptInput();
- m_data->delete_world_spec = spec;
+ m_data->only_refresh = true;
quitMenu();
}