2020-01-30 04:37:51 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-11-28 21:41:29 +08:00
|
|
|
|
using System;
|
2022-12-30 20:17:59 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-06-09 16:24:19 +08:00
|
|
|
|
using System.Linq;
|
2017-06-09 14:25:23 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-06-05 21:04:35 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-06-22 06:11:04 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-21 16:03:47 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-09 14:25:23 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-09-17 03:00:27 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2017-05-25 02:11:07 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-06-15 22:33:08 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2017-06-16 16:36:23 +08:00
|
|
|
|
using osu.Game.Overlays.Profile;
|
2017-07-13 12:53:45 +08:00
|
|
|
|
using osu.Game.Overlays.Profile.Sections;
|
2021-11-05 12:53:00 +08:00
|
|
|
|
using osu.Game.Users;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2021-01-18 15:48:12 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-15 17:03:33 +08:00
|
|
|
|
namespace osu.Game.Overlays
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2020-09-03 15:27:31 +08:00
|
|
|
|
public partial class UserProfileOverlay : FullscreenOverlay<ProfileHeader>
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2022-12-30 20:17:59 +08:00
|
|
|
|
private ProfileSection? lastSection;
|
|
|
|
|
private ProfileSection[]? sections;
|
|
|
|
|
private GetUserRequest? userReq;
|
|
|
|
|
private ProfileSectionsContainer? sectionsContainer;
|
|
|
|
|
private ProfileSectionTabControl? tabs;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-12-22 23:51:24 +08:00
|
|
|
|
public const float CONTENT_X_MARGIN = 70;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-24 17:24:35 +08:00
|
|
|
|
public UserProfileOverlay()
|
2021-01-18 15:48:12 +08:00
|
|
|
|
: base(OverlayColourScheme.Pink)
|
2020-01-24 17:24:35 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 15:48:12 +08:00
|
|
|
|
protected override ProfileHeader CreateHeader() => new ProfileHeader();
|
|
|
|
|
|
2021-02-09 17:32:44 +08:00
|
|
|
|
protected override Color4 BackgroundColour => ColourProvider.Background6;
|
2021-01-18 15:48:12 +08:00
|
|
|
|
|
2021-11-05 12:52:42 +08:00
|
|
|
|
public void ShowUser(IUser user)
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2022-03-28 21:50:31 +08:00
|
|
|
|
if (user.OnlineID == APIUser.SYSTEM_USER_ID)
|
2019-06-05 00:33:55 +08:00
|
|
|
|
return;
|
2018-09-13 12:40:46 +08:00
|
|
|
|
|
2018-09-05 09:23:23 +08:00
|
|
|
|
Show();
|
|
|
|
|
|
2022-12-30 21:56:19 +08:00
|
|
|
|
if (user.OnlineID == Header?.UserProfile.Value?.User.Id)
|
2018-09-05 09:23:23 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-09-03 16:11:34 +08:00
|
|
|
|
if (sectionsContainer != null)
|
|
|
|
|
sectionsContainer.ExpandableHeader = null;
|
|
|
|
|
|
2017-06-15 22:33:08 +08:00
|
|
|
|
userReq?.Cancel();
|
2017-06-15 20:01:46 +08:00
|
|
|
|
Clear();
|
|
|
|
|
lastSection = null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-09-27 14:46:11 +08:00
|
|
|
|
sections = !user.IsBot
|
|
|
|
|
? new ProfileSection[]
|
2019-09-27 14:32:46 +08:00
|
|
|
|
{
|
|
|
|
|
//new AboutSection(),
|
|
|
|
|
new RecentSection(),
|
|
|
|
|
new RanksSection(),
|
|
|
|
|
//new MedalsSection(),
|
|
|
|
|
new HistoricalSection(),
|
|
|
|
|
new BeatmapsSection(),
|
|
|
|
|
new KudosuSection()
|
2019-09-27 14:46:11 +08:00
|
|
|
|
}
|
2019-11-28 21:41:29 +08:00
|
|
|
|
: Array.Empty<ProfileSection>();
|
2018-09-05 09:23:23 +08:00
|
|
|
|
|
2020-03-26 22:44:22 +08:00
|
|
|
|
tabs = new ProfileSectionTabControl
|
2017-06-07 22:49:14 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-06-09 14:25:23 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-06-07 22:49:14 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-22 06:11:04 +08:00
|
|
|
|
Add(sectionsContainer = new ProfileSectionsContainer
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2020-09-03 15:27:31 +08:00
|
|
|
|
ExpandableHeader = Header,
|
2017-06-09 14:25:23 +08:00
|
|
|
|
FixedHeader = tabs,
|
2017-06-07 22:11:38 +08:00
|
|
|
|
HeaderBackground = new Box
|
|
|
|
|
{
|
2020-01-30 04:37:51 +08:00
|
|
|
|
// this is only visible as the ProfileTabControl background
|
2020-01-30 11:50:15 +08:00
|
|
|
|
Colour = ColourProvider.Background5,
|
2017-06-07 22:11:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both
|
2019-06-05 00:33:55 +08:00
|
|
|
|
},
|
2017-06-25 10:40:45 +08:00
|
|
|
|
});
|
2019-02-22 16:51:39 +08:00
|
|
|
|
sectionsContainer.SelectedSection.ValueChanged += section =>
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
if (lastSection != section.NewValue)
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
lastSection = section.NewValue;
|
2017-06-09 14:25:23 +08:00
|
|
|
|
tabs.Current.Value = lastSection;
|
2017-05-25 02:11:07 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
|
tabs.Current.ValueChanged += section =>
|
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;
|
|
|
|
|
}
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
|
if (lastSection != section.NewValue)
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
lastSection = section.NewValue;
|
2017-07-14 22:56:27 +08:00
|
|
|
|
sectionsContainer.ScrollTo(lastSection);
|
2017-05-25 02:11:07 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-05 12:52:42 +08:00
|
|
|
|
sectionsContainer.ScrollToTop();
|
|
|
|
|
|
|
|
|
|
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID) : new GetUserRequest(user.Username);
|
|
|
|
|
userReq.Success += userLoadComplete;
|
|
|
|
|
API.Queue(userReq);
|
2017-06-25 10:40:45 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private void userLoadComplete(APIUser user)
|
2017-06-25 10:40:45 +08:00
|
|
|
|
{
|
2022-12-30 20:17:59 +08:00
|
|
|
|
Debug.Assert(sections != null && sectionsContainer != null && tabs != null);
|
|
|
|
|
|
2022-12-30 21:56:19 +08:00
|
|
|
|
var userProfile = new UserProfile(user);
|
|
|
|
|
Header.UserProfile.Value = userProfile;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-10 23:44:00 +08:00
|
|
|
|
if (user.ProfileOrder != null)
|
2017-06-25 10:40:45 +08:00
|
|
|
|
{
|
2018-03-10 23:44:00 +08:00
|
|
|
|
foreach (string id in user.ProfileOrder)
|
2017-06-22 20:23:49 +08:00
|
|
|
|
{
|
2018-03-10 23:44:00 +08:00
|
|
|
|
var sec = sections.FirstOrDefault(s => s.Identifier == id);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-03-10 23:44:00 +08:00
|
|
|
|
if (sec != null)
|
|
|
|
|
{
|
2022-12-30 21:56:19 +08:00
|
|
|
|
sec.UserProfile.Value = userProfile;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-10 23:44:00 +08:00
|
|
|
|
sectionsContainer.Add(sec);
|
|
|
|
|
tabs.AddItem(sec);
|
|
|
|
|
}
|
2017-06-22 20:23:49 +08:00
|
|
|
|
}
|
2017-06-25 10:40:45 +08:00
|
|
|
|
}
|
2017-05-25 02:11:07 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-26 22:44:22 +08:00
|
|
|
|
private partial class ProfileSectionTabControl : OverlayTabControl<ProfileSection>
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
2020-03-26 22:44:22 +08:00
|
|
|
|
private const float bar_height = 2;
|
|
|
|
|
|
|
|
|
|
public ProfileSectionTabControl()
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
|
|
|
|
TabContainer.RelativeSizeAxes &= ~Axes.X;
|
|
|
|
|
TabContainer.AutoSizeAxes |= Axes.X;
|
|
|
|
|
TabContainer.Anchor |= Anchor.x1;
|
|
|
|
|
TabContainer.Origin |= Anchor.x1;
|
2020-03-26 22:44:22 +08:00
|
|
|
|
|
2020-03-26 23:44:46 +08:00
|
|
|
|
Height = 36 + bar_height;
|
2020-03-26 22:44:22 +08:00
|
|
|
|
BarHeight = bar_height;
|
2017-06-09 14:25:23 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-26 22:44:22 +08:00
|
|
|
|
protected override TabItem<ProfileSection> CreateTabItem(ProfileSection value) => new ProfileSectionTabItem(value)
|
2019-06-18 21:23:57 +08:00
|
|
|
|
{
|
2020-03-26 22:44:22 +08:00
|
|
|
|
AccentColour = AccentColour,
|
2019-06-18 21:23:57 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-18 21:23:57 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-01-30 04:35:17 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2019-06-18 21:23:57 +08:00
|
|
|
|
{
|
2020-01-30 04:35:17 +08:00
|
|
|
|
AccentColour = colourProvider.Highlight1;
|
2019-06-18 21:23:57 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-09-17 03:00:27 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
|
2020-03-26 22:44:22 +08:00
|
|
|
|
private partial class ProfileSectionTabItem : OverlayTabItem
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
2020-03-26 22:44:22 +08:00
|
|
|
|
public ProfileSectionTabItem(ProfileSection value)
|
2019-02-28 12:31:40 +08:00
|
|
|
|
: base(value)
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
|
|
|
|
Text.Text = value.Title;
|
2020-03-26 23:44:46 +08:00
|
|
|
|
Text.Font = Text.Font.With(size: 16);
|
|
|
|
|
Text.Margin = new MarginPadding { Bottom = 10 + bar_height };
|
2020-03-26 22:44:22 +08:00
|
|
|
|
Bar.ExpandedSize = 10;
|
|
|
|
|
Bar.Margin = new MarginPadding { Bottom = bar_height };
|
2017-06-09 14:25:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-22 06:11:04 +08:00
|
|
|
|
private partial class ProfileSectionsContainer : SectionsContainer<ProfileSection>
|
|
|
|
|
{
|
|
|
|
|
public ProfileSectionsContainer()
|
2017-06-09 16:01:16 +08:00
|
|
|
|
{
|
2019-06-22 06:11:04 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-06-09 16:01:16 +08:00
|
|
|
|
}
|
2019-06-22 06:11:04 +08:00
|
|
|
|
|
2020-12-22 23:36:44 +08:00
|
|
|
|
protected override UserTrackingScrollContainer CreateScrollContainer() => new OverlayScrollContainer();
|
2020-04-13 17:23:28 +08:00
|
|
|
|
|
2022-12-07 15:31:24 +08:00
|
|
|
|
// Reverse child ID is required so expanding beatmap panels can appear above sections below them.
|
|
|
|
|
// This can also be done by setting Depth when adding new sections above if using ReverseChildID turns out to have any issues.
|
|
|
|
|
protected override FlowContainer<ProfileSection> CreateScrollContentContainer() => new ReverseChildIDFillFlowContainer<ProfileSection>
|
2019-06-22 06:11:04 +08:00
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
|
};
|
2017-06-09 14:25:23 +08:00
|
|
|
|
}
|
2017-05-25 02:11:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|