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

Move schedule logic to buttons rather than section

It turns out there's some quite convoluted scheduling / order of
execution requirements of ModSelectOverlay and ModSection. Applying
scheduling causes a runaway condition ending in zero frames after many
mod button changes.

I wanted to avoid rewriting the whole component, so have just moved the
schedule to guard against the part where drawables are actually changed.
This commit is contained in:
Dean Herbert 2021-01-05 16:41:03 +09:00
parent 4d6c13f169
commit 5d8c153c1e
2 changed files with 37 additions and 33 deletions

View File

@ -64,41 +64,45 @@ namespace osu.Game.Overlays.Mods
if (newIndex >= 0 && !Mods[newIndex].HasImplementation) if (newIndex >= 0 && !Mods[newIndex].HasImplementation)
return false; return false;
selectedIndex = newIndex; Schedule(() =>
Mod modAfter = SelectedMod ?? Mods[0];
if (beforeSelected != Selected)
{ {
iconsContainer.RotateTo(Selected ? 5f : 0f, 300, Easing.OutElastic); selectedIndex = newIndex;
iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, Easing.OutElastic); Mod modAfter = SelectedMod ?? Mods[0];
}
if (modBefore != modAfter) if (beforeSelected != Selected)
{
const float rotate_angle = 16;
foregroundIcon.RotateTo(rotate_angle * direction, mod_switch_duration, mod_switch_easing);
backgroundIcon.RotateTo(-rotate_angle * direction, mod_switch_duration, mod_switch_easing);
backgroundIcon.Mod = modAfter;
using (BeginDelayedSequence(mod_switch_duration, true))
{ {
foregroundIcon iconsContainer.RotateTo(Selected ? 5f : 0f, 300, Easing.OutElastic);
.RotateTo(-rotate_angle * direction) iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, Easing.OutElastic);
.RotateTo(0f, mod_switch_duration, mod_switch_easing);
backgroundIcon
.RotateTo(rotate_angle * direction)
.RotateTo(0f, mod_switch_duration, mod_switch_easing);
Schedule(() => displayMod(modAfter));
} }
}
foregroundIcon.Selected.Value = Selected; if (modBefore != modAfter)
{
const float rotate_angle = 16;
foregroundIcon.RotateTo(rotate_angle * direction, mod_switch_duration, mod_switch_easing);
backgroundIcon.RotateTo(-rotate_angle * direction, mod_switch_duration, mod_switch_easing);
backgroundIcon.Mod = modAfter;
using (BeginDelayedSequence(mod_switch_duration, true))
{
foregroundIcon
.RotateTo(-rotate_angle * direction)
.RotateTo(0f, mod_switch_duration, mod_switch_easing);
backgroundIcon
.RotateTo(rotate_angle * direction)
.RotateTo(0f, mod_switch_duration, mod_switch_easing);
Schedule(() => displayMod(modAfter));
}
}
foregroundIcon.Selected.Value = Selected;
SelectionChanged?.Invoke(SelectedMod);
});
SelectionChanged?.Invoke(SelectedMod);
return true; return true;
} }

View File

@ -104,7 +104,7 @@ namespace osu.Game.Overlays.Mods
/// </summary> /// </summary>
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param> /// <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> /// <param name="immediate">Set to true to bypass animations and update selections immediately.</param>
public void DeselectTypes(IEnumerable<Type> modTypes, bool immediate = false) => Schedule(() => public void DeselectTypes(IEnumerable<Type> modTypes, bool immediate = false)
{ {
int delay = 0; int delay = 0;
@ -124,13 +124,13 @@ namespace osu.Game.Overlays.Mods
} }
} }
} }
}); }
/// <summary> /// <summary>
/// Select one or more mods in this section and deselects all other ones. /// Select one or more mods in this section and deselects all other ones.
/// </summary> /// </summary>
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be selected.</param> /// <param name="modTypes">The types of <see cref="Mod"/>s which should be selected.</param>
public void SelectTypes(IEnumerable<Type> modTypes) => Schedule(() => public void SelectTypes(IEnumerable<Type> modTypes)
{ {
foreach (var button in buttons) foreach (var button in buttons)
{ {
@ -141,7 +141,7 @@ namespace osu.Game.Overlays.Mods
else else
button.Deselect(); button.Deselect();
} }
}); }
protected ModSection() protected ModSection()
{ {