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

Merge pull request #28763 from peppy/revert-to-default-animation

Add slight animation when revert to default button is displayed
This commit is contained in:
Salman Ahmed 2024-07-08 10:58:53 +03:00 committed by GitHub
commit a3e54a6272
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -87,6 +87,7 @@ namespace osu.Game.Overlays
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
updateState(); updateState();
FinishTransforms(true); FinishTransforms(true);
} }
@ -95,33 +96,50 @@ namespace osu.Game.Overlays
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
UpdateState(); updateHover();
return false; return false;
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
UpdateState(); updateHover();
} }
public void UpdateState() => Scheduler.AddOnce(updateState); public void UpdateState() => Scheduler.AddOnce(updateState);
private const double fade_duration = 200; private const double fade_duration = 200;
private bool? isDisplayed;
private void updateState() private void updateState()
{ {
if (current == null) if (current == null)
return; return;
Enabled.Value = !current.Disabled; // Avoid running animations if we are already in an up-to-date state.
if (Enabled.Value == !current.Disabled && isDisplayed == !current.IsDefault)
return;
if (current.IsDefault) Enabled.Value = !current.Disabled;
isDisplayed = !current.IsDefault;
updateHover();
if (isDisplayed == false)
this.FadeTo(0, fade_duration, Easing.OutQuint); this.FadeTo(0, fade_duration, Easing.OutQuint);
else if (current.Disabled) else if (current.Disabled)
this.FadeTo(0.2f, fade_duration, Easing.OutQuint); this.FadeTo(0.2f, fade_duration, Easing.OutQuint);
else else
this.FadeTo(1, fade_duration, Easing.OutQuint); {
icon.RotateTo(150).RotateTo(0, fade_duration * 2, Easing.OutQuint);
icon.ScaleTo(0.7f).ScaleTo(1, fade_duration * 2, Easing.OutQuint);
this.FadeTo(1, fade_duration, Easing.OutQuint);
}
}
private void updateHover()
{
if (IsHovered && Enabled.Value) if (IsHovered && Enabled.Value)
{ {
icon.RotateTo(-40, 500, Easing.OutQuint); icon.RotateTo(-40, 500, Easing.OutQuint);