From 482f622c94202a483092f8e6df306fbcc234af6a Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 11 Feb 2020 18:46:49 +0300 Subject: [PATCH 01/15] CommentEditor basic implementation --- .../UserInterface/TestSceneCommentEditor.cs | 43 ++++++++++++++ osu.Game/Overlays/Comments/CommentEditor.cs | 59 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs create mode 100644 osu.Game/Overlays/Comments/CommentEditor.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs new file mode 100644 index 0000000000..f349c81b38 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -0,0 +1,43 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Overlays; +using osu.Game.Overlays.Comments; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneCommentEditor : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(CommentEditor), + }; + + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + + public TestSceneCommentEditor() + { + Add(new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Y, + Width = 800, + Child = new TestCommentEditor() + }); + } + + private class TestCommentEditor : CommentEditor + { + protected override string EmptyTextboxText() => @"This textbox is empty"; + + protected override string FooterText() => @"Footer text. And it is pretty long. Cool."; + } + } +} diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs new file mode 100644 index 0000000000..a1995530bb --- /dev/null +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -0,0 +1,59 @@ +// 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.Graphics.Containers; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Overlays.Comments +{ + public abstract class CommentEditor : CompositeDrawable + { + private const int footer_height = 40; + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + RelativeSizeAxes = Axes.X; + Height = footer_height * 2; + Masking = true; + CornerRadius = 6; + + AddRangeInternal(new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colourProvider.Background3 + }, + new Container + { + Name = "Footer", + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + RelativeSizeAxes = Axes.X, + Height = footer_height, + Padding = new MarginPadding { Horizontal = 8 }, + Children = new Drawable[] + { + new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = OsuFont.GetFont(size: 12), + Shadow = false, + Text = FooterText() + } + } + } + }); + } + + protected abstract string FooterText(); + + protected abstract string EmptyTextboxText(); + } +} From 829152c8e89444f3146f582509d8b9879a1b6ba3 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 11 Feb 2020 20:08:24 +0300 Subject: [PATCH 02/15] Implement EditorTextbox --- .../UserInterface/TestSceneCommentEditor.cs | 6 +- osu.Game/Overlays/Comments/CommentEditor.cs | 81 +++++++++++++++---- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index f349c81b38..a1f1999090 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -35,9 +35,11 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestCommentEditor : CommentEditor { - protected override string EmptyTextboxText() => @"This textbox is empty"; + protected override string FooterText => @"Footer text. And it is pretty long. Cool."; - protected override string FooterText() => @"Footer text. And it is pretty long. Cool."; + protected override string CommitButtonText => @"Commit"; + + protected override string TextboxPlaceholderText => @"This textbox is empty"; } } } diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index a1995530bb..9252194377 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -7,20 +7,32 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Graphics.Sprites; +using osuTK.Graphics; namespace osu.Game.Overlays.Comments { public abstract class CommentEditor : CompositeDrawable { private const int footer_height = 40; + private const int side_padding = 8; + + protected abstract string FooterText { get; } + + protected abstract string CommitButtonText { get; } + + protected abstract string TextboxPlaceholderText { get; } [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { RelativeSizeAxes = Axes.X; - Height = footer_height * 2; + AutoSizeAxes = Axes.Y; Masking = true; CornerRadius = 6; + BorderThickness = 3; + BorderColour = colourProvider.Background3; AddRangeInternal(new Drawable[] { @@ -29,31 +41,70 @@ namespace osu.Game.Overlays.Comments RelativeSizeAxes = Axes.Both, Colour = colourProvider.Background3 }, - new Container + new FillFlowContainer { - Name = "Footer", - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, + AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, - Height = footer_height, - Padding = new MarginPadding { Horizontal = 8 }, + Direction = FillDirection.Vertical, Children = new Drawable[] { - new OsuSpriteText + new EditorTextbox { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(size: 12), - Shadow = false, - Text = FooterText() + Height = footer_height, + RelativeSizeAxes = Axes.X, + PlaceholderText = TextboxPlaceholderText + }, + new Container + { + Name = "Footer", + RelativeSizeAxes = Axes.X, + Height = footer_height, + Padding = new MarginPadding { Horizontal = side_padding }, + Children = new Drawable[] + { + new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold), + Text = FooterText + } + } } } } }); } - protected abstract string FooterText(); + private class EditorTextbox : BasicTextBox + { + protected override float LeftRightPadding => side_padding; - protected abstract string EmptyTextboxText(); + protected override Color4 SelectionColour => Color4.LightSkyBlue; + + private OsuSpriteText placeholder; + + public EditorTextbox() + { + Masking = false; + TextContainer.Height = 0.4f; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + BackgroundUnfocused = BackgroundFocused = colourProvider.Background5; + placeholder.Colour = colourProvider.Background3; + BackgroundCommit = Color4.LightSkyBlue; + } + + + protected override SpriteText CreatePlaceholder() => placeholder = new OsuSpriteText + { + Font = OsuFont.GetFont(weight: FontWeight.Regular), + }; + + protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: CalculatedTextSize) }; + } } } From 730c115f49fbb29b5f72f37ad0446e9f4174d939 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 11 Feb 2020 20:11:22 +0300 Subject: [PATCH 03/15] Fix some size values --- osu.Game/Overlays/Comments/CommentEditor.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 9252194377..4ad59ff754 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -15,7 +15,6 @@ namespace osu.Game.Overlays.Comments { public abstract class CommentEditor : CompositeDrawable { - private const int footer_height = 40; private const int side_padding = 8; protected abstract string FooterText { get; } @@ -50,7 +49,7 @@ namespace osu.Game.Overlays.Comments { new EditorTextbox { - Height = footer_height, + Height = 40, RelativeSizeAxes = Axes.X, PlaceholderText = TextboxPlaceholderText }, @@ -58,7 +57,7 @@ namespace osu.Game.Overlays.Comments { Name = "Footer", RelativeSizeAxes = Axes.X, - Height = footer_height, + Height = 35, Padding = new MarginPadding { Horizontal = side_padding }, Children = new Drawable[] { From c022cf72b58a8bd13861c8cde85eca6cc3484672 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 11 Feb 2020 20:47:51 +0300 Subject: [PATCH 04/15] Implement CancellableCommentEditor --- .../UserInterface/TestSceneCommentEditor.cs | 21 +++++- .../Comments/CancellableCommentEditor.cs | 71 +++++++++++++++++++ osu.Game/Overlays/Comments/CommentEditor.cs | 10 +++ osu.Game/Overlays/OverlayColourProvider.cs | 42 +++++------ 4 files changed, 121 insertions(+), 23 deletions(-) create mode 100644 osu.Game/Overlays/Comments/CancellableCommentEditor.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index a1f1999090..86179886e5 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Overlays; using osu.Game.Overlays.Comments; +using osuTK; namespace osu.Game.Tests.Visual.UserInterface { @@ -16,6 +17,7 @@ namespace osu.Game.Tests.Visual.UserInterface public override IReadOnlyList RequiredTypes => new[] { typeof(CommentEditor), + typeof(CancellableCommentEditor), }; [Cached] @@ -23,13 +25,19 @@ namespace osu.Game.Tests.Visual.UserInterface public TestSceneCommentEditor() { - Add(new Container + Add(new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, AutoSizeAxes = Axes.Y, Width = 800, - Child = new TestCommentEditor() + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 20), + Children = new Drawable[] + { + new TestCommentEditor(), + new TestCancellableCommentEditor() + } }); } @@ -41,5 +49,14 @@ namespace osu.Game.Tests.Visual.UserInterface protected override string TextboxPlaceholderText => @"This textbox is empty"; } + + private class TestCancellableCommentEditor : CancellableCommentEditor + { + protected override string FooterText => @"Wow, another one. Sicc"; + + protected override string CommitButtonText => @"Save"; + + protected override string TextboxPlaceholderText => @"Miltiline textboxes soon"; + } } } diff --git a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs new file mode 100644 index 0000000000..ad5686910a --- /dev/null +++ b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs @@ -0,0 +1,71 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Overlays.Comments +{ + public abstract class CancellableCommentEditor : CommentEditor + { + public Action OnCancel; + + [BackgroundDependencyLoader] + private void load() + { + ButtonsContainer.Add(new CancelButton + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Action = () => OnCancel?.Invoke() + }); + } + + private class CancelButton : OsuHoverContainer + { + protected override IEnumerable EffectTargets => new[] { background }; + + private readonly Box background; + + public CancelButton() + { + AutoSizeAxes = Axes.Both; + Child = new CircularContainer + { + Masking = true, + Height = 25, + AutoSizeAxes = Axes.X, + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both + }, + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Margin = new MarginPadding { Horizontal = 20 }, + Text = @"Cancel" + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + IdleColour = colourProvider.GetColour(0.5f, 0.45f); + HoverColour = colourProvider.GetColour(0.5f, 0.6f); + } + } + } +} diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 4ad59ff754..bb8ae7f114 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -23,6 +23,8 @@ namespace osu.Game.Overlays.Comments protected abstract string TextboxPlaceholderText { get; } + protected FillFlowContainer ButtonsContainer; + [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { @@ -67,6 +69,14 @@ namespace osu.Game.Overlays.Comments Origin = Anchor.CentreLeft, Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold), Text = FooterText + }, + ButtonsContainer = new FillFlowContainer + { + Name = "Buttons", + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, } } } diff --git a/osu.Game/Overlays/OverlayColourProvider.cs b/osu.Game/Overlays/OverlayColourProvider.cs index 9816f313ad..c0984073e6 100644 --- a/osu.Game/Overlays/OverlayColourProvider.cs +++ b/osu.Game/Overlays/OverlayColourProvider.cs @@ -16,28 +16,28 @@ namespace osu.Game.Overlays this.colourScheme = colourScheme; } - public Color4 Highlight1 => getColour(1, 0.7f); - public Color4 Content1 => getColour(0.4f, 1); - public Color4 Content2 => getColour(0.4f, 0.9f); - public Color4 Light1 => getColour(0.4f, 0.8f); - public Color4 Light2 => getColour(0.4f, 0.75f); - public Color4 Light3 => getColour(0.4f, 0.7f); - public Color4 Light4 => getColour(0.4f, 0.5f); - public Color4 Dark1 => getColour(0.2f, 0.35f); - public Color4 Dark2 => getColour(0.2f, 0.3f); - public Color4 Dark3 => getColour(0.2f, 0.25f); - public Color4 Dark4 => getColour(0.2f, 0.2f); - public Color4 Dark5 => getColour(0.2f, 0.15f); - public Color4 Dark6 => getColour(0.2f, 0.1f); - public Color4 Foreground1 => getColour(0.1f, 0.6f); - public Color4 Background1 => getColour(0.1f, 0.4f); - public Color4 Background2 => getColour(0.1f, 0.3f); - public Color4 Background3 => getColour(0.1f, 0.25f); - public Color4 Background4 => getColour(0.1f, 0.2f); - public Color4 Background5 => getColour(0.1f, 0.15f); - public Color4 Background6 => getColour(0.1f, 0.1f); + public Color4 Highlight1 => GetColour(1, 0.7f); + public Color4 Content1 => GetColour(0.4f, 1); + public Color4 Content2 => GetColour(0.4f, 0.9f); + public Color4 Light1 => GetColour(0.4f, 0.8f); + public Color4 Light2 => GetColour(0.4f, 0.75f); + public Color4 Light3 => GetColour(0.4f, 0.7f); + public Color4 Light4 => GetColour(0.4f, 0.5f); + public Color4 Dark1 => GetColour(0.2f, 0.35f); + public Color4 Dark2 => GetColour(0.2f, 0.3f); + public Color4 Dark3 => GetColour(0.2f, 0.25f); + public Color4 Dark4 => GetColour(0.2f, 0.2f); + public Color4 Dark5 => GetColour(0.2f, 0.15f); + public Color4 Dark6 => GetColour(0.2f, 0.1f); + public Color4 Foreground1 => GetColour(0.1f, 0.6f); + public Color4 Background1 => GetColour(0.1f, 0.4f); + public Color4 Background2 => GetColour(0.1f, 0.3f); + public Color4 Background3 => GetColour(0.1f, 0.25f); + public Color4 Background4 => GetColour(0.1f, 0.2f); + public Color4 Background5 => GetColour(0.1f, 0.15f); + public Color4 Background6 => GetColour(0.1f, 0.1f); - private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1)); + public Color4 GetColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1)); // See https://github.com/ppy/osu-web/blob/4218c288292d7c810b619075471eaea8bbb8f9d8/app/helpers.php#L1463 private static float getBaseHue(OverlayColourScheme colourScheme) From 5a3daf1bd71939f6f1c4b34d1911d74b6789a6f1 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 12 Feb 2020 00:57:06 +0300 Subject: [PATCH 05/15] Implement CommitButton --- .../Comments/CancellableCommentEditor.cs | 4 +- osu.Game/Overlays/Comments/CommentEditor.cs | 72 ++++++++++++++++++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs index ad5686910a..f58627efb3 100644 --- a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs +++ b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs @@ -22,8 +22,8 @@ namespace osu.Game.Overlays.Comments { ButtonsContainer.Add(new CancelButton { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, Action = () => OnCancel?.Invoke() }); } diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index bb8ae7f114..624e15a047 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -10,6 +10,10 @@ using osu.Game.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.Sprites; using osuTK.Graphics; +using osu.Game.Graphics.UserInterface; +using System.Collections.Generic; +using System; +using osuTK; namespace osu.Game.Overlays.Comments { @@ -17,6 +21,8 @@ namespace osu.Game.Overlays.Comments { private const int side_padding = 8; + public Action OnCommit; + protected abstract string FooterText { get; } protected abstract string CommitButtonText { get; } @@ -28,6 +34,9 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { + EditorTextbox textbox; + CommitButton commitButton; + RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; Masking = true; @@ -49,7 +58,7 @@ namespace osu.Game.Overlays.Comments Direction = FillDirection.Vertical, Children = new Drawable[] { - new EditorTextbox + textbox = new EditorTextbox { Height = 40, RelativeSizeAxes = Axes.X, @@ -77,12 +86,21 @@ namespace osu.Game.Overlays.Comments Origin = Anchor.CentreRight, AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, + Spacing = new Vector2(5, 0), + Child = commitButton = new CommitButton(CommitButtonText) + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Action = () => OnCommit?.Invoke(textbox.Text) + } } } } } } }); + + textbox.OnCommit += (u, v) => commitButton.Click(); } private class EditorTextbox : BasicTextBox @@ -107,7 +125,6 @@ namespace osu.Game.Overlays.Comments BackgroundCommit = Color4.LightSkyBlue; } - protected override SpriteText CreatePlaceholder() => placeholder = new OsuSpriteText { Font = OsuFont.GetFont(weight: FontWeight.Regular), @@ -115,5 +132,56 @@ namespace osu.Game.Overlays.Comments protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: CalculatedTextSize) }; } + + private class CommitButton : LoadingButton + { + private const int duration = 200; + + protected override IEnumerable EffectTargets => new[] { background }; + + private OsuSpriteText drawableText; + private Box background; + + public CommitButton(string text) + { + AutoSizeAxes = Axes.Both; + LoadingAnimationSize = new Vector2(10); + + drawableText.Text = text; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + IdleColour = colourProvider.GetColour(0.5f, 0.45f); + HoverColour = colourProvider.GetColour(0.5f, 0.6f); + } + + protected override Drawable CreateContent() => new CircularContainer + { + Masking = true, + Height = 25, + AutoSizeAxes = Axes.X, + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both + }, + drawableText = new OsuSpriteText + { + AlwaysPresent = true, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Margin = new MarginPadding { Horizontal = 20 } + } + } + }; + + protected override void OnLoadStarted() => drawableText.FadeOut(duration, Easing.OutQuint); + + protected override void OnLoadFinished() => drawableText.FadeIn(duration, Easing.OutQuint); + } } } From 53a2b65dbdffda9ee3f053108dd8080b9ed85a5f Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 12 Feb 2020 01:35:08 +0300 Subject: [PATCH 06/15] Create dependency between textbox and commit button --- osu.Game/Overlays/Comments/CommentEditor.cs | 56 ++++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 624e15a047..7adb33663c 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -14,6 +14,7 @@ using osu.Game.Graphics.UserInterface; using System.Collections.Generic; using System; using osuTK; +using osu.Framework.Bindables; namespace osu.Game.Overlays.Comments { @@ -31,11 +32,14 @@ namespace osu.Game.Overlays.Comments protected FillFlowContainer ButtonsContainer; + private readonly Bindable current = new Bindable(); + + private CommitButton commitButton; + [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { EditorTextbox textbox; - CommitButton commitButton; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -62,7 +66,8 @@ namespace osu.Game.Overlays.Comments { Height = 40, RelativeSizeAxes = Axes.X, - PlaceholderText = TextboxPlaceholderText + PlaceholderText = TextboxPlaceholderText, + Current = current }, new Container { @@ -91,7 +96,7 @@ namespace osu.Game.Overlays.Comments { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, - Action = () => OnCommit?.Invoke(textbox.Text) + Action = () => OnCommit?.Invoke(current.Value) } } } @@ -100,14 +105,28 @@ namespace osu.Game.Overlays.Comments } }); - textbox.OnCommit += (u, v) => commitButton.Click(); + textbox.OnCommit += (u, v) => + { + if (!commitButton.IsReady.Value) + return; + + commitButton.Click(); + current.Value = string.Empty; + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + current.BindValueChanged(text => commitButton.IsReady.Value = !string.IsNullOrEmpty(text.NewValue), true); } private class EditorTextbox : BasicTextBox { protected override float LeftRightPadding => side_padding; - protected override Color4 SelectionColour => Color4.LightSkyBlue; + protected override Color4 SelectionColour => Color4.Gray; private OsuSpriteText placeholder; @@ -122,7 +141,7 @@ namespace osu.Game.Overlays.Comments { BackgroundUnfocused = BackgroundFocused = colourProvider.Background5; placeholder.Colour = colourProvider.Background3; - BackgroundCommit = Color4.LightSkyBlue; + BackgroundCommit = colourProvider.Background3; } protected override SpriteText CreatePlaceholder() => placeholder = new OsuSpriteText @@ -137,8 +156,15 @@ namespace osu.Game.Overlays.Comments { private const int duration = 200; + public readonly BindableBool IsReady = new BindableBool(); + + public override bool PropagatePositionalInputSubTree => IsReady.Value && base.PropagatePositionalInputSubTree; + protected override IEnumerable EffectTargets => new[] { background }; + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + private OsuSpriteText drawableText; private Box background; @@ -151,12 +177,28 @@ namespace osu.Game.Overlays.Comments } [BackgroundDependencyLoader] - private void load(OverlayColourProvider colourProvider) + private void load() { IdleColour = colourProvider.GetColour(0.5f, 0.45f); HoverColour = colourProvider.GetColour(0.5f, 0.6f); } + protected override void LoadComplete() + { + base.LoadComplete(); + IsReady.BindValueChanged(onReadyStateChanged, true); + } + + private void onReadyStateChanged(ValueChangedEvent isReady) + { + drawableText.FadeColour(isReady.NewValue ? Color4.White : colourProvider.Foreground1, duration, Easing.OutQuint); + + if (isReady.NewValue) + background.FadeColour(IsHovered ? HoverColour : IdleColour, duration, Easing.OutQuint); + else + background.FadeColour(colourProvider.Background5, duration, Easing.OutQuint); + } + protected override Drawable CreateContent() => new CircularContainer { Masking = true, From 9ac6c271ac3331e390b8d00d168fee539e97c556 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 12 Feb 2020 02:05:45 +0300 Subject: [PATCH 07/15] Naming adjustments --- .../UserInterface/TestSceneCommentEditor.cs | 36 +++++++++++++++++-- osu.Game/Overlays/Comments/CommentEditor.cs | 26 ++++++++------ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index 86179886e5..e32bf05197 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osu.Game.Overlays.Comments; using osuTK; @@ -23,8 +25,21 @@ namespace osu.Game.Tests.Visual.UserInterface [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + private readonly OsuSpriteText text; + private readonly TestCommentEditor commentEditor; + private readonly TestCancellableCommentEditor cancellableCommentEditor; + public TestSceneCommentEditor() { + Add(new Container + { + AutoSizeAxes = Axes.Both, + Child = text = new OsuSpriteText + { + Font = OsuFont.GetFont() + } + }); + Add(new FillFlowContainer { Anchor = Anchor.Centre, @@ -35,12 +50,29 @@ namespace osu.Game.Tests.Visual.UserInterface Spacing = new Vector2(0, 20), Children = new Drawable[] { - new TestCommentEditor(), - new TestCancellableCommentEditor() + commentEditor = new TestCommentEditor + { + OnCommit = onCommit + }, + cancellableCommentEditor = new TestCancellableCommentEditor + { + OnCommit = onCommit + } } }); } + private void onCommit(string value) + { + text.Text = $@"Invoked text: {value}"; + + Scheduler.AddDelayed(() => + { + commentEditor.IsLoading = false; + cancellableCommentEditor.IsLoading = false; + }, 500); + } + private class TestCommentEditor : CommentEditor { protected override string FooterText => @"Footer text. And it is pretty long. Cool."; diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 7adb33663c..34aa036938 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -24,6 +24,12 @@ namespace osu.Game.Overlays.Comments public Action OnCommit; + public bool IsLoading + { + get => commitButton.IsLoading; + set => commitButton.IsLoading = value; + } + protected abstract string FooterText { get; } protected abstract string CommitButtonText { get; } @@ -107,7 +113,7 @@ namespace osu.Game.Overlays.Comments textbox.OnCommit += (u, v) => { - if (!commitButton.IsReady.Value) + if (commitButton.IsBlocked.Value) return; commitButton.Click(); @@ -119,7 +125,7 @@ namespace osu.Game.Overlays.Comments { base.LoadComplete(); - current.BindValueChanged(text => commitButton.IsReady.Value = !string.IsNullOrEmpty(text.NewValue), true); + current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true); } private class EditorTextbox : BasicTextBox @@ -156,9 +162,9 @@ namespace osu.Game.Overlays.Comments { private const int duration = 200; - public readonly BindableBool IsReady = new BindableBool(); + public readonly BindableBool IsBlocked = new BindableBool(); - public override bool PropagatePositionalInputSubTree => IsReady.Value && base.PropagatePositionalInputSubTree; + public override bool PropagatePositionalInputSubTree => !IsBlocked.Value && base.PropagatePositionalInputSubTree; protected override IEnumerable EffectTargets => new[] { background }; @@ -186,17 +192,17 @@ namespace osu.Game.Overlays.Comments protected override void LoadComplete() { base.LoadComplete(); - IsReady.BindValueChanged(onReadyStateChanged, true); + IsBlocked.BindValueChanged(onBlockedStateChanged, true); } - private void onReadyStateChanged(ValueChangedEvent isReady) + private void onBlockedStateChanged(ValueChangedEvent isBlocked) { - drawableText.FadeColour(isReady.NewValue ? Color4.White : colourProvider.Foreground1, duration, Easing.OutQuint); + drawableText.FadeColour(isBlocked.NewValue ? colourProvider.Foreground1 : Color4.White, duration, Easing.OutQuint); - if (isReady.NewValue) - background.FadeColour(IsHovered ? HoverColour : IdleColour, duration, Easing.OutQuint); - else + if (isBlocked.NewValue) background.FadeColour(colourProvider.Background5, duration, Easing.OutQuint); + else + background.FadeColour(IsHovered ? HoverColour : IdleColour, duration, Easing.OutQuint); } protected override Drawable CreateContent() => new CircularContainer From ab7adb3a9798dd0c68cfd4dab5939c36918faf5a Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 12 Feb 2020 13:28:49 +0300 Subject: [PATCH 08/15] Adjust button colours --- .../Comments/CancellableCommentEditor.cs | 4 +- osu.Game/Overlays/Comments/CommentEditor.cs | 4 +- osu.Game/Overlays/OverlayColourProvider.cs | 42 +++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs index f58627efb3..c226b7f07f 100644 --- a/osu.Game/Overlays/Comments/CancellableCommentEditor.cs +++ b/osu.Game/Overlays/Comments/CancellableCommentEditor.cs @@ -63,8 +63,8 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { - IdleColour = colourProvider.GetColour(0.5f, 0.45f); - HoverColour = colourProvider.GetColour(0.5f, 0.6f); + IdleColour = colourProvider.Light4; + HoverColour = colourProvider.Light3; } } } diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 34aa036938..ac355e9c98 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -185,8 +185,8 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load() { - IdleColour = colourProvider.GetColour(0.5f, 0.45f); - HoverColour = colourProvider.GetColour(0.5f, 0.6f); + IdleColour = colourProvider.Light4; + HoverColour = colourProvider.Light3; } protected override void LoadComplete() diff --git a/osu.Game/Overlays/OverlayColourProvider.cs b/osu.Game/Overlays/OverlayColourProvider.cs index c0984073e6..9816f313ad 100644 --- a/osu.Game/Overlays/OverlayColourProvider.cs +++ b/osu.Game/Overlays/OverlayColourProvider.cs @@ -16,28 +16,28 @@ namespace osu.Game.Overlays this.colourScheme = colourScheme; } - public Color4 Highlight1 => GetColour(1, 0.7f); - public Color4 Content1 => GetColour(0.4f, 1); - public Color4 Content2 => GetColour(0.4f, 0.9f); - public Color4 Light1 => GetColour(0.4f, 0.8f); - public Color4 Light2 => GetColour(0.4f, 0.75f); - public Color4 Light3 => GetColour(0.4f, 0.7f); - public Color4 Light4 => GetColour(0.4f, 0.5f); - public Color4 Dark1 => GetColour(0.2f, 0.35f); - public Color4 Dark2 => GetColour(0.2f, 0.3f); - public Color4 Dark3 => GetColour(0.2f, 0.25f); - public Color4 Dark4 => GetColour(0.2f, 0.2f); - public Color4 Dark5 => GetColour(0.2f, 0.15f); - public Color4 Dark6 => GetColour(0.2f, 0.1f); - public Color4 Foreground1 => GetColour(0.1f, 0.6f); - public Color4 Background1 => GetColour(0.1f, 0.4f); - public Color4 Background2 => GetColour(0.1f, 0.3f); - public Color4 Background3 => GetColour(0.1f, 0.25f); - public Color4 Background4 => GetColour(0.1f, 0.2f); - public Color4 Background5 => GetColour(0.1f, 0.15f); - public Color4 Background6 => GetColour(0.1f, 0.1f); + public Color4 Highlight1 => getColour(1, 0.7f); + public Color4 Content1 => getColour(0.4f, 1); + public Color4 Content2 => getColour(0.4f, 0.9f); + public Color4 Light1 => getColour(0.4f, 0.8f); + public Color4 Light2 => getColour(0.4f, 0.75f); + public Color4 Light3 => getColour(0.4f, 0.7f); + public Color4 Light4 => getColour(0.4f, 0.5f); + public Color4 Dark1 => getColour(0.2f, 0.35f); + public Color4 Dark2 => getColour(0.2f, 0.3f); + public Color4 Dark3 => getColour(0.2f, 0.25f); + public Color4 Dark4 => getColour(0.2f, 0.2f); + public Color4 Dark5 => getColour(0.2f, 0.15f); + public Color4 Dark6 => getColour(0.2f, 0.1f); + public Color4 Foreground1 => getColour(0.1f, 0.6f); + public Color4 Background1 => getColour(0.1f, 0.4f); + public Color4 Background2 => getColour(0.1f, 0.3f); + public Color4 Background3 => getColour(0.1f, 0.25f); + public Color4 Background4 => getColour(0.1f, 0.2f); + public Color4 Background5 => getColour(0.1f, 0.15f); + public Color4 Background6 => getColour(0.1f, 0.1f); - public Color4 GetColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1)); + private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1)); // See https://github.com/ppy/osu-web/blob/4218c288292d7c810b619075471eaea8bbb8f9d8/app/helpers.php#L1463 private static float getBaseHue(OverlayColourScheme colourScheme) From 62051c036b1f90bd16f7972ca6b4d9dd13e8d6ce Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 12 Feb 2020 13:43:56 +0300 Subject: [PATCH 09/15] Small CommitButton improvements --- osu.Game/Overlays/Comments/CommentEditor.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index ac355e9c98..edd09cc95f 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -102,7 +102,11 @@ namespace osu.Game.Overlays.Comments { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, - Action = () => OnCommit?.Invoke(current.Value) + Action = () => + { + OnCommit?.Invoke(current.Value); + current.Value = string.Empty; + } } } } @@ -117,7 +121,6 @@ namespace osu.Game.Overlays.Comments return; commitButton.Click(); - current.Value = string.Empty; }; } @@ -173,6 +176,7 @@ namespace osu.Game.Overlays.Comments private OsuSpriteText drawableText; private Box background; + private Box blockedBackground; public CommitButton(string text) { @@ -187,6 +191,7 @@ namespace osu.Game.Overlays.Comments { IdleColour = colourProvider.Light4; HoverColour = colourProvider.Light3; + blockedBackground.Colour = colourProvider.Background5; } protected override void LoadComplete() @@ -198,11 +203,7 @@ namespace osu.Game.Overlays.Comments private void onBlockedStateChanged(ValueChangedEvent isBlocked) { drawableText.FadeColour(isBlocked.NewValue ? colourProvider.Foreground1 : Color4.White, duration, Easing.OutQuint); - - if (isBlocked.NewValue) - background.FadeColour(colourProvider.Background5, duration, Easing.OutQuint); - else - background.FadeColour(IsHovered ? HoverColour : IdleColour, duration, Easing.OutQuint); + background.FadeTo(isBlocked.NewValue ? 0 : 1, duration, Easing.OutQuint); } protected override Drawable CreateContent() => new CircularContainer @@ -212,6 +213,10 @@ namespace osu.Game.Overlays.Comments AutoSizeAxes = Axes.X, Children = new Drawable[] { + blockedBackground = new Box + { + RelativeSizeAxes = Axes.Both + }, background = new Box { RelativeSizeAxes = Axes.Both From c391a464a5ecffb8fda5ba27cabcc9aa733503fd Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 13 Feb 2020 04:06:34 +0300 Subject: [PATCH 10/15] Add tests --- .../UserInterface/TestSceneCommentEditor.cs | 106 +++++++++++++++--- osu.Game/Overlays/Comments/CommentEditor.cs | 13 ++- 2 files changed, 96 insertions(+), 23 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index e32bf05197..a7888bb0b4 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -3,18 +3,19 @@ using System; using System.Collections.Generic; +using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osu.Game.Overlays.Comments; using osuTK; +using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneCommentEditor : OsuTestScene + public class TestSceneCommentEditor : ManualInputManagerTestScene { public override IReadOnlyList RequiredTypes => new[] { @@ -25,20 +26,76 @@ namespace osu.Game.Tests.Visual.UserInterface [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); - private readonly OsuSpriteText text; - private readonly TestCommentEditor commentEditor; - private readonly TestCancellableCommentEditor cancellableCommentEditor; + private TestCommentEditor commentEditor; + private TestCancellableCommentEditor cancellableCommentEditor; + private string commitText; + private bool cancelActionFired; - public TestSceneCommentEditor() + [Test] + public void TestCommitViaKeyboard() { - Add(new Container + AddStep("Create", createEditors); + AddStep("Click on textbox", () => { - AutoSizeAxes = Axes.Both, - Child = text = new OsuSpriteText - { - Font = OsuFont.GetFont() - } + InputManager.MoveMouseTo(commentEditor); + InputManager.Click(MouseButton.Left); }); + AddStep("Write something", () => commentEditor.Current.Value = "text"); + AddStep("Click Enter", () => press(Key.Enter)); + AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); + AddAssert("Button is loading", () => commentEditor.IsLoading); + } + + [Test] + public void TestCommitViaKeyboardWhenEmpty() + { + AddStep("Create", createEditors); + AddStep("Click on textbox", () => + { + InputManager.MoveMouseTo(commentEditor); + InputManager.Click(MouseButton.Left); + }); + AddStep("Click Enter", () => press(Key.Enter)); + AddAssert("Text not invoked", () => string.IsNullOrEmpty(commitText)); + AddAssert("Button is not loading", () => !commentEditor.IsLoading); + } + + [Test] + public void TestCommitViaButton() + { + AddStep("Create", createEditors); + AddStep("Click on textbox", () => + { + InputManager.MoveMouseTo(commentEditor); + InputManager.Click(MouseButton.Left); + }); + AddStep("Write something", () => commentEditor.Current.Value = "text"); + AddStep("Click on button", () => + { + InputManager.MoveMouseTo(commentEditor.ButtonsContainer); + InputManager.Click(MouseButton.Left); + }); + AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); + AddAssert("Button is loading", () => commentEditor.IsLoading); + } + + [Test] + public void TestCancelAction() + { + AddStep("Create", createEditors); + AddStep("Click on cancel button", () => + { + InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer); + InputManager.Click(MouseButton.Left); + }); + AddAssert("Cancel action is fired", () => cancelActionFired); + } + + private void createEditors() + { + Clear(); + commitText = string.Empty; + cancelActionFired = false; Add(new FillFlowContainer { @@ -52,11 +109,12 @@ namespace osu.Game.Tests.Visual.UserInterface { commentEditor = new TestCommentEditor { - OnCommit = onCommit + OnCommit = onCommit, }, cancellableCommentEditor = new TestCancellableCommentEditor { - OnCommit = onCommit + OnCommit = onCommit, + OnCancel = onCancel } } }); @@ -64,17 +122,29 @@ namespace osu.Game.Tests.Visual.UserInterface private void onCommit(string value) { - text.Text = $@"Invoked text: {value}"; + commitText = value; Scheduler.AddDelayed(() => { commentEditor.IsLoading = false; cancellableCommentEditor.IsLoading = false; - }, 500); + }, 1000); + } + + private void onCancel() => cancelActionFired = true; + + private void press(Key key) + { + InputManager.PressKey(key); + InputManager.ReleaseKey(key); } private class TestCommentEditor : CommentEditor { + public new Bindable Current => base.Current; + + public new FillFlowContainer ButtonsContainer => base.ButtonsContainer; + protected override string FooterText => @"Footer text. And it is pretty long. Cool."; protected override string CommitButtonText => @"Commit"; @@ -84,6 +154,8 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestCancellableCommentEditor : CancellableCommentEditor { + public new FillFlowContainer ButtonsContainer => base.ButtonsContainer; + protected override string FooterText => @"Wow, another one. Sicc"; protected override string CommitButtonText => @"Save"; diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index edd09cc95f..765e5e228c 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -38,7 +38,7 @@ namespace osu.Game.Overlays.Comments protected FillFlowContainer ButtonsContainer; - private readonly Bindable current = new Bindable(); + protected readonly Bindable Current = new Bindable(); private CommitButton commitButton; @@ -73,7 +73,7 @@ namespace osu.Game.Overlays.Comments Height = 40, RelativeSizeAxes = Axes.X, PlaceholderText = TextboxPlaceholderText, - Current = current + Current = Current }, new Container { @@ -104,8 +104,8 @@ namespace osu.Game.Overlays.Comments Origin = Anchor.CentreRight, Action = () => { - OnCommit?.Invoke(current.Value); - current.Value = string.Empty; + OnCommit?.Invoke(Current.Value); + Current.Value = string.Empty; } } } @@ -128,7 +128,7 @@ namespace osu.Game.Overlays.Comments { base.LoadComplete(); - current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true); + Current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true); } private class EditorTextbox : BasicTextBox @@ -219,7 +219,8 @@ namespace osu.Game.Overlays.Comments }, background = new Box { - RelativeSizeAxes = Axes.Both + RelativeSizeAxes = Axes.Both, + Alpha = 0 }, drawableText = new OsuSpriteText { From cc625e3b897dd2669fe6300de9a6924082e97652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Feb 2020 20:44:02 +0100 Subject: [PATCH 11/15] Move initialisation logic to [SetUp] --- .../UserInterface/TestSceneCommentEditor.cs | 122 +++++++++--------- 1 file changed, 59 insertions(+), 63 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index a7888bb0b4..aaf26f78a7 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -31,73 +31,13 @@ namespace osu.Game.Tests.Visual.UserInterface private string commitText; private bool cancelActionFired; - [Test] - public void TestCommitViaKeyboard() + [SetUp] + public void SetUp() { - AddStep("Create", createEditors); - AddStep("Click on textbox", () => - { - InputManager.MoveMouseTo(commentEditor); - InputManager.Click(MouseButton.Left); - }); - AddStep("Write something", () => commentEditor.Current.Value = "text"); - AddStep("Click Enter", () => press(Key.Enter)); - AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); - AddAssert("Button is loading", () => commentEditor.IsLoading); - } - - [Test] - public void TestCommitViaKeyboardWhenEmpty() - { - AddStep("Create", createEditors); - AddStep("Click on textbox", () => - { - InputManager.MoveMouseTo(commentEditor); - InputManager.Click(MouseButton.Left); - }); - AddStep("Click Enter", () => press(Key.Enter)); - AddAssert("Text not invoked", () => string.IsNullOrEmpty(commitText)); - AddAssert("Button is not loading", () => !commentEditor.IsLoading); - } - - [Test] - public void TestCommitViaButton() - { - AddStep("Create", createEditors); - AddStep("Click on textbox", () => - { - InputManager.MoveMouseTo(commentEditor); - InputManager.Click(MouseButton.Left); - }); - AddStep("Write something", () => commentEditor.Current.Value = "text"); - AddStep("Click on button", () => - { - InputManager.MoveMouseTo(commentEditor.ButtonsContainer); - InputManager.Click(MouseButton.Left); - }); - AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); - AddAssert("Button is loading", () => commentEditor.IsLoading); - } - - [Test] - public void TestCancelAction() - { - AddStep("Create", createEditors); - AddStep("Click on cancel button", () => - { - InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer); - InputManager.Click(MouseButton.Left); - }); - AddAssert("Cancel action is fired", () => cancelActionFired); - } - - private void createEditors() - { - Clear(); commitText = string.Empty; cancelActionFired = false; - Add(new FillFlowContainer + Schedule(() => Add(new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -117,7 +57,63 @@ namespace osu.Game.Tests.Visual.UserInterface OnCancel = onCancel } } + })); + } + + [Test] + public void TestCommitViaKeyboard() + { + AddStep("Click on textbox", () => + { + InputManager.MoveMouseTo(commentEditor); + InputManager.Click(MouseButton.Left); }); + AddStep("Write something", () => commentEditor.Current.Value = "text"); + AddStep("Click Enter", () => press(Key.Enter)); + AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); + AddAssert("Button is loading", () => commentEditor.IsLoading); + } + + [Test] + public void TestCommitViaKeyboardWhenEmpty() + { + AddStep("Click on textbox", () => + { + InputManager.MoveMouseTo(commentEditor); + InputManager.Click(MouseButton.Left); + }); + AddStep("Click Enter", () => press(Key.Enter)); + AddAssert("Text not invoked", () => string.IsNullOrEmpty(commitText)); + AddAssert("Button is not loading", () => !commentEditor.IsLoading); + } + + [Test] + public void TestCommitViaButton() + { + AddStep("Click on textbox", () => + { + InputManager.MoveMouseTo(commentEditor); + InputManager.Click(MouseButton.Left); + }); + AddStep("Write something", () => commentEditor.Current.Value = "text"); + AddStep("Click on button", () => + { + InputManager.MoveMouseTo(commentEditor.ButtonsContainer); + InputManager.Click(MouseButton.Left); + }); + AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); + AddAssert("Button is loading", () => commentEditor.IsLoading); + } + + [Test] + public void TestCancelAction() + { + AddStep("Click on cancel button", () => + { + InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer); + InputManager.Click(MouseButton.Left); + }); + AddAssert("Cancel action is fired", () => cancelActionFired); } private void onCommit(string value) From 09b2e7beed1d317bfa0bce11f02b3dd7f86f35bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Feb 2020 20:56:34 +0100 Subject: [PATCH 12/15] Encapsulate test editors --- .../UserInterface/TestSceneCommentEditor.cs | 68 ++++++++----------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index aaf26f78a7..8005e9a2bc 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -28,16 +28,10 @@ namespace osu.Game.Tests.Visual.UserInterface private TestCommentEditor commentEditor; private TestCancellableCommentEditor cancellableCommentEditor; - private string commitText; - private bool cancelActionFired; [SetUp] - public void SetUp() - { - commitText = string.Empty; - cancelActionFired = false; - - Schedule(() => Add(new FillFlowContainer + public void SetUp() => Schedule(() => + Add(new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -47,18 +41,10 @@ namespace osu.Game.Tests.Visual.UserInterface Spacing = new Vector2(0, 20), Children = new Drawable[] { - commentEditor = new TestCommentEditor - { - OnCommit = onCommit, - }, - cancellableCommentEditor = new TestCancellableCommentEditor - { - OnCommit = onCommit, - OnCancel = onCancel - } + commentEditor = new TestCommentEditor(), + cancellableCommentEditor = new TestCancellableCommentEditor() } })); - } [Test] public void TestCommitViaKeyboard() @@ -70,7 +56,7 @@ namespace osu.Game.Tests.Visual.UserInterface }); AddStep("Write something", () => commentEditor.Current.Value = "text"); AddStep("Click Enter", () => press(Key.Enter)); - AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); + AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText)); AddAssert("Button is loading", () => commentEditor.IsLoading); } @@ -83,7 +69,7 @@ namespace osu.Game.Tests.Visual.UserInterface InputManager.Click(MouseButton.Left); }); AddStep("Click Enter", () => press(Key.Enter)); - AddAssert("Text not invoked", () => string.IsNullOrEmpty(commitText)); + AddAssert("Text not invoked", () => string.IsNullOrEmpty(commentEditor.CommittedText)); AddAssert("Button is not loading", () => !commentEditor.IsLoading); } @@ -101,7 +87,7 @@ namespace osu.Game.Tests.Visual.UserInterface InputManager.MoveMouseTo(commentEditor.ButtonsContainer); InputManager.Click(MouseButton.Left); }); - AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commitText)); + AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText)); AddAssert("Button is loading", () => commentEditor.IsLoading); } @@ -113,22 +99,9 @@ namespace osu.Game.Tests.Visual.UserInterface InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer); InputManager.Click(MouseButton.Left); }); - AddAssert("Cancel action is fired", () => cancelActionFired); + AddAssert("Cancel action is fired", () => cancellableCommentEditor.Cancelled); } - private void onCommit(string value) - { - commitText = value; - - Scheduler.AddDelayed(() => - { - commentEditor.IsLoading = false; - cancellableCommentEditor.IsLoading = false; - }, 1000); - } - - private void onCancel() => cancelActionFired = true; - private void press(Key key) { InputManager.PressKey(key); @@ -138,24 +111,39 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestCommentEditor : CommentEditor { public new Bindable Current => base.Current; - public new FillFlowContainer ButtonsContainer => base.ButtonsContainer; + public string CommittedText { get; private set; } + + public TestCommentEditor() + { + OnCommit = onCommit; + } + + private void onCommit(string value) + { + CommittedText = value; + Scheduler.AddDelayed(() => IsLoading = false, 1000); + } + protected override string FooterText => @"Footer text. And it is pretty long. Cool."; - protected override string CommitButtonText => @"Commit"; - protected override string TextboxPlaceholderText => @"This textbox is empty"; } private class TestCancellableCommentEditor : CancellableCommentEditor { public new FillFlowContainer ButtonsContainer => base.ButtonsContainer; - protected override string FooterText => @"Wow, another one. Sicc"; - protected override string CommitButtonText => @"Save"; + public bool Cancelled { get; private set; } + public TestCancellableCommentEditor() + { + OnCancel = () => Cancelled = true; + } + + protected override string CommitButtonText => @"Save"; protected override string TextboxPlaceholderText => @"Miltiline textboxes soon"; } } From 5646083ed9ae4214e9f436b6ff1a7f0d8e107576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Feb 2020 21:01:25 +0100 Subject: [PATCH 13/15] Adjust code style in test --- .../UserInterface/TestSceneCommentEditor.cs | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index 8005e9a2bc..a5ef8b046d 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -49,57 +49,64 @@ namespace osu.Game.Tests.Visual.UserInterface [Test] public void TestCommitViaKeyboard() { - AddStep("Click on textbox", () => + AddStep("click on text box", () => { InputManager.MoveMouseTo(commentEditor); InputManager.Click(MouseButton.Left); }); - AddStep("Write something", () => commentEditor.Current.Value = "text"); - AddStep("Click Enter", () => press(Key.Enter)); - AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText)); - AddAssert("Button is loading", () => commentEditor.IsLoading); + AddStep("enter text", () => commentEditor.Current.Value = "text"); + + AddStep("press Enter", () => press(Key.Enter)); + + AddAssert("text committed", () => commentEditor.CommittedText == "text"); + AddAssert("button is loading", () => commentEditor.IsLoading); } [Test] public void TestCommitViaKeyboardWhenEmpty() { - AddStep("Click on textbox", () => + AddStep("click on text box", () => { InputManager.MoveMouseTo(commentEditor); InputManager.Click(MouseButton.Left); }); - AddStep("Click Enter", () => press(Key.Enter)); - AddAssert("Text not invoked", () => string.IsNullOrEmpty(commentEditor.CommittedText)); - AddAssert("Button is not loading", () => !commentEditor.IsLoading); + + AddStep("press Enter", () => press(Key.Enter)); + + AddAssert("no text committed", () => commentEditor.CommittedText == null); + AddAssert("button is not loading", () => !commentEditor.IsLoading); } [Test] public void TestCommitViaButton() { - AddStep("Click on textbox", () => + AddStep("click on text box", () => { InputManager.MoveMouseTo(commentEditor); InputManager.Click(MouseButton.Left); }); - AddStep("Write something", () => commentEditor.Current.Value = "text"); - AddStep("Click on button", () => + AddStep("enter text", () => commentEditor.Current.Value = "some other text"); + + AddStep("click submit", () => { InputManager.MoveMouseTo(commentEditor.ButtonsContainer); InputManager.Click(MouseButton.Left); }); - AddAssert("Text has been invoked", () => !string.IsNullOrEmpty(commentEditor.CommittedText)); - AddAssert("Button is loading", () => commentEditor.IsLoading); + + AddAssert("text committed", () => commentEditor.CommittedText == "some other text"); + AddAssert("button is loading", () => commentEditor.IsLoading); } [Test] public void TestCancelAction() { - AddStep("Click on cancel button", () => + AddStep("click cancel button", () => { InputManager.MoveMouseTo(cancellableCommentEditor.ButtonsContainer); InputManager.Click(MouseButton.Left); }); - AddAssert("Cancel action is fired", () => cancellableCommentEditor.Cancelled); + + AddAssert("cancel action fired", () => cancellableCommentEditor.Cancelled); } private void press(Key key) @@ -128,7 +135,7 @@ namespace osu.Game.Tests.Visual.UserInterface protected override string FooterText => @"Footer text. And it is pretty long. Cool."; protected override string CommitButtonText => @"Commit"; - protected override string TextboxPlaceholderText => @"This textbox is empty"; + protected override string TextboxPlaceholderText => @"This text box is empty"; } private class TestCancellableCommentEditor : CancellableCommentEditor @@ -144,7 +151,7 @@ namespace osu.Game.Tests.Visual.UserInterface } protected override string CommitButtonText => @"Save"; - protected override string TextboxPlaceholderText => @"Miltiline textboxes soon"; + protected override string TextboxPlaceholderText => @"Multiline textboxes soon"; } } } From 0f25864faed05910713df23ecdf5d6310f295a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Feb 2020 21:04:53 +0100 Subject: [PATCH 14/15] Textbox -> TextBox rename pass --- .../Visual/UserInterface/TestSceneCommentEditor.cs | 4 ++-- osu.Game/Overlays/Comments/CommentEditor.cs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs index a5ef8b046d..7b0b644dab 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneCommentEditor.cs @@ -135,7 +135,7 @@ namespace osu.Game.Tests.Visual.UserInterface protected override string FooterText => @"Footer text. And it is pretty long. Cool."; protected override string CommitButtonText => @"Commit"; - protected override string TextboxPlaceholderText => @"This text box is empty"; + protected override string TextBoxPlaceholder => @"This text box is empty"; } private class TestCancellableCommentEditor : CancellableCommentEditor @@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.UserInterface } protected override string CommitButtonText => @"Save"; - protected override string TextboxPlaceholderText => @"Multiline textboxes soon"; + protected override string TextBoxPlaceholder => @"Multiline textboxes soon"; } } } diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 765e5e228c..f7e53addbe 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -34,7 +34,7 @@ namespace osu.Game.Overlays.Comments protected abstract string CommitButtonText { get; } - protected abstract string TextboxPlaceholderText { get; } + protected abstract string TextBoxPlaceholder { get; } protected FillFlowContainer ButtonsContainer; @@ -45,7 +45,7 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { - EditorTextbox textbox; + EditorTextBox textBox; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -68,11 +68,11 @@ namespace osu.Game.Overlays.Comments Direction = FillDirection.Vertical, Children = new Drawable[] { - textbox = new EditorTextbox + textBox = new EditorTextBox { Height = 40, RelativeSizeAxes = Axes.X, - PlaceholderText = TextboxPlaceholderText, + PlaceholderText = TextBoxPlaceholder, Current = Current }, new Container @@ -115,7 +115,7 @@ namespace osu.Game.Overlays.Comments } }); - textbox.OnCommit += (u, v) => + textBox.OnCommit += (u, v) => { if (commitButton.IsBlocked.Value) return; @@ -131,7 +131,7 @@ namespace osu.Game.Overlays.Comments Current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true); } - private class EditorTextbox : BasicTextBox + private class EditorTextBox : BasicTextBox { protected override float LeftRightPadding => side_padding; @@ -139,7 +139,7 @@ namespace osu.Game.Overlays.Comments private OsuSpriteText placeholder; - public EditorTextbox() + public EditorTextBox() { Masking = false; TextContainer.Height = 0.4f; From 5acaf9b371d9b64d73040673670f7bb3f6ecb71d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 21 Feb 2020 12:33:49 +0900 Subject: [PATCH 15/15] Privatise setter --- osu.Game/Overlays/Comments/CommentEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index f7e53addbe..2fa4cb68f3 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -36,7 +36,7 @@ namespace osu.Game.Overlays.Comments protected abstract string TextBoxPlaceholder { get; } - protected FillFlowContainer ButtonsContainer; + protected FillFlowContainer ButtonsContainer { get; private set; } protected readonly Bindable Current = new Bindable();