Merge branch 'lua_hud_hide' into 'master'

Add functions to lua ui library to toggle HUD visibility, and check current status.

See merge request OpenMW/openmw!3450
macos_ci_fix
psi29a 1 year ago
commit f3931c8321

@ -229,7 +229,8 @@ namespace MWBase
virtual void unsetSelectedWeapon() = 0;
virtual void showCrosshair(bool show) = 0;
virtual bool toggleHud() = 0;
virtual bool setHudVisibility(bool show) = 0;
virtual bool isHudVisible() const = 0;
virtual void disallowMouse() = 0;
virtual void allowMouse() = 0;

@ -1605,9 +1605,9 @@ namespace MWGui
mQuickKeysMenu->activateQuickKey(index);
}
bool WindowManager::toggleHud()
bool WindowManager::setHudVisibility(bool show)
{
mHudEnabled = !mHudEnabled;
mHudEnabled = show;
updateVisible();
mMessageBoxManager->setVisible(mHudEnabled);
return mHudEnabled;

@ -247,7 +247,8 @@ namespace MWGui
void showCrosshair(bool show) override;
/// Turn visibility of HUD on or off
bool toggleHud() override;
bool setHudVisibility(bool show) override;
bool isHudVisible() const override { return mHudEnabled; }
void disallowMouse() override;
void allowMouse() override;

@ -118,7 +118,7 @@ namespace MWInput
quickKey(10);
break;
case A_ToggleHUD:
windowManager->toggleHud();
windowManager->setHudVisibility(!windowManager->isHudVisible());
break;
case A_ToggleDebug:
windowManager->toggleDebugWindow();

@ -111,6 +111,10 @@ namespace MWLua
};
sol::table api = context.mLua->newTable();
api["_setHudVisibility"] = [luaManager = context.mLuaManager](bool state) {
luaManager->addAction([state] { MWBase::Environment::get().getWindowManager()->setHudVisibility(state); });
};
api["_isHudVisible"] = []() -> bool { return MWBase::Environment::get().getWindowManager()->isHudVisible(); };
api["showMessage"]
= [luaManager = context.mLuaManager](std::string_view message) { luaManager->addUIMessage(message); };
api["CONSOLE_COLOR"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string, Misc::Color>({
@ -296,7 +300,6 @@ namespace MWLua
};
// TODO
// api["_showHUD"] = [](bool) {};
// api["_showMouseCursor"] = [](bool) {};
return LuaUtil::makeReadOnly(api);

@ -192,7 +192,8 @@ namespace MWScript
public:
void execute(Interpreter::Runtime& runtime) override
{
bool state = MWBase::Environment::get().getWindowManager()->toggleHud();
bool state = MWBase::Environment::get().getWindowManager()->setHudVisibility(
!MWBase::Environment::get().getWindowManager()->isHudVisible());
runtime.getContext().report(state ? "GUI -> On" : "GUI -> Off");
if (!state)

@ -226,12 +226,21 @@ return {
-- @function [parent=#UI] setPauseOnMode
-- @param #string mode Mode to configure
-- @param #boolean shouldPause
setPauseOnMode = function(mode, shouldPause) modePause[mode] = shouldPause end
setPauseOnMode = function(mode, shouldPause) modePause[mode] = shouldPause end,
--- Set whether the UI should be visible.
-- @function [parent=#UI] setHudVisibility
-- @param #boolean showHud
setHudVisibility = function(showHud) ui._setHudVisibility(showHud) end,
---
-- Returns if the player HUD is visible or not
-- @function [parent=#UI] isHudVisible
-- @return #bool
isHudVisible = function() return ui._isHudVisible() end,
-- TODO
-- registerHudElement = function(name, showFn, hideFn) end,
-- showHud = function(bool) end,
-- isHudVisible = function() end,
-- showHudElement = function(name, bool) end,
-- hudElements, -- map from element name to its visibility
},

Loading…
Cancel
Save