mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 04:36:40 +00:00
Document Settings interface, add scripts to CMakeLists
This commit is contained in:
parent
1b62dda9f6
commit
cd3535cd63
7 changed files with 171 additions and 21 deletions
|
@ -68,3 +68,4 @@ $DOCUMENTOR_PATH -f doc -d $OUTPUT_DIR openmw_aux/*lua
|
|||
$DOCUMENTOR_PATH -f doc -d $OUTPUT_DIR scripts/omw/ai.lua
|
||||
$DOCUMENTOR_PATH -f doc -d $OUTPUT_DIR scripts/omw/camera.lua
|
||||
$DOCUMENTOR_PATH -f doc -d $OUTPUT_DIR scripts/omw/mwui/init.lua
|
||||
$DOCUMENTOR_PATH -f doc -d $OUTPUT_DIR scripts/omw/settings/player.lua
|
||||
|
|
|
@ -27,6 +27,7 @@ Lua API reference
|
|||
interface_ai
|
||||
interface_camera
|
||||
interface_mwui
|
||||
interface_settings
|
||||
iterables
|
||||
|
||||
|
||||
|
@ -94,12 +95,19 @@ Sources can be found in ``resources/vfs/openmw_aux``. In theory mods can overrid
|
|||
|
||||
**Interfaces of built-in scripts**
|
||||
|
||||
+---------------------------------------------------------+--------------------+---------------------------------------------------------------+
|
||||
| Interface | Can be used | Description |
|
||||
+=========================================================+====================+===============================================================+
|
||||
|:ref:`AI <Interface AI>` | by local scripts | | Control basic AI of NPCs and creatures. |
|
||||
+---------------------------------------------------------+--------------------+---------------------------------------------------------------+
|
||||
|:ref:`Camera <Interface Camera>` | by player scripts | | Allows to alter behavior of the built-in camera script |
|
||||
| | | | without overriding the script completely. |
|
||||
+---------------------------------------------------------+--------------------+---------------------------------------------------------------+
|
||||
.. list-table::
|
||||
:widths: 20 20 60
|
||||
|
||||
* - Interface
|
||||
- Can be used
|
||||
- Description
|
||||
* - :ref:`AI <Interface AI>`
|
||||
- by local scripts
|
||||
- Control basic AI of NPCs and creatures.
|
||||
* - :ref:`Camera <Interface Camera>`
|
||||
- by player scripts
|
||||
- | Allows to alter behavior of the built-in camera script
|
||||
| without overriding the script completely.
|
||||
* - :ref:`Settings <Interface Settings>`
|
||||
- by player and global scripts
|
||||
- Save, display and track changes of setting values.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
Interface Settings
|
||||
==================
|
||||
|
||||
.. raw:: html
|
||||
:file: generated_html/scripts_omw_settings_player.html
|
||||
|
|
@ -460,15 +460,22 @@ The order in which the scripts are started is important. So if one mod should ov
|
|||
|
||||
**Interfaces of built-in scripts**
|
||||
|
||||
+---------------------------------------------------------+--------------------+---------------------------------------------------------------+
|
||||
| Interface | Can be used | Description |
|
||||
+=========================================================+====================+===============================================================+
|
||||
|:ref:`AI <Interface AI>` | by local scripts | | Control basic AI of NPCs and creatures. |
|
||||
+---------------------------------------------------------+--------------------+---------------------------------------------------------------+
|
||||
|:ref:`Camera <Interface Camera>` | by player scripts | | Allows to alter behavior of the built-in camera script |
|
||||
| | | | without overriding the script completely. |
|
||||
+---------------------------------------------------------+--------------------+---------------------------------------------------------------+
|
||||
.. list-table::
|
||||
:widths: 20 20 60
|
||||
|
||||
* - Interface
|
||||
- Can be used
|
||||
- Description
|
||||
* - :ref:`AI <Interface AI>`
|
||||
- by local scripts
|
||||
- Control basic AI of NPCs and creatures.
|
||||
* - :ref:`Camera <Interface Camera>`
|
||||
- by player scripts
|
||||
- | Allows to alter behavior of the built-in camera script
|
||||
| without overriding the script completely.
|
||||
* - :ref:`Settings <Interface Settings>`
|
||||
- by player and global scripts
|
||||
- Save, display and track changes of setting values.
|
||||
|
||||
Event system
|
||||
============
|
||||
|
|
|
@ -17,6 +17,10 @@ set(LUA_BUILTIN_FILES
|
|||
scripts/omw/console/player.lua
|
||||
scripts/omw/console/global.lua
|
||||
scripts/omw/console/local.lua
|
||||
scripts/omw/settings/player.lua
|
||||
scripts/omw/settings/global.lua
|
||||
scripts/omw/settings/common.lua
|
||||
scripts/omw/settings/render.lua
|
||||
|
||||
l10n/Calendar/en.yaml
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ local function validateSettingOptions(options)
|
|||
if type(options.key) ~= 'string' then
|
||||
error('Setting must have a key')
|
||||
end
|
||||
if type(options.saveOnly) ~= 'boolean' then
|
||||
error('Setting must be save only or not')
|
||||
if type(options.permanentStorage) ~= 'boolean' then
|
||||
error('Setting must have a permanentStorage flag')
|
||||
end
|
||||
if type(options.renderer) ~= 'string' then
|
||||
error('Setting must have a renderer')
|
||||
|
@ -63,7 +63,7 @@ end
|
|||
local function registerSetting(options)
|
||||
return {
|
||||
key = options.key,
|
||||
saveOnly = options.saveOnly,
|
||||
permanentStorage = options.permanentStorage,
|
||||
default = options.default,
|
||||
renderer = options.renderer,
|
||||
argument = options.argument,
|
||||
|
@ -123,7 +123,7 @@ return {
|
|||
local section = contextSection(groupKey)
|
||||
saved[groupKey] = {}
|
||||
for key, value in pairs(section:asTable()) do
|
||||
if group.settings[key].saveOnly then
|
||||
if not group.settings[key].permanentStorage then
|
||||
saved[groupKey][key] = value
|
||||
end
|
||||
end
|
||||
|
@ -132,5 +132,4 @@ return {
|
|||
return saved
|
||||
end,
|
||||
registerGroup = registerGroup,
|
||||
validateGroupOptions = validateGroupOptions,
|
||||
}
|
|
@ -21,11 +21,136 @@ render.registerRenderer('text', function(value, set, arg)
|
|||
}
|
||||
end)
|
||||
|
||||
---
|
||||
-- @type PageOptions
|
||||
-- @field #string key A unique key
|
||||
-- @field #string l10n A localization context (an argument of core.l10n)
|
||||
-- @field #string name A key from the localization context
|
||||
-- @field #string description A key from the localization context
|
||||
|
||||
---
|
||||
-- @type GroupOptions
|
||||
-- @field #string key A unique key, starts with "Settings" by convention
|
||||
-- @field #string l10n A localization context (an argument of core.l10n)
|
||||
-- @field #string name A key from the localization context
|
||||
-- @field #string description A key from the localization context
|
||||
-- @field #string page Key of a page which will contain this group
|
||||
-- @field #number order Groups within the same page are sorted by this number, or their key for equal values.
|
||||
-- Defaults to 0.
|
||||
-- @field #list<#SettingOptions> settings A [iterables#List](iterables.html#List) of #SettingOptions
|
||||
|
||||
---
|
||||
-- @type SettingOptions
|
||||
-- @field #string key A unique key
|
||||
-- @field #string name A key from the localization context
|
||||
-- @field #string description A key from the localization context
|
||||
-- @field default A default value
|
||||
-- @field #string renderer A renderer key
|
||||
-- @field argument An argument for the renderer
|
||||
-- @field #boolean permanentStorage Whether the setting should is stored in permanent storage, or in the save file
|
||||
|
||||
return {
|
||||
interfaceName = 'Settings',
|
||||
---
|
||||
-- @module Settings
|
||||
-- @usage
|
||||
-- -- In a player script
|
||||
-- local storage = require('openmw.storage')
|
||||
-- local I = require('openmw.interfaces')
|
||||
-- I.Settings.registerGroup({
|
||||
-- key = 'SettingsPlayerMyMod',
|
||||
-- page = 'MyPage',
|
||||
-- l10n = 'mymod',
|
||||
-- name = 'modName',
|
||||
-- description = 'modDescription',
|
||||
-- settings = {
|
||||
-- {
|
||||
-- key = 'Greeting',
|
||||
-- renderer = 'text',
|
||||
-- name = 'greetingName',
|
||||
-- description = 'greetingDescription',
|
||||
-- default = 'Hello, world!',
|
||||
-- argument = {
|
||||
-- size = 200,
|
||||
-- },
|
||||
-- },
|
||||
-- },
|
||||
-- })
|
||||
-- local playerSettings = storage.playerSection('SettingsPlayerMyMod')
|
||||
-- -- access a setting page registered by a global script
|
||||
-- local globalSettings = storage.globalSection('SettingsGlobalMyMod')
|
||||
interface = {
|
||||
---
|
||||
-- @field [parent=#Settings] #string version
|
||||
version = 0,
|
||||
---
|
||||
-- @function [parent=#Settings] registerPage Register a page to be displayed in the settings menu,
|
||||
-- only available in player scripts
|
||||
-- @param #PageOptions options
|
||||
-- @usage
|
||||
-- I.Settings.registerPage({
|
||||
-- key = 'MyModName',
|
||||
-- l10n = 'MyModName',
|
||||
-- name = 'MyModName',
|
||||
-- description = 'MyModDescription',
|
||||
-- })---
|
||||
registerPage = render.registerPage,
|
||||
---
|
||||
-- @function [parent=#Settings] registerRenderer Register a renderer,
|
||||
-- only avaialable in player scripts
|
||||
-- @param #string key
|
||||
-- @param #function renderer A renderer function, receives setting's value,
|
||||
-- a function to change it and an argument from the setting options
|
||||
-- @usage
|
||||
-- I.Settings.registerRenderer('text', function(value, set, arg)
|
||||
-- return {
|
||||
-- type = ui.TYPE.TextEdit,
|
||||
-- props = {
|
||||
-- size = util.vector2(arg and arg.size or 150, 30),
|
||||
-- text = value,
|
||||
-- textColor = util.color.rgb(1, 1, 1),
|
||||
-- textSize = 15,
|
||||
-- textAlignV = ui.ALIGNMENT.End,
|
||||
-- },
|
||||
-- events = {
|
||||
-- textChanged = async:callback(function(s) set(s) end),
|
||||
-- },
|
||||
-- }
|
||||
-- end)
|
||||
registerRenderer = render.registerRenderer,
|
||||
---
|
||||
-- @function [parent=#Settings] registerGroup Register a group to be attached to a page,
|
||||
-- available both in player and global scripts
|
||||
-- @param #GroupOptions options
|
||||
-- @usage
|
||||
-- I.Settings.registerGroup {
|
||||
-- key = 'SettingsTest',
|
||||
-- page = 'test',
|
||||
-- l10n = 'test',
|
||||
-- name = 'Player',
|
||||
-- description = 'Player settings group',
|
||||
-- settings = {
|
||||
-- {
|
||||
-- key = 'Greeting',
|
||||
-- saveOnly = true,
|
||||
-- default = 'Hi',
|
||||
-- renderer = 'text',
|
||||
-- argument = {
|
||||
-- size = 200,
|
||||
-- },
|
||||
-- name = 'Text Input',
|
||||
-- description = 'Short text input',
|
||||
-- },
|
||||
-- {
|
||||
-- key = 'Key',
|
||||
-- saveOnly = false,
|
||||
-- default = input.KEY.LeftAlt,
|
||||
-- renderer = 'keybind',
|
||||
-- name = 'Key',
|
||||
-- description = 'Bind Key',
|
||||
-- },
|
||||
-- }
|
||||
-- }
|
||||
registerGroup = common.registerGroup,
|
||||
},
|
||||
engineHandlers = {
|
||||
|
|
Loading…
Reference in a new issue