osu/osu.Game/Users/UserPanel.cs

91 lines
2.5 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 09:19:50 +00:00
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
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 11:58:15 +00:00
using JetBrains.Annotations;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Users
{
2020-03-04 11:58:15 +00:00
public abstract class UserPanel : OsuClickableContainer, IHasContextMenu
2018-04-13 09:19:50 +00:00
{
public readonly User User;
2018-04-13 09:19:50 +00:00
public new Action Action;
2020-03-16 05:06:42 +00:00
protected Action ViewProfile { get; private set; }
2018-04-13 09:19:50 +00:00
protected Drawable Background { get; private set; }
2020-03-04 11:58:15 +00:00
protected UserPanel(User user)
2018-04-13 09:19:50 +00:00
{
if (user == null)
throw new ArgumentNullException(nameof(user));
User = user;
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-04-13 09:19:50 +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[]
2018-04-13 09:19:50 +00:00
{
2020-03-04 11:58:15 +00:00
new Box
2018-04-13 09:19:50 +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
2018-04-13 09:19:50 +00:00
},
Background = new UserCoverBackground
2018-04-13 09:19:50 +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
base.Action = ViewProfile = () =>
{
Action?.Invoke();
2020-03-04 11:58:15 +00:00
profileOverlay?.ShowUser(User);
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,
};
2018-04-13 09:19:50 +00:00
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
};
}
}