From 49b341daffb677dd5de1c5d6d44101ac029d854b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 10 Oct 2021 11:55:45 +0900 Subject: [PATCH] Remove `HoverTarget` shared state update path Felt quite convoluted to follow. Have just duplicated the single shared line instead. --- osu.Game/Overlays/Settings/SidebarButton.cs | 10 ++----- .../Overlays/Settings/SidebarIconButton.cs | 27 +++++++++---------- osu.Game/Overlays/SettingsSubPanel.cs | 7 +++-- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/osu.Game/Overlays/Settings/SidebarButton.cs b/osu.Game/Overlays/Settings/SidebarButton.cs index 197187e68c..1a34143e1f 100644 --- a/osu.Game/Overlays/Settings/SidebarButton.cs +++ b/osu.Game/Overlays/Settings/SidebarButton.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Graphics; using osu.Framework.Input.Events; using osu.Game.Graphics.UserInterface; @@ -10,13 +9,11 @@ namespace osu.Game.Overlays.Settings { public abstract class SidebarButton : OsuButton { - private const double fade_duration = 50; + protected const double FADE_DURATION = 500; [Resolved] protected OverlayColourProvider ColourProvider { get; private set; } - protected abstract Drawable HoverTarget { get; } - [BackgroundDependencyLoader] private void load() { @@ -38,9 +35,6 @@ namespace osu.Game.Overlays.Settings protected override void OnHoverLost(HoverLostEvent e) => UpdateState(); - protected virtual void UpdateState() - { - HoverTarget.FadeColour(IsHovered ? ColourProvider.Light1 : ColourProvider.Light3, fade_duration, Easing.OutQuint); - } + protected abstract void UpdateState(); } } diff --git a/osu.Game/Overlays/Settings/SidebarIconButton.cs b/osu.Game/Overlays/Settings/SidebarIconButton.cs index d09873c3ea..fd57996b1b 100644 --- a/osu.Game/Overlays/Settings/SidebarIconButton.cs +++ b/osu.Game/Overlays/Settings/SidebarIconButton.cs @@ -15,17 +15,13 @@ namespace osu.Game.Overlays.Settings { public class SidebarIconButton : SidebarButton { - private const double fade_duration = 500; - private const float selection_indicator_height_active = 18; private const float selection_indicator_height_inactive = 4; private readonly ConstrainedIconContainer iconContainer; private readonly SpriteText headerText; private readonly CircularContainer selectionIndicator; - private readonly Container text; - - protected override Drawable HoverTarget => text; + private readonly Container textIconContent; // always consider as part of flow, even when not visible (for the sake of the initial animation). public override bool IsPresent => true; @@ -64,7 +60,7 @@ namespace osu.Game.Overlays.Settings AddRange(new Drawable[] { - text = new Container + textIconContent = new Container { Width = Sidebar.DEFAULT_WIDTH, RelativeSizeAxes = Axes.Y, @@ -117,15 +113,18 @@ namespace osu.Game.Overlays.Settings { if (Selected) { - text.FadeColour(ColourProvider.Content1, fade_duration, Easing.OutQuint); - selectionIndicator.FadeIn(fade_duration, Easing.OutQuint); - selectionIndicator.ResizeHeightTo(selection_indicator_height_active, fade_duration, Easing.OutElasticHalf); - return; - } + textIconContent.FadeColour(ColourProvider.Content1, FADE_DURATION, Easing.OutQuint); - selectionIndicator.FadeOut(fade_duration, Easing.OutQuint); - selectionIndicator.ResizeHeightTo(selection_indicator_height_inactive, fade_duration, Easing.OutQuint); - base.UpdateState(); + selectionIndicator.FadeIn(FADE_DURATION, Easing.OutQuint); + selectionIndicator.ResizeHeightTo(selection_indicator_height_active, FADE_DURATION, Easing.OutElasticHalf); + } + else + { + textIconContent.FadeColour(IsHovered ? ColourProvider.Light1 : ColourProvider.Light3, FADE_DURATION, Easing.OutQuint); + + selectionIndicator.FadeOut(FADE_DURATION, Easing.OutQuint); + selectionIndicator.ResizeHeightTo(selection_indicator_height_inactive, FADE_DURATION, Easing.OutQuint); + } } } } diff --git a/osu.Game/Overlays/SettingsSubPanel.cs b/osu.Game/Overlays/SettingsSubPanel.cs index 25a245472b..a65d792a9f 100644 --- a/osu.Game/Overlays/SettingsSubPanel.cs +++ b/osu.Game/Overlays/SettingsSubPanel.cs @@ -36,8 +36,6 @@ namespace osu.Game.Overlays { private Container content; - protected override Drawable HoverTarget => content; - [BackgroundDependencyLoader] private void load() { @@ -71,6 +69,11 @@ namespace osu.Game.Overlays } }); } + + protected override void UpdateState() + { + content.FadeColour(IsHovered ? ColourProvider.Light1 : ColourProvider.Light3, FADE_DURATION, Easing.OutQuint); + } } } }