1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 15:09:39 +00:00

Control UI pause from Lua

This commit is contained in:
Petr Mikheev 2023-09-03 02:45:18 +02:00
parent b4c8b8308f
commit 23a7661d0b
9 changed files with 65 additions and 7 deletions

View file

@ -134,8 +134,8 @@ namespace MWBase
virtual bool isGuiMode() const = 0;
virtual bool isConsoleMode() const = 0;
virtual bool isPostProcessorHudVisible() const = 0;
virtual bool isInteractiveMessageBoxActive() const = 0;
virtual void toggleVisible(MWGui::GuiWindow wnd) = 0;

View file

@ -1539,8 +1539,7 @@ namespace MWGui
bool WindowManager::isGuiMode() const
{
return !mGuiModes.empty() || isConsoleMode() || (mPostProcessorHud && mPostProcessorHud->isVisible())
|| (mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox());
return !mGuiModes.empty() || isConsoleMode() || isPostProcessorHudVisible() || isInteractiveMessageBoxActive();
}
bool WindowManager::isConsoleMode() const
@ -1550,7 +1549,12 @@ namespace MWGui
bool WindowManager::isPostProcessorHudVisible() const
{
return mPostProcessorHud->isVisible();
return mPostProcessorHud && mPostProcessorHud->isVisible();
}
bool WindowManager::isInteractiveMessageBoxActive() const
{
return mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox();
}
MWGui::GuiMode WindowManager::getMode() const

View file

@ -160,8 +160,8 @@ namespace MWGui
bool isGuiMode() const override;
bool isConsoleMode() const override;
bool isPostProcessorHudVisible() const override;
bool isInteractiveMessageBoxActive() const override;
void toggleVisible(GuiWindow wnd) override;

View file

@ -263,6 +263,8 @@ namespace MWWorld
void DateTimeManager::updateIsPaused()
{
mPaused = !mPausedTags.empty() || MWBase::Environment::get().getWindowManager()->isGuiMode();
auto wm = MWBase::Environment::get().getWindowManager();
mPaused = !mPausedTags.empty() || wm->isConsoleMode() || wm->isPostProcessorHudVisible()
|| wm->isInteractiveMessageBoxActive();
}
}

View file

@ -42,3 +42,22 @@ and ``arg`` (for example in the mode ``Book`` the argument is the book the playe
print('UiModeChanged from', data.oldMode , 'to', data.newMode, '('..tostring(data.arg)..')')
end
}
World events
------------
Global events that just call the corresponding function in `openmw.world`.
.. code-block:: Lua
-- world.pause(tag)
core.sendGlobalEvent('Pause', tag)
-- world.unpause(tag)
core.sendGlobalEvent('Unpause', tag)
-- world.setGameTimeScale(scale)
core.sendGlobalEvent('SetGameTimeScale', scale)
-- world.setSimulationTimeScale(scale)
core.sendGlobalEvent('SetSimulationTimeScale', scale)

View file

@ -91,6 +91,7 @@ set(BUILTIN_DATA_FILES
scripts/omw/mwui/init.lua
scripts/omw/ui.lua
scripts/omw/usehandlers.lua
scripts/omw/worldeventhandlers.lua
shaders/adjustments.omwfx
shaders/bloomlinear.omwfx

View file

@ -9,6 +9,7 @@ PLAYER: scripts/omw/settings/player.lua
GLOBAL: scripts/omw/activationhandlers.lua
GLOBAL: scripts/omw/cellhandlers.lua
GLOBAL: scripts/omw/usehandlers.lua
GLOBAL: scripts/omw/worldeventhandlers.lua
PLAYER: scripts/omw/mechanics/playercontroller.lua
PLAYER: scripts/omw/playercontrols.lua
PLAYER: scripts/omw/camera/camera.lua

View file

@ -1,6 +1,7 @@
local ui = require('openmw.ui')
local util = require('openmw.util')
local self = require('openmw.self')
local core = require('openmw.core')
local ambient = require('openmw.ambient')
local MODE = ui._getAllUiModes()
@ -10,6 +11,11 @@ local replacedWindows = {}
local hiddenWindows = {}
local modeStack = {}
local modePause = {}
for _, mode in pairs(MODE) do
modePause[mode] = true
end
local function registerWindow(window, showFn, hideFn)
if not WINDOW[window] then
error('At the moment it is only possible to override existing windows. Window "'..
@ -114,6 +120,15 @@ local function onUiModeChanged(arg)
end
end
end
local shouldPause = false
for _, m in pairs(modeStack) do
shouldPause = shouldPause or modePause[m]
end
if shouldPause then
core.sendGlobalEvent('Pause', 'ui')
else
core.sendGlobalEvent('Unpause', 'ui')
end
self:sendEvent('UiModeChanged', {oldMode = oldMode, newMode = mode, arg = arg})
oldMode = mode
end
@ -145,7 +160,7 @@ return {
interface = {
--- Interface version
-- @field [parent=#UI] #number version
version = 0,
version = 1,
--- All available UI modes.
-- Use `view(I.UI.MODE)` in `luap` console mode to see the list.
@ -204,6 +219,12 @@ return {
-- @param #string mode Mode to drop
removeMode = removeMode,
--- Set whether the mode should pause the game.
-- @function [parent=#UI] setPauseOnMode
-- @param #string mode Mode to configure
-- @param #boolean shouldPause
setPauseOnMode = function(mode, shouldPause) modePause[mode] = shouldPause end
-- TODO
-- registerHudElement = function(name, showFn, hideFn) end,
-- showHud = function(bool) end,

View file

@ -0,0 +1,10 @@
local world = require('openmw.world')
return {
eventHandlers = {
Pause = function(tag) world.pause(tag) end,
Unpause = function(tag) world.unpause(tag) end,
SetGameTimeScale = function(scale) world.setGameTimeScale(scale) end,
SetSimulationTimeScale = function(scale) world.setSimulationTimeScale(scale) end,
},
}