Automatically toggle preset panels if selected mods match

This commit is contained in:
Bartłomiej Dach 2022-07-23 23:15:28 +02:00
parent 25daaa56e2
commit b1dcd7821c
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
1 changed files with 34 additions and 0 deletions

View File

@ -1,10 +1,12 @@
// 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.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
@ -22,6 +24,11 @@ public class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>, IHas
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
[Resolved]
private IBindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
private ModSettingChangeTracker? settingChangeTracker;
public ModPresetPanel(Live<ModPreset> preset)
{
Preset = preset;
@ -36,6 +43,26 @@ private void load(OsuColour colours)
AccentColour = colours.Orange1;
}
protected override void LoadComplete()
{
base.LoadComplete();
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
}
private void selectedModsChanged()
{
settingChangeTracker?.Dispose();
settingChangeTracker = new ModSettingChangeTracker(selectedMods.Value);
settingChangeTracker.SettingChanged = _ => updateActiveState();
updateActiveState();
}
private void updateActiveState()
{
Active.Value = new HashSet<Mod>(Preset.Value.Mods).SetEquals(selectedMods.Value);
}
#region IHasCustomTooltip
public ModPreset TooltipContent => Preset.Value;
@ -51,5 +78,12 @@ private void load(OsuColour colours)
};
#endregion
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
settingChangeTracker?.Dispose();
}
}
}