1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 04:36:40 +00:00

Move camera settings to a menu script

This commit is contained in:
uramer 2024-01-10 20:32:34 +01:00
parent 6917384fc1
commit 5b97a93169
5 changed files with 45 additions and 47 deletions

View file

@ -13,6 +13,7 @@ GLOBAL: scripts/omw/usehandlers.lua
GLOBAL: scripts/omw/worldeventhandlers.lua
PLAYER: scripts/omw/mechanics/playercontroller.lua
PLAYER: scripts/omw/playercontrols.lua
MENU: scripts/omw/camera/settings.lua
PLAYER: scripts/omw/camera/camera.lua
PLAYER: scripts/omw/input/actionbindings.lua
PLAYER: scripts/omw/input/smoothmovement.lua

View file

@ -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 storage = require('openmw.storage')
local I = require('openmw.interfaces')
local Actor = require('openmw.types').Actor
@ -28,7 +29,7 @@ input.registerAction {
defaultValue = 0,
}
local settings = require('scripts.omw.camera.settings').thirdPerson
local settings = storage.playerSection('SettingsOMWCameraThirdPerson')
local head_bobbing = require('scripts.omw.camera.head_bobbing')
local third_person = require('scripts.omw.camera.third_person')
local pov_auto_switch = require('scripts.omw.camera.first_person_auto_switch')

View file

@ -2,12 +2,13 @@ local camera = require('openmw.camera')
local self = require('openmw.self')
local util = require('openmw.util')
local async = require('openmw.async')
local storage = require('openmw.storage')
local Actor = require('openmw.types').Actor
local M = {}
local settings = require('scripts.omw.camera.settings').headBobbing
local settings = storage.playerSection('SettingsOMWCameraHeadBobbing')
local doubleStepLength, stepHeight, maxRoll
@ -31,7 +32,7 @@ local arcHeight = sampleArc(1)
function M.update(dt, smoothedSpeed)
local speed = Actor.getCurrentSpeed(self)
speed = speed / (1 + speed / 500) -- limit bobbing frequency if the speed is very high
speed = speed / (1 + speed / 500) -- limit bobbing frequency if the speed is very high
totalMovement = totalMovement + speed * dt
if not M.enabled or camera.getMode() ~= camera.MODE.FirstPerson then
effectWeight = 0
@ -44,18 +45,17 @@ function M.update(dt, smoothedSpeed)
end
local doubleStepState = totalMovement / doubleStepLength
doubleStepState = doubleStepState - math.floor(doubleStepState) -- from 0 to 1 during 2 steps
local stepState = math.abs(doubleStepState * 4 - 2) - 1 -- from -1 to 1 on even steps and from 1 to -1 on odd steps
local effect = sampleArc(stepState) / arcHeight -- range from 0 to 1
doubleStepState = doubleStepState - math.floor(doubleStepState) -- from 0 to 1 during 2 steps
local stepState = math.abs(doubleStepState * 4 - 2) - 1 -- from -1 to 1 on even steps and from 1 to -1 on odd steps
local effect = sampleArc(stepState) / arcHeight -- range from 0 to 1
-- Smoothly reduce the effect to zero when the player stops
local coef = math.min(smoothedSpeed / 300, 1) * effectWeight
local zOffset = (0.5 - effect) * coef * stepHeight -- range from -stepHeight/2 to stepHeight/2
local roll = ((stepState > 0 and 1) or -1) * effect * coef * maxRoll -- range from -maxRoll to maxRoll
local zOffset = (0.5 - effect) * coef * stepHeight -- range from -stepHeight/2 to stepHeight/2
local roll = ((stepState > 0 and 1) or -1) * effect * coef * maxRoll -- range from -maxRoll to maxRoll
camera.setFirstPersonOffset(camera.getFirstPersonOffset() + util.vector3(0, 0, zOffset))
camera.setExtraRoll(camera.getExtraRoll() + roll)
end
return M

View file

