fix gui.alert
This commit is contained in:
parent
9443892406
commit
b12982655d
@ -37,7 +37,10 @@ local function complete_app_lib(app)
|
|||||||
app.tick = coroutine.yield
|
app.tick = coroutine.yield
|
||||||
app.get_version = core.get_version
|
app.get_version = core.get_version
|
||||||
app.get_setting_info = core.get_setting_info
|
app.get_setting_info = core.get_setting_info
|
||||||
app.load_content = core.load_content
|
app.load_content = function()
|
||||||
|
core.load_content()
|
||||||
|
app.tick()
|
||||||
|
end
|
||||||
app.reset_content = core.reset_content
|
app.reset_content = core.reset_content
|
||||||
app.is_content_loaded = core.is_content_loaded
|
app.is_content_loaded = core.is_content_loaded
|
||||||
|
|
||||||
@ -416,7 +419,18 @@ end
|
|||||||
|
|
||||||
function start_coroutine(chunk, name)
|
function start_coroutine(chunk, name)
|
||||||
local co = coroutine.create(function()
|
local co = coroutine.create(function()
|
||||||
local status, error = xpcall(chunk, __vc__error)
|
local status, error = xpcall(chunk, function(...)
|
||||||
|
gui.alert(debug.traceback(), function()
|
||||||
|
if world.is_open() then
|
||||||
|
__vc_app.close_world()
|
||||||
|
else
|
||||||
|
__vc_app.reset_content()
|
||||||
|
menu:reset()
|
||||||
|
menu.page = "main"
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return ...
|
||||||
|
end)
|
||||||
if not status then
|
if not status then
|
||||||
debug.error(error)
|
debug.error(error)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -34,13 +34,14 @@ void guiutil::alert(
|
|||||||
auto panel = std::make_shared<Panel>(glm::vec2(500, 300), glm::vec4(4.0f), 4.0f);
|
auto panel = std::make_shared<Panel>(glm::vec2(500, 300), glm::vec4(4.0f), 4.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();
|
auto menuPtr = engine.getGUI()->getMenu();
|
||||||
runnable on_hidden_final = [on_hidden, menu, &engine]() {
|
auto& menu = *menuPtr;
|
||||||
menu->removePage("<alert>");
|
runnable on_hidden_final = [on_hidden, &menu, &engine]() {
|
||||||
|
menu.removePage("<alert>");
|
||||||
if (on_hidden) {
|
if (on_hidden) {
|
||||||
on_hidden();
|
on_hidden();
|
||||||
} else {
|
} else {
|
||||||
menu->back();
|
menu.back();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,21 +51,21 @@ void guiutil::alert(
|
|||||||
panel->add(label);
|
panel->add(label);
|
||||||
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*) {
|
[on_hidden_final](GUI*) {
|
||||||
on_hidden_final();
|
on_hidden_final();
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
panel->refresh();
|
panel->refresh();
|
||||||
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([=](){
|
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([on_hidden_final](){
|
||||||
on_hidden_final();
|
on_hidden_final();
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([=](){
|
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([on_hidden_final](){
|
||||||
on_hidden_final();
|
on_hidden_final();
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
menu->addPage("<alert>", panel, true);
|
menu.addPage("<alert>", panel, true);
|
||||||
menu->setPage("<alert>");
|
menu.setPage("<alert>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void guiutil::confirm(
|
void guiutil::confirm(
|
||||||
|
|||||||
@ -22,6 +22,9 @@ namespace lua {
|
|||||||
|
|
||||||
inline void pop(lua::State* L, int n = 1) {
|
inline void pop(lua::State* L, int n = 1) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
if (n < 0) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
if (lua_gettop(L) < n) {
|
if (lua_gettop(L) < n) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,7 +86,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update() override {
|
void update() override {
|
||||||
if (lua::getglobal(L, "__vc_resume_coroutine")) {
|
if (id == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (lua::requireglobal(L, "__vc_resume_coroutine")) {
|
||||||
lua::pushinteger(L, id);
|
lua::pushinteger(L, id);
|
||||||
if (lua::call(L, 1)) {
|
if (lua::call(L, 1)) {
|
||||||
alive = lua::toboolean(L, -1);
|
alive = lua::toboolean(L, -1);
|
||||||
@ -102,10 +105,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void terminate() override {
|
void terminate() override {
|
||||||
if (lua::getglobal(L, "__vc_stop_coroutine")) {
|
lua::requireglobal(L, "__vc_stop_coroutine");
|
||||||
lua::pushinteger(L, id);
|
lua::pushinteger(L, id);
|
||||||
lua::pop(L, lua::call(L, 1));
|
lua::pop(L, lua::call(L, 1));
|
||||||
}
|
id = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user