Remove HoverTarget shared state update path

Felt quite convoluted to follow. Have just duplicated the single shared
line instead.
This commit is contained in:
Dean Herbert
2021-10-10 11:55:45 +09:00
parent ccc6d8ff40
commit 49b341daff
3 changed files with 20 additions and 24 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -10,13 +9,11 @@ namespace osu.Game.Overlays.Settings
{ {
public abstract class SidebarButton : OsuButton public abstract class SidebarButton : OsuButton
{ {
private const double fade_duration = 50; protected const double FADE_DURATION = 500;
[Resolved] [Resolved]
protected OverlayColourProvider ColourProvider { get; private set; } protected OverlayColourProvider ColourProvider { get; private set; }
protected abstract Drawable HoverTarget { get; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -38,9 +35,6 @@ namespace osu.Game.Overlays.Settings
protected override void OnHoverLost(HoverLostEvent e) => UpdateState(); protected override void OnHoverLost(HoverLostEvent e) => UpdateState();
protected virtual void UpdateState() protected abstract void UpdateState();
{
HoverTarget.FadeColour(IsHovered ? ColourProvider.Light1 : ColourProvider.Light3, fade_duration, Easing.OutQuint);
}
} }
} }

View File

@ -15,17 +15,13 @@ namespace osu.Game.Overlays.Settings
{ {
public class SidebarIconButton : SidebarButton public class SidebarIconButton : SidebarButton
{ {
private const double fade_duration = 500;
private const float selection_indicator_height_active = 18; private const float selection_indicator_height_active = 18;
private const float selection_indicator_height_inactive = 4; private const float selection_indicator_height_inactive = 4;
private readonly ConstrainedIconContainer iconContainer; private readonly ConstrainedIconContainer iconContainer;
private readonly SpriteText headerText; private readonly SpriteText headerText;
private readonly CircularContainer selectionIndicator; private readonly CircularContainer selectionIndicator;
private readonly Container text; private readonly Container textIconContent;
protected override Drawable HoverTarget => text;
// always consider as part of flow, even when not visible (for the sake of the initial animation). // always consider as part of flow, even when not visible (for the sake of the initial animation).
public override bool IsPresent => true; public override bool IsPresent => true;
@ -64,7 +60,7 @@ namespace osu.Game.Overlays.Settings
AddRange(new Drawable[] AddRange(new Drawable[]
{ {
text = new Container textIconContent = new Container
{ {
Width = Sidebar.DEFAULT_WIDTH, Width = Sidebar.DEFAULT_WIDTH,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
@ -117,15 +113,18 @@ namespace osu.Game.Overlays.Settings
{ {
if (Selected) if (Selected)
{ {
text.FadeColour(ColourProvider.Content1, fade_duration, Easing.OutQuint); textIconContent.FadeColour(ColourProvider.Content1, FADE_DURATION, Easing.OutQuint);
selectionIndicator.FadeIn(fade_duration, Easing.OutQuint);
selectionIndicator.ResizeHeightTo(selection_indicator_height_active, fade_duration, Easing.OutElasticHalf);
return;
}
selectionIndicator.FadeOut(fade_duration, Easing.OutQuint); selectionIndicator.FadeIn(FADE_DURATION, Easing.OutQuint);
selectionIndicator.ResizeHeightTo(selection_indicator_height_inactive, fade_duration, Easing.OutQuint); selectionIndicator.ResizeHeightTo(selection_indicator_height_active, FADE_DURATION, Easing.OutElasticHalf);
base.UpdateState(); }
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);
}
} }
} }
} }

View File

@ -36,8 +36,6 @@ namespace osu.Game.Overlays
{ {
private Container content; private Container content;
protected override Drawable HoverTarget => content;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() 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);
}
} }
} }
} }