menus::delete_world

This commit is contained in:
MihailRis 2024-03-22 11:42:00 +03:00
parent b2abd57a71
commit 7c16333850
4 changed files with 20 additions and 0 deletions

View File

@ -48,6 +48,10 @@ fs::path EnginePaths::getWorldFolder() {
return worldFolder;
}
fs::path EnginePaths::getWorldFolder(const std::string& name) {
return getWorldsFolder()/fs::path(name);
}
std::vector<fs::path> EnginePaths::scanForWorlds() {
std::vector<fs::path> folders;

View File

@ -27,6 +27,7 @@ public:
fs::path getScreenshotFile(std::string ext);
fs::path getWorldsFolder();
fs::path getWorldFolder();
fs::path getWorldFolder(const std::string& name);
bool isWorldNameUsed(std::string name);
void setUserfiles(fs::path folder);

View File

@ -234,6 +234,16 @@ void menus::open_world(std::string name, Engine* engine, bool confirmConvert) {
}
}
void menus::delete_world(std::string name, Engine* engine) {
fs::path folder = engine->getPaths()->getWorldFolder(name);
guiutil::confirm(engine->getGUI(), langs::get(L"delete-confirm", L"world")+
L" ("+util::str2wstr_utf8(folder.u8string())+L")", [=]() {
std::cout << "deleting " << folder.u8string() << std::endl;
fs::remove_all(folder);
menus::refresh_menus(engine);
});
}
std::shared_ptr<Panel> create_worlds_panel(Engine* engine) {
auto panel = std::dynamic_pointer_cast<Panel>(guiutil::create(
"<panel size='370' padding='5' color='#FFFFFF11' max-length='400'>"

View File

@ -42,6 +42,11 @@ namespace menus {
/// @param confirmConvert automatically confirm convert if requested
void open_world(std::string name, Engine* engine, bool confirmConvert);
/// @brief Show world removal confirmation dialog
/// @param name world name
/// @param engine engine instance
void delete_world(std::string name, Engine* engine);
/// @brief Create development version label at the top-right screen corner
void create_version_label(Engine* engine);
void create_menus(Engine* engine);