2021-02-10 11:04:16 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Configuration
|
|
|
|
{
|
2021-02-10 11:11:36 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A helper class for tracking changes to the settings of a set of <see cref="Mod"/>s.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Ensure to dispose when usage is finished.
|
|
|
|
/// </remarks>
|
2021-02-10 11:04:16 +00:00
|
|
|
public class ModSettingChangeTracker : IDisposable
|
|
|
|
{
|
2021-02-10 11:11:36 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Notifies that the setting of a <see cref="Mod"/> has changed.
|
|
|
|
/// </summary>
|
2021-02-10 11:04:16 +00:00
|
|
|
public Action<Mod> SettingChanged;
|
|
|
|
|
2021-02-10 11:11:36 +00:00
|
|
|
private readonly List<ISettingsItem> settings = new List<ISettingsItem>();
|
2021-02-10 11:04:16 +00:00
|
|
|
|
2021-02-10 11:11:36 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="ModSettingChangeTracker"/> for a set of <see cref="Mod"/>s.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="mods">The set of <see cref="Mod"/>s whose settings need to be tracked.</param>
|
2021-02-10 11:04:16 +00:00
|
|
|
public ModSettingChangeTracker(IEnumerable<Mod> mods)
|
|
|
|
{
|
|
|
|
foreach (var mod in mods)
|
|
|
|
{
|
|
|
|
foreach (var setting in mod.CreateSettingsControls().OfType<ISettingsItem>())
|
|
|
|
{
|
|
|
|
setting.SettingChanged += () => SettingChanged?.Invoke(mod);
|
2021-02-10 11:11:36 +00:00
|
|
|
settings.Add(setting);
|
2021-02-10 11:04:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
SettingChanged = null;
|
|
|
|
|
2021-02-10 11:11:36 +00:00
|
|
|
foreach (var r in settings)
|
2021-02-10 11:04:16 +00:00
|
|
|
r.Dispose();
|
2021-02-10 11:11:36 +00:00
|
|
|
settings.Clear();
|
2021-02-10 11:04:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|