Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve animation of new song select footer buttons #28142

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ protected override bool OnKeyDown(KeyDownEvent e)
protected override void UpdateState(ValueChangedEvent<Visibility> state)
{
base.UpdateState(state);

if (state.NewValue == Visibility.Hidden)
footerButton.IsActive.Value = false;
footerButton.OverlayState.Value = state.NewValue;
}
}
}
30 changes: 1 addition & 29 deletions osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
Expand All @@ -15,8 +13,6 @@ namespace osu.Game.Screens.Select.FooterV2
{
public partial class FooterButtonOptionsV2 : FooterButtonV2, IHasPopover
{
public readonly BindableBool IsActive = new BindableBool();

[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
Expand All @@ -25,31 +21,7 @@ private void load(OsuColour colour)
AccentColour = colour.Purple1;
Hotkey = GlobalAction.ToggleBeatmapOptions;

Action = () => IsActive.Toggle();
}

protected override void LoadComplete()
{
base.LoadComplete();

IsActive.BindValueChanged(active =>
{
OverlayState.Value = active.NewValue ? Visibility.Visible : Visibility.Hidden;
});

OverlayState.BindValueChanged(state =>
{
switch (state.NewValue)
{
case Visibility.Hidden:
this.HidePopover();
break;

case Visibility.Visible:
this.ShowPopover();
break;
}
});
Action = this.ShowPopover;
}

public Popover GetPopover() => new BeatmapOptionsPopover(this);
Expand Down
64 changes: 30 additions & 34 deletions osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace osu.Game.Screens.Select.FooterV2
{
public partial class FooterButtonV2 : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
{
private const int transition_length = 500;

// This should be 12 by design, but an extra allowance is added due to the corner radius specification.
private const float shear_width = 13.5f;

Expand Down Expand Up @@ -68,6 +66,7 @@ protected LocalisableString Text
protected Container TextContainer;
private readonly Box bar;
private readonly Box backgroundBox;
private readonly Box flashLayer;

public FooterButtonV2()
{
Expand Down Expand Up @@ -137,8 +136,15 @@ public FooterButtonV2()
{
RelativeSizeAxes = Axes.Both,
}
}
}
},
flashLayer = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Colour4.White.Opacity(0.9f),
Blending = BlendingParameters.Additive,
Alpha = 0,
},
},
};
}

Expand All @@ -154,26 +160,20 @@ protected override void LoadComplete()

public GlobalAction? Hotkey;

private bool handlingMouse;

protected override bool OnHover(HoverEvent e)
protected override bool OnClick(ClickEvent e)
{
updateDisplay();
return true;
}
if (Enabled.Value)
Flash();

protected override bool OnMouseDown(MouseDownEvent e)
{
handlingMouse = true;
updateDisplay();
return base.OnMouseDown(e);
return base.OnClick(e);
}

protected override void OnMouseUp(MouseUpEvent e)
protected virtual void Flash() => flashLayer.FadeOutFromOne(800, Easing.OutQuint);

protected override bool OnHover(HoverEvent e)
{
handlingMouse = false;
updateDisplay();
base.OnMouseUp(e);
return true;
}

protected override void OnHoverLost(HoverLostEvent e) => updateDisplay();
Expand All @@ -190,27 +190,23 @@ public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)

private void updateDisplay()
{
Color4 backgroundColour = colourProvider.Background3;
Color4 backgroundColour = OverlayState.Value == Visibility.Visible ? buttonAccentColour : colourProvider.Background3;
Color4 textColour = OverlayState.Value == Visibility.Visible ? colourProvider.Background6 : colourProvider.Content1;
Color4 accentColour = OverlayState.Value == Visibility.Visible ? colourProvider.Background6 : buttonAccentColour;

if (!Enabled.Value)
{
backgroundColour = colourProvider.Background3.Darken(0.4f);
}
else
{
if (OverlayState.Value == Visibility.Visible)
backgroundColour = buttonAccentColour.Darken(0.5f);
backgroundColour = backgroundColour.Darken(1f);
else if (IsHovered)
backgroundColour = backgroundColour.Lighten(0.2f);

if (IsHovered)
{
backgroundColour = backgroundColour.Lighten(0.3f);
backgroundBox.FadeColour(backgroundColour, 150, Easing.OutQuint);

if (handlingMouse)
backgroundColour = backgroundColour.Lighten(0.3f);
}
}
if (!Enabled.Value)
textColour = textColour.Opacity(0.6f);

backgroundBox.FadeColour(backgroundColour, transition_length, Easing.OutQuint);
text.FadeColour(textColour, 150, Easing.OutQuint);
icon.FadeColour(accentColour, 150, Easing.OutQuint);
bar.FadeColour(accentColour, 150, Easing.OutQuint);
}
}
}