@ -3,10 +3,10 @@ local async = require('openmw.async')
local I = require('openmw.interfaces')
I.Settings.registerPage({
key = 'OMWCamera',
l10n = 'OMWCamera',
name = 'Camera',
description = 'settingsPageDescription',
key = 'OMWCamera',
l10n = 'OMWCamera',
name = 'Camera',
description = 'settingsPageDescription',
})
local thirdPersonGroup = 'SettingsOMWCameraThirdPerson'
@ -16,8 +16,8 @@ local function boolSetting(prefix, key, default)
return {
key = key,
renderer = 'checkbox',
name = prefix..key,
description = prefix..key..'Description',
name = prefix .. key,
description = prefix .. key .. 'Description',
default = default,
}
end
@ -26,8 +26,8 @@ local function floatSetting(prefix, key, default)
return {
key = key,
renderer = 'number',
name = prefix..key,
description = prefix..key..'Description',
name = prefix .. key,
description = prefix .. key .. 'Description',
default = default,
}
end
@ -70,33 +70,29 @@ I.Settings.registerGroup({
},
})
local settings = {
thirdPerson = storage.playerSection(thirdPersonGroup),
headBobbing = storage.playerSection(headBobbingGroup),
}
local thirdPerson = storage.playerSection(thirdPersonGroup)
local headBobbing = storage.playerSection(headBobbingGroup)
local function updateViewOverShoulderDisabled()
local shoulderDisabled = not settings.thirdPerson:get('viewOverShoulder')
I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetX', {disabled = shoulderDisabled})
I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetY', {disabled = shoulderDisabled})
I.Settings.updateRendererArgument(thirdPersonGroup, 'autoSwitchShoulder', {disabled = shoulderDisabled})
I.Settings.updateRendererArgument(thirdPersonGroup, 'zoomOutWhenMoveCoef', {disabled = shoulderDisabled})
local shoulderDisabled = not thirdPerson:get('viewOverShoulder')
I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetX', { disabled = shoulderDisabled })
I.Settings.updateRendererArgument(thirdPersonGroup, 'shoulderOffsetY', { disabled = shoulderDisabled })
I.Settings.updateRendererArgument(thirdPersonGroup, 'autoSwitchShoulder', { disabled = shoulderDisabled })
I.Settings.updateRendererArgument(thirdPersonGroup, 'zoomOutWhenMoveCoef', { disabled = shoulderDisabled })
local move360Disabled = not settings.thirdPerson:get('move360')
I.Settings.updateRendererArgument(thirdPersonGroup, 'move360TurnSpeed', {disabled = move360Disabled})
local move360Disabled = not thirdPerson:get('move360')
I.Settings.updateRendererArgument(thirdPersonGroup, 'move360TurnSpeed', { disabled = move360Disabled })
end
local function updateHeadBobbingDisabled()
local disabled = not settings.headBobbing:get('enabled')
I.Settings.updateRendererArgument(headBobbingGroup, 'step', {disabled = disabled, min = 1})
I.Settings.updateRendererArgument(headBobbingGroup, 'height', {disabled = disabled})
I.Settings.updateRendererArgument(headBobbingGroup, 'roll', {disabled = disabled, min = 0, max = 90})
local disabled = not headBobbing:get('enabled')
I.Settings.updateRendererArgument(headBobbingGroup, 'step', { disabled = disabled, min = 1 })
I.Settings.updateRendererArgument(headBobbingGroup, 'height', { disabled = disabled })
I.Settings.updateRendererArgument(headBobbingGroup, 'roll', { disabled = disabled, min = 0, max = 90 })
end
updateViewOverShoulderDisabled()
updateHeadBobbingDisabled()
settings.thirdPerson:subscribe(async:callback(updateViewOverShoulderDisabled))
settings.headBobbing:subscribe(async:callback(updateHeadBobbingDisabled))
return settings
thirdPerson:subscribe(async:callback(updateViewOverShoulderDisabled))
headBobbing:subscribe(async:callback(updateHeadBobbingDisabled))

View file

