Each setting you want to add to the menu has to be marked with an attribute.
You can additionally group settings by adding the SettingPropertyGroup attribute. '/'
is used as the default separator.
Right now, the mod provides these types in the setting menu:
- Bool
- Int Slider / Textbox
- Float Slider / Textbox
- Textbox
- Dropdown
- Button
v1
With v1 of the API, SettingProperty has multiple constructors, each designed for the specific value it represents.
Bool
[SettingProperty("Setting Name", RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public bool SettingVariableName { get; set; } = true;
Int
[SettingProperty("Setting Name", minValue: 0, maxValue: 10, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public int SettingVariableName { get; set; } = 5;
Float
[SettingProperty("Setting Name", minValue: 0f, maxValue: 0.5f, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public float SettingVariableName { get; set; } = 0.2f;
String
[SettingProperty("Setting Name", RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public string SettingVariableName { get; set; } = "The textbox data is here";
v2
With v2 of the API, there's multiple types of setting properties to make using them less confusing, and the settings can also be ordered by indexing them. It's also possible to format the display of the numerical values for the int and float sliders.
Bool (SettingPropertyBool)
[SettingPropertyBool("Setting Name", Order = 0, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public bool SettingVariableName { get; set; } = true;
Int (SettingPropertyInteger)
// Value is displayed as "X Denars"
[SettingPropertyInteger("Setting Name", 0, 100, "0 Denars", Order = 1, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public int SettingVariableName { get; set; } = 25;
Float (SettingPropertyFloatingInteger)
// Value is displayed as a percentage
[SettingPropertyFloatingInteger("Setting Name", 0f, 1f, "#0%", Order = 2, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public float SettingVariableName { get; set; } = 0.75;
String (SettingPropertyText)
// Value is displayed as a percentage
[SettingPropertyText("Setting Name", Order = 3, RequireRestart = false, HintText = "Setting Explanation")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public string SettingVariableName { get; set; } = "The textbox data is here";
To understand how to format the strings take a look at this page for information and examples (specifically the ToString version).
Dropdown (SettingPropertyDropdown)
[SettingPropertyDropdown("Setting Name", Order = 4, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public DropdownDefault<string> SettingVariableName { get; set; } = new DropdownDefault<string>(new string[]
{
"Test1",
"Test2",
"Test3"
}, selectedIndex: 0);
It can also use custom classes. Don't forget to override .ToString()!
[SettingPropertyDropdown("Setting Name", Order = 5, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public DropdownDefault <CustomObject> SettingVariableName { get; set; } = new DropdownDefault <CustomObject>(new CustomObject[]
{
new CustomObject("Test1"),
new CustomObject("Test2"),
new CustomObject("Test3")
}, selectedIndex: 0);
public class CustomObject
{
private readonly string _value;
public CustomObject(string value) => _value = value;
public override string ToString() => _value;
}
Button (SettingPropertyButton)
// Value is displayed as a percentage
[SettingPropertyButton("Setting Name", Content = "Press Me", Order = 2, RequireRestart = false, HintText = "Setting explanation.")]
[SettingPropertyGroup("Main Group Name/Nested Group Name/Second Nested Group Name")]
public Actiom SettingVariableName { get; set; } = (() => { });
Ordering
You can order properties via the Order
attribute property
[SettingPropertyText("Setting Name", Order = 6)]
public string SettingVariableName { get; set; } = "The textbox data is here";
Require Restart
You can the game to restart when the property changes via the RequireRestart
attribute property
[SettingPropertyText("Setting Name", RequireRestart = true)]
public string SettingVariableName { get; set; } = "The textbox data is here";
Hint Text
You can set a description to be displayed when hovering over the setting via the HintText
attribute property
[SettingPropertyText("Setting Name", HintText = "This is a Hint")]
public string SettingVariableName { get; set; } = "The textbox data is here";
Group Order
You can order the setting groups via the GroupOrder
attribute property
[SettingPropertyText("Setting Name")]
[SettingPropertyGroup("Main Group Name", GroupOrder = 1)]
public string SettingVariableName { get; set; } = "The textbox data is here";
Group Toggle
You can make a setting property a group toggle via the IsToggle
attribute property
[SettingPropertyBool("Main Group Name Toggle", IsToggle = true)]
[SettingPropertyGroup("Main Group Name")]
public bool SettingVariableName{ get; set; } = false;
This page was last modified at 01/26/2022 17:20:48 +03:00 (UTC).
Commit Message
Author: Vitaly Mikhailov
Commit: 972bd3d60dd61f4c52acc1cca04f16498b9e82d6
Update mcmv4-attributes.md