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

Centralise deselect logic and add animation to deselection

This commit is contained in:
Dean Herbert 2018-01-02 16:09:22 +09:00
parent 71bcebe7e1
commit f72239ef7a
2 changed files with 23 additions and 15 deletions

View File

@ -51,7 +51,7 @@ namespace osu.Game.Overlays.Mods
return new ModButton(m) return new ModButton(m)
{ {
SelectedColour = selectedColour, SelectedColour = selectedColour,
Action = Action, SelectionChanged = Action,
}; };
}).ToArray(); }).ToArray();
@ -88,21 +88,28 @@ namespace osu.Game.Overlays.Mods
return base.OnKeyDown(state, args); return base.OnKeyDown(state, args);
} }
public void DeselectAll() public void DeselectAll() => DeselectTypes(buttons.Select(b => b.SelectedMod?.GetType()).Where(t => t != null));
{
foreach (ModButton button in buttons)
button.Deselect();
}
public void DeselectTypes(Type[] modTypes) /// <summary>
/// Deselect one or more mods in this section.
/// </summary>
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param>
/// <param name="immediate">Set to true to bypass animations and update selections immediately.</param>
public void DeselectTypes(IEnumerable<Type> modTypes, bool immediate = false)
{ {
int delay = 0;
foreach (var button in buttons) foreach (var button in buttons)
{ {
Mod selected = button.SelectedMod; Mod selected = button.SelectedMod;
if (selected == null) continue; if (selected == null) continue;
foreach (Type type in modTypes) foreach (Type type in modTypes)
if (type.IsInstanceOfType(selected)) if (type.IsInstanceOfType(selected))
button.Deselect(); {
if (immediate)
button.Deselect();
else
Scheduler.AddDelayed(() => button.Deselect(), delay += 50);
}
} }
} }

View File

@ -100,17 +100,22 @@ namespace osu.Game.Overlays.Mods
refreshSelectedMods(); refreshSelectedMods();
} }
public void DeselectTypes(Type[] modTypes) /// <summary>
/// Deselect one or more mods.
/// </summary>
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param>
/// <param name="immediate">Set to true to bypass animations and update selections immediately.</param>
public void DeselectTypes(Type[] modTypes, bool immediate = false)
{ {
if (modTypes.Length == 0) return; if (modTypes.Length == 0) return;
foreach (ModSection section in ModSectionsContainer.Children) foreach (ModSection section in ModSectionsContainer.Children)
section.DeselectTypes(modTypes); section.DeselectTypes(modTypes, immediate);
} }
private void modButtonPressed(Mod selectedMod) private void modButtonPressed(Mod selectedMod)
{ {
if (selectedMod != null) if (selectedMod != null)
DeselectTypes(selectedMod.IncompatibleMods); DeselectTypes(selectedMod.IncompatibleMods, true);
refreshSelectedMods(); refreshSelectedMods();
} }
@ -127,10 +132,6 @@ namespace osu.Game.Overlays.Mods
ranked &= mod.Ranked; ranked &= mod.Ranked;
} }
// 1.00x
// 1.05x
// 1.20x
MultiplierLabel.Text = $"{multiplier:N2}x"; MultiplierLabel.Text = $"{multiplier:N2}x";
if (!ranked) if (!ranked)
MultiplierLabel.Text += " (Unranked)"; MultiplierLabel.Text += " (Unranked)";