@ -3,10 +3,11 @@ local util = require('openmw.util')
local self = require('openmw.self')
local nearby = require('openmw.nearby')
local async = require('openmw.async')
local storage = require('openmw.storage')
local Actor = require('openmw.types').Actor
local settings = require('scripts.omw.camera.settings').thirdPerson
local settings = storage.playerSection('SettingsOMWCameraThirdPerson')
local MODE = camera.MODE
local STATE = { RightShoulder = 0, LeftShoulder = 1, Combat = 2, Swimming = 3 }
@ -31,7 +32,7 @@ local function updateSettings()
viewOverShoulder = settings:get('viewOverShoulder')
autoSwitchShoulder = settings:get('autoSwitchShoulder')
shoulderOffset = util.vector2(settings:get('shoulderOffsetX'),
settings:get('shoulderOffsetY'))
settings:get('shoulderOffsetY'))
zoomOutWhenMoveCoef = settings:get('zoomOutWhenMoveCoef')
defaultShoulder = (shoulderOffset.x > 0 and STATE.RightShoulder) or STATE.LeftShoulder
@ -46,7 +47,7 @@ local state = defaultShoulder
local function ray(from, angle, limit)
local to = from + util.transform.rotateZ(angle) * util.vector3(0, limit, 0)
local res = nearby.castRay(from, to, {collisionType = camera.getCollisionType()})
local res = nearby.castRay(from, to, { collisionType = camera.getCollisionType() })
if res.hit then
return (res.hitPos - from):length()
else
@ -55,8 +56,8 @@ local function ray(from, angle, limit)
end
local function trySwitchShoulder()
local limitToSwitch = 120 -- switch to other shoulder if wall is closer than this limit
local limitToSwitchBack = 300 -- switch back to default shoulder if there is no walls at this distance
local limitToSwitch = 120 -- switch to other shoulder if wall is closer than this limit
local limitToSwitchBack = 300 -- switch back to default shoulder if there is no walls at this distance
local pos = camera.getTrackedPosition()
local rayRight = ray(pos, camera.getYaw() + math.rad(90), limitToSwitchBack + 1)
@ -79,7 +80,7 @@ end
local function calculateDistance(smoothedSpeed)
local smoothedSpeedSqr = smoothedSpeed * smoothedSpeed
return (M.baseDistance + math.max(camera.getPitch(), 0) * 50
+ smoothedSpeedSqr / (smoothedSpeedSqr + 300*300) * zoomOutWhenMoveCoef)
+ smoothedSpeedSqr / (smoothedSpeedSqr + 300 * 300) * zoomOutWhenMoveCoef)
end
local function updateState()
@ -95,7 +96,7 @@ local function updateState()
state = defaultShoulder
end
if (mode == MODE.ThirdPerson or Actor.getCurrentSpeed(self) > 0 or state ~= oldState or noThirdPersonLastFrame)
and (state == STATE.LeftShoulder or state == STATE.RightShoulder) then
and (state == STATE.LeftShoulder or state == STATE.RightShoulder) then
if autoSwitchShoulder then
trySwitchShoulder()
else
@ -108,11 +109,11 @@ local function updateState()
-- Player doesn't touch controls for a long time. Transition should be very slow.
camera.setFocalTransitionSpeed(0.2)
elseif (oldState == STATE.Combat or state == STATE.Combat) and
(mode ~= MODE.Preview or M.standingPreview) then
(mode ~= MODE.Preview or M.standingPreview) then
-- Transition to/from combat mode and we are not in preview mode. Should be fast.
camera.setFocalTransitionSpeed(5.0)
else
camera.setFocalTransitionSpeed(1.0) -- Default transition speed.
camera.setFocalTransitionSpeed(1.0) -- Default transition speed.
end
if state == STATE.RightShoulder then
@ -149,7 +150,7 @@ function M.update(dt, smoothedSpeed)
end
M.preferredDistance = calculateDistance(smoothedSpeed)
if noThirdPersonLastFrame then -- just switched to third person view
if noThirdPersonLastFrame then -- just switched to third person view
camera.setPreferredThirdPersonDistance(M.preferredDistance)
camera.instantTransition()
noThirdPersonLastFrame = false
@ -161,4 +162,3 @@ function M.update(dt, smoothedSpeed)
end
return M