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;
|
2017-06-20 13:54:23 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-07-13 12:06:46 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-06-24 16:05:48 +08:00
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-05-22 11:07:15 +08:00
|
|
|
using osu.Framework.Localisation;
|
2017-06-24 16:05:48 +08:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2017-05-23 00:05:18 +08:00
|
|
|
using osu.Game.Database;
|
2017-05-22 11:07:15 +08:00
|
|
|
using osu.Game.Graphics;
|
2017-06-27 20:05:49 +08:00
|
|
|
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
|
|
|
|
{
|
2017-06-27 20:05:49 +08:00
|
|
|
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;
|
2017-06-24 16:43:52 +08:00
|
|
|
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;
|
2017-06-24 16:21:42 +08:00
|
|
|
private readonly ParticipantInfo participantInfo;
|
2017-06-24 16:43:52 +08:00
|
|
|
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[]>();
|
|
|
|
|
2017-05-23 08:13:57 +08:00
|
|
|
private OsuColour colours;
|
2017-06-24 16:05:48 +08:00
|
|
|
private TextureStore textures;
|
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,
|
2017-06-25 05:37:28 +08:00
|
|
|
Padding = new MarginPadding
|
|
|
|
{
|
2017-06-25 06:11:02 +08:00
|
|
|
Vertical = content_padding,
|
2017-06-25 05:37:28 +08:00
|
|
|
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,
|
|
|
|
},
|
2017-06-24 16:21:42 +08:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-06-24 16:43:52 +08:00
|
|
|
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]
|
2017-06-24 16:05:48 +08:00
|
|
|
private void load(OsuColour colours, TextureStore textures, LocalisationEngine localisation)
|
2017-05-22 11:07:15 +08:00
|
|
|
{
|
2017-05-22 12:01:55 +08:00
|
|
|
this.localisation = localisation;
|
2017-06-24 16:05:48 +08:00
|
|
|
this.textures = textures;
|
2017-05-23 08:13:57 +08:00
|
|
|
this.colours = colours;
|
2017-05-22 12:01:55 +08:00
|
|
|
|
2017-06-24 16:21:42 +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)
|
|
|
|
{
|
2017-06-24 16:21:42 +08:00
|
|
|
participantInfo.Host = value;
|
2017-05-23 00:05:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displayStatus(RoomStatus value)
|
|
|
|
{
|
2017-05-23 08:13:57 +08:00
|
|
|
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 })
|
2017-05-23 08:13:57 +08:00
|
|
|
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)
|
|
|
|
{
|
2017-06-24 16:43:52 +08:00
|
|
|
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
|
|
|
{
|
2017-06-24 16:43:52 +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);
|
|
|
|
coverContainer.Children = new[]
|
|
|
|
{
|
2017-07-13 12:06:46 +08:00
|
|
|
new AsyncLoadWrapper(new BeatmapSetBackgroundSprite(value.BeatmapSet)
|
2017-06-24 16:05:48 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
OnLoadComplete = d => d.FadeInFromZero(400, EasingTypes.Out),
|
2017-06-24 16:54:00 +08:00
|
|
|
}) { RelativeSizeAxes = Axes.Both },
|
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
|
|
|
{
|
2017-06-24 16:21:42 +08:00
|
|
|
participantInfo.Participants = value;
|
2017-05-25 04:02:28 +08:00
|
|
|
}
|
2017-07-13 12:06:46 +08:00
|
|
|
|
|
|
|
private class BeatmapSetBackgroundSprite : Sprite
|
|
|
|
{
|
|
|
|
private readonly BeatmapSetInfo set;
|
|
|
|
public BeatmapSetBackgroundSprite(BeatmapSetInfo set)
|
|
|
|
{
|
|
|
|
this.set = set;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
{
|
|
|
|
string resource = set.OnlineInfo.Covers.Cover;
|
|
|
|
|
|
|
|
if (resource != null)
|
|
|
|
Texture = textures.Get(resource);
|
|
|
|
}
|
|
|
|
}
|
2017-05-22 11:07:15 +08:00
|
|
|
}
|
|
|
|
}
|