1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 01:02:56 +08:00

Split ModSettingChangeTracker into separate file

This commit is contained in:
smoogipoo 2021-02-10 20:04:16 +09:00
parent 822c66033f
commit 4a405bb859
2 changed files with 39 additions and 29 deletions

View File

@ -0,0 +1,39 @@
// 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
{
public class ModSettingChangeTracker : IDisposable
{
public Action<Mod> SettingChanged;
private readonly List<ISettingsItem> references = new List<ISettingsItem>();
public ModSettingChangeTracker(IEnumerable<Mod> mods)
{
foreach (var mod in mods)
{
foreach (var setting in mod.CreateSettingsControls().OfType<ISettingsItem>())
{
setting.SettingChanged += () => SettingChanged?.Invoke(mod);
references.Add(setting);
}
}
}
public void Dispose()
{
SettingChanged = null;
foreach (var r in references)
r.Dispose();
references.Clear();
}
}
}

View File

@ -9,7 +9,6 @@ using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Configuration
{
@ -141,32 +140,4 @@ namespace osu.Game.Configuration
return orderedRelative.Concat(unordered);
}
}
public class ModSettingChangeTracker : IDisposable
{
public Action<Mod> SettingChanged;
private readonly List<ISettingsItem> references = new List<ISettingsItem>();
public ModSettingChangeTracker(IEnumerable<Mod> mods)
{
foreach (var mod in mods)
{
foreach (var setting in mod.CreateSettingsControls().OfType<ISettingsItem>())
{
setting.SettingChanged += () => SettingChanged?.Invoke(mod);
references.Add(setting);
}
}
}
public void Dispose()
{
SettingChanged = null;
foreach (var r in references)
r.Dispose();
references.Clear();
}
}
}