mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-15 18:39:51 +00:00
Move inputBinding renderer to menu context
This commit is contained in:
parent
79deb5f559
commit
c2b8e318cf
@ -134,90 +134,16 @@ function clearBinding(id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateBinding(id, binding)
|
bindingSection:subscribe(async:callback(function(_, id)
|
||||||
bindingSection:set(id, binding)
|
if not id then return end
|
||||||
|
local binding = bindingSection:get(id)
|
||||||
clearBinding(id)
|
clearBinding(id)
|
||||||
if binding ~= nil then
|
if binding ~= nil then
|
||||||
registerBinding(binding, id)
|
registerBinding(binding, id)
|
||||||
end
|
end
|
||||||
return id
|
return id
|
||||||
end
|
end))
|
||||||
|
|
||||||
local interfaceL10n = core.l10n('interface')
|
|
||||||
|
|
||||||
I.Settings.registerRenderer('inputBinding', function(id, set, arg)
|
|
||||||
if type(id) ~= 'string' then error('inputBinding: must have a string default value') end
|
|
||||||
if not arg.type then error('inputBinding: type argument is required') end
|
|
||||||
if not arg.key then error('inputBinding: key argument is required') end
|
|
||||||
local info = input.actions[arg.key] or input.triggers[arg.key]
|
|
||||||
if not info then return {} end
|
|
||||||
|
|
||||||
local l10n = core.l10n(info.key)
|
|
||||||
|
|
||||||
local name = {
|
|
||||||
template = I.MWUI.templates.textNormal,
|
|
||||||
props = {
|
|
||||||
text = l10n(info.name),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local description = {
|
|
||||||
template = I.MWUI.templates.textNormal,
|
|
||||||
props = {
|
|
||||||
text = l10n(info.description),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local binding = bindingSection:get(id)
|
|
||||||
local label = binding and input.getKeyName(binding.code) or interfaceL10n('None')
|
|
||||||
|
|
||||||
local recorder = {
|
|
||||||
template = I.MWUI.templates.textEditLine,
|
|
||||||
props = {
|
|
||||||
readOnly = true,
|
|
||||||
text = label,
|
|
||||||
},
|
|
||||||
events = {
|
|
||||||
focusGain = async:callback(function()
|
|
||||||
if binding == nil then return end
|
|
||||||
updateBinding(id, nil)
|
|
||||||
set(id)
|
|
||||||
end),
|
|
||||||
keyPress = async:callback(function(key)
|
|
||||||
if binding ~= nil or key.code == input.KEY.Escape then return end
|
|
||||||
|
|
||||||
local newBinding = {
|
|
||||||
code = key.code,
|
|
||||||
type = arg.type,
|
|
||||||
key = arg.key,
|
|
||||||
}
|
|
||||||
updateBinding(id, newBinding)
|
|
||||||
set(id)
|
|
||||||
end),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local row = {
|
|
||||||
type = ui.TYPE.Flex,
|
|
||||||
props = {
|
|
||||||
horizontal = true,
|
|
||||||
},
|
|
||||||
content = ui.content {
|
|
||||||
name,
|
|
||||||
{ props = { size = util.vector2(10, 0) } },
|
|
||||||
recorder,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
local column = {
|
|
||||||
type = ui.TYPE.Flex,
|
|
||||||
content = ui.content {
|
|
||||||
row,
|
|
||||||
description,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return column
|
|
||||||
end)
|
|
||||||
|
|
||||||
local initiated = false
|
local initiated = false
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
local core = require('openmw.core')
|
||||||
|
local input = require('openmw.input')
|
||||||
|
local storage = require('openmw.storage')
|
||||||
|
local ui = require('openmw.ui')
|
||||||
|
local util = require('openmw.util')
|
||||||
|
local async = require('openmw.async')
|
||||||
local I = require('openmw.interfaces')
|
local I = require('openmw.interfaces')
|
||||||
|
|
||||||
local settingsGroup = 'SettingsOMWControls'
|
local settingsGroup = 'SettingsOMWControls'
|
||||||
@ -31,3 +37,99 @@ I.Settings.registerGroup({
|
|||||||
boolSetting('smoothControllerMovement', true),
|
boolSetting('smoothControllerMovement', true),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local interfaceL10n = core.l10n('interface')
|
||||||
|
|
||||||
|
local bindingSection = storage.playerSection('OMWInputBindings')
|
||||||
|
|
||||||
|
local recording = nil
|
||||||
|
|
||||||
|
|
||||||
|
I.Settings.registerRenderer('inputBinding', function(id, set, arg)
|
||||||
|
if type(id) ~= 'string' then error('inputBinding: must have a string default value') end
|
||||||
|
if not arg.type then error('inputBinding: type argument is required') end
|
||||||
|
if not arg.key then error('inputBinding: key argument is required') end
|
||||||
|
local info = input.actions[arg.key] or input.triggers[arg.key]
|
||||||
|
if not info then return {} end
|
||||||
|
|
||||||
|
local l10n = core.l10n(info.key)
|
||||||
|
|
||||||
|
local name = {
|
||||||
|
template = I.MWUI.templates.textNormal,
|
||||||
|
props = {
|
||||||
|
text = l10n(info.name),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local description = {
|
||||||
|
template = I.MWUI.templates.textNormal,
|
||||||
|
props = {
|
||||||
|
text = l10n(info.description),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local binding = bindingSection:get(id)
|
||||||
|
local label = interfaceL10n('None')
|
||||||
|
if binding then label = input.getKeyName(binding.code) end
|
||||||
|
if recording and recording.id == id then label = interfaceL10n('N/A') end
|
||||||
|
|
||||||
|
local recorder = {
|
||||||
|
template = I.MWUI.templates.textNormal,
|
||||||
|
props = {
|
||||||
|
text = label,
|
||||||
|
},
|
||||||
|
events = {
|
||||||
|
mouseClick = async:callback(function()
|
||||||
|
if recording ~= nil then return end
|
||||||
|
if binding ~= nil then bindingSection:set(id, nil) end
|
||||||
|
recording = {
|
||||||
|
id = id,
|
||||||
|
arg = arg,
|
||||||
|
refresh = function() set(id) end,
|
||||||
|
}
|
||||||
|
recording.refresh()
|
||||||
|
end),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local row = {
|
||||||
|
type = ui.TYPE.Flex,
|
||||||
|
props = {
|
||||||
|
horizontal = true,
|
||||||
|
},
|
||||||
|
content = ui.content {
|
||||||
|
name,
|
||||||
|
{ props = { size = util.vector2(10, 0) } },
|
||||||
|
recorder,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
local column = {
|
||||||
|
type = ui.TYPE.Flex,
|
||||||
|
content = ui.content {
|
||||||
|
row,
|
||||||
|
description,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return column
|
||||||
|
end)
|
||||||
|
|
||||||
|
return {
|
||||||
|
engineHandlers = {
|
||||||
|
onKeyPress = function(key)
|
||||||
|
if recording == nil then return end
|
||||||
|
local binding = {
|
||||||
|
code = key.code,
|
||||||
|
type = recording.arg.type,
|
||||||
|
key = recording.arg.key,
|
||||||
|
}
|
||||||
|
if key.code == input.KEY.Escape then -- TODO: prevent settings modal from closing
|
||||||
|
binding.code = nil
|
||||||
|
end
|
||||||
|
bindingSection:set(recording.id, binding)
|
||||||
|
local refresh = recording.refresh
|
||||||
|
recording = nil
|
||||||
|
refresh()
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user