SettingsApi
Settings API for allowing mods to add settings.
| Last updated | 4 years ago |
| Total downloads | 138589 |
| Total rating | 3 |
| Categories | |
| Dependency string | Terrain-SettingsApi-1.1.1 |
| Dependants | 28 other packages depend on this package |
README
Muck Settings API
This is a helper mod made to allow easier addition of settings to mods that require configuration, all in the in-game settings menu.
An example of implementing this library can be found in the "MuckSettingsExample" subdirectory of this repository.
To add your own settings, first patch one of the 5 tabs in MuckSettings.Settings: either Gameplay, Controls, Graphics, Video or Audio. Don't worry about the settings overflowing, all pages are scrollable. Next, make sure you take a MuckSettings.Settings.Page argument called page in your patch, and you can add settings to that page. To save your settings, you should be using BepInEx.Configuration;, and create a ConfigFile to store your config. Make sure to specify that config.SaveOnConfigSet = true; or else your config willl not save when the user changes the settings!
Different settings
Boolean Setting
This one is fairly straightforward. It's a toggle that can be either on, or off.
- You should use
page.AddBoolSetting(string name, ConfigEntry<bool> configEntry)to create a setting that assigns the associatedConfigEntry<bool>from your BepInEx config. The first parameter is the display name for the setting. - You can use
page.AddBoolSetting(string name, bool defaultValue, Action<bool> update)to create a low-level setting where you control it.nameis the name that displays for the option.defaultValueis the value to show when the page loads, andupdateis the Action to call with the new value whenever the user changes the setting.
Scroll Setting
A scroll setting lets the user scroll through a list of predetermined options.
- You should use
page.AddScrollSetting<T>(string name, ConfigEntry<T> configEntry) where T : Enumto create a scroll setting from enum values with the givenConfigEntry<T>. For this to work correctly you need the values to be consecutive from 0 (i.e. just the names in the declaration, no values assigned). - You can use
page.AddScrollSetting<T>(string name, T defaultValue, Action<T> update) where T : Enumto create a scroll setting from enum values, starting at the specifieddefaultValueand telling when it changes using theupdatecallback. - You can use
page.AddScrollSetting<T>(string name, int index, Action<int> update) where T : Enum. It works very similarly to the one above, but this one takes the value of the enums, and not the enum object straight up. You should probably only use this when you actually need the index values, such as when storing them and you cannot change that (i.e. the vanilla game's settings store, which is the only reason this overload exists). - You can use
page.AddScrollSetting(string name, string[] values, int defaultIndex, Action<int> update)to create a withnamestill being the name that displays,valuesis the array of options to show,defaultIndexthe index you loaded to show by default, andupdateis a callback giving you the index of the option whenever the user changes it.
Slider Setting
A slider setting is... a slider, that you use to select a number within a range. The sliders are only whole numbers, and you can use divison if you want fractional values, such as with the music slider in the base game, which actually ranges from 0-1 internally but is divided by 10 since the slider range is 0-10.
- You should use
page.AddSliderSetting(string name, ConfigEntry<int> configEntry, int min, int max)to create a slider from the givenConfigEntry<int>, ranging frommin-maxand with the display namename. - You can use
page.AddSliderSetting(string name, int defaultValue, int min, int max, Action<int> update)to create a slider setting with the givennameanddefaultValue, ranging frommintomaxand telling you when it changes withupdate.
Control Setting
A control setting allows the user to choose a button on their keyboard or mouse to bind a specific action to.
- You should use
page.AddControlSetting(string name, ConfigEntry<KeyCode> configEntry)to create a control setting from the givenConfigEntry<KeyCode>.nameis the display name in the settings page. - You can use
page.AddControlSetting(string name, KeyCode defaultValue, Action<KeyCode> update)to create a control setting from the givenname, with thedefaultValueand the callbackupdate.
Two bool setting
Mainly in order to compress "inverted mouse" options, there's a more compact alternative: Two bool setting.
- You should use
page.AddTwoBoolSetting(string name, string label1, string label2, ConfigEntry<bool> configEntry1, ConfigEntry<bool> configEntry2)to create a two bool setting from the givenname,label1forconfigEntry1andlabel2forConfigEntry2. Usually,label1andlabel2will be something like"X", "Y". - You can use
page.AddTwoBoolSetting(string name, string label1, string label2, bool defaultValue1, bool defaultValue2, Action<bool, bool> update)to create a two bool setting from raw values. Its first 3 parameters are the labels for the settingname, for the first value ```label1, and the for second valuelabel2. ThedefaultValue1anddefaultValue2parameters are the values that are assigned to the options when the page loads, and the last parameterupdate`` is a callback to when either option changes.
There's also a Resolution setting, which i will not be documenting here because its only purpose is the resolution setting in the game, which is different from the rest.