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 Dropdown<string> SettingVariableName { get; set; } = new Dropdown<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 Dropdown<CustomObject> SettingVariableName { get; set; } = new Dropdown<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";
If your group is empty (there are no properties that could indicate the group's order), you can use xref:MCM.Abstractions.Attributes.SettingPropertyGroupAttribute to order the group
[SettingPropertyGroupMetadata]
[SettingPropertyGroup("EmptyGroup", GroupOrder = 3)]
public object EmptyGroupMetadata { get; set; } = new();
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 06/20/2024 23:41:40 +03:00 (UTC).
Commit Message
Author: Vitalii Mikhailov
Commit: 22da042e932b2b1a231a7120255b8281d0711bc1
Added SettingPropertyGroupMetadata
Removed obsolete code