1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Explicitly define Hue rather than implicitly provide it by enum value

This commit is contained in:
Salman Ahmed 2024-07-18 00:05:44 +03:00
parent 4eb4d35e2f
commit d61a72b8fb
4 changed files with 91 additions and 35 deletions

View File

@ -7,11 +7,19 @@ namespace osu.Game.Overlays
{
public class OverlayColourProvider
{
public OverlayColourScheme ColourScheme { get; private set; }
/// <summary>
/// The hue degree associated with the colour shades provided by this <see cref="OverlayColourProvider"/>.
/// </summary>
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);
/// <summary>
/// Changes the value of <see cref="ColourScheme"/> to a different colour scheme.
/// Changes the <see cref="Hue"/> 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.
/// </summary>
/// <param name="colourScheme">The proposed colour scheme.</param>
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);
/// <summary>
/// Changes the <see cref="Hue"/> 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.
/// </summary>
/// <param name="hue">The proposed hue degree.</param>
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);
}
}

View File

@ -0,0 +1,60 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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;
}
}
}
}

View File

@ -118,7 +118,7 @@ namespace osu.Game.Overlays
}
: Array.Empty<ProfileSection>();
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();

View File

@ -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);