mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Refactor background creation in OverlayHeader
This commit is contained in:
parent
d0715700eb
commit
e6fa793d56
@ -7,9 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -27,6 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
typeof(TestStringTabControlHeader),
|
typeof(TestStringTabControlHeader),
|
||||||
typeof(TestEnumTabControlHeader),
|
typeof(TestEnumTabControlHeader),
|
||||||
typeof(TestBreadcrumbControlHeader),
|
typeof(TestBreadcrumbControlHeader),
|
||||||
|
typeof(OverlayHeaderBackground)
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly FillFlowContainer flow;
|
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("Blue OverlayHeader", new TestNoControlHeader(), OverlayColourScheme.Blue);
|
||||||
addHeader("Green TabControlOverlayHeader (string)", new TestStringTabControlHeader(), OverlayColourScheme.Green);
|
addHeader("Green TabControlOverlayHeader (string)", new TestStringTabControlHeader(), OverlayColourScheme.Green);
|
||||||
addHeader("Pink TabControlOverlayHeader (enum)", new TestEnumTabControlHeader(), OverlayColourScheme.Pink);
|
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
|
private class TestNoControlHeader : OverlayHeader
|
||||||
{
|
{
|
||||||
protected override Drawable CreateBackground() => new TestBackground();
|
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog");
|
||||||
|
|
||||||
protected override ScreenTitle CreateTitle() => new TestTitle();
|
protected override ScreenTitle CreateTitle() => new TestTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestStringTabControlHeader : TabControlOverlayHeader<string>
|
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();
|
protected override ScreenTitle CreateTitle() => new TestTitle();
|
||||||
|
|
||||||
@ -120,7 +125,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
private class TestEnumTabControlHeader : TabControlOverlayHeader<TestEnum>
|
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();
|
protected override ScreenTitle CreateTitle() => new TestTitle();
|
||||||
}
|
}
|
||||||
@ -134,7 +139,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader
|
private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader
|
||||||
{
|
{
|
||||||
protected override Drawable CreateBackground() => new TestBackground();
|
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/search");
|
||||||
|
|
||||||
protected override ScreenTitle CreateTitle() => new TestTitle();
|
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
|
private class TestTitle : ScreenTitle
|
||||||
{
|
{
|
||||||
public TestTitle()
|
public TestTitle()
|
||||||
|
@ -4,12 +4,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
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
|
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);
|
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
|
private class ChangelogHeaderTitle : ScreenTitle
|
||||||
{
|
{
|
||||||
public string Version
|
public string Version
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using System;
|
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();
|
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 class NewsHeaderTitle : ScreenTitle
|
||||||
{
|
{
|
||||||
private const string post_string = "post";
|
private const string post_string = "post";
|
||||||
|
@ -14,16 +14,10 @@ namespace osu.Game.Overlays
|
|||||||
public abstract class OverlayHeader : Container
|
public abstract class OverlayHeader : Container
|
||||||
{
|
{
|
||||||
private readonly Box titleBackground;
|
private readonly Box titleBackground;
|
||||||
private readonly Container background;
|
|
||||||
private readonly ScreenTitle title;
|
private readonly ScreenTitle title;
|
||||||
|
|
||||||
protected readonly FillFlowContainer HeaderInfo;
|
protected readonly FillFlowContainer HeaderInfo;
|
||||||
|
|
||||||
protected float BackgroundHeight
|
|
||||||
{
|
|
||||||
set => background.Height = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected OverlayHeader()
|
protected OverlayHeader()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
@ -44,13 +38,7 @@ namespace osu.Game.Overlays
|
|||||||
Depth = -float.MaxValue,
|
Depth = -float.MaxValue,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
background = new Container
|
CreateBackground(),
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Height = 80,
|
|
||||||
Masking = true,
|
|
||||||
Child = CreateBackground()
|
|
||||||
},
|
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
@ -86,11 +74,12 @@ namespace osu.Game.Overlays
|
|||||||
title.AccentColour = colourProvider.Highlight1;
|
title.AccentColour = colourProvider.Highlight1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Drawable CreateBackground();
|
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
protected virtual Drawable CreateContent() => new Container();
|
protected virtual Drawable CreateContent() => new Container();
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
protected virtual Drawable CreateBackground() => new Container();
|
||||||
|
|
||||||
protected abstract ScreenTitle CreateTitle();
|
protected abstract ScreenTitle CreateTitle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
osu.Game/Overlays/OverlayHeaderBackground.cs
Normal file
43
osu.Game/Overlays/OverlayHeaderBackground.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,8 +25,6 @@ namespace osu.Game.Overlays.Profile
|
|||||||
|
|
||||||
public ProfileHeader()
|
public ProfileHeader()
|
||||||
{
|
{
|
||||||
BackgroundHeight = 150;
|
|
||||||
|
|
||||||
User.ValueChanged += e => updateDisplay(e.NewValue);
|
User.ValueChanged += e => updateDisplay(e.NewValue);
|
||||||
|
|
||||||
TabControl.AddItem("info");
|
TabControl.AddItem("info");
|
||||||
@ -38,7 +36,9 @@ namespace osu.Game.Overlays.Profile
|
|||||||
protected override Drawable CreateBackground() =>
|
protected override Drawable CreateBackground() =>
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = 150,
|
||||||
|
Masking = true,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
coverContainer = new UserCoverBackground
|
coverContainer = new UserCoverBackground
|
||||||
|
Loading…
Reference in New Issue
Block a user