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
|
|
|
|
2017-07-13 05:32:47 +00:00
|
|
|
using System;
|
2017-05-22 06:11:42 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2017-06-20 05:54:23 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-22 06:11:42 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-06-16 08:23:20 +00:00
|
|
|
using osu.Game.Overlays;
|
2017-09-14 06:43:47 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-11-25 17:41:18 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2020-03-04 11:58:15 +00:00
|
|
|
using JetBrains.Annotations;
|
2021-11-04 09:02:44 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-05-22 06:11:42 +00:00
|
|
|
namespace osu.Game.Users
|
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
public abstract class UserPanel : OsuClickableContainer, IHasContextMenu
|
2017-05-22 06:11:42 +00:00
|
|
|
{
|
2021-11-04 09:02:44 +00:00
|
|
|
public readonly APIUser User;
|
2020-02-13 09:59:15 +00:00
|
|
|
|
2020-11-02 12:09:47 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Perform an action in addition to showing the user's profile.
|
|
|
|
/// This should be used to perform auxiliary tasks and not as a primary action for clicking a user panel (to maintain a consistent UX).
|
|
|
|
/// </summary>
|
2017-07-13 05:32:47 +00:00
|
|
|
public new Action Action;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-16 05:06:42 +00:00
|
|
|
protected Action ViewProfile { get; private set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-07-28 11:50:55 +00:00
|
|
|
protected Drawable Background { get; private set; }
|
2020-03-04 11:58:15 +00:00
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
protected UserPanel(APIUser user)
|
2021-07-30 12:23:49 +00:00
|
|
|
: base(HoverSampleSet.Submit)
|
2017-05-22 06:11:42 +00:00
|
|
|
{
|
2017-11-07 21:51:06 +00:00
|
|
|
if (user == null)
|
|
|
|
throw new ArgumentNullException(nameof(user));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-02-13 09:59:15 +00:00
|
|
|
User = user;
|
2018-01-06 10:27:17 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private UserProfileOverlay profileOverlay { get; set; }
|
|
|
|
|
2020-03-04 22:41:55 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
2020-07-18 17:24:38 +00:00
|
|
|
protected OverlayColourProvider ColourProvider { get; private set; }
|
2020-03-04 22:41:55 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
[Resolved]
|
2020-07-18 17:24:38 +00:00
|
|
|
protected OsuColour Colours { get; private set; }
|
2020-03-04 11:58:15 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2018-01-06 10:27:17 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
Masking = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
AddRange(new[]
|
2017-05-22 06:11:42 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
new Box
|
2017-05-22 06:11:42 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-18 17:24:38 +00:00
|
|
|
Colour = ColourProvider?.Background5 ?? Colours.Gray1
|
2017-05-22 06:11:42 +00:00
|
|
|
},
|
2020-07-28 11:50:55 +00:00
|
|
|
Background = new UserCoverBackground
|
2017-05-22 06:11:42 +00:00
|
|
|
{
|
2020-03-04 11:58:15 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
User = User,
|
|
|
|
},
|
|
|
|
CreateLayout()
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-09-14 06:43:47 +00:00
|
|
|
base.Action = ViewProfile = () =>
|
2017-07-13 05:32:47 +00:00
|
|
|
{
|
|
|
|
Action?.Invoke();
|
2020-11-02 12:09:47 +00:00
|
|
|
profileOverlay?.ShowUser(User);
|
2017-07-13 05:32:47 +00:00
|
|
|
};
|
2017-05-25 07:31:56 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-04 11:58:15 +00:00
|
|
|
[NotNull]
|
|
|
|
protected abstract Drawable CreateLayout();
|
|
|
|
|
|
|
|
protected OsuSpriteText CreateUsername() => new OsuSpriteText
|
|
|
|
{
|
2020-03-07 01:05:17 +00:00
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
|
2020-03-04 23:38:30 +00:00
|
|
|
Shadow = false,
|
2020-03-04 11:58:15 +00:00
|
|
|
Text = User.Username,
|
|
|
|
};
|
|
|
|
|
2017-09-14 06:43:47 +00:00
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
|
|
|
|
};
|
2017-05-22 06:11:42 +00:00
|
|
|
}
|
|
|
|
}
|