1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-12 16:13:06 +00:00

Merge branch 'windowvisiblelua' into 'master'

lua - add binding to check window visibility

Closes #8355

See merge request OpenMW/openmw!4543
This commit is contained in:
Alexei Kotov 2025-07-05 09:57:50 +03:00
commit a6503233a6
6 changed files with 28 additions and 2 deletions

View file

@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
set(OPENMW_VERSION_MAJOR 0)
set(OPENMW_VERSION_MINOR 50)
set(OPENMW_VERSION_RELEASE 0)
set(OPENMW_LUA_API_REVISION 78)
set(OPENMW_LUA_API_REVISION 79)
set(OPENMW_POSTPROCESSING_API_REVISION 2)
set(OPENMW_VERSION_COMMITHASH "")

View file

@ -384,6 +384,7 @@ namespace MWBase
// Used in Lua bindings
virtual const std::vector<MWGui::GuiMode>& getGuiModeStack() const = 0;
virtual void setDisabledByLua(std::string_view windowId, bool disabled) = 0;
virtual bool isWindowVisible(std::string_view windowId) const = 0;
virtual std::vector<std::string_view> getAllWindowIds() const = 0;
virtual std::vector<std::string_view> getAllowedWindowIds(MWGui::GuiMode mode) const = 0;
};

View file

@ -2406,6 +2406,14 @@ namespace MWGui
updateVisible();
}
bool WindowManager::isWindowVisible(std::string_view windowId) const
{
auto it = mLuaIdToWindow.find(windowId);
if (it == mLuaIdToWindow.end())
throw std::logic_error("Invalid window name: " + std::string(windowId));
return it->second->isVisible();
}
std::vector<std::string_view> WindowManager::getAllWindowIds() const
{
std::vector<std::string_view> res;

View file

@ -390,6 +390,7 @@ namespace MWGui
// Used in Lua bindings
const std::vector<GuiMode>& getGuiModeStack() const override { return mGuiModes; }
void setDisabledByLua(std::string_view windowId, bool disabled) override;
bool isWindowVisible(std::string_view windowId) const override;
std::vector<std::string_view> getAllWindowIds() const override;
std::vector<std::string_view> getAllowedWindowIds(GuiMode mode) const override;

View file

@ -296,6 +296,8 @@ namespace MWLua
luaManager->addAction(
[=, window = std::move(window)]() { windowManager->setDisabledByLua(window, disabled); });
};
api["_isWindowVisible"]
= [windowManager](std::string_view window) { return windowManager->isWindowVisible(window); };
// TODO
// api["_showMouseCursor"] = [](bool) {};

View file

@ -155,6 +155,13 @@ local function onUiModeChangedEvent(data)
end
end
local function isWindowVisible(windowName)
if replacedWindows[windowName] then
return replacedWindows[windowName].visible
end
return ui._isWindowVisible(windowName)
end
return {
interfaceName = 'UI',
---
@ -164,7 +171,7 @@ return {
interface = {
--- Interface version
-- @field [parent=#UI] #number version
version = 1,
version = 2,
--- All available UI modes.
-- Use `view(I.UI.MODE)` in `luap` console mode to see the list.
@ -240,6 +247,13 @@ return {
-- @return #boolean
isHudVisible = function() return ui._isHudVisible() end,
---
-- Returns if the given window is visible or not
-- @function [parent=#UI] isWindowVisible
-- @param #string windowName
-- @return #boolean
isWindowVisible = isWindowVisible,
-- TODO
-- registerHudElement = function(name, showFn, hideFn) end,
-- showHudElement = function(name, bool) end,