Skip to content

Commit

Permalink
Merge branch 'lua_hud_hide' into 'master'
Browse files Browse the repository at this point in the history
Add functions to lua ui library to toggle HUD visibility, and check current status.

See merge request OpenMW/openmw!3450
  • Loading branch information
psi29a committed Oct 25, 2023
2 parents 08da357 + ac9cfc7 commit f3931c8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion apps/openmw/mwbase/windowmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwgui/windowmanagerimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion apps/openmw/mwgui/windowmanagerimp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwinput/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace MWInput
quickKey(10);
break;
case A_ToggleHUD:
windowManager->toggleHud();
windowManager->setHudVisibility(!windowManager->isHudVisible());
break;
case A_ToggleDebug:
windowManager->toggleDebugWindow();
Expand Down
5 changes: 4 additions & 1 deletion apps/openmw/mwlua/uibindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>({
Expand Down Expand Up @@ -296,7 +300,6 @@ namespace MWLua
};

// TODO
// api["_showHUD"] = [](bool) {};
// api["_showMouseCursor"] = [](bool) {};

return LuaUtil::makeReadOnly(api);
Expand Down
3 changes: 2 additions & 1 deletion apps/openmw/mwscript/guiextensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions files/data/scripts/omw/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit f3931c8

Please sign in to comment.