From 03bd6069d88827575f19018c0d599cc3e865972d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 8 Jul 2024 15:50:27 +0900 Subject: [PATCH] Add slight animation when revert to default button is displayed This also fixes the transforms running too often (could make the initial transform take longer than expected if adjusting a slider bar, for instance). --- osu.Game/Overlays/RevertToDefaultButton.cs | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/RevertToDefaultButton.cs b/osu.Game/Overlays/RevertToDefaultButton.cs index 6fa5209f64..1ebe7b7934 100644 --- a/osu.Game/Overlays/RevertToDefaultButton.cs +++ b/osu.Game/Overlays/RevertToDefaultButton.cs @@ -87,6 +87,7 @@ namespace osu.Game.Overlays protected override void LoadComplete() { base.LoadComplete(); + updateState(); FinishTransforms(true); } @@ -95,33 +96,50 @@ namespace osu.Game.Overlays protected override bool OnHover(HoverEvent e) { - UpdateState(); + updateHover(); return false; } protected override void OnHoverLost(HoverLostEvent e) { - UpdateState(); + updateHover(); } public void UpdateState() => Scheduler.AddOnce(updateState); private const double fade_duration = 200; + private bool? isDisplayed; + private void updateState() { if (current == null) 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); else if (current.Disabled) this.FadeTo(0.2f, fade_duration, Easing.OutQuint); 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) { icon.RotateTo(-40, 500, Easing.OutQuint);