1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:52:54 +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(RankGraph),
typeof(LineGraph),
typeof(ProfileHeaderTabControl),
typeof(HeaderTabControl),
typeof(CentreHeaderContainer),
typeof(BottomHeaderContainer),
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
{
public class ProfileHeaderTabControl : TabControl<string>
public class HeaderTabControl : TabControl<string>
{
private readonly Box bar;
@ -32,7 +32,7 @@ namespace osu.Game.Overlays.Profile.Header
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;
}
public ProfileHeaderTabControl()
public HeaderTabControl()
{
TabContainer.Masking = false;
TabContainer.Spacing = new Vector2(15, 0);
@ -59,12 +59,12 @@ namespace osu.Game.Overlays.Profile.Header
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
};
private class ProfileHeaderTabItem : TabItem<string>
private class HeaderTabItem : TabItem<string>
{
private readonly OsuSpriteText text;
private readonly Drawable bar;
@ -86,7 +86,7 @@ namespace osu.Game.Overlays.Profile.Header
}
}
public ProfileHeaderTabItem(string value)
public HeaderTabItem(string value)
: base(value)
{
AutoSizeAxes = Axes.X;

View File

@ -15,29 +15,35 @@ using osu.Game.Users;
namespace osu.Game.Overlays.Profile
{
public class ProfileHeader : Container
public class ProfileHeader : OverlayHeader
{
private readonly UserCoverBackground coverContainer;
private readonly ProfileHeaderTabControl infoTabControl;
private UserCoverBackground coverContainer;
private const float cover_height = 150;
private const float cover_info_height = 75;
public Bindable<User> User = new Bindable<User>();
private CentreHeaderContainer centreHeaderContainer;
private DetailHeaderContainer detailHeaderContainer;
public ProfileHeader()
{
CentreHeaderContainer centreHeaderContainer;
DetailHeaderContainer detailHeaderContainer;
User.ValueChanged += e => updateDisplay(e.NewValue);
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
TabControl.AddItem("Info");
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
{
RelativeSizeAxes = Axes.X,
Height = cover_height,
Masking = true,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
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))
},
}
},
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,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
@ -111,28 +91,9 @@ namespace osu.Game.Overlays.Profile
User = { BindTarget = User },
},
}
}
};
infoTabControl.AddItem("Info");
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;
}
protected override ScreenTitle CreateTitle() => new ProfileHeaderTitle();
private class ProfileHeaderTitle : ScreenTitle
{
@ -148,5 +109,7 @@ namespace osu.Game.Overlays.Profile
AccentColour = colours.Seafoam;
}
}
private void updateDisplay(User user) => coverContainer.User = user;
}
}