1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02:54 +08:00

Refactor background creation in OverlayHeader

This commit is contained in:
Andrei Zavatski 2020-01-27 15:36:19 +03:00
parent d0715700eb
commit e6fa793d56
6 changed files with 63 additions and 77 deletions

View File

@ -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,6 +51,7 @@ 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);
@ -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<string>
{
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<TestEnum>
{
protected override Drawable CreateBackground() => new TestBackground();
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/rankings");
protected override ScreenTitle CreateTitle() => new TestTitle();
}
@ -134,7 +139,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader
{
protected override Drawable CreateBackground() => new TestBackground();
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/search");
protected override ScreenTitle CreateTitle() => new TestTitle();
@ -146,21 +151,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()

View File

@ -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

View File

@ -1,11 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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";

View File

@ -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;
@ -44,13 +38,7 @@ namespace osu.Game.Overlays
Depth = -float.MaxValue,
Children = new Drawable[]
{
background = new Container
{
RelativeSizeAxes = Axes.X,
Height = 80,
Masking = true,
Child = CreateBackground()
},
CreateBackground(),
new Container
{
RelativeSizeAxes = Axes.X,
@ -86,11 +74,12 @@ namespace osu.Game.Overlays
title.AccentColour = colourProvider.Highlight1;
}
protected abstract Drawable CreateBackground();
[NotNull]
protected virtual Drawable CreateContent() => new Container();
[NotNull]
protected virtual Drawable CreateBackground() => new Container();
protected abstract ScreenTitle CreateTitle();
}
}

View File

@ -0,0 +1,43 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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);
}
}
}
}

View File

@ -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