1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 00:07:24 +08:00
osu-lazer/osu.Game/Screens/Multiplayer/DrawableRoom.cs

299 lines
12 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-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;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer;
using osu.Game.Users;
namespace osu.Game.Screens.Multiplayer
{
2017-05-22 23:44:58 +08:00
public class DrawableRoom : ClickableContainer
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;
private const float ruleset_height = 30;
2017-05-22 11:07:15 +08:00
private readonly Box sideStrip;
2017-06-24 16:05:48 +08:00
private readonly Container coverContainer, rulesetContainer, gameTypeContainer;
2017-05-22 12:01:55 +08:00
private readonly OsuSpriteText name;
private readonly ParticipantInfo participantInfo;
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;
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-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-24 16:05:48 +08:00
Padding = new MarginPadding { Top = content_padding, Bottom = 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",
},
},
},
},
},
2017-06-24 16:05:48 +08:00
new FillFlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Height = ruleset_height,
Direction = FillDirection.Horizontal,
LayoutDuration = transition_duration,
Spacing = new Vector2(5f, 0f),
Children = new[]
{
rulesetContainer = new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
},
gameTypeContainer = new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
},
},
},
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;
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;
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;
typeBind.ValueChanged += displayGameType;
beatmapBind.ValueChanged += displayBeatmap;
statusBind.TriggerChange();
typeBind.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)
{
gameTypeContainer.Children = new[]
{
new DrawableGameType(value)
{
Size = new Vector2(ruleset_height),
},
};
}
2017-05-30 16:12:11 +08:00
private void displayBeatmap(BeatmapInfo 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[]
{
new AsyncLoadWrapper(new BeatmapBackgroundSprite(new OnlineWorkingBeatmap(value, textures, null))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, EasingTypes.Out),
}) { RelativeSizeAxes = Axes.Both }
};
rulesetContainer.FadeIn(transition_duration);
rulesetContainer.Children = new[]
{
new DifficultyIcon(value)
{
Size = new Vector2(ruleset_height),
}
};
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);
rulesetContainer.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
}
}