1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 19:07:19 +08:00
osu-lazer/osu.Game/Users/UserPanel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.9 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 18:19:50 +09:00
2022-06-17 16:37:17 +09:00
#nullable disable
using System;
2017-05-22 03:11:42 -03:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
2017-05-22 03:11:42 -03:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2017-06-16 16:23:20 +08:00
using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor;
using osu.Game.Graphics.Containers;
2020-03-04 14:58:15 +03:00
using JetBrains.Annotations;
using osu.Game.Online.API.Requests.Responses;
2018-04-13 18:19:50 +09:00
2017-05-22 03:11:42 -03:00
namespace osu.Game.Users
{
2020-03-04 14:58:15 +03:00
public abstract class UserPanel : OsuClickableContainer, IHasContextMenu
2017-05-22 03:11:42 -03:00
{
public readonly APIUser User;
2020-11-02 21:09:47 +09: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>
public new Action Action;
2018-04-13 18:19:50 +09:00
2020-03-16 14:06:42 +09:00
protected Action ViewProfile { get; private set; }
2018-04-13 18:19:50 +09:00
protected Drawable Background { get; private set; }
2020-03-04 14:58:15 +03:00
protected UserPanel(APIUser user)
2022-06-01 21:00:14 +09:00
: base(HoverSampleSet.Button)
2017-05-22 03:11:42 -03:00
{
if (user == null)
throw new ArgumentNullException(nameof(user));
2018-04-13 18:19:50 +09:00
User = user;
2018-01-06 11:27:17 +01:00
}
2018-04-13 18:19:50 +09:00
2020-03-04 14:58:15 +03:00
[Resolved(canBeNull: true)]
private UserProfileOverlay profileOverlay { get; set; }
2020-03-05 01:41:55 +03:00
[Resolved(canBeNull: true)]
2020-07-18 20:24:38 +03:00
protected OverlayColourProvider ColourProvider { get; private set; }
2020-03-05 01:41:55 +03:00
2020-03-04 14:58:15 +03:00
[Resolved]
2020-07-18 20:24:38 +03:00
protected OsuColour Colours { get; private set; }
2020-03-04 14:58:15 +03:00
[BackgroundDependencyLoader]
private void load()
2018-01-06 11:27:17 +01:00
{
2020-03-04 14:58:15 +03:00
Masking = true;
2018-04-13 18:19:50 +09:00
2020-03-04 14:58:15 +03:00
AddRange(new[]
2017-05-22 03:11:42 -03:00
{
2020-03-04 14:58:15 +03:00
new Box
2017-05-22 03:11:42 -03:00
{
2020-03-04 14:58:15 +03:00
RelativeSizeAxes = Axes.Both,
2020-07-18 20:24:38 +03:00
Colour = ColourProvider?.Background5 ?? Colours.Gray1
2017-05-22 03:11:42 -03:00
},
Background = new UserCoverBackground
2017-05-22 03:11:42 -03:00
{
2020-03-04 14:58:15 +03:00
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
User = User,
},
CreateLayout()
});
2018-04-13 18:19:50 +09:00
base.Action = ViewProfile = () =>
{
Action?.Invoke();
2020-11-02 21:09:47 +09:00
profileOverlay?.ShowUser(User);
};
2017-05-25 16:31:56 +09:00
}
2018-04-13 18:19:50 +09:00
2020-03-04 14:58:15 +03:00
[NotNull]
protected abstract Drawable CreateLayout();
protected OsuSpriteText CreateUsername() => new OsuSpriteText
{
2020-03-07 04:05:17 +03:00
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
2020-03-05 02:38:30 +03:00
Shadow = false,
2020-03-04 14:58:15 +03:00
Text = User.Username,
};
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
};
2017-05-22 03:11:42 -03:00
}
}