// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; namespace osu.Framework.Configuration.Tracking { /// /// A singular tracked setting. /// /// The type of the tracked value. public abstract class TrackedSetting : ITrackedSetting { public event Action SettingChanged; private readonly object setting; private readonly Func generateDescription; private Bindable bindable; /// /// Constructs a new . /// /// The config setting to be tracked. /// A function that generates the description for the setting, invoked every time the value changes. protected TrackedSetting(object setting, Func generateDescription) { this.setting = setting; this.generateDescription = generateDescription; } public void LoadFrom(ConfigManager configManager) where TLookup : struct, Enum { bindable = configManager.GetBindable((TLookup)setting); bindable.ValueChanged += displaySetting; } public void Unload() { bindable.ValueChanged -= displaySetting; } private void displaySetting(ValueChangedEvent args) => SettingChanged?.Invoke(generateDescription(args.NewValue)); } }