add gui.alert & critical fixes
This commit is contained in:
parent
b9ff1db086
commit
a3d35cd10f
@ -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->getMenu(), langs::get(L"error.pack-not-found")+L": "+
|
engine, 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->getMenu(), langs::get(L"Assets Load Error", L"menu")+L":\n"+
|
engine, 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->getMenu(), util::str2wstr_utf8(error.errorLog()));
|
guiutil::alert(engine, 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->getMenu(), langs::get(L"Content Error", L"menu")+L":\n"+
|
engine, langs::get(L"Content Error", L"menu")+L":\n"+
|
||||||
util::str2wstr_utf8(error.what())
|
util::str2wstr_utf8(error.what())
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -27,13 +27,23 @@ std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scripten
|
|||||||
}
|
}
|
||||||
|
|
||||||
void guiutil::alert(
|
void guiutil::alert(
|
||||||
const std::shared_ptr<gui::Menu>& menu,
|
Engine& engine,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_hidden
|
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));
|
||||||
|
|
||||||
|
auto menu = engine.getGUI()->getMenu();
|
||||||
|
runnable on_hidden_final = [on_hidden, menu, &engine]() {
|
||||||
|
if (on_hidden) {
|
||||||
|
on_hidden();
|
||||||
|
} else {
|
||||||
|
menu->back();
|
||||||
|
}
|
||||||
|
menu->removePage("<alert>");
|
||||||
|
};
|
||||||
|
|
||||||
auto label = std::make_shared<Label>(text);
|
auto label = std::make_shared<Label>(text);
|
||||||
label->setMultiline(true);
|
label->setMultiline(true);
|
||||||
label->setSize(glm::vec2(1, 90));
|
label->setSize(glm::vec2(1, 90));
|
||||||
@ -41,13 +51,18 @@ void guiutil::alert(
|
|||||||
panel->add(std::make_shared<Button>(
|
panel->add(std::make_shared<Button>(
|
||||||
langs::get(L"Ok"), glm::vec4(10.f),
|
langs::get(L"Ok"), glm::vec4(10.f),
|
||||||
[=](GUI*) {
|
[=](GUI*) {
|
||||||
if (on_hidden) {
|
on_hidden_final();
|
||||||
on_hidden();
|
|
||||||
}
|
|
||||||
menu->back();
|
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
panel->refresh();
|
panel->refresh();
|
||||||
|
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([=](){
|
||||||
|
on_hidden_final();
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
|
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([=](){
|
||||||
|
on_hidden_final();
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
menu->addPage("<alert>", panel);
|
menu->addPage("<alert>", panel);
|
||||||
menu->setPage("<alert>");
|
menu->setPage("<alert>");
|
||||||
}
|
}
|
||||||
@ -74,21 +89,19 @@ void guiutil::confirm(
|
|||||||
runnable on_confirm_final = [on_confirm, menu, &engine]() {
|
runnable on_confirm_final = [on_confirm, menu, &engine]() {
|
||||||
if (on_confirm) {
|
if (on_confirm) {
|
||||||
on_confirm();
|
on_confirm();
|
||||||
}
|
} else {
|
||||||
menu->back();
|
menu->back();
|
||||||
engine.postRunnable([menu]() {
|
}
|
||||||
menu->removePage("<confirm>");
|
menu->removePage("<confirm>");
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
runnable on_deny_final = [on_deny, menu, &engine]() {
|
runnable on_deny_final = [on_deny, menu, &engine]() {
|
||||||
if (on_deny) {
|
if (on_deny) {
|
||||||
on_deny();
|
on_deny();
|
||||||
}
|
} else {
|
||||||
menu->back();
|
menu->back();
|
||||||
engine.postRunnable([menu]() {
|
}
|
||||||
menu->removePage("<confirm>");
|
menu->removePage("<confirm>");
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
subpanel->add(std::make_shared<Button>(yestext, glm::vec4(8.f), [=](GUI*){
|
subpanel->add(std::make_shared<Button>(yestext, glm::vec4(8.f), [=](GUI*){
|
||||||
|
|||||||
@ -15,7 +15,7 @@ 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(
|
||||||
const std::shared_ptr<gui::Menu>& menu,
|
Engine& engine,
|
||||||
const std::wstring& text,
|
const std::wstring& text,
|
||||||
const runnable& on_hidden=nullptr
|
const runnable& on_hidden=nullptr
|
||||||
);
|
);
|
||||||
|
|||||||
@ -151,7 +151,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()->getMenu(),
|
engine,
|
||||||
langs::get(L"Error") + L": " + util::str2wstr_utf8(error.what())
|
langs::get(L"Error") + L": " + util::str2wstr_utf8(error.what())
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -780,6 +780,17 @@ static int l_gui_confirm(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_gui_alert(lua::State* L) {
|
||||||
|
auto message = lua::require_wstring(L, 1);
|
||||||
|
runnable onconfirm = nullptr;
|
||||||
|
if (lua::gettop(L) >= 2) {
|
||||||
|
lua::pushvalue(L, 2);
|
||||||
|
onconfirm = lua::create_runnable(L);
|
||||||
|
}
|
||||||
|
guiutil::alert(*engine, message, onconfirm);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg guilib[] = {
|
const luaL_Reg guilib[] = {
|
||||||
{"get_viewport", lua::wrap<l_gui_getviewport>},
|
{"get_viewport", lua::wrap<l_gui_getviewport>},
|
||||||
{"getattr", lua::wrap<l_gui_getattr>},
|
{"getattr", lua::wrap<l_gui_getattr>},
|
||||||
@ -790,6 +801,7 @@ const luaL_Reg guilib[] = {
|
|||||||
{"clear_markup", lua::wrap<l_gui_clear_markup>},
|
{"clear_markup", lua::wrap<l_gui_clear_markup>},
|
||||||
{"escape_markup", lua::wrap<l_gui_escape_markup>},
|
{"escape_markup", lua::wrap<l_gui_escape_markup>},
|
||||||
{"confirm", lua::wrap<l_gui_confirm>},
|
{"confirm", lua::wrap<l_gui_confirm>},
|
||||||
|
{"alert", lua::wrap<l_gui_alert>},
|
||||||
{"__reindex", lua::wrap<l_gui_reindex>},
|
{"__reindex", lua::wrap<l_gui_reindex>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -241,8 +241,9 @@ runnable lua::create_runnable(State* L) {
|
|||||||
return [=]() {
|
return [=]() {
|
||||||
getglobal(L, LAMBDAS_TABLE);
|
getglobal(L, LAMBDAS_TABLE);
|
||||||
getfield(L, *funcptr);
|
getfield(L, *funcptr);
|
||||||
call_nothrow(L, 0);
|
if (call_nothrow(L, 0)) {
|
||||||
pop(L);
|
pop(L);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,10 +254,9 @@ supplier<bool> lua::create_simple_handler(State* L) {
|
|||||||
getfield(L, *funcptr);
|
getfield(L, *funcptr);
|
||||||
if (call_nothrow(L, 0)) {
|
if (call_nothrow(L, 0)) {
|
||||||
bool result = toboolean(L, -1);
|
bool result = toboolean(L, -1);
|
||||||
pop(L, 2);
|
pop(L);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
pop(L);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -12,7 +12,7 @@ namespace util {
|
|||||||
int nextid = 1;
|
int nextid = 1;
|
||||||
std::unordered_map<int, std::function<bool(Types...)>> handlers;
|
std::unordered_map<int, std::function<bool(Types...)>> handlers;
|
||||||
std::vector<int> order;
|
std::vector<int> order;
|
||||||
std::mutex mutex;
|
std::recursive_mutex mutex;
|
||||||
public:
|
public:
|
||||||
HandlersList() = default;
|
HandlersList() = default;
|
||||||
|
|
||||||
@ -45,7 +45,9 @@ namespace util {
|
|||||||
|
|
||||||
void notify(Types...args) {
|
void notify(Types...args) {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
for (auto it = order.rbegin(); it != order.rend(); ++it) {
|
|
||||||
|
auto orderCopy = order;
|
||||||
|
for (auto it = orderCopy.rbegin(); it != orderCopy.rend(); ++it) {
|
||||||
if (handlers.at(*it)(args...)) {
|
if (handlers.at(*it)(args...)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user