2020-12-19 01:37:47 +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.
|
|
|
|
|
2022-07-18 14:30:21 +08:00
|
|
|
using System;
|
2021-02-09 14:54:17 +08:00
|
|
|
using System.Collections.Generic;
|
2021-02-01 16:54:56 +08:00
|
|
|
using System.Linq;
|
2020-12-19 01:37:47 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-10-18 01:58:38 +08:00
|
|
|
using osu.Game.Online;
|
2020-12-19 01:37:47 +08:00
|
|
|
using osu.Game.Online.API;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2022-02-02 17:42:20 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-02-01 16:54:56 +08:00
|
|
|
using osu.Game.Rulesets;
|
2022-07-18 14:30:21 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-02-01 16:54:56 +08:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2020-12-19 01:37:47 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
public partial class ParticipantPanel : MultiplayerRoomComposite, IHasContextMenu
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
public readonly MultiplayerRoomUser User;
|
|
|
|
|
|
|
|
[Resolved]
|
2022-07-18 14:27:55 +08:00
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2020-12-19 01:37:47 +08:00
|
|
|
|
2021-02-01 16:54:56 +08:00
|
|
|
[Resolved]
|
2022-07-18 14:27:55 +08:00
|
|
|
private IRulesetStore rulesets { get; set; } = null!;
|
2021-02-01 16:54:56 +08:00
|
|
|
|
2022-07-18 14:27:55 +08:00
|
|
|
private SpriteIcon crown = null!;
|
2021-07-30 17:11:11 +08:00
|
|
|
|
2022-07-18 14:27:55 +08:00
|
|
|
private OsuSpriteText userRankText = null!;
|
|
|
|
private ModDisplay userModsDisplay = null!;
|
|
|
|
private StateDisplay userStateDisplay = null!;
|
2020-12-19 01:37:47 +08:00
|
|
|
|
2022-07-18 14:27:55 +08:00
|
|
|
private IconButton kickButton = null!;
|
2021-08-11 16:20:47 +08:00
|
|
|
|
2020-12-19 01:37:47 +08:00
|
|
|
public ParticipantPanel(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
User = user;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2020-12-28 13:56:53 +08:00
|
|
|
var user = User.User;
|
2020-12-19 01:37:47 +08:00
|
|
|
|
|
|
|
var backgroundColour = Color4Extensions.FromHex("#33413C");
|
|
|
|
|
2021-08-02 16:07:08 +08:00
|
|
|
InternalChild = new GridContainer
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
ColumnDimensions = new[]
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-03 22:13:12 +08:00
|
|
|
new Dimension(GridSizeMode.Absolute, 18),
|
2021-08-02 16:07:08 +08:00
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
2021-08-11 16:20:47 +08:00
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
2020-12-19 01:37:47 +08:00
|
|
|
},
|
2021-08-02 16:07:08 +08:00
|
|
|
Content = new[]
|
2021-07-30 17:11:11 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
new Drawable[]
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
crown = new SpriteIcon
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Icon = FontAwesome.Solid.Crown,
|
|
|
|
Size = new Vector2(14),
|
|
|
|
Colour = Color4Extensions.FromHex("#F7E65D"),
|
|
|
|
Alpha = 0
|
|
|
|
},
|
2021-08-16 14:26:00 +08:00
|
|
|
new TeamDisplay(User),
|
2021-08-02 16:07:08 +08:00
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
Children = new Drawable[]
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
new Box
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = backgroundColour
|
|
|
|
},
|
|
|
|
new UserCoverBackground
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 0.75f,
|
|
|
|
User = user,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(0), Color4.White.Opacity(0.25f))
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
new UpdateableAvatar
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
User = user
|
|
|
|
},
|
|
|
|
new UpdateableFlag
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-06-16 01:53:04 +08:00
|
|
|
Size = new Vector2(28, 20),
|
2022-07-18 13:40:34 +08:00
|
|
|
CountryCode = user?.CountryCode ?? default
|
2021-08-02 16:07:08 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
|
2022-07-18 14:27:55 +08:00
|
|
|
Text = user?.Username ?? string.Empty
|
2021-08-02 16:07:08 +08:00
|
|
|
},
|
|
|
|
userRankText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Margin = new MarginPadding { Right = 70 },
|
|
|
|
Child = userModsDisplay = new ModDisplay
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
Scale = new Vector2(0.5f),
|
|
|
|
ExpansionMode = ExpansionMode.AlwaysContracted,
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
2021-08-02 16:07:08 +08:00
|
|
|
},
|
|
|
|
userStateDisplay = new StateDisplay
|
2021-02-01 16:54:56 +08:00
|
|
|
{
|
2021-08-02 16:07:08 +08:00
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
2021-02-01 16:54:56 +08:00
|
|
|
}
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
2021-08-11 16:20:47 +08:00
|
|
|
},
|
|
|
|
kickButton = new KickButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Alpha = 0,
|
|
|
|
Margin = new MarginPadding(4),
|
2022-03-30 22:58:30 +08:00
|
|
|
Action = () => Client.KickUser(User.UserID).FireAndForget(),
|
2021-08-11 16:20:47 +08:00
|
|
|
},
|
2021-08-02 16:07:08 +08:00
|
|
|
},
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-26 09:48:55 +08:00
|
|
|
protected override void OnRoomUpdated()
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2020-12-26 09:48:55 +08:00
|
|
|
base.OnRoomUpdated();
|
2020-12-19 01:37:47 +08:00
|
|
|
|
2021-08-11 16:39:23 +08:00
|
|
|
if (Room == null || Client.LocalUser == null)
|
2020-12-19 01:37:47 +08:00
|
|
|
return;
|
|
|
|
|
2020-12-20 17:36:31 +08:00
|
|
|
const double fade_time = 50;
|
|
|
|
|
2022-02-02 17:42:20 +08:00
|
|
|
var currentItem = Playlist.GetCurrentItem();
|
2022-07-18 14:27:55 +08:00
|
|
|
Ruleset? ruleset = currentItem != null ? rulesets.GetRuleset(currentItem.RulesetID)?.CreateInstance() : null;
|
2021-02-09 02:14:12 +08:00
|
|
|
|
2021-12-04 21:55:35 +08:00
|
|
|
int? currentModeRank = ruleset != null ? User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank : null;
|
2021-02-09 02:14:12 +08:00
|
|
|
userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty;
|
|
|
|
|
2021-01-18 16:09:45 +08:00
|
|
|
userStateDisplay.UpdateStatus(User.State, User.BeatmapAvailability);
|
2020-12-19 01:37:47 +08:00
|
|
|
|
2021-10-18 01:58:38 +08:00
|
|
|
if ((User.BeatmapAvailability.State == DownloadState.LocallyAvailable) && (User.State != MultiplayerUserState.Spectating))
|
|
|
|
userModsDisplay.FadeIn(fade_time);
|
|
|
|
else
|
|
|
|
userModsDisplay.FadeOut(fade_time);
|
|
|
|
|
2022-03-18 13:08:45 +08:00
|
|
|
kickButton.Alpha = Client.IsHost && !User.Equals(Client.LocalUser) ? 1 : 0;
|
2022-03-18 12:25:10 +08:00
|
|
|
crown.Alpha = Room.Host?.Equals(User) == true ? 1 : 0;
|
2021-02-05 17:44:26 +08:00
|
|
|
|
|
|
|
// If the mods are updated at the end of the frame, the flow container will skip a reflow cycle: https://github.com/ppy/osu-framework/issues/4187
|
|
|
|
// This looks particularly jarring here, so re-schedule the update to that start of our frame as a fix.
|
2022-07-18 14:30:21 +08:00
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
userModsDisplay.Current.Value = ruleset != null ? User.Mods.Select(m => m.ToMod(ruleset)).ToList() : Array.Empty<Mod>();
|
|
|
|
});
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
|
2022-07-18 14:27:55 +08:00
|
|
|
public MenuItem[]? ContextMenuItems
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Room == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// If the local user is targetted.
|
|
|
|
if (User.UserID == api.LocalUser.Value.Id)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// If the local user is not the host of the room.
|
|
|
|
if (Room.Host?.UserID != api.LocalUser.Value.Id)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
int targetUser = User.UserID;
|
|
|
|
|
|
|
|
return new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("Give host", MenuItemType.Standard, () =>
|
|
|
|
{
|
|
|
|
// Ensure the local user is still host.
|
2021-08-11 16:45:34 +08:00
|
|
|
if (!Client.IsHost)
|
2020-12-19 01:37:47 +08:00
|
|
|
return;
|
|
|
|
|
2022-03-30 22:58:30 +08:00
|
|
|
Client.TransferHost(targetUser).FireAndForget();
|
2021-08-11 16:45:34 +08:00
|
|
|
}),
|
|
|
|
new OsuMenuItem("Kick", MenuItemType.Destructive, () =>
|
|
|
|
{
|
|
|
|
// Ensure the local user is still host.
|
|
|
|
if (!Client.IsHost)
|
|
|
|
return;
|
|
|
|
|
2022-03-30 22:58:30 +08:00
|
|
|
Client.KickUser(targetUser).FireAndForget();
|
2020-12-19 01:37:47 +08:00
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 16:20:47 +08:00
|
|
|
|
|
|
|
public partial class KickButton : IconButton
|
|
|
|
{
|
|
|
|
public KickButton()
|
|
|
|
{
|
|
|
|
Icon = FontAwesome.Solid.UserTimes;
|
2021-08-11 16:45:34 +08:00
|
|
|
TooltipText = "Kick";
|
2021-08-11 16:20:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
IconHoverColour = colours.Red;
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
}
|