2020-01-29 21:37:51 +01:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 17:43:03 +09:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-11-28 21:41:29 +08:00
|
|
|
|
using System;
|
2022-12-30 13:17:59 +01: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;
|
2023-11-20 01:15:26 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-12-30 17:53:50 +01:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2017-06-05 21:04:35 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-06-22 01:11:04 +03:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-21 17:03:47 +09:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-09 14:25:23 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-09-16 12:00:27 -07:00
|
|
|
|
using osu.Framework.Input.Events;
|
2022-12-30 19:12:50 +01:00
|
|
|
|
using osu.Game.Extensions;
|
2022-12-31 17:17:35 +01:00
|
|
|
|
using osu.Game.Graphics;
|
2017-05-25 02:11:07 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2023-02-07 21:55:01 -08:00
|
|
|
|
using osu.Game.Graphics.Cursor;
|
2022-12-31 17:17:35 +01:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-12-30 20:13:23 +01:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online;
|
2023-11-21 01:55:08 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2017-06-15 22:33:08 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2021-11-04 18:02:44 +09:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2017-06-16 16:36:23 +08:00
|
|
|
|
using osu.Game.Overlays.Profile;
|
2017-07-13 13:53:45 +09:00
|
|
|
|
using osu.Game.Overlays.Profile.Sections;
|
2022-12-30 17:53:50 +01:00
|
|
|
|
using osu.Game.Rulesets;
|
2021-11-05 13:53:00 +09:00
|
|
|
|
using osu.Game.Users;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
2021-01-18 10:48:12 +03:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-06-15 17:03:33 +08:00
|
|
|
|
namespace osu.Game.Overlays
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2020-09-03 16:27:31 +09:00
|
|
|
|
public partial class UserProfileOverlay : FullscreenOverlay<ProfileHeader>
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2022-12-30 20:13:23 +01:00
|
|
|
|
protected override Container<Drawable> Content => onlineViewContainer;
|
|
|
|
|
|
|
|
|
|
private readonly OnlineViewContainer onlineViewContainer;
|
|
|
|
|
private readonly LoadingLayer loadingLayer;
|
|
|
|
|
|
2022-12-30 13:17:59 +01:00
|
|
|
|
private ProfileSection? lastSection;
|
|
|
|
|
private ProfileSection[]? sections;
|
|
|
|
|
private GetUserRequest? userReq;
|
|
|
|
|
private ProfileSectionsContainer? sectionsContainer;
|
|
|
|
|
private ProfileSectionTabControl? tabs;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-11-20 01:15:26 +00:00
|
|
|
|
private IUser? user;
|
|
|
|
|
private IRulesetInfo? ruleset;
|
|
|
|
|
|
2023-11-22 12:02:37 +09:00
|
|
|
|
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
2023-11-20 01:15:26 +00:00
|
|
|
|
|
2022-12-30 17:53:50 +01:00
|
|
|
|
[Resolved]
|
|
|
|
|
private RulesetStore rulesets { get; set; } = null!;
|
|
|
|
|
|
2020-01-24 12:24:35 +03:00
|
|
|
|
public UserProfileOverlay()
|
2021-01-18 10:48:12 +03:00
|
|
|
|
: base(OverlayColourScheme.Pink)
|
2020-01-24 12:24:35 +03:00
|
|
|
|
{
|
2022-12-30 20:13:23 +01:00
|
|
|
|
base.Content.AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
onlineViewContainer = new OnlineViewContainer($"Sign in to view the {Header.Title.Title}")
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
loadingLayer = new LoadingLayer(true)
|
|
|
|
|
});
|
2020-01-24 12:24:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-20 01:15:26 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2023-11-22 12:02:37 +09:00
|
|
|
|
apiState.BindTo(API.State);
|
|
|
|
|
apiState.BindValueChanged(state => Schedule(() =>
|
2023-11-20 01:15:26 +00:00
|
|
|
|
{
|
2023-11-22 12:02:37 +09:00
|
|
|
|
if (state.NewValue == APIState.Online && user != null)
|
2023-11-22 12:03:42 +09:00
|
|
|
|
Scheduler.AddOnce(fetchAndSetContent);
|
2023-11-20 01:15:26 +00:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 10:48:12 +03:00
|
|
|
|
protected override ProfileHeader CreateHeader() => new ProfileHeader();
|
|
|
|
|
|
2022-12-31 16:58:25 +01:00
|
|
|
|
protected override Color4 BackgroundColour => ColourProvider.Background5;
|
2021-01-18 10:48:12 +03:00
|
|
|
|
|
2023-11-20 01:15:26 +00:00
|
|
|
|
public void ShowUser(IUser userToShow, IRulesetInfo? userRuleset = null)
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2023-11-20 01:15:26 +00:00
|
|
|
|
if (userToShow.OnlineID == APIUser.SYSTEM_USER_ID)
|
2019-06-04 19:33:55 +03:00
|
|
|
|
return;
|
2018-09-13 13:40:46 +09:00
|
|
|
|
|
2023-11-20 01:15:26 +00:00
|
|
|
|
user = userToShow;
|
|
|
|
|
ruleset = userRuleset;
|
|
|
|
|
|
2018-09-05 10:23:23 +09:00
|
|
|
|
Show();
|
2023-11-22 12:03:42 +09:00
|
|
|
|
Scheduler.AddOnce(fetchAndSetContent);
|
2023-11-20 01:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fetchAndSetContent()
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(user != null);
|
|
|
|
|
|
2023-01-11 19:11:40 +01:00
|
|
|
|
if (user.OnlineID == Header.User.Value?.User.Id && ruleset?.MatchesOnlineID(Header.User.Value?.Ruleset) == true)
|
2018-09-05 10:23:23 +09:00
|
|
|
|
return;
|
|
|
|
|
|
2024-07-14 15:19:26 +03:00
|
|
|
|
if (sectionsContainer != null)
|
|
|
|
|
sectionsContainer.ExpandableHeader = null;
|
2020-09-03 17:11:34 +09:00
|
|
|
|
|
2017-06-15 22:33:08 +08:00
|
|
|
|
userReq?.Cancel();
|
2017-06-15 20:01:46 +08:00
|
|
|
|
lastSection = null;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-09-27 09:46:11 +03:00
|
|
|
|
sections = !user.IsBot
|
|
|
|
|
? new ProfileSection[]
|
2019-09-27 09:32:46 +03:00
|
|
|
|
{
|
|
|
|
|
//new AboutSection(),
|
|
|
|
|
new RecentSection(),
|
|
|
|
|
new RanksSection(),
|
|
|
|
|
//new MedalsSection(),
|
|
|
|
|
new HistoricalSection(),
|
|
|
|
|
new BeatmapsSection(),
|
|
|
|
|
new KudosuSection()
|
2019-09-27 09:46:11 +03:00
|
|
|
|
}
|
2019-11-28 21:41:29 +08:00
|
|
|
|
: Array.Empty<ProfileSection>();
|
2018-09-05 10:23:23 +09:00
|
|
|
|
|
2024-07-18 00:26:37 +03:00
|
|
|
|
changeOverlayColours(OverlayColourScheme.Pink.GetHue());
|
|
|
|
|
recreateBaseContent();
|
2024-07-13 11:47:36 +03:00
|
|
|
|
|
|
|
|
|
if (API.State.Value != APIState.Offline)
|
2017-06-07 22:49:14 +08:00
|
|
|
|
{
|
2024-07-13 11:47:36 +03:00
|
|
|
|
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID, ruleset) : new GetUserRequest(user.Username, ruleset);
|
|
|
|
|
userReq.Success += u => userLoadComplete(u, ruleset);
|
|
|
|
|
|
|
|
|
|
API.Queue(userReq);
|
|
|
|
|
loadingLayer.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void userLoadComplete(APIUser loadedUser, IRulesetInfo? userRuleset)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(sections != null && sectionsContainer != null && tabs != null);
|
|
|
|
|
|
|
|
|
|
// reuse header and content if same colour scheme, otherwise recreate both.
|
2024-07-18 00:05:44 +03:00
|
|
|
|
int profileHue = loadedUser.ProfileHue ?? OverlayColourScheme.Pink.GetHue();
|
2024-07-18 00:26:37 +03:00
|
|
|
|
|
|
|
|
|
if (changeOverlayColours(profileHue))
|
|
|
|
|
recreateBaseContent();
|
2024-07-13 11:47:36 +03:00
|
|
|
|
|
|
|
|
|
var actualRuleset = rulesets.GetRuleset(userRuleset?.ShortName ?? loadedUser.PlayMode).AsNonNull();
|
|
|
|
|
|
|
|
|
|
var userProfile = new UserProfileData(loadedUser, actualRuleset);
|
|
|
|
|
Header.User.Value = userProfile;
|
|
|
|
|
|
|
|
|
|
if (loadedUser.ProfileOrder != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (string id in loadedUser.ProfileOrder)
|
|
|
|
|
{
|
|
|
|
|
var sec = sections.FirstOrDefault(s => s.Identifier == id);
|
|
|
|
|
|
|
|
|
|
if (sec != null)
|
|
|
|
|
{
|
|
|
|
|
sec.User.Value = userProfile;
|
|
|
|
|
|
|
|
|
|
sectionsContainer.Add(sec);
|
|
|
|
|
tabs.AddItem(sec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadingLayer.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 00:26:37 +03:00
|
|
|
|
private void recreateBaseContent()
|
2024-07-13 11:47:36 +03:00
|
|
|
|
{
|
|
|
|
|
Child = new OsuContextMenuContainer
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2023-02-07 21:55:01 -08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = sectionsContainer = new ProfileSectionsContainer
|
2017-06-07 22:11:38 +08:00
|
|
|
|
{
|
2023-02-07 21:55:01 -08:00
|
|
|
|
ExpandableHeader = Header,
|
2024-07-13 11:47:36 +03:00
|
|
|
|
FixedHeader = tabs = new ProfileSectionTabControl
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
},
|
2023-02-07 21:55:01 -08:00
|
|
|
|
HeaderBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
// this is only visible as the ProfileTabControl background
|
|
|
|
|
Colour = ColourProvider.Background5,
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
}
|
2024-07-13 11:47:36 +03:00
|
|
|
|
};
|
2023-02-07 21:55:01 -08:00
|
|
|
|
|
2019-02-22 17:51:39 +09:00
|
|
|
|
sectionsContainer.SelectedSection.ValueChanged += section =>
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2019-02-22 17:51:39 +09:00
|
|
|
|
if (lastSection != section.NewValue)
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2019-02-22 17:51:39 +09:00
|
|
|
|
lastSection = section.NewValue;
|
2023-06-07 14:53:37 +09:00
|
|
|
|
tabs.Current.Value = lastSection!;
|
2017-05-25 02:11:07 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-02-22 17:51:39 +09: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 13:31:40 +09:00
|
|
|
|
|
2019-02-22 17:51:39 +09:00
|
|
|
|
if (lastSection != section.NewValue)
|
2017-05-25 02:11:07 +08:00
|
|
|
|
{
|
2019-02-22 17:51:39 +09: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 18:19:50 +09:00
|
|
|
|
|
2024-07-18 00:26:37 +03:00
|
|
|
|
private bool changeOverlayColours(int hue)
|
|
|
|
|
{
|
|
|
|
|
if (hue == ColourProvider.Hue)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ColourProvider.ChangeColourScheme(hue);
|
|
|
|
|
|
|
|
|
|
RecreateHeader();
|
|
|
|
|
UpdateColours();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-31 17:17:35 +01:00
|
|
|
|
private partial class ProfileSectionTabControl : OsuTabControl<ProfileSection>
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
2020-03-26 15:44:22 +01:00
|
|
|
|
public ProfileSectionTabControl()
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
2022-12-31 17:17:35 +01:00
|
|
|
|
Height = 40;
|
2023-04-02 17:11:19 -07:00
|
|
|
|
Padding = new MarginPadding { Horizontal = HORIZONTAL_PADDING };
|
2022-12-31 17:17:35 +01:00
|
|
|
|
TabContainer.Spacing = new Vector2(20);
|
2017-06-09 14:25:23 +08:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-12-31 17:17:35 +01:00
|
|
|
|
protected override TabItem<ProfileSection> CreateTabItem(ProfileSection value) => new ProfileSectionTabItem(value);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-09-16 12:00:27 -07:00
|
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
|
2022-12-31 17:17:35 +01:00
|
|
|
|
private partial class ProfileSectionTabItem : TabItem<ProfileSection>
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
2022-12-31 17:17:35 +01:00
|
|
|
|
private OsuSpriteText text = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
2020-03-26 15:44:22 +01:00
|
|
|
|
public ProfileSectionTabItem(ProfileSection value)
|
2019-02-28 13:31:40 +09:00
|
|
|
|
: base(value)
|
2017-06-09 14:25:23 +08:00
|
|
|
|
{
|
2022-12-31 17:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
|
|
InternalChild = text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = Value.Title
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
updateState();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => updateState();
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
|
|
|
|
text.Font = OsuFont.Default.With(size: 14, weight: Active.Value ? FontWeight.SemiBold : FontWeight.Regular);
|
|
|
|
|
|
|
|
|
|
Colour4 textColour;
|
|
|
|
|
|
|
|
|
|
if (IsHovered)
|
|
|
|
|
textColour = colourProvider.Light1;
|
|
|
|
|
else
|
|
|
|
|
textColour = Active.Value ? colourProvider.Content1 : colourProvider.Light2;
|
|
|
|
|
|
|
|
|
|
text.FadeColour(textColour, 300, Easing.OutQuint);
|
2017-06-09 14:25:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-06-22 01:11:04 +03:00
|
|
|
|
private partial class ProfileSectionsContainer : SectionsContainer<ProfileSection>
|
|
|
|
|
{
|
2023-05-17 15:42:38 +09:00
|
|
|
|
private OverlayScrollContainer scroll = null!;
|
|
|
|
|
|
2019-06-22 01:11:04 +03:00
|
|
|
|
public ProfileSectionsContainer()
|
2017-06-09 16:01:16 +08:00
|
|
|
|
{
|
2019-06-22 01:11:04 +03:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-06-09 16:01:16 +08:00
|
|
|
|
}
|
2019-06-22 01:11:04 +03:00
|
|
|
|
|
2023-05-17 15:42:38 +09:00
|
|
|
|
protected override UserTrackingScrollContainer CreateScrollContainer() => scroll = new OverlayScrollContainer();
|
2020-04-13 12:23:28 +03:00
|
|
|
|
|
2022-12-07 16:31:24 +09: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 01:11:04 +03:00
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-12-31 17:32:20 +01:00
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 },
|
|
|
|
|
Margin = new MarginPadding { Bottom = 10 },
|
2019-06-22 01:11:04 +03:00
|
|
|
|
};
|
2023-05-17 15:42:38 +09:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
// Ensure the scroll-to-top button is displayed above the fixed header.
|
|
|
|
|
AddInternal(scroll.Button.CreateProxy());
|
|
|
|
|
}
|
2017-06-09 14:25:23 +08:00
|
|
|
|
}
|
2017-05-25 02:11:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|