AinaVT / LethalConfig

A mod configuration menu for Lethal Company
https://thunderstore.io/c/lethal-company/p/AinaVT/LethalConfig/
GNU General Public License v3.0
15 stars 6 forks source link

[Suggestion] Adding a delegate for OnValueChanged on Options allowing actions on those values #33

Open VELD-Dev opened 7 months ago

VELD-Dev commented 7 months ago

I know it's not very clear. You'd think "just use ConfigEntry.OnChanged" but it will work in some cases.
I couldn't find any better name for the suggestion to be honest.
Here is an example use case.

class Config
{
  public enum ExampleEnum
  {
    ChoiceOne,
    ChoiceTwo,
    ChoiceThree,
  }

  public static ConfigEntry<ExampleEnum> ExEnumValue;
  public static ConfigEntry<int> ExEnumValueChild;

  public Config(ConfigFile cfg)
  {
    ExEnumValue = cfg.Bind("general", "testEnum", ExampleEnum.ChoiceOne, "eeee");
    ExEnumValueChild = cfg.Bind("general", "testValue", 0, "aaaa");

    var enumOption = new EnumDropDownConfigItem<ExampleEnum>(ExEnumValue, new EnumDropDownOptions
    {
      RequiresRestart = false
    });

    var intOption = new IntSliderConfigItem(ExEnumValueChild, new IntSliderOptions
    {
      Min = 0,
      Max = 12,
      OnValueChanged += (changedOption, thisOption) =>
      {
        if(changedOption is not ConfigEntry<ExampleEnum>)
          return;

        var enumChangedOpt = changedOption as ConfigEntry<ExampleEnum>;        

        switch(enumChangedOpt.Value)
        {
          case ExampleEnum.ChoiceTwo:
            thisOption.Max = 6;
          break;
          case ExampleEnum.ChoiceThree:
            thisOption.Max = 1;
          break;
          default:
            thisOption.Max = 12;
          break;
        }
      },
      RequiresRestart = false
    });
  }
}

That's quite complex but basically it would allow to change other options limits and datas when another option of the menu is triggered.

I'm not good at all to explain, but if you want more precise explanations, I'm always open.