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.
|
|
|
|
|
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;
|
|
|
|
using osu.Game.Online.API;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-02-01 16:54:56 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
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 class ParticipantPanel : MultiplayerRoomComposite, IHasContextMenu
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
public readonly MultiplayerRoomUser User;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2021-02-01 16:54:56 +08:00
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
2021-02-09 02:14:12 +08:00
|
|
|
private SpriteIcon crown;
|
|
|
|
private OsuSpriteText userRankText;
|
2021-02-01 16:57:32 +08:00
|
|
|
private ModDisplay userModsDisplay;
|
2020-12-22 17:25:45 +08:00
|
|
|
private StateDisplay userStateDisplay;
|
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");
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
crown = new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Icon = FontAwesome.Solid.Crown,
|
|
|
|
Size = new Vector2(14),
|
|
|
|
Colour = Color4Extensions.FromHex("#F7E65D"),
|
|
|
|
Alpha = 0
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Left = 24 },
|
|
|
|
Child = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = backgroundColour
|
|
|
|
},
|
|
|
|
new UserCoverBackground
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 0.75f,
|
2020-12-28 13:56:53 +08:00
|
|
|
User = user,
|
2020-12-19 01:37:47 +08:00
|
|
|
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[]
|
|
|
|
{
|
|
|
|
new UpdateableAvatar
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
FillMode = FillMode.Fit,
|
2020-12-28 13:56:53 +08:00
|
|
|
User = user
|
2020-12-19 01:37:47 +08:00
|
|
|
},
|
|
|
|
new UpdateableFlag
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Size = new Vector2(30, 20),
|
2020-12-28 13:56:53 +08:00
|
|
|
Country = user?.Country
|
2020-12-19 01:37:47 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
|
2020-12-28 13:56:53 +08:00
|
|
|
Text = user?.Username
|
2020-12-19 01:37:47 +08:00
|
|
|
},
|
2021-02-09 02:14:12 +08:00
|
|
|
userRankText = new OsuSpriteText
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-02-01 17:25:09 +08:00
|
|
|
new Container
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2021-02-01 16:54:56 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2021-02-01 17:25:09 +08:00
|
|
|
Margin = new MarginPadding { Right = 70 },
|
|
|
|
Child = userModsDisplay = new ModDisplay
|
2021-02-01 16:54:56 +08:00
|
|
|
{
|
2021-02-01 17:25:09 +08:00
|
|
|
Scale = new Vector2(0.5f),
|
|
|
|
ExpansionMode = ExpansionMode.AlwaysContracted,
|
|
|
|
DisplayUnrankedText = false,
|
2021-02-01 16:54:56 +08:00
|
|
|
}
|
2021-02-01 17:25:09 +08:00
|
|
|
},
|
|
|
|
userStateDisplay = new StateDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
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
|
|
|
|
|
|
|
if (Room == null)
|
|
|
|
return;
|
|
|
|
|
2020-12-20 17:36:31 +08:00
|
|
|
const double fade_time = 50;
|
|
|
|
|
2021-02-09 02:14:12 +08:00
|
|
|
var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID);
|
|
|
|
|
2021-02-16 09:51:21 +08:00
|
|
|
var currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank;
|
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
|
|
|
|
|
|
|
if (Room.Host?.Equals(User) == true)
|
2020-12-20 17:36:31 +08:00
|
|
|
crown.FadeIn(fade_time);
|
2020-12-19 01:37:47 +08:00
|
|
|
else
|
2020-12-20 17:36:31 +08:00
|
|
|
crown.FadeOut(fade_time);
|
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.
|
2021-02-09 02:14:12 +08:00
|
|
|
Schedule(() => userModsDisplay.Current.Value = User.Mods.Select(m => m.ToMod(ruleset.CreateInstance())).ToList());
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
if (Room.Host?.UserID != api.LocalUser.Value.Id)
|
|
|
|
return;
|
|
|
|
|
2021-01-29 15:32:28 +08:00
|
|
|
Client.TransferHost(targetUser);
|
2020-12-19 01:37:47 +08:00
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|