forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModSettingChangeTracker.cs
More file actions
56 lines (49 loc) · 1.89 KB
/
Copy pathModSettingChangeTracker.cs
File metadata and controls
56 lines (49 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Configuration
{
/// <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>
public class ModSettingChangeTracker : IDisposable
{
/// <summary>
/// Notifies that the setting of a <see cref="Mod"/> has changed.
/// </summary>
public Action<Mod> SettingChanged;
private readonly List<ISettingsItem> settings = new List<ISettingsItem>();
/// <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>
[UnconditionalSuppressMessage("ILLink", "IL2026", Justification = "SettingSourceAttribute uses reflection intentionally; callers on trimmed targets must ensure mod types are preserved.")]
public ModSettingChangeTracker(IEnumerable<Mod> mods)
{
foreach (var mod in mods)
{
foreach (var setting in mod.CreateSettingsControls().OfType<ISettingsItem>())
{
setting.SettingChanged += () => SettingChanged?.Invoke(mod);
settings.Add(setting);
}
}
}
public void Dispose()
{
SettingChanged = null;
foreach (var r in settings)
r.Dispose();
settings.Clear();
}
}
}