1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 15:12:57 +08:00

add multimod animation

This commit is contained in:
Jorolf 2017-05-26 16:10:28 +02:00
parent e67a00f1f6
commit 64612ef34b

View File

@ -27,6 +27,7 @@ namespace osu.Game.Overlays.Mods
public class ModButton : ModButtonEmpty, IHasTooltip public class ModButton : ModButtonEmpty, IHasTooltip
{ {
private ModIcon foregroundIcon; private ModIcon foregroundIcon;
private ModIcon backgroundIcon;
private readonly SpriteText text; private readonly SpriteText text;
private readonly Container<ModIcon> iconsContainer; private readonly Container<ModIcon> iconsContainer;
private SampleChannel sampleOn, sampleOff; private SampleChannel sampleOn, sampleOff;
@ -35,6 +36,9 @@ namespace osu.Game.Overlays.Mods
public string TooltipText => (SelectedMod?.Description ?? Mods.FirstOrDefault()?.Description) ?? string.Empty; public string TooltipText => (SelectedMod?.Description ?? Mods.FirstOrDefault()?.Description) ?? string.Empty;
private const EasingTypes modSwitchEasing = EasingTypes.InOutQuint;
private const double modSwitchDuration = 100;
private int _selectedIndex = -1; private int _selectedIndex = -1;
private int selectedIndex private int selectedIndex
{ {
@ -45,6 +49,9 @@ namespace osu.Game.Overlays.Mods
set set
{ {
if (value == _selectedIndex) return; if (value == _selectedIndex) return;
bool beforeSelected = Selected;
_selectedIndex = value; _selectedIndex = value;
if (value >= Mods.Length) if (value >= Mods.Length)
@ -55,13 +62,30 @@ namespace osu.Game.Overlays.Mods
{ {
_selectedIndex = Mods.Length - 1; _selectedIndex = Mods.Length - 1;
} }
if (beforeSelected ^ Selected)
{
iconsContainer.RotateTo(Selected ? 5f : 0f, 300, EasingTypes.OutElastic); iconsContainer.RotateTo(Selected ? 5f : 0f, 300, EasingTypes.OutElastic);
iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, EasingTypes.OutElastic); iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, EasingTypes.OutElastic);
}
else
{
foregroundIcon.RotateTo(15f, modSwitchDuration, modSwitchEasing);
backgroundIcon.RotateTo(-15f, modSwitchDuration, modSwitchEasing);
using (foregroundIcon.BeginDelayedSequence(modSwitchDuration))
{
foregroundIcon.RotateTo(-15f);
foregroundIcon.RotateTo(0f, modSwitchDuration, modSwitchEasing);
}
using (backgroundIcon.BeginDelayedSequence(modSwitchDuration))
{
backgroundIcon.RotateTo(15f);
backgroundIcon.RotateTo(0f, modSwitchDuration, modSwitchEasing);
}
}
foregroundIcon.Highlighted = Selected; foregroundIcon.Highlighted = Selected;
if (mod != null) if (mod != null)
displayMod(SelectedMod ?? Mods[0]); Scheduler.AddDelayed(() => displayMod(SelectedMod ?? Mods[0]), beforeSelected ^ Selected ? 0 : modSwitchDuration);
} }
} }
@ -159,6 +183,8 @@ namespace osu.Game.Overlays.Mods
private void displayMod(Mod mod) private void displayMod(Mod mod)
{ {
if(backgroundIcon != null)
backgroundIcon.Icon = foregroundIcon.Icon;
foregroundIcon.Icon = mod.Icon; foregroundIcon.Icon = mod.Icon;
text.Text = mod.Name; text.Text = mod.Name;
} }
@ -170,17 +196,17 @@ namespace osu.Game.Overlays.Mods
{ {
iconsContainer.Add(new[] iconsContainer.Add(new[]
{ {
new ModIcon(Mods[0]) backgroundIcon = new ModIcon(Mods[1])
{ {
Origin = Anchor.Centre, Origin = Anchor.BottomRight,
Anchor = Anchor.Centre, Anchor = Anchor.BottomRight,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Position = new Vector2(1.5f), Position = new Vector2(1.5f),
}, },
foregroundIcon = new ModIcon(Mods[0]) foregroundIcon = new ModIcon(Mods[0])
{ {
Origin = Anchor.Centre, Origin = Anchor.BottomRight,
Anchor = Anchor.Centre, Anchor = Anchor.BottomRight,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Position = new Vector2(-1.5f), Position = new Vector2(-1.5f),
}, },