Merge pull request #668 from MihailRis/add-hud-is-open
add hud.is_open(layoutid) -> bool
This commit is contained in:
commit
840c0f3c12
@ -20,6 +20,12 @@ hud.open(
|
||||
[optional] invid: int
|
||||
) -> int
|
||||
|
||||
-- Returns true if specified layout is open.
|
||||
hud.is_open(
|
||||
layoutid: str
|
||||
) -> bool
|
||||
|
||||
|
||||
-- Open block UI and inventory.
|
||||
-- Throws an exception if block has no UI layout.
|
||||
-- Returns block inventory ID (if *"inventory-size"=0* a virtual
|
||||
|
||||
@ -20,6 +20,10 @@ hud.open(
|
||||
[опционально] invid: int
|
||||
) -> int
|
||||
|
||||
-- Возвращает true если указаный макет UI открыт.
|
||||
hud.is_open(
|
||||
layoutid: str
|
||||
) -> bool
|
||||
|
||||
-- Открывает инвентарь и UI блока.
|
||||
-- Если блок не имеет макета UI - бросается исключение.
|
||||
|
||||
@ -756,3 +756,13 @@ void Hud::setAllowPause(bool flag) {
|
||||
}
|
||||
allowPause = flag;
|
||||
}
|
||||
|
||||
bool Hud::isOpen(const std::string& layoutid) const {
|
||||
for (const auto& element : elements) {
|
||||
auto doc = element.getDocument();
|
||||
if (doc && doc->getId() == layoutid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -213,6 +213,8 @@ public:
|
||||
|
||||
void setAllowPause(bool flag);
|
||||
|
||||
bool isOpen(const std::string& layoutid) const;
|
||||
|
||||
static bool showGeneratorMinimap;
|
||||
|
||||
/// @brief Runtime updating debug visualization texture
|
||||
|
||||
@ -189,6 +189,11 @@ static int l_reload_script(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_open(lua::State* L) {
|
||||
auto layoutid = lua::require_string(L, 1);
|
||||
return lua::pushboolean(L, hud->isOpen(layoutid));
|
||||
}
|
||||
|
||||
const luaL_Reg hudlib[] = {
|
||||
{"open_inventory", wrap_hud<l_open_inventory>},
|
||||
{"close_inventory", wrap_hud<l_close_inventory>},
|
||||
@ -208,5 +213,6 @@ const luaL_Reg hudlib[] = {
|
||||
{"_set_debug_cheats", wrap_hud<l_set_debug_cheats>},
|
||||
{"set_allow_pause", wrap_hud<l_set_allow_pause>},
|
||||
{"reload_script", wrap_hud<l_reload_script>},
|
||||
{"is_open", wrap_hud<l_is_open>},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user