diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeader.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeader.cs index be0933e9d4..c899ccb9eb 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeader.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeader.cs @@ -7,9 +7,7 @@ using System; using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Graphics.Sprites; -using osu.Framework.Graphics.Sprites; using osu.Framework.Allocation; -using osu.Framework.Graphics.Textures; using osu.Game.Graphics.UserInterface; using osu.Framework.Graphics.Shapes; using osuTK.Graphics; @@ -27,6 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface typeof(TestStringTabControlHeader), typeof(TestEnumTabControlHeader), typeof(TestBreadcrumbControlHeader), + typeof(OverlayHeaderBackground) }; private readonly FillFlowContainer flow; @@ -52,10 +51,11 @@ namespace osu.Game.Tests.Visual.UserInterface } }); + addHeader("Orange OverlayHeader (no background)", new TestNoBackgroundHeader(), OverlayColourScheme.Orange); addHeader("Blue OverlayHeader", new TestNoControlHeader(), OverlayColourScheme.Blue); addHeader("Green TabControlOverlayHeader (string)", new TestStringTabControlHeader(), OverlayColourScheme.Green); addHeader("Pink TabControlOverlayHeader (enum)", new TestEnumTabControlHeader(), OverlayColourScheme.Pink); - addHeader("Red BreadcrumbControlOverlayHeader", new TestBreadcrumbControlHeader(), OverlayColourScheme.Red); + addHeader("Red BreadcrumbControlOverlayHeader (no background)", new TestBreadcrumbControlHeader(), OverlayColourScheme.Red); } private void addHeader(string name, OverlayHeader header, OverlayColourScheme colourScheme) @@ -98,16 +98,21 @@ namespace osu.Game.Tests.Visual.UserInterface } } + private class TestNoBackgroundHeader : OverlayHeader + { + protected override ScreenTitle CreateTitle() => new TestTitle(); + } + private class TestNoControlHeader : OverlayHeader { - protected override Drawable CreateBackground() => new TestBackground(); + protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog"); protected override ScreenTitle CreateTitle() => new TestTitle(); } private class TestStringTabControlHeader : TabControlOverlayHeader { - protected override Drawable CreateBackground() => new TestBackground(); + protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news"); protected override ScreenTitle CreateTitle() => new TestTitle(); @@ -120,7 +125,7 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestEnumTabControlHeader : TabControlOverlayHeader { - protected override Drawable CreateBackground() => new TestBackground(); + protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/rankings"); protected override ScreenTitle CreateTitle() => new TestTitle(); } @@ -134,8 +139,6 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader { - protected override Drawable CreateBackground() => new TestBackground(); - protected override ScreenTitle CreateTitle() => new TestTitle(); public TestBreadcrumbControlHeader() @@ -146,21 +149,6 @@ namespace osu.Game.Tests.Visual.UserInterface } } - private class TestBackground : Sprite - { - public TestBackground() - { - RelativeSizeAxes = Axes.Both; - FillMode = FillMode.Fill; - } - - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - Texture = textures.Get(@"Headers/changelog"); - } - } - private class TestTitle : ScreenTitle { public TestTitle() diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeaderBackground.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeaderBackground.cs new file mode 100644 index 0000000000..5a0b28e24a --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOverlayHeaderBackground.cs @@ -0,0 +1,42 @@ +// 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.Containers; +using osu.Game.Overlays; +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osuTK; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneOverlayHeaderBackground : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OverlayHeaderBackground) + }; + + public TestSceneOverlayHeaderBackground() + { + Add(new BasicScrollContainer + { + RelativeSizeAxes = Axes.Both, + Child = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 20), + Children = new[] + { + new OverlayHeaderBackground(@"Headers/changelog"), + new OverlayHeaderBackground(@"Headers/news"), + new OverlayHeaderBackground(@"Headers/rankings"), + new OverlayHeaderBackground(@"Headers/search"), + } + } + }); + } + } +} diff --git a/osu.Game/Overlays/Changelog/ChangelogHeader.cs b/osu.Game/Overlays/Changelog/ChangelogHeader.cs index 2fbfdec3d1..4165a180da 100644 --- a/osu.Game/Overlays/Changelog/ChangelogHeader.cs +++ b/osu.Game/Overlays/Changelog/ChangelogHeader.cs @@ -4,12 +4,9 @@ using System; using System.Collections.Generic; using System.Linq; -using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API.Requests.Responses; @@ -67,7 +64,7 @@ namespace osu.Game.Overlays.Changelog } } - protected override Drawable CreateBackground() => new HeaderBackground(); + protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog"); protected override Drawable CreateContent() => new Container { @@ -95,21 +92,6 @@ namespace osu.Game.Overlays.Changelog Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == Current.Value.UpdateStream.Name); } - public class HeaderBackground : Sprite - { - public HeaderBackground() - { - RelativeSizeAxes = Axes.Both; - FillMode = FillMode.Fill; - } - - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - Texture = textures.Get(@"Headers/changelog"); - } - } - private class ChangelogHeaderTitle : ScreenTitle { public string Version diff --git a/osu.Game/Overlays/News/NewsHeader.cs b/osu.Game/Overlays/News/NewsHeader.cs index 2f9cde1687..b525ba7a82 100644 --- a/osu.Game/Overlays/News/NewsHeader.cs +++ b/osu.Game/Overlays/News/NewsHeader.cs @@ -1,11 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osu.Game.Graphics.UserInterface; using System; @@ -53,25 +50,10 @@ namespace osu.Game.Overlays.News } } - protected override Drawable CreateBackground() => new NewsHeaderBackground(); + protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news"); protected override ScreenTitle CreateTitle() => title = new NewsHeaderTitle(); - private class NewsHeaderBackground : Sprite - { - public NewsHeaderBackground() - { - RelativeSizeAxes = Axes.Both; - FillMode = FillMode.Fill; - } - - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - Texture = textures.Get(@"Headers/news"); - } - } - private class NewsHeaderTitle : ScreenTitle { private const string post_string = "post"; diff --git a/osu.Game/Overlays/OverlayHeader.cs b/osu.Game/Overlays/OverlayHeader.cs index 0575f6f296..5596f71dd0 100644 --- a/osu.Game/Overlays/OverlayHeader.cs +++ b/osu.Game/Overlays/OverlayHeader.cs @@ -14,16 +14,10 @@ namespace osu.Game.Overlays public abstract class OverlayHeader : Container { private readonly Box titleBackground; - private readonly Container background; private readonly ScreenTitle title; protected readonly FillFlowContainer HeaderInfo; - protected float BackgroundHeight - { - set => background.Height = value; - } - protected OverlayHeader() { RelativeSizeAxes = Axes.X; @@ -42,15 +36,9 @@ namespace osu.Game.Overlays AutoSizeAxes = Axes.Y, Direction = FillDirection.Vertical, Depth = -float.MaxValue, - Children = new Drawable[] + Children = new[] { - background = new Container - { - RelativeSizeAxes = Axes.X, - Height = 80, - Masking = true, - Child = CreateBackground() - }, + CreateBackground(), new Container { RelativeSizeAxes = Axes.X, @@ -86,10 +74,11 @@ namespace osu.Game.Overlays title.AccentColour = colourProvider.Highlight1; } - protected abstract Drawable CreateBackground(); + [NotNull] + protected virtual Drawable CreateContent() => Drawable.Empty(); [NotNull] - protected virtual Drawable CreateContent() => new Container(); + protected virtual Drawable CreateBackground() => Drawable.Empty(); protected abstract ScreenTitle CreateTitle(); } diff --git a/osu.Game/Overlays/OverlayHeaderBackground.cs b/osu.Game/Overlays/OverlayHeaderBackground.cs new file mode 100644 index 0000000000..2fef593285 --- /dev/null +++ b/osu.Game/Overlays/OverlayHeaderBackground.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 osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; + +namespace osu.Game.Overlays +{ + public class OverlayHeaderBackground : CompositeDrawable + { + public OverlayHeaderBackground(string textureName) + { + Height = 80; + RelativeSizeAxes = Axes.X; + Masking = true; + InternalChild = new Background(textureName); + } + + private class Background : Sprite + { + private readonly string textureName; + + public Background(string textureName) + { + this.textureName = textureName; + + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + RelativeSizeAxes = Axes.Both; + FillMode = FillMode.Fill; + } + + [BackgroundDependencyLoader] + private void load(TextureStore textures) + { + Texture = textures.Get(textureName); + } + } + } +} diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index 203df2ec12..3e78423a5a 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -25,8 +25,6 @@ namespace osu.Game.Overlays.Profile public ProfileHeader() { - BackgroundHeight = 150; - User.ValueChanged += e => updateDisplay(e.NewValue); TabControl.AddItem("info"); @@ -38,7 +36,9 @@ namespace osu.Game.Overlays.Profile protected override Drawable CreateBackground() => new Container { - RelativeSizeAxes = Axes.Both, + RelativeSizeAxes = Axes.X, + Height = 150, + Masking = true, Children = new Drawable[] { coverContainer = new UserCoverBackground