mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-22 22:11:33 +00:00
Add functions to lua ui library to toggle HUD visibility, and check current status.
This commit is contained in:
parent
e1973f342e
commit
ac9cfc782a
7 changed files with 25 additions and 10 deletions
|
@ -229,7 +229,8 @@ namespace MWBase
|
||||||
virtual void unsetSelectedWeapon() = 0;
|
virtual void unsetSelectedWeapon() = 0;
|
||||||
|
|
||||||
virtual void showCrosshair(bool show) = 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 disallowMouse() = 0;
|
||||||
virtual void allowMouse() = 0;
|
virtual void allowMouse() = 0;
|
||||||
|
|
|
@ -1605,9 +1605,9 @@ namespace MWGui
|
||||||
mQuickKeysMenu->activateQuickKey(index);
|
mQuickKeysMenu->activateQuickKey(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowManager::toggleHud()
|
bool WindowManager::setHudVisibility(bool show)
|
||||||
{
|
{
|
||||||
mHudEnabled = !mHudEnabled;
|
mHudEnabled = show;
|
||||||
updateVisible();
|
updateVisible();
|
||||||
mMessageBoxManager->setVisible(mHudEnabled);
|
mMessageBoxManager->setVisible(mHudEnabled);
|
||||||
return mHudEnabled;
|
return mHudEnabled;
|
||||||
|
|
|
@ -247,7 +247,8 @@ namespace MWGui
|
||||||
void showCrosshair(bool show) override;
|
void showCrosshair(bool show) override;
|
||||||
|
|
||||||
/// Turn visibility of HUD on or off
|
/// 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 disallowMouse() override;
|
||||||
void allowMouse() override;
|
void allowMouse() override;
|
||||||
|
|
|
@ -118,7 +118,7 @@ namespace MWInput
|
||||||
quickKey(10);
|
quickKey(10);
|
||||||
break;
|
break;
|
||||||
case A_ToggleHUD:
|
case A_ToggleHUD:
|
||||||
windowManager->toggleHud();
|
windowManager->setHudVisibility(!windowManager->isHudVisible());
|
||||||
break;
|
break;
|
||||||
case A_ToggleDebug:
|
case A_ToggleDebug:
|
||||||
windowManager->toggleDebugWindow();
|
windowManager->toggleDebugWindow();
|
||||||
|
|
|
@ -111,6 +111,10 @@ namespace MWLua
|
||||||
};
|
};
|
||||||
|
|
||||||
sol::table api = context.mLua->newTable();
|
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"]
|
api["showMessage"]
|
||||||
= [luaManager = context.mLuaManager](std::string_view message) { luaManager->addUIMessage(message); };
|
= [luaManager = context.mLuaManager](std::string_view message) { luaManager->addUIMessage(message); };
|
||||||
api["CONSOLE_COLOR"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string, Misc::Color>({
|
api["CONSOLE_COLOR"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string, Misc::Color>({
|
||||||
|
@ -296,7 +300,6 @@ namespace MWLua
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// api["_showHUD"] = [](bool) {};
|
|
||||||
// api["_showMouseCursor"] = [](bool) {};
|
// api["_showMouseCursor"] = [](bool) {};
|
||||||
|
|
||||||
return LuaUtil::makeReadOnly(api);
|
return LuaUtil::makeReadOnly(api);
|
||||||
|
|
|
@ -192,7 +192,8 @@ namespace MWScript
|
||||||
public:
|
public:
|
||||||
void execute(Interpreter::Runtime& runtime) override
|
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");
|
runtime.getContext().report(state ? "GUI -> On" : "GUI -> Off");
|
||||||
|
|
||||||
if (!state)
|
if (!state)
|
||||||
|
|
|
@ -226,12 +226,21 @@ return {
|
||||||
-- @function [parent=#UI] setPauseOnMode
|
-- @function [parent=#UI] setPauseOnMode
|
||||||
-- @param #string mode Mode to configure
|
-- @param #string mode Mode to configure
|
||||||
-- @param #boolean shouldPause
|
-- @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
|
-- TODO
|
||||||
-- registerHudElement = function(name, showFn, hideFn) end,
|
-- registerHudElement = function(name, showFn, hideFn) end,
|
||||||
-- showHud = function(bool) end,
|
|
||||||
-- isHudVisible = function() end,
|
|
||||||
-- showHudElement = function(name, bool) end,
|
-- showHudElement = function(name, bool) end,
|
||||||
-- hudElements, -- map from element name to its visibility
|
-- hudElements, -- map from element name to its visibility
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue