Create an account

Mod Config Menu  

Upload: 07 Aug 2022, 09:34
Created by: mezz [X]
Uploaded by: Aqxaro
Mod Config Menu

This mod was born out of frustrations with the limitations of Mod Options. Instead of waiting for it to be eventually updated to include features I needed, I've built a new mod configuration manager from scratch instead. They can be used alongside each other, they shouldn't be conflicting, however to use MCM a different setup is required from modders.

Implementing MCM into your mod


A very basic structure of a MCM implementation could look like this:

local MyModVariable = 12.5 if Mod.IsMCMInstalled_v1 then -- initialize the main mod option table local MyModOptions = ModOptionTable:New("MyMod", "My cool mod [-|-]/", false) -- Add options MyModOptions:AddModOption("MyModVariable", "number_slider", MyModVariable, { min = 1, max = 20, step = 0.5}, "My Setting", "This setting does this and that", function(value) MyModVariable = value end) end

Allow me now to elaborate in detail what each bit does. First we check, if MCM is even installed at all:

if Mod.IsMCMInstalled_v1 then -- ... end


If it isn't, the rest of the MCM code will simply not run, but your mod can still function properly, it will just not be configurable and have all variables retain the value that you originally set them to.

However if MCM is present, then the next step is creating an Option Table for your mod:

-- function ModOptionTable:New(Mod_id, DisplayStr, bExtraTab) local MyModOptions = ModOptionTable:New("MyMod", "My cool mod [-|-]/", false)


Let's go over the individual arguments.

"Mod_id" is the unique identifier that MCM uses to keep track of your mod and the data it keeps saved for you. You only have to make sure that you pick an identifier that's unique and won't conflict with any other mod. Changing the identifier will make MCM "forget" about any data it might have saved about your mod.

"DisplayStr" is the string that will be displayed at the very top of your options section.

If "bExtraTab" is set to "true", then your mod will get its very own tab in the option screen, instead of sharing one page with other mods. This makes sense for large mods with overwhelmingly many options, but otherwise you should keep it to "false"

-- function ModOptionTable:AddModOption(Option_id, Option_type, DefaultValue, OptionData, DisplayStr, TooltipStr, CommitValueFunc) MyModOptions:AddModOption("MyModVariable", "number_slider", MyModVariable, { min = 1, max = 20, step = 0.5}, "My Setting", "This setting does this and that", function(value) MyModVariable = value end)


We are now getting into the interesting part. "AddModOption" is the function that describes a UI element that can be used to drive the value of a variable.

"Option_id" is another identifier that should be unique, however it only needs to be unique within your own mod.

"Option_type" determines what type of UI element this option will be, there are several to choose from for different purposes, we will get into them later.

"DefaultValue" sets the initial value of your option, it's most convenient to just place the variable here that you wish to have MCM manipulate, and place your default value there instead.

"OptionData" provides additional data to drive behavior of your UI element. It's highly dependent on what UI type you have chosen, some don't require any OptionData at all, in which case you can leave this argument as "nil". We will cover the rest later.

"DisplayStr" is the name of the option that users are going to see on their screen.

"TooltipStr" will have its contents displayed when the user hovers over your option with the mouse.

"CommitValueFunc" is the function that will be called, when your option has been manipulated by the user. You can use it to directly assign the value that MCM returns to your variable.

And that's pretty much it. The basic process for creating each option involves the same function, until you have everything you need.

Option Types


"text" - A text box that you can enter any strings into.
Value Type: String
Optiondаta: nil

"number" - A text box that only takes numeric values
Value Type: Number
Optiondаta: Table with following structure
{
(optional) min = [Lower bound of acceptable values]
(optional) max = [Upper bound of acceptable values]
(optional) step = [Number that all entered numbers must be divisible by, they will be rounded if need be. Set to 1 to only allow integers]
}

"number_slider" - A slider that can be dragged with the mouse to produce numeric values
Value Type: Number
Optiondаta: same as "number" but all fields are mandatory to define

"checkbox" - A single checkbox that can be either ticked or unticked
Value Type: Boolean
Optiondаta: nil

"checkbox_multi" - An array of checkboxes, each with their own value
Value Type: Table of Boolean values, corresponding to one tickbox each
Optiondаta: Table with Strings, containing the labels for each individual tick box

"color" - A color picker
Value Type: Table with following structure
{
(mandatory) r = [Number from 0 to 1]
(mandatory) g = [Number from 0 to 1]
(mandatory) b = [Number from 0 to 1]
}
Optiondаta: nil

"combobox" - A dropdown menu offering a finite amount of choices
Value Type: Number (to use as an index in your own code)
Optiondаta: Table with Strings, containing the labels for each individual dropbox entry

"keybind" - A special option, that doesn't return a value when set in the options menu, but invokes the function in "CommitValueFunc" when the user presses the associated key.
DefaultValue: Key code to bind action to initially.
Optiondаta: nil
CommitValueFunc: Function to run when key is pressed.

AddModOptionTable

AddModOptionTable is a syntactic alternative to AddModOption, that takes a table instead of loose arguments:

local Option = {} Option.Option_id = "MyModVariable" Option.Option_type = "number_slider" Option.DefaultValue = MyModVariable Option.OptionData = { min = 1, max = 20, step = 0.5} Option.DisplayStr = "My Setting" Option.TooltipStr = "This setting does this and that" Option.CommitValueFunc = function(value) MyModVariable = value end MyModOptions:AddModOptionTable(Option)


Using this is identical in effect to AddModOption, it's simply a different way of conveying the same information to MCM, which may be more convenient in some cases.

Custom Sandbox Settings

MCM can also allow modders to add additional options to Sandbox. It works similarly to normal mod options, but is more restricted at the moment. I will provide short documentation for it later.

Further Help

If you still want something clarified, feel free to give me a shout. I also included a working example mod, that implements the various different option types. Feel free to copy implementations from there or use them as a reference.

Comments
The minimum comment length is 10 characters.