mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 23:22:24 +01:00
New world removal GUI code
This commit is contained in:
parent
5b31d32da8
commit
405347769a
@ -93,12 +93,21 @@ void GUIConfirmMenu::regenerateGui(v2u32 screensize)
|
|||||||
|
|
||||||
v2s32 size = rect.getSize();
|
v2s32 size = rect.getSize();
|
||||||
|
|
||||||
|
gui::IGUISkin *skin = Environment->getSkin();
|
||||||
|
gui::IGUIFont *font = skin->getFont();
|
||||||
|
s32 msg_h = font->getDimension(m_message_text.c_str()).Height;
|
||||||
|
s32 msg_w = font->getDimension(m_message_text.c_str()).Width;
|
||||||
|
if(msg_h > 200)
|
||||||
|
msg_h = 200;
|
||||||
|
if(msg_w > 540)
|
||||||
|
msg_w = 540;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add stuff
|
Add stuff
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 300, 20);
|
core::rect<s32> rect(0, 0, msg_w, msg_h);
|
||||||
rect += v2s32(size.X/2-300/2, size.Y/2-30/2-25);
|
rect += v2s32(size.X/2-msg_w/2, size.Y/2-30/2 - msg_h/2);
|
||||||
Environment->addStaticText(m_message_text.c_str(),
|
Environment->addStaticText(m_message_text.c_str(),
|
||||||
rect, false, true, this, -1);
|
rect, false, true, this, -1);
|
||||||
}
|
}
|
||||||
@ -106,13 +115,13 @@ void GUIConfirmMenu::regenerateGui(v2u32 screensize)
|
|||||||
int bw = 100;
|
int bw = 100;
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, bw, 30);
|
core::rect<s32> rect(0, 0, bw, 30);
|
||||||
rect = rect + v2s32(size.X/2-bw/2-(bw/2+5), size.Y/2-30/2+25);
|
rect = rect + v2s32(size.X/2-bw/2-(bw/2+5), size.Y/2-30/2+5 + msg_h/2);
|
||||||
Environment->addButton(rect, this, GUI_ID_YES,
|
Environment->addButton(rect, this, GUI_ID_YES,
|
||||||
wgettext("Yes"));
|
wgettext("Yes"));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, bw, 30);
|
core::rect<s32> rect(0, 0, bw, 30);
|
||||||
rect = rect + v2s32(size.X/2-bw/2+(bw/2+5), size.Y/2-30/2+25);
|
rect = rect + v2s32(size.X/2-bw/2+(bw/2+5), size.Y/2-30/2+5 + msg_h/2);
|
||||||
Environment->addButton(rect, this, GUI_ID_NO,
|
Environment->addButton(rect, this, GUI_ID_NO,
|
||||||
wgettext("No"));
|
wgettext("No"));
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "tile.h" // getTexturePath
|
#include "tile.h" // getTexturePath
|
||||||
|
#include "filesys.h"
|
||||||
|
|
||||||
struct CreateWorldDestMainMenu : public CreateWorldDest
|
struct CreateWorldDestMainMenu : public CreateWorldDest
|
||||||
{
|
{
|
||||||
@ -53,18 +54,21 @@ struct CreateWorldDestMainMenu : public CreateWorldDest
|
|||||||
|
|
||||||
struct ConfirmDestDeleteWorld : public ConfirmDest
|
struct ConfirmDestDeleteWorld : public ConfirmDest
|
||||||
{
|
{
|
||||||
ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu):
|
ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu,
|
||||||
|
const std::vector<std::string> &paths):
|
||||||
m_spec(spec),
|
m_spec(spec),
|
||||||
m_menu(menu)
|
m_menu(menu),
|
||||||
|
m_paths(paths)
|
||||||
{}
|
{}
|
||||||
void answer(bool answer)
|
void answer(bool answer)
|
||||||
{
|
{
|
||||||
if(answer == false)
|
if(answer == false)
|
||||||
return;
|
return;
|
||||||
m_menu->deleteWorld(m_spec);
|
m_menu->deleteWorld(m_paths);
|
||||||
}
|
}
|
||||||
WorldSpec m_spec;
|
WorldSpec m_spec;
|
||||||
GUIMainMenu *m_menu;
|
GUIMainMenu *m_menu;
|
||||||
|
std::vector<std::string> m_paths;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -819,12 +823,25 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
|
|||||||
)->drop();
|
)->drop();
|
||||||
} else {
|
} else {
|
||||||
WorldSpec spec = m_data->worlds[cur.selected_world];
|
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 *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,
|
(new GUIConfirmMenu(env, parent, -1, menumgr, dest,
|
||||||
(std::wstring(wgettext("Delete world "))
|
text.c_str()))->drop();
|
||||||
+L"\""+narrow_to_wide(spec.name)+L"\"?").c_str()
|
|
||||||
))->drop();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -889,12 +906,18 @@ void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
|
|||||||
quitMenu();
|
quitMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIMainMenu::deleteWorld(WorldSpec spec)
|
void GUIMainMenu::deleteWorld(const std::vector<std::string> &paths)
|
||||||
{
|
{
|
||||||
if(!spec.isValid())
|
// Delete files
|
||||||
return;
|
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();
|
acceptInput();
|
||||||
m_data->delete_world_spec = spec;
|
m_data->only_refresh = true;
|
||||||
quitMenu();
|
quitMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ struct MainMenuData
|
|||||||
int selected_world;
|
int selected_world;
|
||||||
bool simple_singleplayer_mode;
|
bool simple_singleplayer_mode;
|
||||||
// Actions
|
// Actions
|
||||||
WorldSpec delete_world_spec;
|
|
||||||
std::wstring create_world_name;
|
std::wstring create_world_name;
|
||||||
std::string create_world_gameid;
|
std::string create_world_gameid;
|
||||||
|
bool only_refresh;
|
||||||
|
|
||||||
std::vector<WorldSpec> worlds;
|
std::vector<WorldSpec> worlds;
|
||||||
std::vector<SubgameSpec> games;
|
std::vector<SubgameSpec> games;
|
||||||
@ -64,7 +64,9 @@ struct MainMenuData
|
|||||||
creative_mode(false),
|
creative_mode(false),
|
||||||
enable_damage(false),
|
enable_damage(false),
|
||||||
selected_world(0),
|
selected_world(0),
|
||||||
simple_singleplayer_mode(false)
|
simple_singleplayer_mode(false),
|
||||||
|
// Actions
|
||||||
|
only_refresh(false)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,7 +90,7 @@ public:
|
|||||||
{ return m_accepted; }
|
{ return m_accepted; }
|
||||||
bool OnEvent(const SEvent& event);
|
bool OnEvent(const SEvent& event);
|
||||||
void createNewWorld(std::wstring name, std::string gameid);
|
void createNewWorld(std::wstring name, std::string gameid);
|
||||||
void deleteWorld(WorldSpec spec);
|
void deleteWorld(const std::vector<std::string> &paths);
|
||||||
int getTab();
|
int getTab();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
32
src/main.cpp
32
src/main.cpp
@ -1446,6 +1446,24 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(skip_main_menu == false)
|
if(skip_main_menu == false)
|
||||||
{
|
{
|
||||||
|
video::IVideoDriver* driver = device->getVideoDriver();
|
||||||
|
|
||||||
|
infostream<<"Waiting for other menus"<<std::endl;
|
||||||
|
while(device->run() && kill == false)
|
||||||
|
{
|
||||||
|
if(noMenuActive())
|
||||||
|
break;
|
||||||
|
driver->beginScene(true, true,
|
||||||
|
video::SColor(255,128,128,128));
|
||||||
|
drawMenuBackground(driver);
|
||||||
|
guienv->drawAll();
|
||||||
|
driver->endScene();
|
||||||
|
// On some computers framerate doesn't seem to be
|
||||||
|
// automatically limited
|
||||||
|
sleep_ms(25);
|
||||||
|
}
|
||||||
|
infostream<<"Waited for other menus"<<std::endl;
|
||||||
|
|
||||||
GUIMainMenu *menu =
|
GUIMainMenu *menu =
|
||||||
new GUIMainMenu(guienv, guiroot, -1,
|
new GUIMainMenu(guienv, guiroot, -1,
|
||||||
&g_menumgr, &menudata, g_gamecallback);
|
&g_menumgr, &menudata, g_gamecallback);
|
||||||
@ -1463,8 +1481,6 @@ int main(int argc, char *argv[])
|
|||||||
error_message = L"";
|
error_message = L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
video::IVideoDriver* driver = device->getVideoDriver();
|
|
||||||
|
|
||||||
infostream<<"Created main menu"<<std::endl;
|
infostream<<"Created main menu"<<std::endl;
|
||||||
|
|
||||||
while(device->run() && kill == false)
|
while(device->run() && kill == false)
|
||||||
@ -1539,15 +1555,9 @@ int main(int argc, char *argv[])
|
|||||||
<<" ["<<worldspec.path<<"]"<<std::endl;
|
<<" ["<<worldspec.path<<"]"<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete world if requested
|
// Only refresh if so requested
|
||||||
if(menudata.delete_world_spec.isValid())
|
if(menudata.only_refresh){
|
||||||
{
|
infostream<<"Refreshing menu"<<std::endl;
|
||||||
bool r = fs::RecursiveDeleteContent(
|
|
||||||
menudata.delete_world_spec.path);
|
|
||||||
if(r == false){
|
|
||||||
error_message = L"World delete failed";
|
|
||||||
errorstream<<wide_to_narrow(error_message)<<std::endl;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user