1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 08:07:24 +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)
{
SelectedColour = selectedColour,
Action = Action,
SelectionChanged = Action,
};
}).ToArray();
@ -88,21 +88,28 @@ namespace osu.Game.Overlays.Mods
return base.OnKeyDown(state, args);
}
public void DeselectAll()
{
foreach (ModButton button in buttons)
button.Deselect();
}
public void DeselectAll() => DeselectTypes(buttons.Select(b => b.SelectedMod?.GetType()).Where(t => t != null));
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)
{
Mod selected = button.SelectedMod;
if (selected == null) continue;
foreach (Type type in modTypes)
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();
}
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;
foreach (ModSection section in ModSectionsContainer.Children)
section.DeselectTypes(modTypes);
section.DeselectTypes(modTypes, immediate);
}
private void modButtonPressed(Mod selectedMod)
{
if (selectedMod != null)
DeselectTypes(selectedMod.IncompatibleMods);
DeselectTypes(selectedMod.IncompatibleMods, true);
refreshSelectedMods();
}
@ -127,10 +132,6 @@ namespace osu.Game.Overlays.Mods
ranked &= mod.Ranked;
}
// 1.00x
// 1.05x
// 1.20x
MultiplierLabel.Text = $"{multiplier:N2}x";
if (!ranked)
MultiplierLabel.Text += " (Unranked)";