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));
|
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||||
// could not to find or read pack
|
// could not to find or read pack
|
||||||
guiutil::alert(
|
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())
|
util::str2wstr_utf8(error.getPackId())
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
} catch (const assetload::error& error) {
|
} catch (const assetload::error& error) {
|
||||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||||
guiutil::alert(
|
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())
|
util::str2wstr_utf8(error.what())
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
} catch (const parsing_error& error) {
|
} catch (const parsing_error& error) {
|
||||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
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;
|
return false;
|
||||||
} catch (const std::runtime_error& error) {
|
} catch (const std::runtime_error& error) {
|
||||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||||
guiutil::alert(
|
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())
|
util::str2wstr_utf8(error.what())
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -23,8 +23,11 @@ std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scripten
|
|||||||
return reader.readXML("[string]", source);
|
return reader.readXML("[string]", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void guiutil::alert(GUI* gui, const std::wstring& text, const runnable& on_hidden) {
|
void guiutil::alert(
|
||||||
auto menu = gui->getMenu();
|
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);
|
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));
|
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(
|
void guiutil::confirm(
|
||||||
GUI* gui,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_confirm,
|
const runnable& on_confirm,
|
||||||
std::wstring yestext,
|
std::wstring yestext,
|
||||||
@ -55,7 +58,6 @@ void guiutil::confirm(
|
|||||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||||
if (notext.empty()) notext = langs::get(L"No");
|
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);
|
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->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||||
panel->add(std::make_shared<Label>(text));
|
panel->add(std::make_shared<Label>(text));
|
||||||
@ -79,8 +81,8 @@ void guiutil::confirm(
|
|||||||
menu->setPage("<confirm>");
|
menu->setPage("<confirm>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void guiutil::confirmWithMemo(
|
void guiutil::confirm_with_memo(
|
||||||
gui::GUI* gui,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const std::wstring& memo,
|
const std::wstring& memo,
|
||||||
const runnable& on_confirm,
|
const runnable& on_confirm,
|
||||||
@ -90,7 +92,6 @@ void guiutil::confirmWithMemo(
|
|||||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||||
if (notext.empty()) notext = langs::get(L"No");
|
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);
|
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->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||||
panel->add(std::make_shared<Label>(text));
|
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);
|
std::shared_ptr<gui::UINode> create(const std::string& source, scriptenv env=0);
|
||||||
|
|
||||||
void alert(
|
void alert(
|
||||||
gui::GUI* gui,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_hidden=nullptr
|
const runnable& on_hidden=nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
void confirm(
|
void confirm(
|
||||||
gui::GUI* gui,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_confirm=nullptr,
|
const runnable& on_confirm=nullptr,
|
||||||
std::wstring yestext=L"",
|
std::wstring yestext=L"",
|
||||||
std::wstring notext=L"");
|
std::wstring notext=L"");
|
||||||
|
|
||||||
void confirmWithMemo(
|
void confirm_with_memo(
|
||||||
gui::GUI* gui,
|
const std::shared_ptr<gui::Menu>& menu,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const std::wstring& memo,
|
const std::wstring& memo,
|
||||||
const runnable& on_confirm=nullptr,
|
const runnable& on_confirm=nullptr,
|
||||||
|
|||||||
@ -33,7 +33,7 @@ EngineController::EngineController(Engine& engine) : engine(engine) {
|
|||||||
void EngineController::deleteWorld(const std::string& name) {
|
void EngineController::deleteWorld(const std::string& name) {
|
||||||
fs::path folder = engine.getPaths().getWorldFolderByName(name);
|
fs::path folder = engine.getPaths().getWorldFolderByName(name);
|
||||||
guiutil::confirm(
|
guiutil::confirm(
|
||||||
engine.getGUI(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(L"delete-confirm", L"world") + L" (" +
|
langs::get(L"delete-confirm", L"world") + L" (" +
|
||||||
util::str2wstr_utf8(folder.u8string()) + L")",
|
util::str2wstr_utf8(folder.u8string()) + L")",
|
||||||
[=]() {
|
[=]() {
|
||||||
@ -100,8 +100,8 @@ static void show_convert_request(
|
|||||||
for (const auto& line : report->getDataLoss()) {
|
for (const auto& line : report->getDataLoss()) {
|
||||||
text += util::str2wstr_utf8(line) + L"\n";
|
text += util::str2wstr_utf8(line) + L"\n";
|
||||||
}
|
}
|
||||||
guiutil::confirmWithMemo(
|
guiutil::confirm_with_memo(
|
||||||
engine.getGUI(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(message),
|
langs::get(message),
|
||||||
text,
|
text,
|
||||||
on_confirm,
|
on_confirm,
|
||||||
@ -111,7 +111,7 @@ static void show_convert_request(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
guiutil::confirm(
|
guiutil::confirm(
|
||||||
engine.getGUI(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(message),
|
langs::get(message),
|
||||||
on_confirm,
|
on_confirm,
|
||||||
L"",
|
L"",
|
||||||
@ -156,7 +156,7 @@ static void load_world(
|
|||||||
engine.onWorldOpen(std::move(level));
|
engine.onWorldOpen(std::move(level));
|
||||||
} catch (const world_load_error& error) {
|
} catch (const world_load_error& error) {
|
||||||
guiutil::alert(
|
guiutil::alert(
|
||||||
engine.getGUI(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(L"Error") + L": " + util::str2wstr_utf8(error.what())
|
langs::get(L"Error") + L": " + util::str2wstr_utf8(error.what())
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -326,7 +326,7 @@ void EngineController::reconfigPacks(
|
|||||||
|
|
||||||
if (hasIndices) {
|
if (hasIndices) {
|
||||||
guiutil::confirm(
|
guiutil::confirm(
|
||||||
engine.getGUI(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(L"remove-confirm", L"pack") + L" (" +
|
langs::get(L"remove-confirm", L"pack") + L" (" +
|
||||||
util::str2wstr_utf8(ss.str()) + L")",
|
util::str2wstr_utf8(ss.str()) + L")",
|
||||||
[=]() { removeFunc(); }
|
[=]() { removeFunc(); }
|
||||||
|
|||||||
@ -100,32 +100,23 @@ static int l_delete_world(lua::State* L) {
|
|||||||
/// @param remPacks An array of packs to remove
|
/// @param remPacks An array of packs to remove
|
||||||
static int l_reconfig_packs(lua::State* L) {
|
static int l_reconfig_packs(lua::State* L) {
|
||||||
if (!lua::istable(L, 1)) {
|
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)) {
|
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;
|
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);
|
int addLen = lua::objlen(L, 1);
|
||||||
for (int i = 0; i < addLen; i++) {
|
for (int i = 0; i < addLen; i++) {
|
||||||
lua::rawgeti(L, i + 1, 1);
|
lua::rawgeti(L, i + 1, 1);
|
||||||
addPacks.emplace_back(lua::tostring(L, -1));
|
addPacks.emplace_back(lua::require_lstring(L, -1));
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> remPacks;
|
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);
|
int remLen = lua::objlen(L, 2);
|
||||||
for (int i = 0; i < remLen; i++) {
|
for (int i = 0; i < remLen; i++) {
|
||||||
lua::rawgeti(L, i + 1, 2);
|
lua::rawgeti(L, i + 1, 2);
|
||||||
remPacks.emplace_back(lua::tostring(L, -1));
|
remPacks.emplace_back(lua::require_lstring(L, -1));
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
auto engineController = engine->getController();
|
auto engineController = engine->getController();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user