2017-05-22 11:07:15 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
using osu.Framework.Allocation;
|
2017-05-22 12:01:55 +08:00
|
|
|
using osu.Framework.Configuration;
|
2017-05-22 11:07:15 +08:00
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multiplayer
|
|
|
|
{
|
|
|
|
public class DrawableMultiplayerRoom : ClickableContainer
|
|
|
|
{
|
|
|
|
private const float content_padding = 5;
|
|
|
|
private const float height = 90;
|
|
|
|
|
|
|
|
private readonly Box sideStrip;
|
2017-05-22 12:01:55 +08:00
|
|
|
private readonly UpdateableAvatar avatar;
|
|
|
|
private readonly OsuSpriteText name;
|
|
|
|
private readonly Container flagContainer;
|
2017-05-22 11:07:15 +08:00
|
|
|
private readonly OsuSpriteText host;
|
|
|
|
private readonly OsuSpriteText rankBounds;
|
2017-05-22 12:01:55 +08:00
|
|
|
private readonly OsuSpriteText status;
|
2017-05-22 11:07:15 +08:00
|
|
|
private readonly FillFlowContainer<OsuSpriteText> beatmapInfoFlow;
|
|
|
|
private readonly OsuSpriteText beatmapTitle;
|
2017-05-22 12:01:55 +08:00
|
|
|
private readonly OsuSpriteText beatmapDash;
|
2017-05-22 11:07:15 +08:00
|
|
|
private readonly OsuSpriteText beatmapArtist;
|
|
|
|
|
|
|
|
private Color4 openColour;
|
|
|
|
private Color4 playingColour;
|
2017-05-22 12:01:55 +08:00
|
|
|
private LocalisationEngine localisation;
|
2017-05-22 11:07:15 +08:00
|
|
|
|
2017-05-22 12:01:55 +08:00
|
|
|
public readonly Bindable<MultiplayerRoom> Room;
|
2017-05-22 11:07:15 +08:00
|
|
|
|
|
|
|
public DrawableMultiplayerRoom(MultiplayerRoom room)
|
|
|
|
{
|
2017-05-22 12:01:55 +08:00
|
|
|
Room = new Bindable<MultiplayerRoom>(room);
|
2017-05-22 11:07:15 +08:00
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = height;
|
|
|
|
CornerRadius = 5;
|
|
|
|
Masking = true;
|
|
|
|
EdgeEffect = new EdgeEffect
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Colour = Color4.Black.Opacity(40),
|
|
|
|
Radius = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(34),
|
|
|
|
},
|
|
|
|
new Background(@"Backgrounds/bg4")
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
sideStrip = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2017-05-22 12:01:55 +08:00
|
|
|
Width = content_padding,
|
|
|
|
},
|
|
|
|
avatar = new UpdateableAvatar
|
|
|
|
{
|
|
|
|
Size = new Vector2(Height - content_padding* 2),
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5f,
|
|
|
|
Margin = new MarginPadding { Left = content_padding * 2, Top = content_padding },
|
2017-05-22 11:07:15 +08:00
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-05-22 12:01:55 +08:00
|
|
|
Padding = new MarginPadding { Top = content_padding, Bottom = content_padding, Left = Height + content_padding * 2, Right = content_padding },
|
2017-05-22 11:07:15 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(5f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2017-05-22 12:01:55 +08:00
|
|
|
name = new OsuSpriteText
|
2017-05-22 11:07:15 +08:00
|
|
|
{
|
|
|
|
TextSize = 18,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 20f,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2017-05-22 12:01:55 +08:00
|
|
|
flagContainer = new Container
|
2017-05-22 11:07:15 +08:00
|
|
|
{
|
|
|
|
Width = 30f,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Width = 40f,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "hosted by",
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
TextSize = 14,
|
|
|
|
},
|
|
|
|
host = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
TextSize = 14,
|
|
|
|
Font = @"Exo2.0-BoldItalic",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
rankBounds = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2017-05-22 12:01:55 +08:00
|
|
|
Text = "#0 - #0",
|
2017-05-22 11:07:15 +08:00
|
|
|
TextSize = 14,
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-05-22 12:01:55 +08:00
|
|
|
Margin = new MarginPadding { Bottom = content_padding },
|
2017-05-22 11:07:15 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
status = new OsuSpriteText
|
|
|
|
{
|
|
|
|
TextSize = 14,
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
},
|
|
|
|
beatmapInfoFlow = new FillFlowContainer<OsuSpriteText>
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
beatmapTitle = new OsuSpriteText
|
|
|
|
{
|
|
|
|
TextSize = 14,
|
|
|
|
Font = @"Exo2.0-BoldItalic",
|
|
|
|
},
|
2017-05-22 12:01:55 +08:00
|
|
|
beatmapDash = new OsuSpriteText
|
2017-05-22 11:07:15 +08:00
|
|
|
{
|
|
|
|
TextSize = 14,
|
|
|
|
Font = @"Exo2.0-RegularItalic",
|
|
|
|
},
|
|
|
|
beatmapArtist = new OsuSpriteText
|
|
|
|
{
|
|
|
|
TextSize = 14,
|
|
|
|
Font = @"Exo2.0-RegularItalic",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2017-05-22 12:01:55 +08:00
|
|
|
|
|
|
|
Room.ValueChanged += displayRoom;
|
2017-05-22 11:07:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, LocalisationEngine localisation)
|
|
|
|
{
|
2017-05-22 12:01:55 +08:00
|
|
|
this.localisation = localisation;
|
|
|
|
|
2017-05-22 11:07:15 +08:00
|
|
|
openColour = colours.GreenLight;
|
|
|
|
playingColour = colours.Purple;
|
|
|
|
beatmapInfoFlow.Colour = rankBounds.Colour = colours.Gray9;
|
|
|
|
host.Colour = colours.Blue;
|
|
|
|
|
2017-05-22 12:01:55 +08:00
|
|
|
Room.TriggerChange();
|
2017-05-22 11:07:15 +08:00
|
|
|
}
|
|
|
|
|
2017-05-22 12:01:55 +08:00
|
|
|
private void displayRoom(MultiplayerRoom room)
|
2017-05-22 11:07:15 +08:00
|
|
|
{
|
2017-05-22 12:01:55 +08:00
|
|
|
name.Text = room.Name;
|
|
|
|
status.Text = room.Status.GetDescription();
|
|
|
|
host.Text = room.Host.Username;
|
|
|
|
flagContainer.Children = new[] { new DrawableFlag(room.Host.Country?.FlagName ?? @"__") { RelativeSizeAxes = Axes.Both } };
|
|
|
|
avatar.User = room.Host;
|
2017-05-22 11:07:15 +08:00
|
|
|
|
2017-05-22 12:01:55 +08:00
|
|
|
if (room.CurrentBeatmap != null)
|
|
|
|
{
|
|
|
|
beatmapTitle.Current = localisation.GetUnicodePreference(room.CurrentBeatmap.TitleUnicode, room.CurrentBeatmap.Title);
|
|
|
|
beatmapDash.Text = @" - ";
|
|
|
|
beatmapArtist.Current = localisation.GetUnicodePreference(room.CurrentBeatmap.ArtistUnicode, room.CurrentBeatmap.Artist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
beatmapTitle.Current = null;
|
|
|
|
beatmapArtist.Current = null;
|
|
|
|
|
|
|
|
beatmapTitle.Text = @"Changing map";
|
|
|
|
beatmapDash.Text = string.Empty;
|
|
|
|
beatmapArtist.Text = string.Empty;
|
|
|
|
}
|
2017-05-22 11:07:15 +08:00
|
|
|
|
|
|
|
foreach (Drawable d in new Drawable[] { sideStrip, status })
|
2017-05-22 12:01:55 +08:00
|
|
|
d.FadeColour(room.Status == MultiplayerRoomStatus.Playing? playingColour : openColour, 100);
|
2017-05-22 11:07:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|