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] 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(); } }