1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 03:57:25 +08:00
osu-lazer/osu.Game/Screens/Multiplayer/DrawableRoom.cs

264 lines
10 KiB
C#
Raw Normal View History

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-06-24 16:05:48 +08:00
using osu.Framework.Configuration;
2017-05-22 11:07:15 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2017-05-22 11:07:15 +08:00
using osu.Framework.Localisation;
2017-07-26 12:22:46 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
2017-05-22 11:07:15 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2017-05-22 11:07:15 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer;
using osu.Game.Users;
namespace osu.Game.Screens.Multiplayer
{
public class DrawableRoom : OsuClickableContainer
2017-05-22 11:07:15 +08:00
{
2017-06-24 16:05:48 +08:00
private const float transition_duration = 100;
private const float content_padding = 10;
private const float height = 100;
private const float side_strip_width = 5;
private const float cover_width = 145;
2017-05-22 11:07:15 +08:00
private readonly Box sideStrip;
private readonly Container coverContainer;
2017-06-24 16:54:00 +08:00
private readonly OsuSpriteText name, status, beatmapTitle, beatmapDash, beatmapArtist;
private readonly FillFlowContainer<OsuSpriteText> beatmapInfoFlow;
private readonly ParticipantInfo participantInfo;
private readonly ModeTypeInfo modeTypeInfo;
2017-05-22 11:07:15 +08:00
2017-06-24 16:05:48 +08:00
private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<User> hostBind = new Bindable<User>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<User[]> participantsBind = new Bindable<User[]>();
private OsuColour colours;
2017-05-22 12:01:55 +08:00
private LocalisationEngine localisation;
2017-05-22 11:07:15 +08:00
2017-05-23 00:05:18 +08:00
public readonly Room Room;
2017-05-22 11:07:15 +08:00
2017-05-22 23:44:58 +08:00
public DrawableRoom(Room room)
2017-05-22 11:07:15 +08:00
{
2017-05-23 00:05:18 +08:00
Room = room;
2017-05-22 11:07:15 +08:00
RelativeSizeAxes = Axes.X;
Height = height;
CornerRadius = 5;
Masking = true;
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
2017-05-22 11:07:15 +08:00
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(40),
Radius = 5,
};
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2017-06-24 16:05:48 +08:00
Colour = OsuColour.FromHex(@"212121"),
2017-05-22 11:07:15 +08:00
},
sideStrip = new Box
{
RelativeSizeAxes = Axes.Y,
2017-06-24 16:05:48 +08:00
Width = side_strip_width,
2017-05-22 12:01:55 +08:00
},
2017-06-24 16:05:48 +08:00
new Container
2017-05-22 12:01:55 +08:00
{
2017-06-24 16:05:48 +08:00
Width = cover_width,
RelativeSizeAxes = Axes.Y,
2017-05-22 12:01:55 +08:00
Masking = true,
2017-06-24 16:05:48 +08:00
Margin = new MarginPadding { Left = side_strip_width },
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
coverContainer = new Container
{
RelativeSizeAxes = Axes.Both,
},
},
2017-05-22 11:07:15 +08:00
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Vertical = content_padding,
Left = side_strip_width + cover_width + content_padding,
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,
},
participantInfo = new ParticipantInfo(),
2017-05-22 11:07:15 +08:00
},
},
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
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,
2017-06-24 16:05:48 +08:00
Font = @"Exo2.0-BoldItalic",
2017-05-22 11:07:15 +08:00
},
beatmapArtist = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-RegularItalic",
},
},
},
},
},
modeTypeInfo = new ModeTypeInfo
2017-06-24 16:05:48 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
},
2017-05-22 11:07:15 +08:00
},
},
};
2017-05-22 12:01:55 +08:00
2017-06-24 16:05:48 +08:00
nameBind.ValueChanged += displayName;
hostBind.ValueChanged += displayUser;
2017-06-24 16:54:00 +08:00
typeBind.ValueChanged += displayGameType;
2017-06-24 16:05:48 +08:00
participantsBind.ValueChanged += displayParticipants;
nameBind.BindTo(Room.Name);
hostBind.BindTo(Room.Host);
statusBind.BindTo(Room.Status);
typeBind.BindTo(Room.Type);
beatmapBind.BindTo(Room.Beatmap);
participantsBind.BindTo(Room.Participants);
2017-05-22 11:07:15 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation)
2017-05-22 11:07:15 +08:00
{
2017-05-22 12:01:55 +08:00
this.localisation = localisation;
this.colours = colours;
2017-05-22 12:01:55 +08:00
beatmapInfoFlow.Colour = colours.Gray9;
2017-05-22 11:07:15 +08:00
2017-06-24 16:05:48 +08:00
//binded here instead of ctor because dependencies are needed
statusBind.ValueChanged += displayStatus;
beatmapBind.ValueChanged += displayBeatmap;
statusBind.TriggerChange();
beatmapBind.TriggerChange();
2017-05-22 11:07:15 +08:00
}
2017-05-23 00:05:18 +08:00
private void displayName(string value)
2017-05-22 11:07:15 +08:00
{
2017-05-23 00:05:18 +08:00
name.Text = value;
}
private void displayUser(User value)
{
participantInfo.Host = value;
2017-05-23 00:05:18 +08:00
}
private void displayStatus(RoomStatus value)
{
if (value == null) return;
status.Text = value.Message;
2017-05-22 11:07:15 +08:00
2017-05-23 00:05:18 +08:00
foreach (Drawable d in new Drawable[] { sideStrip, status })
d.FadeColour(value.GetAppropriateColour(colours), 100);
2017-05-23 00:05:18 +08:00
}
2017-06-24 16:05:48 +08:00
private void displayGameType(GameType value)
{
modeTypeInfo.Type = value;
2017-06-24 16:05:48 +08:00
}
2017-05-30 16:12:11 +08:00
private void displayBeatmap(BeatmapInfo value)
2017-05-23 00:05:18 +08:00
{
modeTypeInfo.Beatmap = value;
2017-05-23 00:05:18 +08:00
if (value != null)
2017-05-22 12:01:55 +08:00
{
2017-06-24 16:05:48 +08:00
coverContainer.FadeIn(transition_duration);
2017-11-22 02:16:44 +08:00
LoadComponentAsync(new BeatmapSetCover(value.BeatmapSet)
2017-06-24 16:05:48 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
},
2017-11-22 02:16:44 +08:00
bsc => coverContainer.Add(bsc));
2017-06-24 16:05:48 +08:00
2017-05-30 16:12:11 +08:00
beatmapTitle.Current = localisation.GetUnicodePreference(value.Metadata.TitleUnicode, value.Metadata.Title);
2017-05-22 12:01:55 +08:00
beatmapDash.Text = @" - ";
2017-05-30 16:12:11 +08:00
beatmapArtist.Current = localisation.GetUnicodePreference(value.Metadata.ArtistUnicode, value.Metadata.Artist);
2017-05-22 12:01:55 +08:00
}
else
{
2017-06-24 16:05:48 +08:00
coverContainer.FadeOut(transition_duration);
2017-05-22 12:01:55 +08:00
beatmapTitle.Current = null;
beatmapArtist.Current = null;
2017-06-24 16:05:48 +08:00
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = string.Empty;
2017-05-22 12:01:55 +08:00
}
2017-05-22 11:07:15 +08:00
}
2017-05-25 04:02:28 +08:00
2017-06-24 16:05:48 +08:00
private void displayParticipants(User[] value)
2017-05-25 04:02:28 +08:00
{
participantInfo.Participants = value;
2017-05-25 04:02:28 +08:00
}
2017-05-22 11:07:15 +08:00
}
}