mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 21:39:41 +00:00
Merge branch 'time' into 'master'
[Lua] Ability to unpause the game when UI is opened. See merge request OpenMW/openmw!3398
This commit is contained in:
commit
938c487684
13 changed files with 76 additions and 15 deletions
|
@ -134,8 +134,8 @@ namespace MWBase
|
||||||
virtual bool isGuiMode() const = 0;
|
virtual bool isGuiMode() const = 0;
|
||||||
|
|
||||||
virtual bool isConsoleMode() const = 0;
|
virtual bool isConsoleMode() const = 0;
|
||||||
|
|
||||||
virtual bool isPostProcessorHudVisible() const = 0;
|
virtual bool isPostProcessorHudVisible() const = 0;
|
||||||
|
virtual bool isInteractiveMessageBoxActive() const = 0;
|
||||||
|
|
||||||
virtual void toggleVisible(MWGui::GuiWindow wnd) = 0;
|
virtual void toggleVisible(MWGui::GuiWindow wnd) = 0;
|
||||||
|
|
||||||
|
|
|
@ -1539,8 +1539,7 @@ namespace MWGui
|
||||||
|
|
||||||
bool WindowManager::isGuiMode() const
|
bool WindowManager::isGuiMode() const
|
||||||
{
|
{
|
||||||
return !mGuiModes.empty() || isConsoleMode() || (mPostProcessorHud && mPostProcessorHud->isVisible())
|
return !mGuiModes.empty() || isConsoleMode() || isPostProcessorHudVisible() || isInteractiveMessageBoxActive();
|
||||||
|| (mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowManager::isConsoleMode() const
|
bool WindowManager::isConsoleMode() const
|
||||||
|
@ -1550,7 +1549,12 @@ namespace MWGui
|
||||||
|
|
||||||
bool WindowManager::isPostProcessorHudVisible() const
|
bool WindowManager::isPostProcessorHudVisible() const
|
||||||
{
|
{
|
||||||
return mPostProcessorHud->isVisible();
|
return mPostProcessorHud && mPostProcessorHud->isVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowManager::isInteractiveMessageBoxActive() const
|
||||||
|
{
|
||||||
|
return mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
MWGui::GuiMode WindowManager::getMode() const
|
MWGui::GuiMode WindowManager::getMode() const
|
||||||
|
|
|
@ -160,8 +160,8 @@ namespace MWGui
|
||||||
bool isGuiMode() const override;
|
bool isGuiMode() const override;
|
||||||
|
|
||||||
bool isConsoleMode() const override;
|
bool isConsoleMode() const override;
|
||||||
|
|
||||||
bool isPostProcessorHudVisible() const override;
|
bool isPostProcessorHudVisible() const override;
|
||||||
|
bool isInteractiveMessageBoxActive() const override;
|
||||||
|
|
||||||
void toggleVisible(GuiWindow wnd) override;
|
void toggleVisible(GuiWindow wnd) override;
|
||||||
|
|
||||||
|
|
|
@ -138,13 +138,11 @@ namespace MWRender
|
||||||
if (mProcessViewChange)
|
if (mProcessViewChange)
|
||||||
processViewChange();
|
processViewChange();
|
||||||
|
|
||||||
if (paused)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// only show the crosshair in game mode
|
// only show the crosshair in game mode
|
||||||
MWBase::WindowManager* wm = MWBase::Environment::get().getWindowManager();
|
MWBase::WindowManager* wm = MWBase::Environment::get().getWindowManager();
|
||||||
wm->showCrosshair(!wm->isGuiMode() && mShowCrosshair);
|
wm->showCrosshair(!wm->isGuiMode() && mShowCrosshair);
|
||||||
|
|
||||||
|
if (!paused)
|
||||||
updateFocalPointOffset(duration);
|
updateFocalPointOffset(duration);
|
||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,6 +263,8 @@ namespace MWWorld
|
||||||
|
|
||||||
void DateTimeManager::updateIsPaused()
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)..')')
|
print('UiModeChanged from', data.oldMode , 'to', data.newMode, '('..tostring(data.arg)..')')
|
||||||
end
|
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)
|
||||||
|
|
|
@ -91,6 +91,7 @@ set(BUILTIN_DATA_FILES
|
||||||
scripts/omw/mwui/init.lua
|
scripts/omw/mwui/init.lua
|
||||||
scripts/omw/ui.lua
|
scripts/omw/ui.lua
|
||||||
scripts/omw/usehandlers.lua
|
scripts/omw/usehandlers.lua
|
||||||
|
scripts/omw/worldeventhandlers.lua
|
||||||
|
|
||||||
shaders/adjustments.omwfx
|
shaders/adjustments.omwfx
|
||||||
shaders/bloomlinear.omwfx
|
shaders/bloomlinear.omwfx
|
||||||
|
|
|
@ -9,6 +9,7 @@ PLAYER: scripts/omw/settings/player.lua
|
||||||
GLOBAL: scripts/omw/activationhandlers.lua
|
GLOBAL: scripts/omw/activationhandlers.lua
|
||||||
GLOBAL: scripts/omw/cellhandlers.lua
|
GLOBAL: scripts/omw/cellhandlers.lua
|
||||||
GLOBAL: scripts/omw/usehandlers.lua
|
GLOBAL: scripts/omw/usehandlers.lua
|
||||||
|
GLOBAL: scripts/omw/worldeventhandlers.lua
|
||||||
PLAYER: scripts/omw/mechanics/playercontroller.lua
|
PLAYER: scripts/omw/mechanics/playercontroller.lua
|
||||||
PLAYER: scripts/omw/playercontrols.lua
|
PLAYER: scripts/omw/playercontrols.lua
|
||||||
PLAYER: scripts/omw/camera/camera.lua
|
PLAYER: scripts/omw/camera/camera.lua
|
||||||
|
|
|
@ -23,6 +23,9 @@ local handlersPerType = {}
|
||||||
handlersPerType[types.ESM4Door] = { ESM4DoorActivation }
|
handlersPerType[types.ESM4Door] = { ESM4DoorActivation }
|
||||||
|
|
||||||
local function onActivate(obj, actor)
|
local function onActivate(obj, actor)
|
||||||
|
if world.isWorldPaused() then
|
||||||
|
return
|
||||||
|
end
|
||||||
local handlers = handlersPerObject[obj.id]
|
local handlers = handlersPerObject[obj.id]
|
||||||
if handlers then
|
if handlers then
|
||||||
for i = #handlers, 1, -1 do
|
for i = #handlers, 1, -1 do
|
||||||
|
|
|
@ -5,6 +5,7 @@ local util = require('openmw.util')
|
||||||
local self = require('openmw.self')
|
local self = require('openmw.self')
|
||||||
local nearby = require('openmw.nearby')
|
local nearby = require('openmw.nearby')
|
||||||
local async = require('openmw.async')
|
local async = require('openmw.async')
|
||||||
|
local I = require('openmw.interfaces')
|
||||||
|
|
||||||
local Actor = require('openmw.types').Actor
|
local Actor = require('openmw.types').Actor
|
||||||
|
|
||||||
|
@ -189,7 +190,7 @@ local function updateIdleTimer(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onFrame(dt)
|
local function onFrame(dt)
|
||||||
if core.isWorldPaused() then return end
|
if core.isWorldPaused() or I.UI.getMode() then return end
|
||||||
updateIdleTimer(dt)
|
updateIdleTimer(dt)
|
||||||
local mode = camera.getMode()
|
local mode = camera.getMode()
|
||||||
if (mode == MODE.FirstPerson or mode == MODE.ThirdPerson) and not camera.getQueuedMode() then
|
if (mode == MODE.FirstPerson or mode == MODE.ThirdPerson) and not camera.getQueuedMode() then
|
||||||
|
@ -273,7 +274,7 @@ return {
|
||||||
onUpdate = onUpdate,
|
onUpdate = onUpdate,
|
||||||
onFrame = onFrame,
|
onFrame = onFrame,
|
||||||
onInputAction = function(action)
|
onInputAction = function(action)
|
||||||
if core.isWorldPaused() then return end
|
if core.isWorldPaused() or I.UI.getMode() then return end
|
||||||
if action == input.ACTION.ZoomIn then
|
if action == input.ACTION.ZoomIn then
|
||||||
zoom(10)
|
zoom(10)
|
||||||
elseif action == input.ACTION.ZoomOut then
|
elseif action == input.ACTION.ZoomOut then
|
||||||
|
|
|
@ -107,7 +107,8 @@ local function processAttacking()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onFrame(dt)
|
local function onFrame(dt)
|
||||||
local controlsAllowed = input.getControlSwitch(input.CONTROL_SWITCH.Controls) and not core.isWorldPaused()
|
local controlsAllowed = input.getControlSwitch(input.CONTROL_SWITCH.Controls)
|
||||||
|
and not core.isWorldPaused() and not I.UI.getMode()
|
||||||
if not movementControlsOverridden then
|
if not movementControlsOverridden then
|
||||||
if controlsAllowed then
|
if controlsAllowed then
|
||||||
processMovement()
|
processMovement()
|
||||||
|
@ -165,7 +166,7 @@ local function onInputAction(action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if core.isWorldPaused() then
|
if core.isWorldPaused() or I.UI.getMode() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
local ui = require('openmw.ui')
|
local ui = require('openmw.ui')
|
||||||
local util = require('openmw.util')
|
local util = require('openmw.util')
|
||||||
local self = require('openmw.self')
|
local self = require('openmw.self')
|
||||||
|
local core = require('openmw.core')
|
||||||
local ambient = require('openmw.ambient')
|
local ambient = require('openmw.ambient')
|
||||||
|
|
||||||
local MODE = ui._getAllUiModes()
|
local MODE = ui._getAllUiModes()
|
||||||
|
@ -10,6 +11,11 @@ local replacedWindows = {}
|
||||||
local hiddenWindows = {}
|
local hiddenWindows = {}
|
||||||
local modeStack = {}
|
local modeStack = {}
|
||||||
|
|
||||||
|
local modePause = {}
|
||||||
|
for _, mode in pairs(MODE) do
|
||||||
|
modePause[mode] = true
|
||||||
|
end
|
||||||
|
|
||||||
local function registerWindow(window, showFn, hideFn)
|
local function registerWindow(window, showFn, hideFn)
|
||||||
if not WINDOW[window] then
|
if not WINDOW[window] then
|
||||||
error('At the moment it is only possible to override existing windows. Window "'..
|
error('At the moment it is only possible to override existing windows. Window "'..
|
||||||
|
@ -114,6 +120,15 @@ local function onUiModeChanged(arg)
|
||||||
end
|
end
|
||||||
end
|
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})
|
self:sendEvent('UiModeChanged', {oldMode = oldMode, newMode = mode, arg = arg})
|
||||||
oldMode = mode
|
oldMode = mode
|
||||||
end
|
end
|
||||||
|
@ -145,7 +160,7 @@ return {
|
||||||
interface = {
|
interface = {
|
||||||
--- Interface version
|
--- Interface version
|
||||||
-- @field [parent=#UI] #number version
|
-- @field [parent=#UI] #number version
|
||||||
version = 0,
|
version = 1,
|
||||||
|
|
||||||
--- All available UI modes.
|
--- All available UI modes.
|
||||||
-- Use `view(I.UI.MODE)` in `luap` console mode to see the list.
|
-- Use `view(I.UI.MODE)` in `luap` console mode to see the list.
|
||||||
|
@ -204,6 +219,12 @@ return {
|
||||||
-- @param #string mode Mode to drop
|
-- @param #string mode Mode to drop
|
||||||
removeMode = removeMode,
|
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
|
-- TODO
|
||||||
-- registerHudElement = function(name, showFn, hideFn) end,
|
-- registerHudElement = function(name, showFn, hideFn) end,
|
||||||
-- showHud = function(bool) end,
|
-- showHud = function(bool) end,
|
||||||
|
|
10
files/data/scripts/omw/worldeventhandlers.lua
Normal file
10
files/data/scripts/omw/worldeventhandlers.lua
Normal 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,
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in a new issue