settings extensions; proper enable/disable multiselect

This commit is contained in:
Tyfon
2024-06-25 15:19:07 -07:00
parent bc166b808f
commit a6e622013e
5 changed files with 51 additions and 35 deletions

View File

@@ -1,4 +1,5 @@
using BepInEx.Configuration;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
@@ -623,10 +624,6 @@ namespace UIFixes
if (!primaryConfig.Value)
{
dependentConfig.Value = false;
if (dependentConfig.Description.Tags[0] is ConfigurationManagerAttributes attributes)
{
attributes.ReadOnly = true;
}
}
primaryConfig.SettingChanged += (_, _) =>
@@ -653,4 +650,19 @@ namespace UIFixes
};
}
}
public static class SettingExtensions
{
public static void Subscribe<T>(this ConfigEntry<T> configEntry, Action<T> onChange)
{
configEntry.SettingChanged += (_, _) => onChange(configEntry.Value);
}
public static void Bind<T>(this ConfigEntry<T> configEntry, Action<T> onChange)
{
configEntry.Subscribe(onChange);
onChange(configEntry.Value);
}
}
}