refactor
This commit is contained in:
parent
19bef1ae76
commit
10f0bd0290
@ -86,25 +86,25 @@ bool menus::call(Engine& engine, runnable func) {
|
||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||
// could not to find or read pack
|
||||
guiutil::alert(
|
||||
gui, langs::get(L"error.pack-not-found")+L": "+
|
||||
gui->getMenu(), langs::get(L"error.pack-not-found")+L": "+
|
||||
util::str2wstr_utf8(error.getPackId())
|
||||
);
|
||||
return false;
|
||||
} catch (const assetload::error& error) {
|
||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(
|
||||
gui, langs::get(L"Assets Load Error", L"menu")+L":\n"+
|
||||
gui->getMenu(), langs::get(L"Assets Load Error", L"menu")+L":\n"+
|
||||
util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return false;
|
||||
} catch (const parsing_error& error) {
|
||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(gui, util::str2wstr_utf8(error.errorLog()));
|
||||
guiutil::alert(gui->getMenu(), util::str2wstr_utf8(error.errorLog()));
|
||||
return false;
|
||||
} catch (const std::runtime_error& error) {
|
||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||
guiutil::alert(
|
||||
gui, langs::get(L"Content Error", L"menu")+L":\n"+
|
||||
gui->getMenu(), langs::get(L"Content Error", L"menu")+L":\n"+
|
||||
util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return false;
|
||||
|
||||
@ -23,8 +23,11 @@ std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scripten
|
||||
return reader.readXML("[string]", source);
|
||||
}
|
||||
|
||||
void guiutil::alert(GUI* gui, const std::wstring& text, const runnable& on_hidden) {
|
||||
auto menu = gui->getMenu();
|
||||
void guiutil::alert(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
const std::wstring& text,
|
||||
const runnable& on_hidden
|
||||
) {
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(500, 300), glm::vec4(8.0f), 8.0f);
|
||||
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
|
||||
@ -47,7 +50,7 @@ void guiutil::alert(GUI* gui, const std::wstring& text, const runnable& on_hidde
|
||||
}
|
||||
|
||||
void guiutil::confirm(
|
||||
GUI* gui,
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
const std::wstring& text,
|
||||
const runnable& on_confirm,
|
||||
std::wstring yestext,
|
||||
@ -55,7 +58,6 @@ void guiutil::confirm(
|
||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||
if (notext.empty()) notext = langs::get(L"No");
|
||||
|
||||
auto menu = gui->getMenu();
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(600, 200), glm::vec4(8.0f), 8.0f);
|
||||
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
panel->add(std::make_shared<Label>(text));
|
||||
@ -79,8 +81,8 @@ void guiutil::confirm(
|
||||
menu->setPage("<confirm>");
|
||||
}
|
||||
|
||||
void guiutil::confirmWithMemo(
|
||||
gui::GUI* gui,
|
||||
void guiutil::confirm_with_memo(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
const std::wstring& text,
|
||||
const std::wstring& memo,
|
||||
const runnable& on_confirm,
|
||||
@ -90,7 +92,6 @@ void guiutil::confirmWithMemo(
|
||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||
if (notext.empty()) notext = langs::get(L"No");
|
||||
|
||||
auto menu = gui->getMenu();
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(600, 500), glm::vec4(8.0f), 8.0f);
|
||||
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
panel->add(std::make_shared<Label>(text));
|
||||
|
||||
@ -13,20 +13,20 @@ namespace guiutil {
|
||||
std::shared_ptr<gui::UINode> create(const std::string& source, scriptenv env=0);
|
||||
|
||||
void alert(
|
||||
gui::GUI* gui,
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
const std::wstring& text,
|
||||
const runnable& on_hidden=nullptr
|
||||
);
|
||||
|
||||
void confirm(
|
||||
gui::GUI* gui,
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
const std::wstring& text,
|
||||
const runnable& on_confirm=nullptr,
|
||||
std::wstring yestext=L"",
|
||||
std::wstring notext=L"");
|
||||
|
||||
void confirmWithMemo(
|
||||
gui::GUI* gui,
|
||||
void confirm_with_memo(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
const std::wstring& text,
|
||||
const std::wstring& memo,
|
||||
const runnable& on_confirm=nullptr,
|
||||
|
||||
@ -33,7 +33,7 @@ EngineController::EngineController(Engine& engine) : engine(engine) {
|
||||
void EngineController::deleteWorld(const std::string& name) {
|
||||
fs::path folder = engine.getPaths().getWorldFolderByName(name);
|
||||
guiutil::confirm(
|
||||
engine.getGUI(),
|
||||
engine.getGUI()->getMenu(),
|
||||
langs::get(L"delete-confirm", L"world") + L" (" +
|
||||
util::str2wstr_utf8(folder.u8string()) + L")",
|
||||
[=]() {
|
||||
@ -100,8 +100,8 @@ static void show_convert_request(
|
||||
for (const auto& line : report->getDataLoss()) {
|
||||
text += util::str2wstr_utf8(line) + L"\n";
|
||||
}
|
||||
guiutil::confirmWithMemo(
|
||||
engine.getGUI(),
|
||||
guiutil::confirm_with_memo(
|
||||
engine.getGUI()->getMenu(),
|
||||
langs::get(message),
|
||||
text,
|
||||
on_confirm,
|
||||
@ -111,7 +111,7 @@ static void show_convert_request(
|
||||
return;
|
||||
}
|
||||
guiutil::confirm(
|
||||
engine.getGUI(),
|
||||
engine.getGUI()->getMenu(),
|
||||
langs::get(message),
|
||||
on_confirm,
|
||||
L"",
|
||||
@ -156,7 +156,7 @@ static void load_world(
|
||||
engine.onWorldOpen(std::move(level));
|
||||
} catch (const world_load_error& error) {
|
||||
guiutil::alert(
|
||||
engine.getGUI(),
|
||||
engine.getGUI()->getMenu(),
|
||||
langs::get(L"Error") + L": " + util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return;
|
||||
@ -326,7 +326,7 @@ void EngineController::reconfigPacks(
|
||||
|
||||
if (hasIndices) {
|
||||
guiutil::confirm(
|
||||
engine.getGUI(),
|
||||
engine.getGUI()->getMenu(),
|
||||
langs::get(L"remove-confirm", L"pack") + L" (" +
|
||||
util::str2wstr_utf8(ss.str()) + L")",
|
||||
[=]() { removeFunc(); }
|
||||
|
||||
@ -100,32 +100,23 @@ static int l_delete_world(lua::State* L) {
|
||||
/// @param remPacks An array of packs to remove
|
||||
static int l_reconfig_packs(lua::State* L) {
|
||||
if (!lua::istable(L, 1)) {
|
||||
throw std::runtime_error("strings array expected as the first argument"
|
||||
);
|
||||
throw std::runtime_error("strings array expected as the first argument");
|
||||
}
|
||||
if (!lua::istable(L, 2)) {
|
||||
throw std::runtime_error("strings array expected as the second argument"
|
||||
);
|
||||
throw std::runtime_error("strings array expected as the second argument");
|
||||
}
|
||||
std::vector<std::string> addPacks;
|
||||
if (!lua::istable(L, 1)) {
|
||||
throw std::runtime_error("an array expected as argument 1");
|
||||
}
|
||||
int addLen = lua::objlen(L, 1);
|
||||
for (int i = 0; i < addLen; i++) {
|
||||
lua::rawgeti(L, i + 1, 1);
|
||||
addPacks.emplace_back(lua::tostring(L, -1));
|
||||
addPacks.emplace_back(lua::require_lstring(L, -1));
|
||||
lua::pop(L);
|
||||
}
|
||||
|
||||
std::vector<std::string> remPacks;
|
||||
if (!lua::istable(L, 2)) {
|
||||
throw std::runtime_error("an array expected as argument 2");
|
||||
}
|
||||
int remLen = lua::objlen(L, 2);
|
||||
for (int i = 0; i < remLen; i++) {
|
||||
lua::rawgeti(L, i + 1, 2);
|
||||
remPacks.emplace_back(lua::tostring(L, -1));
|
||||
remPacks.emplace_back(lua::require_lstring(L, -1));
|
||||
lua::pop(L);
|
||||
}
|
||||
auto engineController = engine->getController();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user