1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Move UserProfileOverlay's header into an abstract implementation

This commit is contained in:
Dean Herbert 2019-05-20 18:02:13 +09:00
parent 455301de2c
commit a5bd3262be
4 changed files with 142 additions and 108 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Online
typeof(ProfileHeader), typeof(ProfileHeader),
typeof(RankGraph), typeof(RankGraph),
typeof(LineGraph), typeof(LineGraph),
typeof(ProfileHeaderTabControl), typeof(HeaderTabControl),
typeof(CentreHeaderContainer), typeof(CentreHeaderContainer),
typeof(BottomHeaderContainer), typeof(BottomHeaderContainer),
typeof(DetailHeaderContainer), typeof(DetailHeaderContainer),

View File

@ -0,0 +1,71 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Profile.Header;
namespace osu.Game.Overlays
{
public abstract class OverlayHeader : Container
{
protected readonly HeaderTabControl TabControl;
private const float cover_height = 150;
private const float cover_info_height = 75;
protected OverlayHeader()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
Height = cover_height,
Masking = true,
Child = CreateBackground()
},
new Container
{
Margin = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN },
Y = cover_height,
Height = cover_info_height,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopLeft,
Origin = Anchor.BottomLeft,
Depth = -float.MaxValue,
Children = new Drawable[]
{
CreateTitle().With(t => t.X = -ScreenTitle.ICON_WIDTH),
TabControl = new HeaderTabControl
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = cover_info_height - 30,
Margin = new MarginPadding { Left = -UserProfileOverlay.CONTENT_X_MARGIN },
Padding = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN }
}
}
},
new Container
{
Margin = new MarginPadding { Top = cover_height },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = CreateContent()
}
};
}
protected abstract Drawable CreateBackground();
protected abstract Drawable CreateContent();
protected abstract ScreenTitle CreateTitle();
}
}

View File

@ -13,7 +13,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header namespace osu.Game.Overlays.Profile.Header
{ {
public class ProfileHeaderTabControl : TabControl<string> public class HeaderTabControl : TabControl<string>
{ {
private readonly Box bar; private readonly Box bar;
@ -32,7 +32,7 @@ namespace osu.Game.Overlays.Profile.Header
foreach (TabItem<string> tabItem in TabContainer) foreach (TabItem<string> tabItem in TabContainer)
{ {
((ProfileHeaderTabItem)tabItem).AccentColour = value; ((HeaderTabItem)tabItem).AccentColour = value;
} }
} }
} }
@ -43,7 +43,7 @@ namespace osu.Game.Overlays.Profile.Header
set => TabContainer.Padding = value; set => TabContainer.Padding = value;
} }
public ProfileHeaderTabControl() public HeaderTabControl()
{ {
TabContainer.Masking = false; TabContainer.Masking = false;
TabContainer.Spacing = new Vector2(15, 0); TabContainer.Spacing = new Vector2(15, 0);
@ -59,12 +59,12 @@ namespace osu.Game.Overlays.Profile.Header
protected override Dropdown<string> CreateDropdown() => null; protected override Dropdown<string> CreateDropdown() => null;
protected override TabItem<string> CreateTabItem(string value) => new ProfileHeaderTabItem(value) protected override TabItem<string> CreateTabItem(string value) => new HeaderTabItem(value)
{ {
AccentColour = AccentColour AccentColour = AccentColour
}; };
private class ProfileHeaderTabItem : TabItem<string> private class HeaderTabItem : TabItem<string>
{ {
private readonly OsuSpriteText text; private readonly OsuSpriteText text;
private readonly Drawable bar; private readonly Drawable bar;
@ -86,7 +86,7 @@ namespace osu.Game.Overlays.Profile.Header
} }
} }
public ProfileHeaderTabItem(string value) public HeaderTabItem(string value)
: base(value) : base(value)
{ {
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;

View File

@ -15,29 +15,35 @@ using osu.Game.Users;
namespace osu.Game.Overlays.Profile namespace osu.Game.Overlays.Profile
{ {
public class ProfileHeader : Container public class ProfileHeader : OverlayHeader
{ {
private readonly UserCoverBackground coverContainer; private UserCoverBackground coverContainer;
private readonly ProfileHeaderTabControl infoTabControl;
private const float cover_height = 150; public Bindable<User> User = new Bindable<User>();
private const float cover_info_height = 75;
private CentreHeaderContainer centreHeaderContainer;
private DetailHeaderContainer detailHeaderContainer;
public ProfileHeader() public ProfileHeader()
{ {
CentreHeaderContainer centreHeaderContainer; User.ValueChanged += e => updateDisplay(e.NewValue);
DetailHeaderContainer detailHeaderContainer;
RelativeSizeAxes = Axes.X; TabControl.AddItem("Info");
AutoSizeAxes = Axes.Y; TabControl.AddItem("Modding");
Children = new Drawable[] centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{ {
TabControl.AccentColour = colours.Seafoam;
}
protected override Drawable CreateBackground() =>
new Container new Container
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
Height = cover_height,
Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
coverContainer = new UserCoverBackground coverContainer = new UserCoverBackground
@ -50,36 +56,10 @@ namespace osu.Game.Overlays.Profile
Colour = ColourInfo.GradientVertical(OsuColour.FromHex("222").Opacity(0.8f), OsuColour.FromHex("222").Opacity(0.2f)) Colour = ColourInfo.GradientVertical(OsuColour.FromHex("222").Opacity(0.8f), OsuColour.FromHex("222").Opacity(0.2f))
}, },
} }
}, };
new Container
protected override Drawable CreateContent() => new FillFlowContainer
{ {
Margin = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN },
Y = cover_height,
Height = cover_info_height,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopLeft,
Origin = Anchor.BottomLeft,
Depth = -float.MaxValue,
Children = new Drawable[]
{
new ProfileHeaderTitle
{
X = -ScreenTitle.ICON_WIDTH,
},
infoTabControl = new ProfileHeaderTabControl
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = cover_info_height - 30,
Margin = new MarginPadding { Left = -UserProfileOverlay.CONTENT_X_MARGIN },
Padding = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN }
}
}
},
new FillFlowContainer
{
Margin = new MarginPadding { Top = cover_height },
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
@ -111,28 +91,9 @@ namespace osu.Game.Overlays.Profile
User = { BindTarget = User }, User = { BindTarget = User },
}, },
} }
}
}; };
infoTabControl.AddItem("Info"); protected override ScreenTitle CreateTitle() => new ProfileHeaderTitle();
infoTabControl.AddItem("Modding");
centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true);
User.ValueChanged += e => updateDisplay(e.NewValue);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
infoTabControl.AccentColour = colours.Seafoam;
}
public Bindable<User> User = new Bindable<User>();
private void updateDisplay(User user)
{
coverContainer.User = user;
}
private class ProfileHeaderTitle : ScreenTitle private class ProfileHeaderTitle : ScreenTitle
{ {
@ -148,5 +109,7 @@ namespace osu.Game.Overlays.Profile
AccentColour = colours.Seafoam; AccentColour = colours.Seafoam;
} }
} }
private void updateDisplay(User user) => coverContainer.User = user;
} }
} }