You are viewing a potentially older version of this package. View all versions.
AinaVT-LethalConfig-1.0.1 icon

LethalConfig

Provides an in-game config menu for other mods to use

Date uploaded 4 months ago
Version 1.0.1
Download link AinaVT-LethalConfig-1.0.1.zip
Downloads 15588
Dependency string AinaVT-LethalConfig-1.0.1

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100

README

LethalConfig Icon

LethalConfig

LethalConfig is an in-game mod configuration menu that can be used by any mod developer to let players change their BepInEx's ConfigEntry's within the game through a variety of UI controls.

Inspired by Rune580's RiskOfOptions

Summary

Supported Types

Currently, LethalConfig allows developers to add the following types of interfaces for ConfigEntry's:

Component Value Type ConfigItem Type
Integer Slider int IntSliderConfigItem
Integer Input Field int IntInputFieldConfigItem
Float Slider float FloatSliderConfigItem
Float Step Slider float FloatStepSliderConfigItem
Float Input Field float FloatInputFieldConfigItem
Text Input Field string TextInputFieldConfigItem
Enum Dropdown Enum EnumDropDownConfigItem<>
Boolean Checkbox Enum BoolCheckBoxConfigItem

LethalConfig Menu Example An example of the LethalConfig menu and its element types

Usage

Setting up

To start using LethalConfig on your mod, add a reference on your project to the LethalConfig's dll file. You can get the dll by downloading the LethalConfig mod on Thunderstore.

To access the API, simply use the LethalConfig namespace or import it on your source file:

using LethalConfig;

It is also recommended to add a BepInDependency attribute to your plugin to hint BepInEx that your mod has a dependency to it:

[BepInPlugin(PluginInfo.Guid, PluginInfo.Name, PluginInfo.Version)]
[BepInDependency("ainavt.lc.lethalconfig")]
public class MyVeryCoolPlugin: BaseUnityPlugin {
    ...
}

Adding a ConfigItem

With everything setup, you should now have access to the main LethalConfigManager and are able to add any of the available components you want.

First, you create your ConfigEntry from BepInEx like you would normally:

var configEntry = Config.Bind("General", "Example", 0, "This is an example component!");

With your ConfigEntry in hand, you can now create and register a new item to the menu by using the following method:

var exampleSlider = new IntSliderConfigItem(configEntry, new IntSliderOptions 
{
    Min = 0,
    Max = 100
});
LethalConfigManager.AddConfigItem(exampleSlider);

And that's it, you now have created your first component! Slider example

LethalConfig automatically picks up some of your mod info, and it automatically creates sections based on the section of the provided ConfigEntry, so you do not have to worry about any extra setup in terms of layout.

ConfigItem restart requirement

By default, all items will be set to require a restart if changed. This will give a warning to the player once they apply the settings.

If you want your items to not be flagged as restart required, simply flag the constructor of the config items, either through the bool constructor overload or passing it inside the item's specific options:

// Using the slider options object
var exampleSlider = new IntSliderConfigItem(configEntry, new IntSliderOptions 
{
    RequiresRestart = false,
    Min = 0,
    Max = 100
});

// Using the bool constructor overload
var exampleSlider = new IntSliderConfigItem(configEntry, requiresRestart: false);

Listening to setting changes

Note that players will most likely expect settings to take effect immediately if not prompted to restart. If you need to listen to changes to values of your configuration, ConfigEntry provides a mechanism for that:

configEntry.SettingChanged += (obj, args) =>
{
    logSource.LogInfo($"Slider value changed to {configEntry.Value}");
};

Issues and Suggestions

If you have an issue with LethalConfig, or want to suggest a feature, feel free to open an issue at the GitHub repository.

Alternatively, you can also leave your suggestions and issues on the LethalConfig post under the Mod Releases forum in the Unofficial Lethal Company Discord Server.

Changelog

Version 1.0.1

- Added two new config types:
    - IntInputConfigItem (an integer text field)
    - FloatInputConfigItem (a float text field)
- Fixed missing default value in the enum dropdown's description.

Version 1.0.0

Initial release, which includes the following types:
    - IntSliderConfigItem
    - FloatSliderConfigItem
    - FloatStepSliderConfigItem
    - EnumDropDownConfigItem
    - BoolCheckBoxConfigItem
    - TextInputFieldConfigItem

