Developing Categories with Configurable Company
What is a Category
Categories are another way to organize your configurations, like configuration pages they don't modify how configurations work however they will allow players to focus on what configurations they want to change, specially when there are many configurations.
Creating a Category
Categories are used to organize your configuration in a folder-like structure so that the final user can easily navigate the menu. These are symbolic and do not change the behavior of the configurations at all.
To create a category is as simple as calling LethalConfiguration.CreateCategory
. You can choose to provide an ID right from the start or later, however all categories must contain an unique ID.
IDs must be lowercase, contain only letters, numbers, hypens -
and underscores _
. I'd recommend to make your IDs look something like owner_your-plugin-name_category-name
.
Here is an example on how you can create a category:
INFO
If you don't know what a parameter does, check parameters section.
ConfigurationCategory sampleCategory = LethalConfiguration.CreateCategory()
.SetID("developer_some-mod_sample-category")
.SetName("Sample category")
.SetPage(ConfigurationPage) // Optional
.SetColorRGB(255, 0, 0) // Optional
.HideIfEmpty(false) // Optional
.Build();
TIP
It's not necesary to call Build()
if you are assigning the builder to a ConfigurationCategory
as it will implicitly call the build method to create the category.
Parameters
SetID(string)
: The unique ID of the category.SetName(string)
: The name that will be displayed on the in-game menu.SetColor(Color[white])
: (There are multiples methods to set the color. choose the prefered one based on your preferences) Sets the color of the category panel in the in-game menu.HideIfEmpty(bool[true])
: Marks the category to not be displayed at all if there are no configurations inside this category.SetPage(ConfigurationPage)
: Makes this category go listed on the provided page. One is generated by default but I encourage you to create a page for your mod.
Build()
will create the category. It will not be created until the method is called (However as mentioned above, the method will called automatically if you assign the creation to a category).
WARNING
Once the Build()
is called, you will not be able to modify the category any further.
Using a Category
To use a defined category, you must store the variable with the ConfigurationCategory
and assign your configurations to it.
You also have the option to get a category from it's ID, allowing you to even get categories declared in other plugins.
string categoryId = "some-mod_category";
if (LethalConfiguration.TryGetCategory(categoryId, out ConfigurationCategory category)) {
// If the category exists you can use it
} else {
// If the category does not exists you might need to create it
}
TIP
You can declare categories as internal static readonly
variables to access them anywhere in your project.