Skip to content

Custom Mod Settings

piotrulos edited this page Sep 12, 2023 · 5 revisions

This creates custom mod settings that uses in-game UI instead of UMM OnGUI. Because this settings uses vanilla UI elements it should be interactable in VR mode.

For settings to be visible you need to have Better Mod Menu UI installed
Preview of currently possible settings (and it's variants):
obraz

How to register mod settings

You need to first Setup ModSettings function, you can only create settings inside that function.

Example

static bool Load(UnityModManager.ModEntry m)
{          
    DVModAPI.Setup(m, FunctionType.ModSettings, MyModSettings);
    return true;
}
private static void MyModSettings()
{
    //Create your settings here
}

Any examples below that shows how to create settings are done inside MyModSettings() created using above example

How to create mod settings

All settings are created from DVModSettings class, settings order in menu is same as the order you created them.

ModSettingsSlider and ModSettingsSliderInt

Used to add slider to mod settings

SettingsSliderInt - Accepts integer values, can also show values as text from string[] array.

ModSettingsSliderInt AddSlider(string id, string name, string tooltip, int minValue, int maxValue, int value = 0, Action onValueChanged = null)
ModSettingsSliderInt AddSlider(string id, string name, string tooltip, string[] textValues, int value = 0, Action onValueChanged = null)

id - Unique id for this slider
name - Name visible on slider
tooltip - Tooltip displayed when you hover over slider
minValue - Min allowed value for slider
maxValue - Max allowed value for slider
value - Default value for slider (default 0)
onValueChanged - Function to execute if value is changed (optional)
Optional overload: textValues - String Array of text values

* ModSettingsSlider - Accepts float values.

 ModSettingsSlider AddSlider(string id, string name, string tooltip, float minValue, float maxValue, float value = 0f, int decimalPoints = 2, Action onValueChanged = null)

similar values to ModSettingsSliderInt except:
(Optional) decimalPoints - how many decimal points round the float value (default 2)

Usage Examples

public static ModSettingsSlider myTestSlider;
            
private static void MyModSettings()
{
    myTestSlider = DVModSettings.AddSlider("myTestSlider", "This is Slider (float)", "This is float slider between 5 and 15 with default value 6.5f", 5f, 15f, 6.5f);
}

Result
Float slider with range from 5 to 15 with default value as 6.5f
obraz

You can access it's value anywhere using myTestSlider.GetValue()

public static ModSettingsSliderInt myTestSlider;
            
private static void MyModSettings()
{
    myTestSlider = DVModSettings.AddSlider("TestSliderText", "This is Slider (text)", "This is float slider that has text as values", new string[] { "value1","value2","value3"});
}

Result
Slider with text values, range is from 0 to based on array lenght.
obraz

ModSettingsCheckBox

ModSettingsCheckBox AddCheckBox(string id, string name, string tooltip, bool value = false, Action onValueChanged = null)

id - Unique id for this CheckBox
name - Name visible on CheckBox
tooltip - Tooltip displayed when you hover over CheckBox
value - Default value for CheckBox (default false)
onValueChanged - Function to execute if value is changed (optional)

Usage Examples

public static ModSettingsCheckBox myTestCheckbox;
            
private static void MyModSettings()
{
    myTestCheckbox = DVModSettings.AddCheckBox("myTestCheckbox", "This is checkbox", "This is tooltip for checkbox", true);
}

Result
obraz

Other Settings Types

AddButton

Adds clickable button

AddButton(string name, string tooltip, Action onClick)

name - Name visible on button
tooltip - Tooltip displayed when you hover over button
onClick - Function to execute if button is clicked

Usage Examples

private static void MyModSettings()
{
    DVModSettings.AddButton("This is Button", "This is button that executes function when clicked",TestButtonClick);
}
static void TestButtonClick()
{
    //Do something when button is clicked
}

Result
obraz

AddText

Adds just a static text

AddText(string text)

text - Just a text

Usage Examples

private static void MyModSettings()
{
    DVModSettings.AddText("This is just a text");
}

Result
obraz