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

Merge pull request #4832 from peppy/abstract-profile-header

Abstract profile header
This commit is contained in:
Dan Balasescu 2019-05-21 17:04:43 +09:00 committed by GitHub
commit 3cf60d63a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 144 additions and 110 deletions

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Overlays;
using osu.Game.Overlays.Profile; using osu.Game.Overlays.Profile;
using osu.Game.Overlays.Profile.Header; using osu.Game.Overlays.Profile.Header;
using osu.Game.Overlays.Profile.Header.Components; using osu.Game.Overlays.Profile.Header.Components;
@ -21,7 +22,7 @@ namespace osu.Game.Tests.Visual.Online
typeof(ProfileHeader), typeof(ProfileHeader),
typeof(RankGraph), typeof(RankGraph),
typeof(LineGraph), typeof(LineGraph),
typeof(ProfileHeaderTabControl), typeof(OverlayHeaderTabControl),
typeof(CentreHeaderContainer), typeof(CentreHeaderContainer),
typeof(BottomHeaderContainer), typeof(BottomHeaderContainer),
typeof(DetailHeaderContainer), typeof(DetailHeaderContainer),

View File

@ -0,0 +1,70 @@
// 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;
namespace osu.Game.Overlays
{
public abstract class OverlayHeader : Container
{
protected readonly OverlayHeaderTabControl 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 OverlayHeaderTabControl
{
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

@ -11,13 +11,13 @@ using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header namespace osu.Game.Overlays
{ {
public class ProfileHeaderTabControl : TabControl<string> public class OverlayHeaderTabControl : TabControl<string>
{ {
private readonly Box bar; private readonly Box bar;
private Color4 accentColour; private Color4 accentColour = Color4.White;
public Color4 AccentColour public Color4 AccentColour
{ {
@ -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 OverlayHeaderTabControl()
{ {
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,124 +15,87 @@ 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[]
{
new Container
{
RelativeSizeAxes = Axes.X,
Height = cover_height,
Masking = true,
Children = new Drawable[]
{
coverContainer = new UserCoverBackground
{
RelativeSizeAxes = Axes.Both,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(OsuColour.FromHex("222").Opacity(0.8f), OsuColour.FromHex("222").Opacity(0.2f))
},
}
},
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[]
{
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,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new TopHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
centreHeaderContainer = new CentreHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
detailHeaderContainer = new DetailHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
new MedalHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
new BottomHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
}
}
};
infoTabControl.AddItem("Info");
infoTabControl.AddItem("Modding");
centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true); centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true);
User.ValueChanged += e => updateDisplay(e.NewValue);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
infoTabControl.AccentColour = colours.Seafoam; TabControl.AccentColour = colours.Seafoam;
} }
public Bindable<User> User = new Bindable<User>(); protected override Drawable CreateBackground() =>
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
coverContainer = new UserCoverBackground
{
RelativeSizeAxes = Axes.Both,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(OsuColour.FromHex("222").Opacity(0.8f), OsuColour.FromHex("222").Opacity(0.2f))
},
}
};
private void updateDisplay(User user) protected override Drawable CreateContent() => new FillFlowContainer
{ {
coverContainer.User = user; RelativeSizeAxes = Axes.X,
} AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new TopHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
centreHeaderContainer = new CentreHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
detailHeaderContainer = new DetailHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
new MedalHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
new BottomHeaderContainer
{
RelativeSizeAxes = Axes.X,
User = { BindTarget = User },
},
}
};
protected override ScreenTitle CreateTitle() => new ProfileHeaderTitle();
private void updateDisplay(User user) => coverContainer.User = user;
private class ProfileHeaderTitle : ScreenTitle private class ProfileHeaderTitle : ScreenTitle
{ {