2021-08-02 16:07:08 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2021-09-08 12:45:05 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2021-08-02 16:07:08 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
|
|
|
{
|
|
|
|
internal class TeamDisplay : MultiplayerRoomComposite
|
|
|
|
{
|
2021-08-16 14:26:00 +08:00
|
|
|
private readonly MultiplayerRoomUser user;
|
|
|
|
|
2021-08-02 16:07:08 +08:00
|
|
|
private Drawable box;
|
|
|
|
|
2021-09-08 12:45:05 +08:00
|
|
|
private Sample sampleTeamSwap;
|
|
|
|
|
2021-08-02 16:07:08 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2021-11-10 12:38:02 +08:00
|
|
|
private OsuClickableContainer clickableContent;
|
|
|
|
|
2021-08-16 14:26:00 +08:00
|
|
|
public TeamDisplay(MultiplayerRoomUser user)
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
2021-11-10 12:38:02 +08:00
|
|
|
AutoSizeAxes = Axes.X;
|
2021-08-03 22:13:12 +08:00
|
|
|
|
2021-11-10 12:38:02 +08:00
|
|
|
Margin = new MarginPadding { Horizontal = 3 };
|
2021-08-02 16:07:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-09-08 12:45:05 +08:00
|
|
|
private void load(AudioManager audio)
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
2021-11-10 12:38:02 +08:00
|
|
|
InternalChild = clickableContent = new OsuClickableContainer
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
2021-11-10 12:38:02 +08:00
|
|
|
Width = 15,
|
|
|
|
Alpha = 0,
|
2021-08-02 16:07:08 +08:00
|
|
|
Scale = new Vector2(0, 1),
|
2021-11-10 12:38:02 +08:00
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Child = box = new Container
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-11-10 12:38:02 +08:00
|
|
|
CornerRadius = 5,
|
|
|
|
Masking = true,
|
|
|
|
Scale = new Vector2(0, 1),
|
2021-08-02 16:07:08 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2021-11-10 12:38:02 +08:00
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
}
|
2021-08-02 16:07:08 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-16 14:26:00 +08:00
|
|
|
if (Client.LocalUser?.Equals(user) == true)
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
2021-11-10 12:38:02 +08:00
|
|
|
clickableContent.Action = changeTeam;
|
|
|
|
clickableContent.TooltipText = "Change team";
|
2021-08-02 16:07:08 +08:00
|
|
|
}
|
2021-09-08 12:45:05 +08:00
|
|
|
|
|
|
|
sampleTeamSwap = audio.Samples.Get(@"Multiplayer/team-swap");
|
2021-08-02 16:07:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void changeTeam()
|
|
|
|
{
|
2021-08-16 14:26:00 +08:00
|
|
|
Client.SendMatchRequest(new ChangeTeamRequest
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
2021-08-16 14:26:00 +08:00
|
|
|
TeamID = ((Client.LocalUser?.MatchState as TeamVersusUserState)?.TeamID + 1) % 2 ?? 0,
|
2021-08-02 16:07:08 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-10 12:44:24 +08:00
|
|
|
public int? DisplayedTeam { get; private set; }
|
2021-08-02 16:07:08 +08:00
|
|
|
|
|
|
|
protected override void OnRoomUpdated()
|
|
|
|
{
|
|
|
|
base.OnRoomUpdated();
|
|
|
|
|
|
|
|
// we don't have a way of knowing when an individual user's state has updated, so just handle on RoomUpdated for now.
|
|
|
|
|
2021-08-16 14:26:00 +08:00
|
|
|
var userRoomState = Room?.Users.FirstOrDefault(u => u.Equals(user))?.MatchState;
|
2021-08-02 16:07:08 +08:00
|
|
|
|
|
|
|
const double duration = 400;
|
|
|
|
|
|
|
|
int? newTeam = (userRoomState as TeamVersusUserState)?.TeamID;
|
|
|
|
|
2021-11-10 12:44:24 +08:00
|
|
|
if (newTeam == DisplayedTeam)
|
2021-08-02 16:07:08 +08:00
|
|
|
return;
|
|
|
|
|
2021-09-13 13:12:18 +08:00
|
|
|
// only play the sample if an already valid team changes to another valid team.
|
|
|
|
// this avoids playing a sound for each user if the match type is changed to/from a team mode.
|
2021-11-10 12:44:24 +08:00
|
|
|
if (newTeam != null && DisplayedTeam != null)
|
2021-09-08 12:45:05 +08:00
|
|
|
sampleTeamSwap?.Play();
|
|
|
|
|
2021-11-10 12:44:24 +08:00
|
|
|
DisplayedTeam = newTeam;
|
2021-08-02 16:07:08 +08:00
|
|
|
|
2021-11-10 12:44:24 +08:00
|
|
|
if (DisplayedTeam != null)
|
2021-08-02 16:07:08 +08:00
|
|
|
{
|
2021-11-10 12:44:24 +08:00
|
|
|
box.FadeColour(getColourForTeam(DisplayedTeam.Value), duration, Easing.OutQuint);
|
2021-08-02 16:07:08 +08:00
|
|
|
box.ScaleTo(new Vector2(box.Scale.X < 0 ? 1 : -1, 1), duration, Easing.OutQuint);
|
2021-08-03 22:13:12 +08:00
|
|
|
|
2021-11-10 12:38:02 +08:00
|
|
|
clickableContent.ScaleTo(Vector2.One, duration, Easing.OutQuint);
|
|
|
|
clickableContent.FadeIn(duration);
|
2021-08-02 16:07:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-10 12:38:02 +08:00
|
|
|
clickableContent.ScaleTo(new Vector2(0, 1), duration, Easing.OutQuint);
|
|
|
|
clickableContent.FadeOut(duration);
|
2021-08-02 16:07:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ColourInfo getColourForTeam(int id)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return colours.Red;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return colours.Blue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|