CHANGELOG

Version 1.4.2

  • Reverted changes to most config item's constructors from #42, as it was an unintentional breaking change. (#47)

Version 1.4.1

  • Exposing BaseConfigItem#ApplyChanges, BaseConfigItem#CancelChanges, and BaseConfigItem#ChangeToDefault
  • Added optional Assembly argument for LethalConfigManager#AddConfigItem
  • Marking dynamically loaded mod icons as non-readable to improve memory usage.

Version 1.4.0

  • Updating config appearances whenever a ConfigEntry is modified directly.
  • Added QueueCustomConfigFileForAutoGeneration method, allowing the auto generation of configs for manually created config files.
  • Added new options to TextInputFieldOptions:
    • NumberOfLines Sets how many lines a text field can have. Setting it to 0 means no limit.
    • TrimText When true, automatically removes empty space from the start and end of the text.
  • Added new component TextDropDownConfigItem, which allows you to make a dropdown selector for strings (including configs with AcceptableValueList) (thank you @Kittenji)
  • Adjusted colors of the menu to be darker.
  • Added "Hide Lethal Config" config to disable LethalConfig in-game. This setting is only visible on the r2modman's config editor and is false by default.
  • Fixed issue where a mod couldn't have more than one generic button (comparison would always think they're the same).
  • Attempt to fix issue where configs would not be generated if a plugin's instance was null at the time of the generation.

Version 1.3.4

  • Fixed issue where some assemblies' depedencies could cause the UI to not load properly.
  • Fixed issue with sliders/numeric inputs not using the AcceptableValueRange, this time for real.

Version 1.3.3

  • Fixed uncommon issue where closing LethalConfig would make the main menu/quick menu unusable due to not being deactivated and blocking the UI raycasts.
  • Forcing LethalConfig to be set as the last sibling when it's opened. This ensures the menu will be shown above UI that may be added by other mods.

Version 1.3.2

  • Reverted type for slider and numeric input options from nullable.

Version 1.3.1

  • Fixed issue where duplicated fields were autogenerated when the section or name of the item was overriden
  • Fixed issue where providing an options objects to sliders without setting their min/max values would not fallback into the AcceptableValueRange of the entry if one was present.

Version 1.3.0

  • Added new GenericButtonConfigItem, which allows you to create a button that provides you with a callback to run your own code when it's clicked.
  • Added item's Section, Name, and Description overrides, which allows you to change what LethalConfig will show without changing the section, keys, or descriptions in your ConfigEntry directly.
  • Fixed issue when trying to automatically read the mod's icon and description from mods installed manually with their dll at the root of the BepInEx's plugins folder. (@Rune580)
  • Fixed exception caused in the quick menu when running LethalConfig with AdvancedCompany.

Version 1.2.0

  • LethalConfig now reads both the mod's icons and descriptions directly from its thunderstore manifest if one can be found. (@Rune580)
  • Added methods to make LethalConfig skip the autogeneration for your entire mod, a config section, or individual configs. (@Rune580)
  • Added callbacks to the ConfigItem's options to tell whether a field is modifiable or not. (@Rune580)
  • Added LethalConfig to the in-game quick menu.
  • Did a change to how the mod adds the menu button in the main menu, so it conflicts a bit less with other mods like LethalExpansion or IntroTweaks.

Version 1.1.0

  • Automatically generating mod entries and config items for all loaded mods that creates their own ConfigEntry. With this, mods technically don't have the need to necessarily have LethalConfig as a dependency unless they want to use specific components, mark certain settings as non-restart required, or want to set their mod icon and description.
  • Adjusted some layout stuff.
  • Fixed a bug with the initialization of sliders.
  • Added customizable mod icons and mod descriptions.

Version 1.0.1

  • Added two new config types:
    • IntInputConfigItem (an integer text field)
    • FloatInputConfigItem (a float text field)
  • Fixed missing default value in the enum dropdown's description.

Version 1.0.0

  • Initial release, which includes the following types:
    • IntSliderConfigItem
    • FloatSliderConfigItem
    • FloatStepSliderConfigItem
    • EnumDropDownConfigItem
    • BoolCheckBoxConfigItem
    • TextInputFieldConfigItem