From fa22d1f20277e23a77dca20ee0fa0cac36acdcde Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 27 Jan 2026 18:58:03 +0900 Subject: [PATCH] Use enum for background states --- .../Graphics/UserInterfaceV2/FormButton.cs | 8 +- .../Graphics/UserInterfaceV2/FormCheckBox.cs | 9 +- .../UserInterfaceV2/FormColourPalette.cs | 5 +- .../UserInterfaceV2/FormControlBackground.cs | 89 +++++++++---------- .../Graphics/UserInterfaceV2/FormDropdown.cs | 11 ++- .../UserInterfaceV2/FormFileSelector.cs | 11 ++- .../Graphics/UserInterfaceV2/FormSliderBar.cs | 11 ++- .../Graphics/UserInterfaceV2/FormTextBox.cs | 11 ++- 8 files changed, 93 insertions(+), 62 deletions(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/FormButton.cs b/osu.Game/Graphics/UserInterfaceV2/FormButton.cs index 36c2ad8098..afab77490b 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormButton.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormButton.cs @@ -169,8 +169,12 @@ namespace osu.Game.Graphics.UserInterfaceV2 { text.Colour = Enabled.Value ? colourProvider.Content1 : colourProvider.Background1; - background.StyleHovered = IsHovered; - background.StyleDisabled = !Enabled.Value; + if (!Enabled.Value) + background.VisualStyle = VisualStyle.Disabled; + else if (IsHovered) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; // TODO: Support BackgroundColour? } diff --git a/osu.Game/Graphics/UserInterfaceV2/FormCheckBox.cs b/osu.Game/Graphics/UserInterfaceV2/FormCheckBox.cs index 2b751d98e5..0242472db1 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormCheckBox.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormCheckBox.cs @@ -141,8 +141,13 @@ namespace osu.Game.Graphics.UserInterfaceV2 private void updateState() { caption.Colour = Current.Disabled ? colourProvider.Background1 : colourProvider.Content2; - background.StyleHovered = IsHovered; - background.StyleDisabled = IsDisabled; + + if (IsDisabled) + background.VisualStyle = VisualStyle.Disabled; + else if (IsHovered) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; } public IEnumerable FilterTerms => Caption.Yield(); diff --git a/osu.Game/Graphics/UserInterfaceV2/FormColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/FormColourPalette.cs index 2f1c72fcc9..0eb59415c0 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormColourPalette.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormColourPalette.cs @@ -135,7 +135,10 @@ namespace osu.Game.Graphics.UserInterfaceV2 { caption.Colour = colourProvider.Content2; - background.StyleHovered = IsHovered; + if (IsHovered) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; } private void updateColours() diff --git a/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs b/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs index 43c1c87f1c..46042ea08c 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -18,36 +19,15 @@ namespace osu.Game.Graphics.UserInterfaceV2 public const float CORNER_EXPONENT = 2.5f; public const float BORDER_THICKNESS = 2.5f; - private bool styleDisabled; + private VisualStyle visualStyle; - public bool StyleDisabled + public VisualStyle VisualStyle { + get => visualStyle; set { - styleDisabled = value; - updateStyling(); - } - } - - private bool styleFocused; - - public bool StyleFocused - { - set - { - styleFocused = value; - updateStyling(); - } - } - - private bool styleHovered; - - public bool StyleHovered - { - set - { - styleHovered = value; - updateStyling(); + visualStyle = value; + updateStyle(); } } @@ -83,7 +63,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { base.LoadComplete(); - updateStyling(); + updateStyle(); FinishTransforms(true); } @@ -92,30 +72,41 @@ namespace osu.Game.Graphics.UserInterfaceV2 box.FlashColour(ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark2), 800, Easing.OutQuint); } - private void updateStyling() + private void updateStyle() { - sounds.Enabled.Value = !styleDisabled; + sounds.Enabled.Value = visualStyle != VisualStyle.Disabled; - ColourInfo colour = colourProvider.Background4.Darken(0.1f); - ColourInfo borderColour = colourProvider.Light4; + ColourInfo colour; + ColourInfo borderColour; bool border = false; - if (styleDisabled) + switch (visualStyle) { - colour = colourProvider.Background4; - borderColour = colourProvider.Dark1; - } - else if (styleFocused) - { - colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark3); - border = true; - borderColour = colourProvider.Highlight1; - } - else if (styleHovered) - { - colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark4); - border = true; + case VisualStyle.Normal: + colour = colourProvider.Background4.Darken(0.1f); + borderColour = colourProvider.Light4; + break; + + case VisualStyle.Disabled: + colour = colourProvider.Background4; + borderColour = colourProvider.Dark1; + break; + + case VisualStyle.Hovered: + colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark4); + borderColour = colourProvider.Light4; + border = true; + break; + + case VisualStyle.Focused: + colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark3); + border = true; + borderColour = colourProvider.Highlight1; + break; + + default: + throw new ArgumentOutOfRangeException(); } this.TransformTo(nameof(BorderColour), border ? borderColour : colour, 250, Easing.OutQuint); @@ -123,4 +114,12 @@ namespace osu.Game.Graphics.UserInterfaceV2 box.FadeColour(colour, 250, Easing.OutQuint); } } + + public enum VisualStyle + { + Normal, + Disabled, + Hovered, + Focused + } } diff --git a/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs b/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs index 009d439b08..86ca6fc425 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs @@ -246,9 +246,14 @@ namespace osu.Game.Graphics.UserInterfaceV2 else label.Alpha = 1; - background.StyleDisabled = Dropdown.Current.Disabled; - background.StyleHovered = IsHovered; - background.StyleFocused = dropdownOpen; + if (Dropdown.Current.Disabled) + background.VisualStyle = VisualStyle.Disabled; + else if (dropdownOpen) + background.VisualStyle = VisualStyle.Focused; + else if (IsHovered) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; } private void updateChevron() diff --git a/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs b/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs index 5cafdc3650..d4edcd2ff3 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs @@ -212,9 +212,14 @@ namespace osu.Game.Graphics.UserInterfaceV2 caption.Colour = Current.Disabled ? colourProvider.Foreground1 : colourProvider.Content2; filenameText.Colour = Current.Disabled || Current.Value == null ? colourProvider.Foreground1 : colourProvider.Content1; - background.StyleDisabled = Current.Disabled; - background.StyleFocused = popoverState.Value == Visibility.Visible; - background.StyleHovered = IsHovered; + if (Current.Disabled) + background.VisualStyle = VisualStyle.Disabled; + else if (popoverState.Value == Visibility.Visible) + background.VisualStyle = VisualStyle.Focused; + else if (IsHovered) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs b/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs index 597a22773b..501e3106b3 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs @@ -395,9 +395,14 @@ namespace osu.Game.Graphics.UserInterfaceV2 textBox.Colour = currentNumberInstantaneous.Disabled ? colourProvider.Background1 : colourProvider.Content1; valueLabel.Colour = currentNumberInstantaneous.Disabled ? colourProvider.Background1 : colourProvider.Content1; - background.StyleDisabled = Current.Disabled; - background.StyleFocused = childHasFocus; - background.StyleHovered = IsHovered || slider.IsDragging.Value; + if (Current.Disabled) + background.VisualStyle = VisualStyle.Disabled; + else if (childHasFocus) + background.VisualStyle = VisualStyle.Focused; + else if (IsHovered || slider.IsDragging.Value) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; } private void updateValueDisplay() diff --git a/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs b/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs index be90689819..78fb438828 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormTextBox.cs @@ -185,9 +185,14 @@ namespace osu.Game.Graphics.UserInterfaceV2 caption.Colour = disabled ? colourProvider.Background1 : colourProvider.Content2; textBox.Colour = disabled ? colourProvider.Foreground1 : colourProvider.Content1; - background.StyleDisabled = Current.Disabled; - background.StyleFocused = textBox.Focused.Value; - background.StyleHovered = IsHovered; + if (Current.Disabled) + background.VisualStyle = VisualStyle.Disabled; + else if (textBox.Focused.Value) + background.VisualStyle = VisualStyle.Focused; + else if (IsHovered) + background.VisualStyle = VisualStyle.Hovered; + else + background.VisualStyle = VisualStyle.Normal; } internal partial class InnerTextBox : OsuTextBox