From a7f3beabe3561d371e248025f62532f0541e7cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 12:36:21 +0200 Subject: [PATCH 1/5] Modify `OsuTextBox` test scene to test against colour provider --- .../UserInterface/TestSceneOsuTextBox.cs | 93 ++++++++----------- .../UserInterface/ThemeComparisonTestScene.cs | 4 +- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs index 756928d3ec..fc1866cdf3 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs @@ -1,80 +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 System.Collections.Generic; +using System.Linq; using NUnit.Framework; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; using osuTK; -using osuTK.Graphics; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneOsuTextBox : OsuTestScene + public class TestSceneOsuTextBox : ThemeComparisonTestScene { - private readonly OsuNumberBox numberBox; + private IEnumerable numberBoxes => this.ChildrenOfType(); - public TestSceneOsuTextBox() + protected override Drawable CreateContent() => new FillFlowContainer { - Child = new Container + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Padding = new MarginPadding(50f), + Spacing = new Vector2(0f, 50f), + Children = new[] { - Masking = true, - CornerRadius = 10f, - AutoSizeAxes = Axes.Both, - Padding = new MarginPadding(15f), - Children = new Drawable[] + new OsuTextBox { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.DarkSlateGray, - Alpha = 0.75f, - }, - new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, - Padding = new MarginPadding(50f), - Spacing = new Vector2(0f, 50f), - Children = new[] - { - new OsuTextBox - { - Width = 500f, - PlaceholderText = "Normal textbox", - }, - new OsuPasswordTextBox - { - Width = 500f, - PlaceholderText = "Password textbox", - }, - numberBox = new OsuNumberBox - { - Width = 500f, - PlaceholderText = "Number textbox" - } - } - } + RelativeSizeAxes = Axes.X, + PlaceholderText = "Normal textbox", + }, + new OsuPasswordTextBox + { + RelativeSizeAxes = Axes.X, + PlaceholderText = "Password textbox", + }, + new OsuNumberBox + { + RelativeSizeAxes = Axes.X, + PlaceholderText = "Number textbox" } - }; - } + } + }; [Test] public void TestNumberBox() { - clearTextbox(numberBox); - AddStep("enter numbers", () => numberBox.Text = "987654321"); - expectedValue(numberBox, "987654321"); + AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red)); - clearTextbox(numberBox); - AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3"); - expectedValue(numberBox, "123"); + clearTextboxes(numberBoxes); + AddStep("enter numbers", () => numberBoxes.ForEach(numberBox => numberBox.Text = "987654321")); + expectedValue(numberBoxes, "987654321"); - clearTextbox(numberBox); + clearTextboxes(numberBoxes); + AddStep("enter text + single number", () => numberBoxes.ForEach(numberBox => numberBox.Text = "1 hello 2 world 3")); + expectedValue(numberBoxes, "123"); + + clearTextboxes(numberBoxes); } - private void clearTextbox(OsuTextBox textBox) => AddStep("clear textbox", () => textBox.Text = null); - private void expectedValue(OsuTextBox textBox, string value) => AddAssert("expected textbox value", () => textBox.Text == value); + private void clearTextboxes(IEnumerable textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null)); + private void expectedValue(IEnumerable textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textbox => textbox.Text == value)); } } diff --git a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs index f8b9e8223b..db1c90f287 100644 --- a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs +++ b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs @@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.UserInterface }); } - private void createThemedContent(OverlayColourScheme colourScheme) + protected void CreateThemedContent(OverlayColourScheme colourScheme) { var colourProvider = new OverlayColourProvider(colourScheme); @@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.UserInterface public void TestAllColourSchemes() { foreach (var scheme in Enum.GetValues(typeof(OverlayColourScheme)).Cast()) - AddStep($"set {scheme} scheme", () => createThemedContent(scheme)); + AddStep($"set {scheme} scheme", () => CreateThemedContent(scheme)); } } } From addcef4f5d9e6abca6776149a391401a350f71e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 12:51:51 +0200 Subject: [PATCH 2/5] Recolour text box using `OverlayColourProvider` --- osu.Game/Graphics/UserInterface/OsuTextBox.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuTextBox.cs b/osu.Game/Graphics/UserInterface/OsuTextBox.cs index 75af9efc38..b8f8518bb4 100644 --- a/osu.Game/Graphics/UserInterface/OsuTextBox.cs +++ b/osu.Game/Graphics/UserInterface/OsuTextBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -17,18 +19,13 @@ using osu.Framework.Input.Events; using osu.Framework.Utils; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Graphics.Containers; +using osu.Game.Overlays; using osuTK; namespace osu.Game.Graphics.UserInterface { public class OsuTextBox : BasicTextBox { - private readonly Sample[] textAddedSamples = new Sample[4]; - private Sample capsTextAddedSample; - private Sample textRemovedSample; - private Sample textCommittedSample; - private Sample caretMovedSample; - /// /// Whether to allow playing a different samples based on the type of character. /// If set to false, the same sample will be used for all characters. @@ -42,10 +39,15 @@ namespace osu.Game.Graphics.UserInterface protected override SpriteText CreatePlaceholder() => new OsuSpriteText { Font = OsuFont.GetFont(italics: true), - Colour = new Color4(180, 180, 180, 255), Margin = new MarginPadding { Left = 2 }, }; + private readonly Sample?[] textAddedSamples = new Sample[4]; + private Sample? capsTextAddedSample; + private Sample? textRemovedSample; + private Sample? textCommittedSample; + private Sample? caretMovedSample; + public OsuTextBox() { Height = 40; @@ -56,12 +58,14 @@ namespace osu.Game.Graphics.UserInterface Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; }; } - [BackgroundDependencyLoader] - private void load(OsuColour colour, AudioManager audio) + [BackgroundDependencyLoader(true)] + private void load(OverlayColourProvider? colourProvider, OsuColour colour, AudioManager audio) { - BackgroundUnfocused = Color4.Black.Opacity(0.5f); - BackgroundFocused = OsuColour.Gray(0.3f).Opacity(0.8f); - BackgroundCommit = BorderColour = colour.Yellow; + BackgroundUnfocused = colourProvider?.Background5 ?? Color4.Black.Opacity(0.5f); + BackgroundFocused = colourProvider?.Background3 ?? OsuColour.Gray(0.3f).Opacity(0.8f); + BackgroundCommit = BorderColour = colourProvider?.Highlight1 ?? colour.Yellow; + + Placeholder.Colour = colourProvider?.Foreground1 ?? new Color4(180, 180, 180, 255); for (int i = 0; i < textAddedSamples.Length; i++) textAddedSamples[i] = audio.Samples.Get($@"Keyboard/key-press-{1 + i}"); From 1ec881ce1d9306c4d3b326b1d44e81a64206a490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 12:58:37 +0200 Subject: [PATCH 3/5] Recolour focused text box variant --- osu.Game/Graphics/UserInterface/FocusedTextBox.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index ceea9620c8..88608bf43c 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + using osuTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Input.Events; @@ -8,6 +10,7 @@ using osu.Framework.Platform; using osu.Game.Input.Bindings; using osuTK.Input; using osu.Framework.Input.Bindings; +using osu.Game.Overlays; namespace osu.Game.Graphics.UserInterface { @@ -42,13 +45,13 @@ namespace osu.Game.Graphics.UserInterface } [Resolved] - private GameHost host { get; set; } + private GameHost? host { get; set; } - [BackgroundDependencyLoader] - private void load() + [BackgroundDependencyLoader(true)] + private void load(OverlayColourProvider? colourProvider) { - BackgroundUnfocused = new Color4(10, 10, 10, 255); - BackgroundFocused = new Color4(10, 10, 10, 255); + BackgroundUnfocused = colourProvider?.Background5 ?? new Color4(10, 10, 10, 255); + BackgroundFocused = colourProvider?.Background5 ?? new Color4(10, 10, 10, 255); } // We may not be focused yet, but we need to handle keyboard input to be able to request focus From 9ad9465020eee89a421f80d9a5ce2027548a65ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 13:10:23 +0200 Subject: [PATCH 4/5] Remove online-screen-local textbox recolours --- .../OnlinePlay/Lounge/LoungeSubScreen.cs | 13 +--------- .../Match/Components/RoomSettingsOverlay.cs | 26 ------------------- .../Match/MultiplayerMatchSettingsOverlay.cs | 6 ++--- .../Playlists/PlaylistsRoomSettingsOverlay.cs | 8 +++--- 4 files changed, 8 insertions(+), 45 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs index 08bdd0487a..62012906a7 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs @@ -17,7 +17,6 @@ using osu.Framework.Input.Events; using osu.Framework.Logging; using osu.Framework.Screens; using osu.Framework.Threading; -using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Input; @@ -126,7 +125,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge { RelativeSizeAxes = Axes.X, Height = Header.HEIGHT, - Child = searchTextBox = new LoungeSearchTextBox + Child = searchTextBox = new SearchTextBox { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, @@ -362,15 +361,5 @@ namespace osu.Game.Screens.OnlinePlay.Lounge protected abstract RoomSubScreen CreateRoomSubScreen(Room room); protected abstract ListingPollingComponent CreatePollingComponent(); - - private class LoungeSearchTextBox : SearchTextBox - { - [BackgroundDependencyLoader] - private void load() - { - BackgroundUnfocused = OsuColour.Gray(0.06f); - BackgroundFocused = OsuColour.Gray(0.12f); - } - } } } diff --git a/osu.Game/Screens/OnlinePlay/Match/Components/RoomSettingsOverlay.cs b/osu.Game/Screens/OnlinePlay/Match/Components/RoomSettingsOverlay.cs index a6cdde14f6..6d14b95aec 100644 --- a/osu.Game/Screens/OnlinePlay/Match/Components/RoomSettingsOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Match/Components/RoomSettingsOverlay.cs @@ -12,7 +12,6 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Input.Bindings; using osu.Game.Online.Rooms; using osuTK; -using osuTK.Graphics; namespace osu.Game.Screens.OnlinePlay.Match.Components { @@ -91,31 +90,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components { } - protected class SettingsTextBox : OsuTextBox - { - [BackgroundDependencyLoader] - private void load() - { - BackgroundUnfocused = Color4.Black; - BackgroundFocused = Color4.Black; - } - } - - protected class SettingsNumberTextBox : SettingsTextBox - { - protected override bool CanAddCharacter(char character) => char.IsNumber(character); - } - - protected class SettingsPasswordTextBox : OsuPasswordTextBox - { - [BackgroundDependencyLoader] - private void load() - { - BackgroundUnfocused = Color4.Black; - BackgroundFocused = Color4.Black; - } - } - protected class SectionContainer : FillFlowContainer
{ public SectionContainer() diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerMatchSettingsOverlay.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerMatchSettingsOverlay.cs index 0edf5dde6d..5bc76a10bc 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerMatchSettingsOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerMatchSettingsOverlay.cs @@ -153,7 +153,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match { new Section("Room name") { - Child = NameField = new SettingsTextBox + Child = NameField = new OsuTextBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, @@ -202,7 +202,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match new Section("Max participants") { Alpha = disabled_alpha, - Child = MaxParticipantsField = new SettingsNumberTextBox + Child = MaxParticipantsField = new OsuNumberBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, @@ -211,7 +211,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match }, new Section("Password (optional)") { - Child = PasswordTextBox = new SettingsPasswordTextBox + Child = PasswordTextBox = new OsuPasswordTextBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs index 9e000aa712..c2bd7730e9 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSettingsOverlay.cs @@ -121,7 +121,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists { new Section("Room name") { - Child = NameField = new SettingsTextBox + Child = NameField = new OsuTextBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, @@ -150,7 +150,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists }, new Section("Allowed attempts (across all playlist items)") { - Child = MaxAttemptsField = new SettingsNumberTextBox + Child = MaxAttemptsField = new OsuNumberBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, @@ -168,7 +168,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists new Section("Max participants") { Alpha = disabled_alpha, - Child = MaxParticipantsField = new SettingsNumberTextBox + Child = MaxParticipantsField = new OsuNumberBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, @@ -178,7 +178,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists new Section("Password (optional)") { Alpha = disabled_alpha, - Child = new SettingsPasswordTextBox + Child = new OsuPasswordTextBox { RelativeSizeAxes = Axes.X, TabbableContentContainer = this, From 7bc8f5cd5cf4628626c76e65c81484b3609556a9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 21 Oct 2021 12:59:40 +0900 Subject: [PATCH 5/5] Change selection colour to also match the colour provider scheme --- osu.Game/Graphics/UserInterface/OsuTextBox.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuTextBox.cs b/osu.Game/Graphics/UserInterface/OsuTextBox.cs index b8f8518bb4..96319b9fdd 100644 --- a/osu.Game/Graphics/UserInterface/OsuTextBox.cs +++ b/osu.Game/Graphics/UserInterface/OsuTextBox.cs @@ -48,6 +48,8 @@ namespace osu.Game.Graphics.UserInterface private Sample? textCommittedSample; private Sample? caretMovedSample; + private OsuCaret? caret; + public OsuTextBox() { Height = 40; @@ -62,8 +64,12 @@ namespace osu.Game.Graphics.UserInterface private void load(OverlayColourProvider? colourProvider, OsuColour colour, AudioManager audio) { BackgroundUnfocused = colourProvider?.Background5 ?? Color4.Black.Opacity(0.5f); - BackgroundFocused = colourProvider?.Background3 ?? OsuColour.Gray(0.3f).Opacity(0.8f); + BackgroundFocused = colourProvider?.Background4 ?? OsuColour.Gray(0.3f).Opacity(0.8f); BackgroundCommit = BorderColour = colourProvider?.Highlight1 ?? colour.Yellow; + selectionColour = colourProvider?.Background1 ?? new Color4(249, 90, 255, 255); + + if (caret != null) + caret.SelectionColour = selectionColour; Placeholder.Colour = colourProvider?.Foreground1 ?? new Color4(180, 180, 180, 255); @@ -76,7 +82,9 @@ namespace osu.Game.Graphics.UserInterface caretMovedSample = audio.Samples.Get(@"Keyboard/key-movement"); } - protected override Color4 SelectionColour => new Color4(249, 90, 255, 255); + private Color4 selectionColour; + + protected override Color4 SelectionColour => selectionColour; protected override void OnUserTextAdded(string added) { @@ -128,7 +136,7 @@ namespace osu.Game.Graphics.UserInterface Child = new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: CalculatedTextSize) }, }; - protected override Caret CreateCaret() => new OsuCaret + protected override Caret CreateCaret() => caret = new OsuCaret { CaretWidth = CaretWidth, SelectionColour = SelectionColour,