1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00
osu-lazer/osu.Game/Overlays/UserProfileOverlay.cs

183 lines
5.7 KiB
C#
Raw Normal View History

2017-05-25 02:11:07 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-06-09 16:24:19 +08:00
using System.Linq;
2017-06-09 16:01:16 +08:00
using OpenTK;
using osu.Framework.Allocation;
2017-06-05 21:04:35 +08:00
using osu.Framework.Graphics;
2017-06-16 16:13:23 +08:00
using osu.Framework.Graphics.Containers;
2017-06-07 21:15:43 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
2017-06-07 21:15:43 +08:00
using osu.Game.Graphics;
2017-05-25 02:11:07 +08:00
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
2017-06-15 22:33:08 +08:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
2017-06-15 17:03:33 +08:00
using osu.Game.Users;
2017-06-05 21:07:57 +08:00
using osu.Game.Users.Profile;
2017-05-25 02:11:07 +08:00
2017-06-15 17:03:33 +08:00
namespace osu.Game.Overlays
2017-05-25 02:11:07 +08:00
{
2017-06-16 16:13:23 +08:00
public class UserProfileOverlay : FocusedOverlayContainer
2017-05-25 02:11:07 +08:00
{
2017-06-05 21:07:57 +08:00
private ProfileSection lastSection;
2017-06-15 22:33:08 +08:00
private GetUserRequest userReq;
private APIAccess api;
2017-06-06 11:25:16 +08:00
public const float CONTENT_X_MARGIN = 50;
2017-06-16 16:13:23 +08:00
private const float transition_length = 500;
public UserProfileOverlay()
{
RelativeSizeAxes = Axes.Both;
RelativePositionAxes = Axes.Both;
Padding = new MarginPadding { Horizontal = 50 };
}
2017-06-06 11:25:16 +08:00
2017-06-15 22:33:08 +08:00
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
this.api = api;
}
2017-06-15 20:01:46 +08:00
public void ShowUser(User user)
2017-05-25 02:11:07 +08:00
{
2017-06-15 22:33:08 +08:00
userReq?.Cancel();
2017-06-15 20:01:46 +08:00
Clear();
lastSection = null;
2017-06-15 22:33:08 +08:00
2017-06-07 22:49:14 +08:00
var sections = new ProfileSection[]
{
2017-06-15 08:00:15 +08:00
new AboutSection(),
new RecentSection(),
new RanksSection(),
new MedalsSection(),
new HistoricalSection(),
new BeatmapsSection(),
new KudosuSection()
2017-06-07 22:49:14 +08:00
};
2017-06-15 07:58:20 +08:00
var tabs = new ProfileTabControl
2017-06-07 22:49:14 +08:00
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2017-06-15 07:23:30 +08:00
Height = 30
2017-06-07 22:49:14 +08:00
};
2017-06-07 21:15:43 +08:00
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
});
2017-06-15 22:33:08 +08:00
var header = new ProfileHeader(user);
2017-06-09 16:24:19 +08:00
var sectionsContainer = new SectionsContainer<ProfileSection>
2017-05-25 02:11:07 +08:00
{
2017-06-05 21:04:35 +08:00
RelativeSizeAxes = Axes.Both,
2017-06-15 22:33:08 +08:00
ExpandableHeader = header,
FixedHeader = tabs,
HeaderBackground = new Box
{
Colour = OsuColour.Gray(34),
RelativeSizeAxes = Axes.Both
2017-06-15 22:33:08 +08:00
}
2017-05-25 02:11:07 +08:00
};
Add(sectionsContainer);
sectionsContainer.SelectedSection.ValueChanged += s =>
{
if (lastSection != s)
{
2017-06-09 16:24:19 +08:00
lastSection = s;
tabs.Current.Value = lastSection;
2017-05-25 02:11:07 +08:00
}
};
tabs.Current.ValueChanged += s =>
2017-05-25 02:11:07 +08:00
{
2017-06-09 16:05:05 +08:00
if (lastSection == null)
{
2017-06-09 16:24:19 +08:00
lastSection = sectionsContainer.Children.FirstOrDefault();
if (lastSection != null)
tabs.Current.Value = lastSection;
2017-06-09 16:05:05 +08:00
return;
}
2017-05-25 02:11:07 +08:00
if (lastSection != s)
{
lastSection = s;
sectionsContainer.ScrollContainer.ScrollIntoView(lastSection);
}
};
2017-06-15 22:33:08 +08:00
userReq = new GetUserRequest(user.Id); //fetch latest full data
userReq.Success += u =>
{
header.FillFullData(u);
2017-06-15 23:47:34 +08:00
var reorderedSections = u.ProfileOrder.Select(x => sections.FirstOrDefault(s => s.Identifier == x)).Where(s => s != null).ToList();
sectionsContainer.Children = reorderedSections;
reorderedSections.ForEach(tabs.AddItem);
2017-06-15 22:33:08 +08:00
};
api.Queue(userReq);
2017-06-15 20:01:46 +08:00
Show();
2017-05-25 02:11:07 +08:00
}
2017-06-16 16:13:23 +08:00
protected override void PopIn()
{
MoveToY(0, transition_length, EasingTypes.OutQuint);
FadeIn(transition_length, EasingTypes.OutQuint);
base.PopIn();
}
protected override void PopOut()
{
MoveToY(Height, transition_length, EasingTypes.OutQuint);
FadeOut(transition_length, EasingTypes.OutQuint);
base.PopOut();
}
2017-06-09 16:01:16 +08:00
private class ProfileTabControl : PageTabControl<ProfileSection>
{
2017-06-09 16:01:16 +08:00
private readonly Box bottom;
public ProfileTabControl()
{
TabContainer.RelativeSizeAxes &= ~Axes.X;
TabContainer.AutoSizeAxes |= Axes.X;
TabContainer.Anchor |= Anchor.x1;
TabContainer.Origin |= Anchor.x1;
2017-06-09 16:01:16 +08:00
Add(bottom = new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
EdgeSmoothness = new Vector2(1)
});
}
protected override TabItem<ProfileSection> CreateTabItem(ProfileSection value) => new ProfileTabItem(value);
2017-06-15 22:42:15 +08:00
protected override Dropdown<ProfileSection> CreateDropdown() => null;
2017-06-09 16:01:16 +08:00
private class ProfileTabItem : PageTabItem
{
public ProfileTabItem(ProfileSection value) : base(value)
{
Text.Text = value.Title;
}
}
2017-06-09 16:01:16 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
bottom.Colour = colours.Yellow;
}
}
2017-05-25 02:11:07 +08:00
}
}