2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
2017-07-13 13:32:47 +08:00
|
|
|
using System;
|
2022-12-26 01:57:42 +08:00
|
|
|
using System.Collections.Generic;
|
2023-10-03 04:55:53 +08:00
|
|
|
using System.Linq;
|
2017-05-22 14:11:42 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
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;
|
2017-09-14 14:43:47 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-11-26 01:41:18 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-12-26 01:57:42 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2022-12-26 01:57:42 +08:00
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-12-26 02:07:42 +08:00
|
|
|
using osu.Game.Localisation;
|
2023-10-03 04:55:53 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
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
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
public readonly APIUser User;
|
2020-02-13 17:59:15 +08:00
|
|
|
|
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
|
|
|
|
2021-11-04 17:02:44 +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
|
|
|
{
|
2022-12-23 04:27:59 +08:00
|
|
|
ArgumentNullException.ThrowIfNull(user);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-02-13 17:59:15 +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
|
|
|
|
2022-12-26 01:57:42 +08:00
|
|
|
[Resolved]
|
2022-12-26 07:03:08 +08:00
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2022-12-26 01:57:42 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-12-26 07:03:08 +08:00
|
|
|
private ChannelManager? channelManager { get; set; }
|
2022-12-26 01:57:42 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-12-26 07:03:08 +08:00
|
|
|
private ChatOverlay? chatOverlay { get; set; }
|
2022-12-26 01:57:42 +08:00
|
|
|
|
2022-12-26 07:03:08 +08:00
|
|
|
[Resolved]
|
|
|
|
protected OverlayColourProvider? ColourProvider { get; private set; }
|
2020-03-05 06:41:55 +08:00
|
|
|
|
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
|
|
|
|
2023-10-03 04:55:53 +08:00
|
|
|
[Resolved]
|
2023-10-04 14:35:45 +08:00
|
|
|
private MultiplayerClient? multiplayerClient { get; set; }
|
2023-10-03 04:55:53 +08:00
|
|
|
|
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
|
|
|
|
2020-03-04 19:58:15 +08:00
|
|
|
AddRange(new[]
|
2017-05-22 14:11:42 +08:00
|
|
|
{
|
2020-03-04 19:58:15 +08:00
|
|
|
new Box
|
2017-05-22 14:11:42 +08:00
|
|
|
{
|
2020-03-04 19:58:15 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-19 01:24:38 +08:00
|
|
|
Colour = ColourProvider?.Background5 ?? Colours.Gray1
|
2017-05-22 14:11:42 +08:00
|
|
|
},
|
2020-07-28 19:50:55 +08:00
|
|
|
Background = new UserCoverBackground
|
2017-05-22 14:11:42 +08:00
|
|
|
{
|
2020-03-04 19:58:15 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
User = User,
|
|
|
|
},
|
|
|
|
CreateLayout()
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-09-14 14:43:47 +08:00
|
|
|
base.Action = ViewProfile = () =>
|
2017-07-13 13:32:47 +08:00
|
|
|
{
|
|
|
|
Action?.Invoke();
|
2020-11-02 20:09:47 +08:00
|
|
|
profileOverlay?.ShowUser(User);
|
2017-07-13 13:32:47 +08:00
|
|
|
};
|
2017-05-25 15:31:56 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-03-04 19:58:15 +08:00
|
|
|
protected abstract Drawable CreateLayout();
|
|
|
|
|
|
|
|
protected OsuSpriteText CreateUsername() => new OsuSpriteText
|
|
|
|
{
|
2020-03-07 09:05:17 +08:00
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
|
2020-03-05 07:38:30 +08:00
|
|
|
Shadow = false,
|
2020-03-04 19:58:15 +08:00
|
|
|
Text = User.Username,
|
|
|
|
};
|
|
|
|
|
2022-12-26 01:57:42 +08:00
|
|
|
public MenuItem[] ContextMenuItems
|
2017-09-14 14:43:47 +08:00
|
|
|
{
|
2022-12-26 01:57:42 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
List<MenuItem> items = new List<MenuItem>
|
|
|
|
{
|
2022-12-26 02:07:42 +08:00
|
|
|
new OsuMenuItem(ContextMenuStrings.ViewProfile, MenuItemType.Highlighted, ViewProfile)
|
2022-12-26 01:57:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!User.Equals(api.LocalUser.Value))
|
|
|
|
{
|
|
|
|
items.Add(new OsuMenuItem(UsersStrings.CardSendMessage, MenuItemType.Standard, () =>
|
|
|
|
{
|
|
|
|
channelManager?.OpenPrivateChannel(User);
|
|
|
|
chatOverlay?.Show();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2023-10-03 04:55:53 +08:00
|
|
|
if (
|
2023-10-12 16:41:31 +08:00
|
|
|
// TODO: uncomment this once lazer / osu-web is updating online states
|
|
|
|
// User.IsOnline &&
|
2023-10-04 14:35:45 +08:00
|
|
|
multiplayerClient?.Room != null &&
|
2023-10-03 04:55:53 +08:00
|
|
|
multiplayerClient.Room.Users.All(u => u.UserID != User.Id)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
items.Add(new OsuMenuItem(ContextMenuStrings.InvitePlayer, MenuItemType.Standard, () => multiplayerClient.InvitePlayer(User.Id)));
|
|
|
|
}
|
|
|
|
|
2022-12-26 01:57:42 +08:00
|
|
|
return items.ToArray();
|
|
|
|
}
|
|
|
|
}
|
2017-05-22 14:11:42 +08:00
|
|
|
}
|
|
|
|
}
|