1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 22:33:05 +08:00
osu-lazer/osu.Game/Users/UserProfile.cs
2017-06-09 14:53:30 +08:00

114 lines
3.6 KiB
C#

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Users.Profile;
namespace osu.Game.Users
{
public class UserProfile : FocusedOverlayContainer
{
private readonly User user;
private ProfileSection lastSection;
private readonly ProfileTabControl tabs;
public const float CONTENT_X_MARGIN = 50;
public UserProfile(User user)
{
this.user = user;
var sections = new ProfileSection[]
{
new AboutSection(user),
new RecentSection(user),
new RanksSection(user),
new MedalsSection(user),
new HistoricalSection(user),
new BeatmapsSection(user),
new KudosuSection(user)
};
tabs = new ProfileTabControl
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Height = 24
};
sections.ForEach(tabs.AddItem);
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
});
var sectionsContainer = new SectionsContainer
{
RelativeSizeAxes = Axes.Both,
ExpandableHeader = new ProfileHeader(user),
FixedHeader = tabs,
HeaderBackground = new Box
{
Colour = OsuColour.Gray(34),
RelativeSizeAxes = Axes.Both
},
Sections = sections
};
Add(sectionsContainer);
sectionsContainer.SelectedSection.ValueChanged += s =>
{
if (lastSection != s)
{
lastSection = s as ProfileSection;
tabs.Current.Value = lastSection;
}
};
tabs.Current.ValueChanged += s =>
{
if (lastSection != s)
{
lastSection = s;
sectionsContainer.ScrollContainer.ScrollIntoView(lastSection);
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
tabs.AccentColour = colours.Yellow;
}
private class ProfileTabControl : OsuTabControl<ProfileSection>
{
public ProfileTabControl()
{
TabContainer.RelativeSizeAxes &= ~Axes.X;
TabContainer.AutoSizeAxes |= Axes.X;
TabContainer.Anchor |= Anchor.x1;
TabContainer.Origin |= Anchor.x1;
}
protected override TabItem<ProfileSection> CreateTabItem(ProfileSection value) => new ProfileTabItem(value);
private class ProfileTabItem : OsuTabItem
{
public ProfileTabItem(ProfileSection value) : base(value)
{
Text.Text = value.Title;
}
}
}
}
}