From 16a4805f1fe95aaa9348c9321402cd0cc612a6ce Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 21 Jun 2019 15:04:10 +0200 Subject: [PATCH 1/8] add OsuNumberBox with basic tests --- .../UserInterface/TestSceneNumberBox.cs | 55 +++++++++++++++++++ .../Graphics/UserInterface/OsuNumberBox.cs | 10 ++++ 2 files changed, 65 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneNumberBox.cs create mode 100644 osu.Game/Graphics/UserInterface/OsuNumberBox.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneNumberBox.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneNumberBox.cs new file mode 100644 index 0000000000..f73450db60 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneNumberBox.cs @@ -0,0 +1,55 @@ +// 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 NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tests.Visual.UserInterface +{ + [TestFixture] + public class TestSceneNumberBox : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OsuNumberBox), + }; + + private OsuNumberBox numberBox; + + [BackgroundDependencyLoader] + private void load() + { + Child = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Padding = new MarginPadding { Horizontal = 250 }, + Child = numberBox = new OsuNumberBox + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + PlaceholderText = "Insert numbers here" + } + }; + + clearInput(); + AddStep("enter numbers", () => numberBox.Text = "987654321"); + expectedValue("987654321"); + clearInput(); + AddStep("enter text + single number", () => numberBox.Text = "1 hello 2 world 3"); + expectedValue("123"); + clearInput(); + } + + private void clearInput() => AddStep("clear input", () => numberBox.Text = null); + + private void expectedValue(string value) => AddAssert("expect number", () => numberBox.Text == value); + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuNumberBox.cs b/osu.Game/Graphics/UserInterface/OsuNumberBox.cs new file mode 100644 index 0000000000..36288c745a --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuNumberBox.cs @@ -0,0 +1,10 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuNumberBox : OsuTextBox + { + protected override bool CanAddCharacter(char character) => char.IsNumber(character); + } +} From 1bc1e2459ed865edf05dc0c69a1d1e3bd4639596 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 21 Jun 2019 15:04:34 +0200 Subject: [PATCH 2/8] add SettingsNumberBox and use it in tournament tools --- .../Screens/Editors/RoundEditorScreen.cs | 2 +- .../Screens/Editors/TeamEditorScreen.cs | 2 +- osu.Game/Overlays/Settings/SettingsNumberBox.cs | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 osu.Game/Overlays/Settings/SettingsNumberBox.cs diff --git a/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs index 1dc91abe6d..b036350879 100644 --- a/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs @@ -183,7 +183,7 @@ namespace osu.Game.Tournament.Screens.Editors AutoSizeAxes = Axes.Both, Children = new Drawable[] { - new SettingsTextBox + new SettingsNumberBox { LabelText = "Beatmap ID", RelativeSizeAxes = Axes.None, diff --git a/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs index 93745acabf..a4479f3cfd 100644 --- a/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs @@ -231,7 +231,7 @@ namespace osu.Game.Tournament.Screens.Editors AutoSizeAxes = Axes.Both, Children = new Drawable[] { - new SettingsTextBox + new SettingsNumberBox { LabelText = "User ID", RelativeSizeAxes = Axes.None, diff --git a/osu.Game/Overlays/Settings/SettingsNumberBox.cs b/osu.Game/Overlays/Settings/SettingsNumberBox.cs new file mode 100644 index 0000000000..cb7e63ae6f --- /dev/null +++ b/osu.Game/Overlays/Settings/SettingsNumberBox.cs @@ -0,0 +1,17 @@ +// 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.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Overlays.Settings +{ + public class SettingsNumberBox : SettingsItem + { + protected override Drawable CreateControl() => new OsuNumberBox + { + Margin = new MarginPadding { Top = 5 }, + RelativeSizeAxes = Axes.X, + }; + } +} From ba97b887b44ab21b87bcbb565dfeba7512510520 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 23 Jun 2019 19:49:23 +0900 Subject: [PATCH 3/8] Allow cusotmisation of the colour portion of the tournament logo header --- .../Screens/Gameplay/Components/MatchHeader.cs | 8 -------- osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs | 6 +----- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/osu.Game.Tournament/Screens/Gameplay/Components/MatchHeader.cs b/osu.Game.Tournament/Screens/Gameplay/Components/MatchHeader.cs index cfa44537d6..9e1888b44b 100644 --- a/osu.Game.Tournament/Screens/Gameplay/Components/MatchHeader.cs +++ b/osu.Game.Tournament/Screens/Gameplay/Components/MatchHeader.cs @@ -5,7 +5,6 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; @@ -191,8 +190,6 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components public RoundDisplay() { - CornerRadius = 10; - Masking = true; Width = 200; Height = 20; } @@ -208,11 +205,6 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components { InternalChildren = new Drawable[] { - new Box - { - Colour = new Color4(47, 71, 67, 255), - RelativeSizeAxes = Axes.Both, - }, new OsuSpriteText { Anchor = Anchor.Centre, diff --git a/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs b/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs index 0db3348e5d..6ca542626e 100644 --- a/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs +++ b/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs @@ -6,7 +6,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; -using osuTK; namespace osu.Game.Tournament.Screens.Showcase { @@ -15,7 +14,7 @@ namespace osu.Game.Tournament.Screens.Showcase public TournamentLogo() { RelativeSizeAxes = Axes.X; - Height = 95; + AutoSizeAxes = Axes.Y; Margin = new MarginPadding { Vertical = 5 }; } @@ -27,9 +26,6 @@ namespace osu.Game.Tournament.Screens.Showcase Texture = textures.Get("game-screen-logo"), Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - FillMode = FillMode.Fit, - RelativeSizeAxes = Axes.Both, - Size = Vector2.One }; } } From d595860b1471e32f1b41f799aab5f90459502cf9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 23 Jun 2019 20:09:42 +0900 Subject: [PATCH 4/8] Remove background from team intro screen --- .../Screens/Showcase/TournamentLogo.cs | 13 +++++++++++-- .../Screens/TeamIntro/TeamIntroScreen.cs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs b/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs index 6ca542626e..1fee2b29e8 100644 --- a/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs +++ b/osu.Game.Tournament/Screens/Showcase/TournamentLogo.cs @@ -11,11 +11,20 @@ namespace osu.Game.Tournament.Screens.Showcase { public class TournamentLogo : CompositeDrawable { - public TournamentLogo() + public TournamentLogo(bool includeRoundBackground = true) { RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; Margin = new MarginPadding { Vertical = 5 }; + + if (includeRoundBackground) + { + AutoSizeAxes = Axes.Y; + } + else + { + Masking = true; + Height = 100; + } } [BackgroundDependencyLoader] diff --git a/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs b/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs index 2cb4ffe4e9..c901a5c7ef 100644 --- a/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs +++ b/osu.Game.Tournament/Screens/TeamIntro/TeamIntroScreen.cs @@ -34,7 +34,7 @@ namespace osu.Game.Tournament.Screens.TeamIntro RelativeSizeAxes = Axes.Both, Loop = true, }, - new TournamentLogo(), + new TournamentLogo(false), mainContainer = new Container { RelativeSizeAxes = Axes.Both, From 3f22c0a311abfc79bf32104a0b99c44fa30412c8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 14:39:20 +0900 Subject: [PATCH 5/8] Add SkinnableSprite implementation --- osu.Game/Skinning/SkinnableDrawable.cs | 26 +++++++++++++++++++------- osu.Game/Skinning/SkinnableSprite.cs | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 osu.Game/Skinning/SkinnableSprite.cs diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs index 3ca58dc625..dcbb63435a 100644 --- a/osu.Game/Skinning/SkinnableDrawable.cs +++ b/osu.Game/Skinning/SkinnableDrawable.cs @@ -23,6 +23,8 @@ namespace osu.Game.Skinning /// protected Drawable Drawable { get; private set; } + protected virtual T CreateDefault(string name) => createDefault(name); + private readonly Func createDefault; private readonly string componentName; @@ -37,34 +39,44 @@ namespace osu.Game.Skinning /// A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present. /// Whether a user-skin drawable should be limited to the size of our parent. public SkinnableDrawable(string name, Func defaultImplementation, Func allowFallback = null, bool restrictSize = true) + : this(name, allowFallback, restrictSize) + { + createDefault = defaultImplementation; + } + + protected SkinnableDrawable(string name, Func allowFallback = null, bool restrictSize = true) : base(allowFallback) { componentName = name; - createDefault = defaultImplementation; this.restrictSize = restrictSize; RelativeSizeAxes = Axes.Both; } + protected virtual bool ApplySizeToDefault => false; + protected override void SkinChanged(ISkinSource skin, bool allowFallback) { Drawable = skin.GetDrawableComponent(componentName); + bool isDefault = false; + + if (Drawable == null && allowFallback) + { + Drawable = CreateDefault(componentName); + isDefault = true; + } + if (Drawable != null) { - if (restrictSize) + if (restrictSize && (!isDefault || ApplySizeToDefault)) { Drawable.RelativeSizeAxes = Axes.Both; Drawable.Size = Vector2.One; Drawable.Scale = Vector2.One; Drawable.FillMode = FillMode.Fit; } - } - else if (allowFallback) - Drawable = createDefault(componentName); - if (Drawable != null) - { Drawable.Origin = Anchor.Centre; Drawable.Anchor = Anchor.Centre; diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs new file mode 100644 index 0000000000..72b5740bd6 --- /dev/null +++ b/osu.Game/Skinning/SkinnableSprite.cs @@ -0,0 +1,25 @@ +// 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 osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; + +namespace osu.Game.Skinning +{ + public class SkinnableSprite : SkinnableDrawable + { + protected override bool ApplySizeToDefault => true; + + protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) }; + + [Resolved] + private TextureStore textures { get; set; } + + public SkinnableSprite(string name, Func allowFallback = null, bool restrictSize = true) + : base(name, allowFallback, restrictSize) + { + } + } +} From aca9289d89df4c0984a0416ad689cff0ddff6f16 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 15:17:56 +0900 Subject: [PATCH 6/8] Use SkinnableSprite for approach circle --- .../Objects/Drawables/Pieces/ApproachCircle.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs index 8ee065aaea..9981585f9e 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Game.Skinning; @@ -25,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces [BackgroundDependencyLoader] private void load(TextureStore textures) { - Child = new SkinnableDrawable("Play/osu/approachcircle", name => new Sprite { Texture = textures.Get(name) }); + Child = new SkinnableSprite("Play/osu/approachcircle"); } } } From 9593e66a968d075066512f2a5540d2cfe6b37cc5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 15:25:01 +0900 Subject: [PATCH 7/8] Add some more xmldoc --- osu.Game/Skinning/SkinnableDrawable.cs | 13 ++++++++++--- osu.Game/Skinning/SkinnableSprite.cs | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs index dcbb63435a..0a7c398990 100644 --- a/osu.Game/Skinning/SkinnableDrawable.cs +++ b/osu.Game/Skinning/SkinnableDrawable.cs @@ -15,6 +15,10 @@ namespace osu.Game.Skinning } } + /// + /// A drawable which can be skinned via an . + /// + /// The type of drawable. public class SkinnableDrawable : SkinReloadableDrawable where T : Drawable { @@ -32,7 +36,7 @@ namespace osu.Game.Skinning private readonly bool restrictSize; /// - /// + /// Create a new skinnable drawable. /// /// The namespace-complete resource name for this skinnable element. /// A function to create the default skin implementation of this element. @@ -53,7 +57,10 @@ namespace osu.Game.Skinning RelativeSizeAxes = Axes.Both; } - protected virtual bool ApplySizeToDefault => false; + /// + /// Whether to apply size restrictions (specified via ) to the default implementation. + /// + protected virtual bool ApplySizeRestrictionsToDefault => false; protected override void SkinChanged(ISkinSource skin, bool allowFallback) { @@ -69,7 +76,7 @@ namespace osu.Game.Skinning if (Drawable != null) { - if (restrictSize && (!isDefault || ApplySizeToDefault)) + if (restrictSize && (!isDefault || ApplySizeRestrictionsToDefault)) { Drawable.RelativeSizeAxes = Axes.Both; Drawable.Size = Vector2.One; diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs index 72b5740bd6..9771f4cc19 100644 --- a/osu.Game/Skinning/SkinnableSprite.cs +++ b/osu.Game/Skinning/SkinnableSprite.cs @@ -8,9 +8,12 @@ using osu.Framework.Graphics.Textures; namespace osu.Game.Skinning { + /// + /// A skinnable element which uses a stable sprite and can therefore share implementation logic. + /// public class SkinnableSprite : SkinnableDrawable { - protected override bool ApplySizeToDefault => true; + protected override bool ApplySizeRestrictionsToDefault => true; protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) }; From 06eaba766b93261b0ecdbc5732202ec40955247a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 15:27:46 +0900 Subject: [PATCH 8/8] Move method below ctor --- osu.Game/Skinning/SkinnableDrawable.cs | 8 ++++---- osu.Game/Skinning/SkinnableSprite.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs index 0a7c398990..995cb15136 100644 --- a/osu.Game/Skinning/SkinnableDrawable.cs +++ b/osu.Game/Skinning/SkinnableDrawable.cs @@ -27,10 +27,6 @@ namespace osu.Game.Skinning /// protected Drawable Drawable { get; private set; } - protected virtual T CreateDefault(string name) => createDefault(name); - - private readonly Func createDefault; - private readonly string componentName; private readonly bool restrictSize; @@ -57,6 +53,10 @@ namespace osu.Game.Skinning RelativeSizeAxes = Axes.Both; } + private readonly Func createDefault; + + protected virtual T CreateDefault(string name) => createDefault(name); + /// /// Whether to apply size restrictions (specified via ) to the default implementation. /// diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs index 9771f4cc19..ceb1ed0f70 100644 --- a/osu.Game/Skinning/SkinnableSprite.cs +++ b/osu.Game/Skinning/SkinnableSprite.cs @@ -15,8 +15,6 @@ namespace osu.Game.Skinning { protected override bool ApplySizeRestrictionsToDefault => true; - protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) }; - [Resolved] private TextureStore textures { get; set; } @@ -24,5 +22,7 @@ namespace osu.Game.Skinning : base(name, allowFallback, restrictSize) { } + + protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) }; } }