mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 16:09:39 +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 isConsoleMode() const = 0;
|
||||
|
||||
virtual bool isPostProcessorHudVisible() const = 0;
|
||||
virtual bool isInteractiveMessageBoxActive() const = 0;
|
||||
|
||||
virtual void toggleVisible(MWGui::GuiWindow wnd) = 0;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -138,14 +138,12 @@ namespace MWRender
|
|||
if (mProcessViewChange)
|
||||
processViewChange();
|
||||
|
||||
if (paused)
|
||||
return;
|
||||
|
||||
// only show the crosshair in game mode
|
||||
MWBase::WindowManager* wm = MWBase::Environment::get().getWindowManager();
|
||||
wm->showCrosshair(!wm->isGuiMode() && mShowCrosshair);
|
||||
|
||||
updateFocalPointOffset(duration);
|
||||
if (!paused)
|
||||
updateFocalPointOffset(duration);
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,9 @@ local handlersPerType = {}
|
|||
handlersPerType[types.ESM4Door] = { ESM4DoorActivation }
|
||||
|
||||
local function onActivate(obj, actor)
|
||||
if world.isWorldPaused() then
|
||||
return
|
||||
end
|
||||
local handlers = handlersPerObject[obj.id]
|
||||
if handlers then
|
||||
for i = #handlers, 1, -1 do
|
||||
|
|
|
@ -5,6 +5,7 @@ local util = require('openmw.util')
|
|||
local self = require('openmw.self')
|
||||
local nearby = require('openmw.nearby')
|
||||
local async = require('openmw.async')
|
||||
local I = require('openmw.interfaces')
|
||||
|
||||
local Actor = require('openmw.types').Actor
|
||||
|
||||
|
@ -189,7 +190,7 @@ local function updateIdleTimer(dt)
|
|||
end
|
||||
|
||||
local function onFrame(dt)
|
||||
if core.isWorldPaused() then return end
|
||||
if core.isWorldPaused() or I.UI.getMode() then return end
|
||||
updateIdleTimer(dt)
|
||||
local mode = camera.getMode()
|
||||
if (mode == MODE.FirstPerson or mode == MODE.ThirdPerson) and not camera.getQueuedMode() then
|
||||
|
@ -273,7 +274,7 @@ return {
|
|||
onUpdate = onUpdate,
|
||||
onFrame = onFrame,
|
||||
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
|
||||
zoom(10)
|
||||
elseif action == input.ACTION.ZoomOut then
|
||||
|
|
|
@ -107,7 +107,8 @@ local function processAttacking()
|
|||
end
|
||||
|
||||
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 controlsAllowed then
|
||||
processMovement()
|
||||
|
@ -165,7 +166,7 @@ local function onInputAction(action)
|
|||
end
|
||||
end
|
||||
|
||||
if core.isWorldPaused() then
|
||||
if core.isWorldPaused() or I.UI.getMode() then
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
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