Avorion

Avorion

UI lib
 This topic has been pinned, so it's probably important
Joenyan  [developer] Aug 14 @ 1:58am
How to use
Settings menu
Create config file with default settings:
data/scripts/uiLib/settingsPages.lua
Use mod id here + 1 letter. NEVER USE PLAIN MOD ID, it leads to crashes
local id = "u3548610240" pages[id] = {} local config = pages[id] config.name = "UI lib" config.version = "3.0" config.defaults = { music_volume = {value = 40, type_ = "integer", range_min = 0, range_max = 100}, show_recources = {value = false, type_ = "bool"}, } config.lines = { {type_ = "headline", text = "UI lib"}, {type_ = "button", config_text = "show_top_bar", text = "Show top bar"%_t, tooltip = "Tooltip text here"%_t}, {type_ = "headline", text = "Sound"}, {type_ = "slider", config_text = "music_volume", text = "Music"%_t, min_ = 0, max_ = 100, steps = 50}, }
  • 'config.name' - just use readable name here
  • 'config.version' - match with mod version to properly update config on updates
  • 'config.defaults' - default values for your settings
  • 'music_volume' - name of the entry, you can use them later to read values currently selected by player
  • 'value' - default value of the entry above
  • 'type_' - type of the value, currently there are "integer" and "bool" only
  • 'range_min' and range_max - use them as a limit for your value
  • 'config.lines' - creates buttons in the setting menu that the player will actually see
  • 'type_' = "headline" - text, not clickable for player
  • 'type_' = "button" - creates 'On/Off' button
  • 'config_text' - button will change 'config.lines' entry with this name
  • 'text' - button name that the player will see
  • 'tooltip' - text that the player will see when the mouse hovers over the button
  • 'type_' = "slider" - creates slider
  • 'min_' - minimal value for the slider
  • 'max_' - maximum value for the slider
  • 'steps' - number of steps for the slider, increse to make a gradual selection

    Use this to load latest user settings to check them:
    local err, config = Player():invokeFunction("data/scripts/player/uiLib/UIManager.lua", "sendUserConfig", put_ID_here)
    'put_ID_here' is the ID that you set earlier in the 'settingsPages.lua', like "u3548610240"
    'config.music_volume', 'config.show_recources', etc. will give you a value that the player has set in the settings menu or default value if it was not changed
Your mod updates
'config.defaults': 'type_', 'range_min' and 'range_max' are meant to enshure that the user config is updated properly. If you delete some lines in 'config.defaults', the user config will lose them on next update. If you change 'type_' to another one, this entry will be reset to defaults. The same thing goes for the 'range_min' and 'range_max'. If you add new lines, the user config will get them in the next update with default values. You can safely update your mod without breaking existing player settings

Backgrounds and dialogs
Work in progress, I need to clean up some stuff and fix small bugs. Then I can make a proper description of the process
Last edited by Joenyan; Aug 19 @ 6:05am