From d61a72b8fbda78a475428549090e90ee9e840a97 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 18 Jul 2024 00:05:44 +0300 Subject: [PATCH] Explicitly define `Hue` rather than implicitly provide it by enum value --- osu.Game/Overlays/OverlayColourProvider.cs | 42 +++++++-------- osu.Game/Overlays/OverlayColourScheme.cs | 60 ++++++++++++++++++++++ osu.Game/Overlays/UserProfileOverlay.cs | 16 +++--- osu.Game/Screens/Footer/ScreenFooter.cs | 8 +-- 4 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 osu.Game/Overlays/OverlayColourScheme.cs diff --git a/osu.Game/Overlays/OverlayColourProvider.cs b/osu.Game/Overlays/OverlayColourProvider.cs index 9613bc2857..9f5583cf73 100644 --- a/osu.Game/Overlays/OverlayColourProvider.cs +++ b/osu.Game/Overlays/OverlayColourProvider.cs @@ -7,11 +7,19 @@ namespace osu.Game.Overlays { public class OverlayColourProvider { - public OverlayColourScheme ColourScheme { get; private set; } + /// + /// The hue degree associated with the colour shades provided by this . + /// + public int Hue { get; private set; } public OverlayColourProvider(OverlayColourScheme colourScheme) + : this(colourScheme.GetHue()) { - ColourScheme = colourScheme; + } + + public OverlayColourProvider(int hue) + { + Hue = hue; } // Note that the following five colours are also defined in `OsuColour` as `{colourScheme}{0,1,2,3,4}`. @@ -46,31 +54,19 @@ namespace osu.Game.Overlays public Color4 Background6 => getColour(0.1f, 0.1f); /// - /// Changes the value of to a different colour scheme. + /// Changes the to a different degree. /// Note that this does not trigger any kind of signal to any drawable that received colours from here, all drawables need to be updated manually. /// /// The proposed colour scheme. - public void ChangeColourScheme(OverlayColourScheme colourScheme) - { - ColourScheme = colourScheme; - } + public void ChangeColourScheme(OverlayColourScheme colourScheme) => ChangeColourScheme(colourScheme.GetHue()); - private Color4 getColour(float saturation, float lightness) => Framework.Graphics.Colour4.FromHSL(getBaseHue(ColourScheme), saturation, lightness); + /// + /// Changes the to a different degree. + /// Note that this does not trigger any kind of signal to any drawable that received colours from here, all drawables need to be updated manually. + /// + /// The proposed hue degree. + public void ChangeColourScheme(int hue) => Hue = hue; - private static float getBaseHue(OverlayColourScheme colourScheme) => (int)colourScheme / 360f; - } - - // See https://github.com/ppy/osu-web/blob/5a536d217a21582aad999db50a981003d3ad5659/app/helpers.php#L1620-L1628 - public enum OverlayColourScheme - { - Red = 0, - Orange = 45, - Lime = 90, - Green = 125, - Aquamarine = 160, - Blue = 200, - Purple = 255, - Plum = 320, - Pink = 333, + private Color4 getColour(float saturation, float lightness) => Framework.Graphics.Colour4.FromHSL(Hue / 360f, saturation, lightness); } } diff --git a/osu.Game/Overlays/OverlayColourScheme.cs b/osu.Game/Overlays/OverlayColourScheme.cs new file mode 100644 index 0000000000..0126f9060f --- /dev/null +++ b/osu.Game/Overlays/OverlayColourScheme.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; + +namespace osu.Game.Overlays +{ + public enum OverlayColourScheme + { + Red, + Orange, + Lime, + Green, + Aquamarine, + Blue, + Purple, + Plum, + Pink, + } + + public static class OverlayColourSchemeExtensions + { + public static int GetHue(this OverlayColourScheme colourScheme) + { + // See https://github.com/ppy/osu-web/blob/5a536d217a21582aad999db50a981003d3ad5659/app/helpers.php#L1620-L1628 + switch (colourScheme) + { + default: + throw new ArgumentOutOfRangeException(nameof(colourScheme)); + + case OverlayColourScheme.Red: + return 0; + + case OverlayColourScheme.Orange: + return 45; + + case OverlayColourScheme.Lime: + return 90; + + case OverlayColourScheme.Green: + return 125; + + case OverlayColourScheme.Aquamarine: + return 160; + + case OverlayColourScheme.Blue: + return 200; + + case OverlayColourScheme.Purple: + return 255; + + case OverlayColourScheme.Plum: + return 320; + + case OverlayColourScheme.Pink: + return 333; + } + } + } +} diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 8c750b5d83..815f4b545f 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -118,7 +118,7 @@ namespace osu.Game.Overlays } : Array.Empty(); - setupBaseContent(OverlayColourScheme.Pink, forceContentRecreation: true); + setupBaseContent(OverlayColourScheme.Pink.GetHue(), forceContentRecreation: true); if (API.State.Value != APIState.Offline) { @@ -135,9 +135,9 @@ namespace osu.Game.Overlays Debug.Assert(sections != null && sectionsContainer != null && tabs != null); // reuse header and content if same colour scheme, otherwise recreate both. - var profileScheme = (OverlayColourScheme?)loadedUser.ProfileHue ?? OverlayColourScheme.Pink; - if (profileScheme != ColourProvider.ColourScheme) - setupBaseContent(profileScheme, forceContentRecreation: false); + int profileHue = loadedUser.ProfileHue ?? OverlayColourScheme.Pink.GetHue(); + if (profileHue != ColourProvider.Hue) + setupBaseContent(profileHue, forceContentRecreation: false); var actualRuleset = rulesets.GetRuleset(userRuleset?.ShortName ?? loadedUser.PlayMode).AsNonNull(); @@ -163,12 +163,12 @@ namespace osu.Game.Overlays loadingLayer.Hide(); } - private void setupBaseContent(OverlayColourScheme colourScheme, bool forceContentRecreation) + private void setupBaseContent(int hue, bool forceContentRecreation) { - var previousColourScheme = ColourProvider.ColourScheme; - ColourProvider.ChangeColourScheme(colourScheme); + int previousHue = ColourProvider.Hue; + ColourProvider.ChangeColourScheme(hue); - if (colourScheme != previousColourScheme) + if (hue != previousHue) { RecreateHeader(); UpdateColours(); diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index 6a1efcf87a..ea32507ca0 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -219,7 +219,7 @@ namespace osu.Game.Screens.Footer var targetPosition = targetButton?.ToSpaceOfOtherDrawable(targetButton.LayoutRectangle.TopRight, this) ?? fallbackPosition; - updateColourScheme(overlay.ColourProvider.ColourScheme); + updateColourScheme(overlay.ColourProvider.Hue); footerContent = overlay.CreateFooterContent(); @@ -256,16 +256,16 @@ namespace osu.Game.Screens.Footer temporarilyHiddenButtons.Clear(); - updateColourScheme(OverlayColourScheme.Aquamarine); + updateColourScheme(OverlayColourScheme.Aquamarine.GetHue()); contentContainer.Delay(timeUntilRun).Expire(); contentContainer = null; activeOverlay = null; } - private void updateColourScheme(OverlayColourScheme colourScheme) + private void updateColourScheme(int hue) { - colourProvider.ChangeColourScheme(colourScheme); + colourProvider.ChangeColourScheme(hue); background.FadeColour(colourProvider.Background5, 150, Easing.OutQuint);