1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-17 22:17:25 +08:00

Refactor mod panel selection logic to avoid overwriting

This commit is contained in:
Bartłomiej Dach 2022-08-16 22:41:32 +02:00
parent a494e55d93
commit 6bfdfeb153
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 35 additions and 21 deletions

View File

@ -37,8 +37,6 @@ namespace osu.Game.Overlays.Mods
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Scale = new Vector2(HEIGHT / ModSwitchSmall.DEFAULT_SIZE)
};
Action = select;
}
public ModPanel(Mod mod)
@ -59,18 +57,16 @@ namespace osu.Game.Overlays.Mods
Filtered.BindValueChanged(_ => updateFilterState(), true);
}
private void select()
protected override void Select()
{
if (!Active.Value)
{
modState.RequiresConfiguration = Mod.RequiresConfiguration;
Active.Value = true;
}
else
{
modState.RequiresConfiguration = false;
Active.Value = false;
}
modState.RequiresConfiguration = Mod.RequiresConfiguration;
Active.Value = true;
}
protected override void Deselect()
{
modState.RequiresConfiguration = false;
Active.Value = false;
}
#region Filtering support

View File

@ -37,8 +37,6 @@ namespace osu.Game.Overlays.Mods
Title = preset.Value.Name;
Description = preset.Value.Description;
Action = toggleRequestedByUser;
}
[BackgroundDependencyLoader]
@ -54,15 +52,19 @@ namespace osu.Game.Overlays.Mods
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
}
private void toggleRequestedByUser()
protected override void Select()
{
// 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,
// which will also have the side effect of activating the preset (see `updateActiveState()`).
selectedMods.Value = Preset.Value.Mods.ToArray();
}
protected override void Deselect()
{
// 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>();
selectedMods.Value = Array.Empty<Mod>();
}
private void selectedModsChanged()

View File

@ -143,9 +143,25 @@ namespace osu.Game.Overlays.Mods
}
};
Action = () => Active.Toggle();
Action = () =>
{
if (!Active.Value)
Select();
else
Deselect();
};
}
/// <summary>
/// Performs all actions necessary to select this <see cref="ModSelectPanel"/>.
/// </summary>
protected abstract void Select();
/// <summary>
/// Performs all actions necessary to deselect this <see cref="ModSelectPanel"/>.
/// </summary>
protected abstract void Deselect();
[BackgroundDependencyLoader]
private void load(AudioManager audio, ISamplePlaybackDisabler? samplePlaybackDisabler)
{