add gui.alert & critical fixes
This commit is contained in:
@@ -27,12 +27,22 @@ std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scripten
|
||||
}
|
||||
|
||||
void guiutil::alert(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
Engine& engine,
|
||||
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));
|
||||
|
||||
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);
|
||||
label->setMultiline(true);
|
||||
@@ -41,13 +51,18 @@ void guiutil::alert(
|
||||
panel->add(std::make_shared<Button>(
|
||||
langs::get(L"Ok"), glm::vec4(10.f),
|
||||
[=](GUI*) {
|
||||
if (on_hidden) {
|
||||
on_hidden();
|
||||
}
|
||||
menu->back();
|
||||
on_hidden_final();
|
||||
}
|
||||
));
|
||||
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->setPage("<alert>");
|
||||
}
|
||||
@@ -74,21 +89,19 @@ void guiutil::confirm(
|
||||
runnable on_confirm_final = [on_confirm, menu, &engine]() {
|
||||
if (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]() {
|
||||
if (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*){
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace guiutil {
|
||||
std::shared_ptr<gui::UINode> create(const std::string& source, scriptenv env=0);
|
||||
|
||||
void alert(
|
||||
const std::shared_ptr<gui::Menu>& menu,
|
||||
Engine& engine,
|
||||
const std::wstring& text,
|
||||
const runnable& on_hidden=nullptr
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user