lua: hud.pause/resume + menu:back() method
This commit is contained in:
@@ -545,6 +545,10 @@ void Hud::setPause(bool pause) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->pause = pause;
|
this->pause = pause;
|
||||||
|
|
||||||
|
if (inventoryOpen) {
|
||||||
|
closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
auto menu = gui->getMenu();
|
auto menu = gui->getMenu();
|
||||||
if (pause) {
|
if (pause) {
|
||||||
|
|||||||
@@ -104,16 +104,6 @@ static bool getattr(lua_State* L, gui::FullCheckBox* box, const std::string& att
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool getattr(lua_State* L, gui::PagesControl* menu, const std::string& attr) {
|
|
||||||
if (menu == nullptr)
|
|
||||||
return false;
|
|
||||||
if (attr == "page") {
|
|
||||||
lua_pushstring(L, menu->getCurrentName().c_str());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool getattr(lua_State* L, gui::TextBox* box, const std::string& attr) {
|
static bool getattr(lua_State* L, gui::TextBox* box, const std::string& attr) {
|
||||||
if (box == nullptr)
|
if (box == nullptr)
|
||||||
return false;
|
return false;
|
||||||
@@ -127,6 +117,32 @@ static bool getattr(lua_State* L, gui::TextBox* box, const std::string& attr) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int menu_back(lua_State* L) {
|
||||||
|
lua_getfield(L, 1, "docname");
|
||||||
|
lua_getfield(L, 1, "name");
|
||||||
|
auto docname = lua_tostring(L, -2);
|
||||||
|
auto name = lua_tostring(L, -1);
|
||||||
|
auto node = getDocumentNode(L, docname, name);
|
||||||
|
lua_pop(L, 2);
|
||||||
|
|
||||||
|
auto menu = dynamic_cast<gui::PagesControl*>(node);
|
||||||
|
menu->back();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool getattr(lua_State* L, gui::PagesControl* menu, const std::string& attr) {
|
||||||
|
if (menu == nullptr)
|
||||||
|
return false;
|
||||||
|
if (attr == "page") {
|
||||||
|
lua_pushstring(L, menu->getCurrentName().c_str());
|
||||||
|
return true;
|
||||||
|
} else if (attr == "back") {
|
||||||
|
lua_pushcfunction(L, menu_back);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool setattr(lua_State* L, gui::FullCheckBox* box, const std::string& attr) {
|
static bool setattr(lua_State* L, gui::FullCheckBox* box, const std::string& attr) {
|
||||||
if (box == nullptr)
|
if (box == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -99,6 +99,16 @@ static int l_hud_close(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_hud_pause(lua_State* L) {
|
||||||
|
scripting::hud->setPause(true);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_hud_resume(lua_State* L) {
|
||||||
|
scripting::hud->setPause(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg hudlib [] = {
|
const luaL_Reg hudlib [] = {
|
||||||
{"open_inventory", lua_wrap_errors<l_hud_open_inventory>},
|
{"open_inventory", lua_wrap_errors<l_hud_open_inventory>},
|
||||||
{"close_inventory", lua_wrap_errors<l_hud_close_inventory>},
|
{"close_inventory", lua_wrap_errors<l_hud_close_inventory>},
|
||||||
@@ -106,5 +116,7 @@ const luaL_Reg hudlib [] = {
|
|||||||
{"open_permanent", lua_wrap_errors<l_hud_open_permanent>},
|
{"open_permanent", lua_wrap_errors<l_hud_open_permanent>},
|
||||||
{"show_overlay", lua_wrap_errors<l_hud_show_overlay>},
|
{"show_overlay", lua_wrap_errors<l_hud_show_overlay>},
|
||||||
{"close", lua_wrap_errors<l_hud_close>},
|
{"close", lua_wrap_errors<l_hud_close>},
|
||||||
|
{"pause", lua_wrap_errors<l_hud_pause>},
|
||||||
|
{"resume", lua_wrap_errors<l_hud_resume>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user