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