diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index dbe79ca377..d26de4336a 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -71,9 +71,10 @@ namespace MWLua = [](LuaUtil::InputAction::Registry& registry, std::string_view key) { return registry[key]; }; { auto pairs = [](LuaUtil::InputAction::Registry& registry) { - auto next = [](LuaUtil::InputAction::Registry& registry, std::string_view key) - -> sol::optional> { - std::optional nextKey(registry.nextKey(key)); + auto next + = [](LuaUtil::InputAction::Registry& registry, + std::string_view key) -> sol::optional> { + std::optional nextKey(registry.nextKey(key)); if (!nextKey.has_value()) return sol::nullopt; else @@ -102,9 +103,10 @@ namespace MWLua = [](LuaUtil::InputTrigger::Registry& registry, std::string_view key) { return registry[key]; }; { auto pairs = [](LuaUtil::InputTrigger::Registry& registry) { - auto next = [](LuaUtil::InputTrigger::Registry& registry, std::string_view key) - -> sol::optional> { - std::optional nextKey(registry.nextKey(key)); + auto next + = [](LuaUtil::InputTrigger::Registry& registry, + std::string_view key) -> sol::optional> { + std::optional nextKey(registry.nextKey(key)); if (!nextKey.has_value()) return sol::nullopt; else diff --git a/files/data/l10n/OMWControls/en.yaml b/files/data/l10n/OMWControls/en.yaml index d4df56436b..1be6da6baf 100644 --- a/files/data/l10n/OMWControls/en.yaml +++ b/files/data/l10n/OMWControls/en.yaml @@ -82,3 +82,49 @@ SmoothMoveLeft_description: "Left movement adjusted for smooth Walk-Run transiti SmoothMoveRight_name: "Smooth Move Right" SmoothMoveRight_description: "Right movement adjusted for smooth Walk-Run transitions." + +# Non-dehardcoded actions +Activate_name: "Activate" +Activate_description: "Fallback for input.ACTIONS.Activate, binding does not do anything yet" +Console_name: "Console" +Console_description: "Fallback for input.ACTIONS.Console, binding does not do anything yet" +CycleSpellLeft_name: "CycleSpellLeft" +CycleSpellLeft_description: "Fallback for input.ACTIONS.CycleSpellLeft, binding does not do anything yet" +CycleSpellRight_name: "CycleSpellRight" +CycleSpellRight_description: "Fallback for input.ACTIONS.CycleSpellRight, binding does not do anything yet" +CycleWeaponLeft_name: "CycleWeaponLeft" +CycleWeaponLeft_description: "Fallback for input.ACTIONS.CycleWeaponLeft, binding does not do anything yet" +CycleWeaponRight_name: "CycleWeaponRight" +CycleWeaponRight_description: "Fallback for input.ACTIONS.CycleWeaponRight, binding does not do anything yet" +GameMenu_name: "GameMenu" +GameMenu_description: "Fallback for input.ACTIONS.GameMenu, binding does not do anything yet" +QuickLoad_name: "QuickLoad" +QuickLoad_description: "Fallback for input.ACTIONS.QuickLoad, binding does not do anything yet" +QuickSave_name: "QuickSave" +QuickSave_description: "Fallback for input.ACTIONS.QuickSave, binding does not do anything yet" +Screenshot_name: "Screenshot" +Screenshot_description: "Fallback for input.ACTIONS.Screenshot, binding does not do anything yet" +ToggleDebug_name: "ToggleDebug" +ToggleDebug_description: "Fallback for input.ACTIONS.ToggleDebug, binding does not do anything yet" +ToggleHUD_name: "ToggleHUD" +ToggleHUD_description: "Fallback for input.ACTIONS.ToggleHUD, binding does not do anything yet" +TogglePostProcessorHUD_name: "TogglePostProcessorHUD" +TogglePostProcessorHUD_description: "Fallback for input.ACTIONS.TogglePostProcessorHUD, binding does not do anything yet" +QuickKey1_name: "QuickKey1" +QuickKey1_description: "Fallback for input.ACTIONS.QuickKey1, binding does not do anything yet" +QuickKey2_name: "QuickKey2" +QuickKey2_description: "Fallback for input.ACTIONS.QuickKey2, binding does not do anything yet" +QuickKey3_name: "QuickKey3" +QuickKey3_description: "Fallback for input.ACTIONS.QuickKey3, binding does not do anything yet" +QuickKey4_name: "QuickKey4" +QuickKey4_description: "Fallback for input.ACTIONS.QuickKey4, binding does not do anything yet" +QuickKey5_name: "QuickKey5" +QuickKey5_description: "Fallback for input.ACTIONS.QuickKey5, binding does not do anything yet" +QuickKey6_name: "QuickKey6" +QuickKey6_description: "Fallback for input.ACTIONS.QuickKey6, binding does not do anything yet" +QuickKey7_name: "QuickKey7" +QuickKey7_description: "Fallback for input.ACTIONS.QuickKey7, binding does not do anything yet" +QuickKey8_name: "QuickKey8" +QuickKey8_description: "Fallback for input.ACTIONS.QuickKey8, binding does not do anything yet" +QuickKey9_name: "QuickKey9" +QuickKey9_description: "Fallback for input.ACTIONS.QuickKey9, binding does not do anything yet" diff --git a/files/data/scripts/omw/input/actionbindings.lua b/files/data/scripts/omw/input/actionbindings.lua index bc871a3934..741376bc75 100644 --- a/files/data/scripts/omw/input/actionbindings.lua +++ b/files/data/scripts/omw/input/actionbindings.lua @@ -29,6 +29,38 @@ local function bindTrigger(key, actionid) end) end +do -- Actions and Triggers currently unused by builtin scripts + -- TODO: as more mechanics are dehardcoded, move these declarations to relevant files + local triggers = { + Activate = input.ACTION.Activate, + Console = input.ACTION.Console, + CycleSpellLeft = input.ACTION.CycleSpellLeft, + CycleSpellRight = input.ACTION.CycleSpellRight, + CycleWeaponLeft = input.ACTION.CycleWeaponLeft, + CycleWeaponRight = input.ACTION.CycleWeaponRight, + GameMenu = input.ACTION.GameMenu, + QuickLoad = input.ACTION.QuickLoad, + QuickSave = input.ACTION.QuickSave, + Screenshot = input.ACTION.Screenshot, + ToggleDebug = input.ACTION.ToggleDebug, + ToggleHUD = input.ACTION.ToggleHUD, + TogglePostProcessorHUD = input.ACTION.ToggleHUD, + } + for i = 1, 9 do + local key = string.format('QuickKey%s', i) + triggers[key] = input.ACTION[key] + end + for key, action in pairs(triggers) do + input.registerTrigger { + key = key, + l10n = 'OMWControls', + name = key .. '_name', + description = key .. '_description', + } + bindTrigger(key, action) + end +end + bindTrigger('AlwaysRun', input.ACTION.AlwaysRun) bindTrigger('ToggleSneak', input.ACTION.Sneak) bindTrigger('ToggleWeapon', input.ACTION.ToggleWeapon) diff --git a/files/lua_api/openmw/input.lua b/files/lua_api/openmw/input.lua index a34bc040da..b8e5e51261 100644 --- a/files/lua_api/openmw/input.lua +++ b/files/lua_api/openmw/input.lua @@ -1,7 +1,34 @@ --- -- `openmw.input` can be used only in menu scripts and scripts attached to a player. +-- Most mods should prefer to use the actions/triggers API over the direct input device methods. +-- Actions have one value on each frame (resolved just before the `onFrame` engine handler), +-- while Triggers don't have a value, but can occur multiple times on each frame. +-- Prefer to use built-in methods of binding actions, such as the [inputBinding setting renderer](setting_renderers.html#inputbinding) -- @module input -- @usage local input = require('openmw.input') +-- -- Example of Action usage +-- input.registerAction { +-- key = 'MyAction', +-- type = input.ACTION_TYPE.Boolean, +-- l10n = 'MyLocalizationContext', +-- name = 'MyAction_name', +-- description = 'MyAction_full_description', +-- defaultValue = false, +-- } +-- return { +-- onFrame = function() +-- local myAction = input.getBooleanActionValue('MyAction') +-- if (myAction) then print('My action is active!') end +-- end, +-- } +-- -- Example of Trigger usage +-- input.registerTrigger { +-- key = 'MyTrigger', +-- l10n = 'MyLocalizationContext', +-- name = 'MyTrigger_name', +-- description = 'MyTrigger_full_description', +-- } +-- input.registerTriggerHandler('MyTrigger', async:callback(function() print('MyTrigger') end))