mirror of
https://github.com/osukey/osukey.git
synced 2025-05-07 22:57:31 +09:00
Implement user selection logic for mod presets
This commit is contained in:
parent
de64b83532
commit
0287c49ca8
@ -1,7 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
@ -25,7 +27,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
private IDialogOverlay? dialogOverlay { get; set; }
|
private IDialogOverlay? dialogOverlay { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
||||||
|
|
||||||
private ModSettingChangeTracker? settingChangeTracker;
|
private ModSettingChangeTracker? settingChangeTracker;
|
||||||
|
|
||||||
@ -35,6 +37,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
Title = preset.Value.Name;
|
Title = preset.Value.Name;
|
||||||
Description = preset.Value.Description;
|
Description = preset.Value.Description;
|
||||||
|
|
||||||
|
Action = toggleRequestedByUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -50,6 +54,17 @@ namespace osu.Game.Overlays.Mods
|
|||||||
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
|
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggleRequestedByUser()
|
||||||
|
{
|
||||||
|
// if the preset is not active at the point of the user click, then set the mods using the preset directly, discarding any previous selections.
|
||||||
|
// if the preset is active when the user has clicked it, then it means that the set of active mods is exactly equal to the set of mods in the preset
|
||||||
|
// (there are no other active mods than what the preset specifies, and the mod settings match exactly).
|
||||||
|
// therefore it's safe to just clear selected mods, since it will have the effect of toggling the preset off.
|
||||||
|
selectedMods.Value = !Active.Value
|
||||||
|
? Preset.Value.Mods.ToArray()
|
||||||
|
: Array.Empty<Mod>();
|
||||||
|
}
|
||||||
|
|
||||||
private void selectedModsChanged()
|
private void selectedModsChanged()
|
||||||
{
|
{
|
||||||
settingChangeTracker?.Dispose();
|
settingChangeTracker?.Dispose();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user