From 1b2c43b92cab2badef24f03755e3d8b282cfc04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 19:29:04 +0200 Subject: [PATCH 1/9] Add basic structure of colour palette --- .../TestSceneLabelledColourPalette.cs | 49 +++++++++ .../Graphics/UserInterfaceV2/ColourDisplay.cs | 103 ++++++++++++++++++ .../Graphics/UserInterfaceV2/ColourPalette.cs | 67 ++++++++++++ .../UserInterfaceV2/LabelledColourPalette.cs | 20 ++++ 4 files changed, 239 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs create mode 100644 osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs create mode 100644 osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs create mode 100644 osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs new file mode 100644 index 0000000000..afe95a3745 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs @@ -0,0 +1,49 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.UserInterfaceV2; +using osuTK.Graphics; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneLabelledColourPalette : OsuTestScene + { + private LabelledColourPalette component; + + [Test] + public void TestPalette([Values] bool hasDescription) => createColourPalette(hasDescription); + + private void createColourPalette(bool hasDescription = false) + { + AddStep("create component", () => + { + Child = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Width = 500, + AutoSizeAxes = Axes.Y, + Child = component = new LabelledColourPalette + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }; + + component.Label = "a sample component"; + component.Description = hasDescription ? "this text describes the component" : string.Empty; + + component.Colours.AddRange(new[] + { + Color4.DarkRed, + Color4.Aquamarine, + Color4.Goldenrod, + Color4.Gainsboro + }); + }); + } + } +} diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs new file mode 100644 index 0000000000..ef5be62a37 --- /dev/null +++ b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs @@ -0,0 +1,103 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Localisation; +using osu.Game.Graphics.Sprites; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Graphics.UserInterfaceV2 +{ + public class ColourDisplay : CompositeDrawable, IHasCurrentValue + { + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + private Box fill; + private OsuSpriteText colourHexCode; + private OsuSpriteText colourName; + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } + + private LocalisableString name; + + public LocalisableString ColourName + { + get => name; + set + { + if (name == value) + return; + + name = value; + + colourName.Text = name; + } + } + + [BackgroundDependencyLoader] + private void load() + { + AutoSizeAxes = Axes.Y; + Width = 100; + + InternalChild = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 10), + Children = new Drawable[] + { + new CircularContainer + { + RelativeSizeAxes = Axes.X, + Height = 100, + Masking = true, + Children = new Drawable[] + { + fill = new Box + { + RelativeSizeAxes = Axes.Both + }, + colourHexCode = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.Default.With(size: 12) + } + } + }, + colourName = new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre + } + } + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + current.BindValueChanged(_ => updateColour(), true); + } + + private void updateColour() + { + fill.Colour = current.Value; + colourHexCode.Text = current.Value.ToHex(); + } + } +} diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs new file mode 100644 index 0000000000..8fa76a017c --- /dev/null +++ b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs @@ -0,0 +1,67 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Graphics.UserInterfaceV2 +{ + public class ColourPalette : CompositeDrawable + { + public BindableList Colours { get; } = new BindableList(); + + private FillFlowContainer palette; + + [BackgroundDependencyLoader] + private void load() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + InternalChild = palette = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(10), + Direction = FillDirection.Full + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + Colours.BindCollectionChanged((_, __) => updatePalette(), true); + } + + private void updatePalette() + { + palette.Clear(); + + foreach (var item in Colours) + { + palette.Add(new ColourDisplay + { + Current = { Value = item } + }); + } + + reindexItems(); + } + + private void reindexItems() + { + int index = 1; + + foreach (var colour in palette) + { + colour.ColourName = $"Colour {index}"; + index += 1; + } + } + } +} diff --git a/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs new file mode 100644 index 0000000000..f6f2d92d01 --- /dev/null +++ b/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; +using osuTK.Graphics; + +namespace osu.Game.Graphics.UserInterfaceV2 +{ + public class LabelledColourPalette : LabelledDrawable + { + public LabelledColourPalette() + : base(true) + { + } + + public BindableList Colours => Component.Colours; + + protected override ColourPalette CreateComponent() => new ColourPalette(); + } +} From 67c19df00050c9d0f6fef7f69e9dc98edb2f4c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 19:35:42 +0200 Subject: [PATCH 2/9] Add test coverage for adding/removing colours --- .../TestSceneLabelledColourPalette.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs index afe95a3745..77d313e6ee 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Utils; using osu.Game.Graphics.UserInterfaceV2; using osuTK.Graphics; @@ -14,7 +15,17 @@ namespace osu.Game.Tests.Visual.UserInterface private LabelledColourPalette component; [Test] - public void TestPalette([Values] bool hasDescription) => createColourPalette(hasDescription); + public void TestPalette([Values] bool hasDescription) + { + createColourPalette(hasDescription); + + AddRepeatStep("add random colour", () => component.Colours.Add(randomColour()), 4); + AddRepeatStep("remove random colour", () => + { + if (component.Colours.Count > 0) + component.Colours.RemoveAt(RNG.Next(component.Colours.Count)); + }, 5); + } private void createColourPalette(bool hasDescription = false) { @@ -45,5 +56,11 @@ namespace osu.Game.Tests.Visual.UserInterface }); }); } + + private Color4 randomColour() => new Color4( + RNG.NextSingle(), + RNG.NextSingle(), + RNG.NextSingle(), + 1); } } From a8027d87b6c9bd31c895d1eb243fdf6af689567e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 19:46:54 +0200 Subject: [PATCH 3/9] Fix unreadable colour hex code text due to low contrast Logic is shared with the timeline blueprints which also have the same problem of displaying text on top of a combo colour. Slightly modified the formula. Seems to yield better results on a subjective check. --- .../Graphics/UserInterfaceV2/ColourDisplay.cs | 2 ++ .../Timeline/TimelineHitObjectBlueprint.cs | 6 ++--- osu.Game/Utils/ColourUtils.cs | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 osu.Game/Utils/ColourUtils.cs diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs index ef5be62a37..5d9d2521cb 100644 --- a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs +++ b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; using osu.Game.Graphics.Sprites; +using osu.Game.Utils; using osuTK; using osuTK.Graphics; @@ -98,6 +99,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { fill.Colour = current.Value; colourHexCode.Text = current.Value.ToHex(); + colourHexCode.Colour = ColourUtils.ForegroundTextColourFor(current.Value); } } } diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index 105e04d441..dc67009d08 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -21,6 +21,7 @@ using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Skinning; +using osu.Game.Utils; using osuTK; using osuTK.Graphics; @@ -158,10 +159,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline circle.Colour = comboColour; var col = circle.Colour.TopLeft.Linear; - float brightness = col.R + col.G + col.B; - - // decide the combo index colour based on brightness? - colouredComponents.Colour = OsuColour.Gray(brightness > 0.5f ? 0.2f : 0.9f); + colouredComponents.Colour = ColourUtils.ForegroundTextColourFor(col); } protected override void Update() diff --git a/osu.Game/Utils/ColourUtils.cs b/osu.Game/Utils/ColourUtils.cs new file mode 100644 index 0000000000..33f6f5981f --- /dev/null +++ b/osu.Game/Utils/ColourUtils.cs @@ -0,0 +1,23 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Graphics; +using osuTK.Graphics; + +namespace osu.Game.Utils +{ + public static class ColourUtils + { + /// + /// Returns a foreground text colour that is supposed to contrast well on top of + /// the supplied . + /// + public static Color4 ForegroundTextColourFor(Color4 backgroundColour) + { + // formula taken from the RGB->YIQ conversions: https://en.wikipedia.org/wiki/YIQ + // brightness here is equivalent to the Y component in the above colour model, which is a rough estimate of lightness. + float brightness = 0.299f * backgroundColour.R + 0.587f * backgroundColour.G + 0.114f * backgroundColour.B; + return OsuColour.Gray(brightness > 0.5f ? 0.2f : 0.9f); + } + } +} From 0cd1aa8c1cca9a984968a6c84ae25a5b55ee2cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 19:56:03 +0200 Subject: [PATCH 4/9] Add support for custom colour prefixes --- .../TestSceneLabelledColourPalette.cs | 3 +++ .../Graphics/UserInterfaceV2/ColourPalette.cs | 19 ++++++++++++++++++- .../UserInterfaceV2/LabelledColourPalette.cs | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs index 77d313e6ee..325e71f76a 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs @@ -25,6 +25,8 @@ namespace osu.Game.Tests.Visual.UserInterface if (component.Colours.Count > 0) component.Colours.RemoveAt(RNG.Next(component.Colours.Count)); }, 5); + + AddStep("set custom prefix", () => component.ColourNamePrefix = "Combo"); } private void createColourPalette(bool hasDescription = false) @@ -41,6 +43,7 @@ namespace osu.Game.Tests.Visual.UserInterface { Anchor = Anchor.Centre, Origin = Anchor.Centre, + ColourNamePrefix = "My colour #" } }; diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs index 8fa76a017c..38ac51b955 100644 --- a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs +++ b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs @@ -14,6 +14,23 @@ namespace osu.Game.Graphics.UserInterfaceV2 { public BindableList Colours { get; } = new BindableList(); + private string colourNamePrefix = "Colour"; + + public string ColourNamePrefix + { + get => colourNamePrefix; + set + { + if (colourNamePrefix == value) + return; + + colourNamePrefix = value; + + if (IsLoaded) + reindexItems(); + } + } + private FillFlowContainer palette; [BackgroundDependencyLoader] @@ -59,7 +76,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 foreach (var colour in palette) { - colour.ColourName = $"Colour {index}"; + colour.ColourName = $"{colourNamePrefix} {index}"; index += 1; } } diff --git a/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs index f6f2d92d01..58443953bc 100644 --- a/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs +++ b/osu.Game/Graphics/UserInterfaceV2/LabelledColourPalette.cs @@ -15,6 +15,12 @@ namespace osu.Game.Graphics.UserInterfaceV2 public BindableList Colours => Component.Colours; + public string ColourNamePrefix + { + get => Component.ColourNamePrefix; + set => Component.ColourNamePrefix = value; + } + protected override ColourPalette CreateComponent() => new ColourPalette(); } } From 577755ee1943c65b4e26dfa7cef7c39a43896a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 20:15:30 +0200 Subject: [PATCH 5/9] Add placeholder when no colours are visible Will be removed once combo colours are mutable. --- .../TestSceneLabelledColourPalette.cs | 7 ++-- .../Graphics/UserInterfaceV2/ColourPalette.cs | 42 ++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs index 325e71f76a..826da17ca8 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledColourPalette.cs @@ -20,13 +20,14 @@ namespace osu.Game.Tests.Visual.UserInterface createColourPalette(hasDescription); AddRepeatStep("add random colour", () => component.Colours.Add(randomColour()), 4); + + AddStep("set custom prefix", () => component.ColourNamePrefix = "Combo"); + AddRepeatStep("remove random colour", () => { if (component.Colours.Count > 0) component.Colours.RemoveAt(RNG.Next(component.Colours.Count)); - }, 5); - - AddStep("set custom prefix", () => component.ColourNamePrefix = "Combo"); + }, 8); } private void createColourPalette(bool hasDescription = false) diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs index 38ac51b955..3ca5c2d8d1 100644 --- a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs +++ b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs @@ -1,10 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.Sprites; using osuTK; using osuTK.Graphics; @@ -32,6 +34,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 } private FillFlowContainer palette; + private Container placeholder; [BackgroundDependencyLoader] private void load() @@ -39,12 +42,27 @@ namespace osu.Game.Graphics.UserInterfaceV2 RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - InternalChild = palette = new FillFlowContainer + InternalChildren = new Drawable[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Spacing = new Vector2(10), - Direction = FillDirection.Full + palette = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(10), + Direction = FillDirection.Full + }, + placeholder = new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Child = new OsuSpriteText + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Text = "(none)", + Font = OsuFont.Default.With(weight: FontWeight.Bold) + } + } }; } @@ -53,12 +71,26 @@ namespace osu.Game.Graphics.UserInterfaceV2 base.LoadComplete(); Colours.BindCollectionChanged((_, __) => updatePalette(), true); + FinishTransforms(true); } + private const int fade_duration = 200; + private void updatePalette() { palette.Clear(); + if (Colours.Any()) + { + palette.FadeIn(fade_duration, Easing.OutQuint); + placeholder.FadeOut(fade_duration, Easing.OutQuint); + } + else + { + palette.FadeOut(fade_duration, Easing.OutQuint); + placeholder.FadeIn(fade_duration, Easing.OutQuint); + } + foreach (var item in Colours) { palette.Add(new ColourDisplay From 07a00cd68130e973de37e68f119191c8bc971f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 20:16:17 +0200 Subject: [PATCH 6/9] Add colours section with combo colour display --- osu.Game/Screens/Edit/Setup/ColoursSection.cs | 37 +++++++++++++++++++ osu.Game/Screens/Edit/Setup/SetupScreen.cs | 1 + 2 files changed, 38 insertions(+) create mode 100644 osu.Game/Screens/Edit/Setup/ColoursSection.cs diff --git a/osu.Game/Screens/Edit/Setup/ColoursSection.cs b/osu.Game/Screens/Edit/Setup/ColoursSection.cs new file mode 100644 index 0000000000..91dfd74a78 --- /dev/null +++ b/osu.Game/Screens/Edit/Setup/ColoursSection.cs @@ -0,0 +1,37 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Localisation; +using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Skinning; +using osuTK.Graphics; + +namespace osu.Game.Screens.Edit.Setup +{ + internal class ColoursSection : SetupSection + { + public override LocalisableString Title => "Colours"; + + private LabelledColourPalette comboColours; + + [BackgroundDependencyLoader] + private void load() + { + Children = new Drawable[] + { + comboColours = new LabelledColourPalette + { + Label = "Hitcircle / Slider Combos", + ColourNamePrefix = "Combo" + } + }; + + var colours = Beatmap.BeatmapSkin.GetConfig>(GlobalSkinColours.ComboColours)?.Value; + if (colours != null) + comboColours.Colours.AddRange(colours); + } + } +} diff --git a/osu.Game/Screens/Edit/Setup/SetupScreen.cs b/osu.Game/Screens/Edit/Setup/SetupScreen.cs index 70671b487c..dc81b31f65 100644 --- a/osu.Game/Screens/Edit/Setup/SetupScreen.cs +++ b/osu.Game/Screens/Edit/Setup/SetupScreen.cs @@ -61,6 +61,7 @@ namespace osu.Game.Screens.Edit.Setup new ResourcesSection(), new MetadataSection(), new DifficultySection(), + new ColoursSection() } }, } From 6f2ebb20a7fedc0d02037540b3610e7e64288239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 18 Apr 2021 20:29:09 +0200 Subject: [PATCH 7/9] Fix test failing due to null beatmap skin Also annotate the field on `EditorBeatmap` as nullable for future travelers. --- osu.Game/Screens/Edit/EditorBeatmap.cs | 1 + osu.Game/Screens/Edit/Setup/ColoursSection.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index 4f1b0484d2..4bf4a3b8f3 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -46,6 +46,7 @@ namespace osu.Game.Screens.Edit public readonly IBeatmap PlayableBeatmap; + [CanBeNull] public readonly ISkin BeatmapSkin; [Resolved] diff --git a/osu.Game/Screens/Edit/Setup/ColoursSection.cs b/osu.Game/Screens/Edit/Setup/ColoursSection.cs index 91dfd74a78..cb7deadcb7 100644 --- a/osu.Game/Screens/Edit/Setup/ColoursSection.cs +++ b/osu.Game/Screens/Edit/Setup/ColoursSection.cs @@ -29,7 +29,7 @@ namespace osu.Game.Screens.Edit.Setup } }; - var colours = Beatmap.BeatmapSkin.GetConfig>(GlobalSkinColours.ComboColours)?.Value; + var colours = Beatmap.BeatmapSkin?.GetConfig>(GlobalSkinColours.ComboColours)?.Value; if (colours != null) comboColours.Colours.AddRange(colours); } From f9f514ffec646a245d8c310594c4bae619b4a0c8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Apr 2021 12:37:56 +0900 Subject: [PATCH 8/9] Add basic xmldoc to show how the two colour classes interact --- osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs | 3 +++ osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs index 5d9d2521cb..c07e5d5bf7 100644 --- a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs +++ b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs @@ -16,6 +16,9 @@ using osuTK.Graphics; namespace osu.Game.Graphics.UserInterfaceV2 { + /// + /// A component which displays a colour along with related description text. + /// public class ColourDisplay : CompositeDrawable, IHasCurrentValue { private readonly BindableWithCurrent current = new BindableWithCurrent(); diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs index 3ca5c2d8d1..ba950048dc 100644 --- a/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs +++ b/osu.Game/Graphics/UserInterfaceV2/ColourPalette.cs @@ -12,6 +12,9 @@ using osuTK.Graphics; namespace osu.Game.Graphics.UserInterfaceV2 { + /// + /// A component which displays a collection of colours in individual s. + /// public class ColourPalette : CompositeDrawable { public BindableList Colours { get; } = new BindableList(); From 0825fc57a9f50a86594b4090954366d47aa82725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 19 Apr 2021 18:24:15 +0200 Subject: [PATCH 9/9] Move foreground colour helper into `OsuColour` --- osu.Game/Graphics/OsuColour.cs | 12 ++++++++++ .../Graphics/UserInterfaceV2/ColourDisplay.cs | 3 +-- .../Timeline/TimelineHitObjectBlueprint.cs | 3 +-- osu.Game/Utils/ColourUtils.cs | 23 ------------------- 4 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 osu.Game/Utils/ColourUtils.cs diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index c3b9b6006c..15967c37c2 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -94,6 +94,18 @@ namespace osu.Game.Graphics } } + /// + /// Returns a foreground text colour that is supposed to contrast well with + /// the supplied . + /// + public static Color4 ForegroundTextColourFor(Color4 backgroundColour) + { + // formula taken from the RGB->YIQ conversions: https://en.wikipedia.org/wiki/YIQ + // brightness here is equivalent to the Y component in the above colour model, which is a rough estimate of lightness. + float brightness = 0.299f * backgroundColour.R + 0.587f * backgroundColour.G + 0.114f * backgroundColour.B; + return Gray(brightness > 0.5f ? 0.2f : 0.9f); + } + // See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less public readonly Color4 PurpleLighter = Color4Extensions.FromHex(@"eeeeff"); public readonly Color4 PurpleLight = Color4Extensions.FromHex(@"aa88ff"); diff --git a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs index c07e5d5bf7..01d91f7cfd 100644 --- a/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs +++ b/osu.Game/Graphics/UserInterfaceV2/ColourDisplay.cs @@ -10,7 +10,6 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; using osu.Game.Graphics.Sprites; -using osu.Game.Utils; using osuTK; using osuTK.Graphics; @@ -102,7 +101,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { fill.Colour = current.Value; colourHexCode.Text = current.Value.ToHex(); - colourHexCode.Colour = ColourUtils.ForegroundTextColourFor(current.Value); + colourHexCode.Colour = OsuColour.ForegroundTextColourFor(current.Value); } } } diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index dc67009d08..0425370ae5 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -21,7 +21,6 @@ using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Skinning; -using osu.Game.Utils; using osuTK; using osuTK.Graphics; @@ -159,7 +158,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline circle.Colour = comboColour; var col = circle.Colour.TopLeft.Linear; - colouredComponents.Colour = ColourUtils.ForegroundTextColourFor(col); + colouredComponents.Colour = OsuColour.ForegroundTextColourFor(col); } protected override void Update() diff --git a/osu.Game/Utils/ColourUtils.cs b/osu.Game/Utils/ColourUtils.cs deleted file mode 100644 index 33f6f5981f..0000000000 --- a/osu.Game/Utils/ColourUtils.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Graphics; -using osuTK.Graphics; - -namespace osu.Game.Utils -{ - public static class ColourUtils - { - /// - /// Returns a foreground text colour that is supposed to contrast well on top of - /// the supplied . - /// - public static Color4 ForegroundTextColourFor(Color4 backgroundColour) - { - // formula taken from the RGB->YIQ conversions: https://en.wikipedia.org/wiki/YIQ - // brightness here is equivalent to the Y component in the above colour model, which is a rough estimate of lightness. - float brightness = 0.299f * backgroundColour.R + 0.587f * backgroundColour.G + 0.114f * backgroundColour.B; - return OsuColour.Gray(brightness > 0.5f ? 0.2f : 0.9f); - } - } -}