1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 01:45:35 +08:00
osu-lazer/osu.Game/Overlays/UserProfileOverlay.cs

185 lines
5.6 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests;
using osu.Game.Overlays.Profile;
using osu.Game.Overlays.Profile.Sections;
using osu.Game.Users;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays
{
2019-05-14 13:18:06 +08:00
public class UserProfileOverlay : FullscreenOverlay
2018-04-13 17:19:50 +08:00
{
private ProfileSection lastSection;
private ProfileSection[] sections;
private GetUserRequest userReq;
protected ProfileHeader Header;
private SectionsContainer<ProfileSection> sectionsContainer;
private ProfileTabControl tabs;
2018-12-22 23:51:24 +08:00
public const float CONTENT_X_MARGIN = 70;
2018-04-13 17:19:50 +08:00
public void ShowUser(long userId) => ShowUser(new User { Id = userId });
2018-04-13 17:19:50 +08:00
public void ShowUser(User user, bool fetchOnline = true)
{
2018-09-13 13:03:21 +08:00
if (user == User.SYSTEM_USER) return;
Show();
2019-03-10 06:58:14 +08:00
if (user.Id == Header?.User.Value?.Id)
return;
2018-04-13 17:19:50 +08:00
userReq?.Cancel();
Clear();
lastSection = null;
sections = new ProfileSection[]
{
//new AboutSection(),
new RecentSection(),
new RanksSection(),
//new MedalsSection(),
new HistoricalSection(),
new BeatmapsSection(),
new KudosuSection()
};
2018-04-13 17:19:50 +08:00
tabs = new ProfileTabControl
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Height = 30
};
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
});
Add(sectionsContainer = new SectionsContainer<ProfileSection>
{
RelativeSizeAxes = Axes.Both,
2018-12-22 23:51:24 +08:00
ExpandableHeader = Header = new ProfileHeader(),
2018-04-13 17:19:50 +08:00
FixedHeader = tabs,
HeaderBackground = new Box
{
Colour = OsuColour.Gray(34),
RelativeSizeAxes = Axes.Both
}
});
sectionsContainer.SelectedSection.ValueChanged += section =>
2018-04-13 17:19:50 +08:00
{
if (lastSection != section.NewValue)
2018-04-13 17:19:50 +08:00
{
lastSection = section.NewValue;
2018-04-13 17:19:50 +08:00
tabs.Current.Value = lastSection;
}
};
tabs.Current.ValueChanged += section =>
2018-04-13 17:19:50 +08:00
{
if (lastSection == null)
{
lastSection = sectionsContainer.Children.FirstOrDefault();
if (lastSection != null)
tabs.Current.Value = lastSection;
return;
}
2019-02-28 12:31:40 +08:00
if (lastSection != section.NewValue)
2018-04-13 17:19:50 +08:00
{
lastSection = section.NewValue;
2018-04-13 17:19:50 +08:00
sectionsContainer.ScrollTo(lastSection);
}
};
if (fetchOnline)
{
userReq = new GetUserRequest(user.Id);
userReq.Success += userLoadComplete;
2019-05-14 13:18:06 +08:00
API.Queue(userReq);
2018-04-13 17:19:50 +08:00
}
else
{
userReq = null;
userLoadComplete(user);
}
sectionsContainer.ScrollToTop();
}
private void userLoadComplete(User user)
{
2019-03-10 06:58:14 +08:00
Header.User.Value = user;
2018-04-13 17:19:50 +08:00
if (user.ProfileOrder != null)
{
foreach (string id in user.ProfileOrder)
{
var sec = sections.FirstOrDefault(s => s.Identifier == id);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
if (sec != null)
{
sec.User.Value = user;
sectionsContainer.Add(sec);
tabs.AddItem(sec);
}
}
}
}
private class ProfileTabControl : PageTabControl<ProfileSection>
{
private readonly Box bottom;
public ProfileTabControl()
{
TabContainer.RelativeSizeAxes &= ~Axes.X;
TabContainer.AutoSizeAxes |= Axes.X;
TabContainer.Anchor |= Anchor.x1;
TabContainer.Origin |= Anchor.x1;
AddInternal(bottom = new Box
2018-04-13 17:19:50 +08:00
{
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);
protected override Dropdown<ProfileSection> CreateDropdown() => null;
private class ProfileTabItem : PageTabItem
{
2019-02-28 12:31:40 +08:00
public ProfileTabItem(ProfileSection value)
: base(value)
2018-04-13 17:19:50 +08:00
{
Text.Text = value.Title;
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
bottom.Colour = colours.Yellow;
}
}
}
}