From be2358007f60e838c12f705c0c58811afab5587c Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 23 Oct 2024 22:42:02 +0200 Subject: [PATCH] Add slider bar focus effect --- osu.Game/Graphics/UserInterface/Nub.cs | 40 ++++++++++++------- .../Graphics/UserInterface/OsuCheckbox.cs | 4 +- .../UserInterface/RoundedSliderBar.cs | 24 ++++++++++- .../Graphics/UserInterfaceV2/FormSliderBar.cs | 23 ++++++++++- 4 files changed, 71 insertions(+), 20 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/Nub.cs b/osu.Game/Graphics/UserInterface/Nub.cs index 4b953718bc7c..fc27dfe813be 100644 --- a/osu.Game/Graphics/UserInterface/Nub.cs +++ b/osu.Game/Graphics/UserInterface/Nub.cs @@ -77,30 +77,40 @@ protected override void LoadComplete() Current.BindValueChanged(onCurrentValueChanged, true); } - private bool glowing; + private int glow; - public bool Glowing + public int Glow { - get => glowing; + get => glow; set { - glowing = value; - - if (value) + if (value > 0) { - main.FadeColour(GlowingAccentColour.Lighten(0.5f), 40, Easing.OutQuint) - .Then() - .FadeColour(GlowingAccentColour, 800, Easing.OutQuint); + float extraGlow = (value - 1) * 0.10f; + + if (value > glow) + { + main.FadeColour(GlowingAccentColour.Lighten(0.5f), 40, Easing.OutQuint) + .Then() + .FadeColour(GlowingAccentColour.Lighten(extraGlow), 800, Easing.OutQuint); - main.FadeEdgeEffectTo(Color4.White.Opacity(0.1f), 40, Easing.OutQuint) - .Then() - .FadeEdgeEffectTo(GlowColour.Opacity(0.1f), 800, Easing.OutQuint); + main.FadeEdgeEffectTo(Color4.White.Opacity(0.1f), 40, Easing.OutQuint) + .Then() + .FadeEdgeEffectTo(GlowColour.Lighten(extraGlow).Opacity(0.1f), 800, Easing.OutQuint); + } + else + { + main.FadeColour(GlowingAccentColour.Lighten(extraGlow), 800, Easing.OutQuint); + main.FadeEdgeEffectTo(GlowColour.Lighten(extraGlow).Opacity(0.1f), 800, Easing.OutQuint); + } } else { main.FadeEdgeEffectTo(GlowColour.Opacity(0), 800, Easing.OutQuint); main.FadeColour(AccentColour, 800, Easing.OutQuint); } + + glow = value; } } @@ -126,7 +136,7 @@ public Color4 AccentColour set { accentColour = value; - if (!Glowing) + if (Glow == 0) main.Colour = value; } } @@ -139,7 +149,7 @@ public Color4 GlowingAccentColour set { glowingAccentColour = value; - if (Glowing) + if (Glow > 0) main.Colour = value; } } @@ -154,7 +164,7 @@ public Color4 GlowColour glowColour = value; var effect = main.EdgeEffect; - effect.Colour = Glowing ? value : value.Opacity(0); + effect.Colour = Glow > 0 ? value : value.Opacity(0); main.EdgeEffect = effect; } } diff --git a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs index caab3d97f82b..90a352588338 100644 --- a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs +++ b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs @@ -97,13 +97,13 @@ private void load(AudioManager audio) protected override bool OnHover(HoverEvent e) { - Nub.Glowing = true; + Nub.Glow = 1; return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { - Nub.Glowing = false; + Nub.Glow = 0; base.OnHoverLost(e); } diff --git a/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs b/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs index 56047173bb0b..57f39cc48fd3 100644 --- a/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs @@ -156,9 +156,31 @@ protected override void OnDragEnd(DragEndEvent e) base.OnDragEnd(e); } + protected override void OnFocus(FocusEvent e) + { + updateGlow(); + base.OnFocus(e); + } + + protected override void OnFocusLost(FocusLostEvent e) + { + updateGlow(); + base.OnFocusLost(e); + } + private void updateGlow() { - Nub.Glowing = !Current.Disabled && (IsHovered || IsDragged); + int glow = 0; + + if (!Current.Disabled) + { + if (IsHovered || IsDragged) + glow++; + if (HasFocus) + glow++; + } + + Nub.Glow = glow; } protected override void UpdateAfterChildren() diff --git a/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs b/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs index da28437eee2c..50d1093d554b 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs @@ -382,11 +382,30 @@ protected override void OnHoverLost(HoverLostEvent e) base.OnHoverLost(e); } + protected override void OnFocus(FocusEvent e) + { + updateState(); + base.OnFocus(e); + } + + protected override void OnFocusLost(FocusLostEvent e) + { + updateState(); + base.OnFocusLost(e); + } + private void updateState() { + int glow = 0; + + if (IsHovered || IsDragged) + glow++; + if (HasFocus) + glow++; + rightBox.Colour = colourProvider.Background6; - leftBox.Colour = IsHovered || IsDragged ? colourProvider.Highlight1.Opacity(0.5f) : colourProvider.Dark2; - nub.Colour = IsHovered || IsDragged ? colourProvider.Highlight1 : colourProvider.Light4; + leftBox.Colour = glow >= 2 ? colourProvider.Highlight1.Opacity(0.5f) : glow >= 1 ? colourProvider.Colour2.Opacity(0.5f) : colourProvider.Dark2; + nub.Colour = glow >= 2 ? colourProvider.Highlight1 : glow >= 1 ? colourProvider.Colour2 : colourProvider.Light4; } protected override void UpdateValue(float value)