1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +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.

167 lines
5.2 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 17:19:50 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2017-05-22 14:11:42 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
2017-05-22 14:11:42 +08: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.Framework.Screens;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Localisation;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens;
using osu.Game.Screens.Play;
using osu.Game.Users.Drawables;
using osuTK;
2018-04-13 17:19:50 +08:00
2017-05-22 14:11:42 +08:00
namespace osu.Game.Users
{
2020-03-04 19:58:15 +08:00
public abstract partial class UserPanel : OsuClickableContainer, IHasContextMenu
2017-05-22 14:11:42 +08:00
{
public readonly APIUser User;
2020-11-02 20:09:47 +08: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>
2022-12-26 07:03:08 +08:00
public new Action? Action;
2018-04-13 17:19:50 +08:00
2022-12-26 07:03:08 +08:00
protected Action ViewProfile { get; private set; } = null!;
2018-04-13 17:19:50 +08:00
2022-12-26 07:03:08 +08:00
protected Drawable Background { get; private set; } = null!;
2020-03-04 19:58:15 +08:00
protected UserPanel(APIUser user)
2022-06-01 20:00:14 +08:00
: base(HoverSampleSet.Button)
2017-05-22 14:11:42 +08:00
{
ArgumentNullException.ThrowIfNull(user);
2018-04-13 17:19:50 +08:00
User = user;
2018-01-06 18:27:17 +08:00
}
2018-04-13 17:19:50 +08:00
2022-12-26 07:03:08 +08:00
[Resolved]
private UserProfileOverlay? profileOverlay { get; set; }
2020-03-04 19:58:15 +08:00
[Resolved]
2022-12-26 07:03:08 +08:00
private IAPIProvider api { get; set; } = null!;
[Resolved]
2022-12-26 07:03:08 +08:00
private ChannelManager? channelManager { get; set; }
[Resolved]
2022-12-26 07:03:08 +08:00
private ChatOverlay? chatOverlay { get; set; }
2022-12-26 07:03:08 +08:00
[Resolved]
protected OverlayColourProvider? ColourProvider { get; private set; }
2020-03-05 06:41:55 +08:00
[Resolved]
private IPerformFromScreenRunner? performer { get; set; }
2020-03-04 19:58:15 +08:00
[Resolved]
2022-12-26 07:03:08 +08:00
protected OsuColour Colours { get; private set; } = null!;
2020-03-04 19:58:15 +08:00
[Resolved]
private MultiplayerClient? multiplayerClient { get; set; }
2020-03-04 19:58:15 +08:00
[BackgroundDependencyLoader]
private void load()
2018-01-06 18:27:17 +08:00
{
2020-03-04 19:58:15 +08:00
Masking = true;
2018-04-13 17:19:50 +08:00
Add(new Box
2017-05-22 14:11:42 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider?.Background5 ?? Colours.Gray1
2020-03-04 19:58:15 +08:00
});
2018-04-13 17:19:50 +08:00
var background = CreateBackground();
if (background != null)
Add(background);
Add(CreateLayout());
base.Action = ViewProfile = () =>
{
Action?.Invoke();
2020-11-02 20:09:47 +08:00
profileOverlay?.ShowUser(User);
};
2017-05-25 15:31:56 +08:00
}
2018-04-13 17:19:50 +08:00
2024-01-17 15:57:22 +08:00
// TODO: this whole api is messy. half these Create methods are expected to by the implementation and half are implictly called.
2020-03-04 19:58:15 +08:00
protected abstract Drawable CreateLayout();
2024-01-03 19:39:48 +08:00
/// <summary>
/// Panel background container. Can be null if a panel doesn't want a background under it's layout
/// </summary>
protected virtual Drawable? CreateBackground() => Background = new UserCoverBackground
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
User = User
};
2024-01-03 19:39:48 +08:00
protected OsuSpriteText CreateUsername() => new OsuSpriteText
{
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
Shadow = false,
Text = User.Username,
};
protected UpdateableAvatar CreateAvatar() => new UpdateableAvatar(User, false);
protected UpdateableFlag CreateFlag() => new UpdateableFlag(User.CountryCode)
{
Size = new Vector2(36, 26),
Action = Action,
};
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>
{
new OsuMenuItem(ContextMenuStrings.ViewProfile, MenuItemType.Highlighted, ViewProfile)
};
if (User.Equals(api.LocalUser.Value))
return items.ToArray();
items.Add(new OsuMenuItem(UsersStrings.CardSendMessage, MenuItemType.Standard, () =>
{
channelManager?.OpenPrivateChannel(User);
chatOverlay?.Show();
}));
if (User.IsOnline)
{
items.Add(new OsuMenuItem(ContextMenuStrings.SpectatePlayer, MenuItemType.Standard, () =>
{
performer?.PerformFromScreen(s => s.Push(new SoloSpectatorScreen(User)));
}));
if (multiplayerClient?.Room?.Users.All(u => u.UserID != User.Id) == true)
{
items.Add(new OsuMenuItem(ContextMenuStrings.InvitePlayer, MenuItemType.Standard, () => multiplayerClient.InvitePlayer(User.Id)));
}
}
return items.ToArray();
}
}
2017-05-22 14:11:42 +08:00
}
}