Rune580-Risk_Of_Options icon

Risk Of Options

A convenient API for adding BepInEx ConfigEntry's to a option menu

Last updated 6 months ago
Total downloads 1554692
Total rating 39 
Categories Mods Libraries Client-side
Dependency string Rune580-Risk_Of_Options-2.7.1
Dependants 794 other packages depend on this package

This mod requires the following mods to function

bbepis-BepInExPack-5.4.1905 icon
bbepis-BepInExPack

Unified BepInEx all-in-one modding pack - plugin framework, detour library

Preferred version: 5.4.1905

README

RiskOfOptions

Animated icon made by UnsavedTrash#0001 on discord

An API to provide a user interface in game to interact with BepInEx ConfigEntry's.

Currently supported options

  • CheckBoxes bool
  • Sliders float
  • StepSliders float
  • IntSliders int
  • KeyBinds KeyboardShortcut
  • String Input Fields string
  • Choice DropDowns Enum
  • Color Picker UnityEngine.Color

Additional Components

  • GenericButtons

For feature requests or issues head over to my repository.

Developer Resources

Getting Started

First you need to grab the latest release from the Thunderstore. Extract the mod to your plugins folder, and then add a reference to the dll in your project in Visual Studio. [Project->Add Reference...->Browse]

Then add to where ever you will use this.

using RiskOfOptions;

Next you need to add Risk Of Options as a dependency for your mod.

[BepInDependency("com.rune580.riskofoptions")]

Finally make sure you know how to use BepInEx Config

Now you're ready to start adding options.

Adding an option

Given a ConfigEntry<bool>

ConfigEntry<bool> enableThing = Config.Bind(...);

ModSettingsManager.AddOption(new CheckBoxOption(enableThing);

Need a volume slider?

ConfigEntry<float> volume = Config.Bind(...);

ModSettingsManager.AddOption(new SliderOption(volume));

Every option constructor can take a Config for the example above it would be SliderConfig. Say you need a slider that only goes between 60 - 130. You would do:

ModSettingsManager.AddOption(new SliderOption(limitedRangeFloat, new SliderConfig() { min = 60, max = 130 }));

What about a slider that goes in increments of 0.15 and is limited between 1 - 5?

ModSettingsManager.AddOption(new StepSliderOption(incrementedFloat, new StepSliderConfig() { min = 1, max = 5, increment = 0.15f }));

Enough about floats, let's talk about the spaghetti and meatballs, KeyBinds.

ConfigEntry<KeyboardShortcut> keyBind = Config.Bind(...);

ModSettingsManager.AddOption(new KeyBindOption(keyBind)); // This also has a KeyBindConfig but can be omitted if defaults are desired.

And that's it, said KeyboardShortcut will show up on the ModOptions menu.

Checkbox and Slider configs can be set with a delegate that will be used to check if said option should be disabled in the menu.

ConfigEntry<bool> disableThing = Config.Bind(...);
ConfigEntry<bool> overridenThing = Config.Bind(...); 

ModSettingsManager.AddOption(new CheckBoxOption(disableThing));
ModSettingsManager.AddOption(new CheckBoxOption(overridenThing, new CheckBoxConfig() { checkIfDisabled = Check }));

...

private bool Check()
{
    return disabledThing.value;
}

When disableThing is enabled overridenThing will show up as non-interactable in the menu.

"Okay that's all fine but how do I, you know, do stuff when an value is changed?" Well thankfully ConfigEntry's have this innately:

ConfigEntry<bool> toggleThing = Config.Bind(...);

toggleThing.SettingChanged += (object, args) => { Debug.Log(toggleThing.Value) };

Of course when an option changes the value of a passed ConfigEntry, the value updates in real time, so in some cases where you are checking the value of the entry directly you don't need to do anything.

There may be cases where you just want a convenient button to open your own menu, as such you can do this:

ModSettingsManager.AddOption(new GenericButtonOption("Custom Menu", "Misc", "Configure stuff in here", "Open Custom Menu", OpenMenu));

private void OpenMenu()
{
    /// Do stuff
}

The GenericButtonOption may be used to provide an entry point for opening your custom GUI's.

Setting the description of the mod

ModSettingsManager.SetModDescription("Describe your mod in incredible detail over the course of the next 2 hours");

Setting the icon of the mod

Sprite icon = ...;

ModSettingsManager.SetModIcon(icon);

Quick Showcase

Showcase

Contact

Discord: @rune

Github: Rune580

Changelog

2.7.1:
  StringInputFields have improved newline behavior.
    - InputFieldConfig has a new field `lineType`, it represents TMP's `lineType` enum.
    - SubmitEnum is now marked with the `Flags` attribute, should allow for more fine-tuned input field behavior.
    - `Shift` + `Enter` will always insert a newline, if the StringInputField is configured to allow newlines, without submitting.
  Because of the above changes, StringInputFields may behave differently to prior versions. If you relied on the 
    previous behavior, sorry for making more work for you, but this should make input fields be more reliable.
  In addition the default behavior for StringInputFields are `MultiLineSubmit` as this mimics the previous
    behavior the closest.

2.7.0:
  All numeric InputFields now properly use InvariantCulture, for example numbers are formatted as `1,000,000.20`.
    - RiskOfOptions exposes an option to change this behavior in-game.
  RiskOfOptions option menu.
  Experimental support for Prefabs as mod icons.
    - The root object's RectTransform must have a width and height of 45.
  Animated icon has been updated.

2.6.1:
  Forgot to include some assets that are required for the color picker.

2.6.0:
  Added Method for setting mod descriptions with a language token.
  Added event when the mod options panel is closed.
  Slight behaviour change for color wheel, (I did this like a year ago and forgot to push it out in an update, so here you go.)
  Any other commits that happened between last year and now.

2.5.3:
  Merged PR by Bubbet https://github.com/Rune580/RiskOfOptions/pull/28
    - Abstracts references to bepinexconfig out.
    - Allows mods to extend off of RoO's options.
  Updated to preview C# language.

2.5.2:
  Fixed descriptions not wrapping.

2.5.1:
  Minor improvements to the layout of the mod options menu.
  Fixed some minor stutters when opening the settings menu for the first time.
  Removed HookGenPatcher/MMHook as a dependency.

2.5.0:
  Added ColorOption.
  Added ColorPickerUtil for manually opening a color picker.
  Added 2 new submit modes for input fields:
    - OnExitOrSubmit
    - OnSubmit
    These can be used with the `submitOn` Field in the InputFieldConfig.
  Fixed an issue where having multiple input fields causes hitching.
  Fixed an issue where input fields wouldn't visually revert.

2.4.2:
  Sliders can now have their values be manually set in the text box. No more finagling the slider to get the value you want.
    The future is now!

2.4.1:
  Fixed category indicators taking up more vertical space than intended.

2.4.0:
  Added IntSlider option, which is just a normal slider but it accepts an ConfigEntry<int> instead.

2.3.2:
  Added overrides for modGuid and modName when adding an option.
  CheckBox is now a prefab instead of being copied from a button in game. What does that mean for the normal user?
    realistically nothing at all, you shouldn't notice anything different. For the dev however, this puts us a step closer
    to having RiskOfOptions ui elements be accessible to other mods.

2.3.1:
  Disable functionality is now fully implemented on all simple options.

2.3.0:
  Quite a few things in this update, as always let me know if you have any issues.
    - Added ChoiceOption, takes an CongiEntry<enum>.
    - Removed dependency on R2API, I didn't really use it anyways, now you don't have to worry about an unnecessary dependency.
        haha dependencies bad ;))))))))))))))))
    - Fixed animation issues with the Mod Options menu while playing in singleplayer.
    - Added workaround for when a mod embeds it's own settings api (the reason why one would do this alludes me...),
        as they can break the Mod Options panel.

2.2.0 - Added GenericButtonOption which allows for devs to supply a UnityAction that is invoked when the button is pressed.
Cleaned up a few things. Should work for the newest patch, let me know if you find any issues.

2.1.0 - Added StringInputFieldOption. Configuration option `restartRequired` has been fully implemented,
set this to true to show a restart warning when the option is modified. Description panels now scroll.

2.0.0 - Massive Rewrite of the entire mod. Now exclusively uses BepInEx ConfigEntry's.
Completely new UI, with a working revert button. Added Stepped Slider, and KeyBind options.
Mods dependent on 1.0 will not work with 2.0

1.0.4 - Quick update for SOTV.

1.0.3 - Added R2API as a dependency because I forgot about that. Also I'm currently rewriting ROO,
so hopefully the next update should be a pretty big one. No ETA on that, but progress is good
so far.