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

277 lines
12 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-05-11 09:48:07 +08:00
using System;
using osu.Framework;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2018-05-11 09:48:07 +08:00
using osu.Game.Graphics.UserInterface;
2018-04-13 17:19:50 +08:00
using osu.Game.Online.Multiplayer;
using osu.Game.Users;
using OpenTK;
using OpenTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Multi.Components
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
private const float corner_radius = 5;
private const float selection_border_width = 4;
2018-04-13 17:19:50 +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;
2018-05-11 09:48:07 +08:00
private readonly Box selectionBox;
2018-04-13 17:19:50 +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[]>();
public readonly Room Room;
2018-05-11 09:48:07 +08:00
private SelectionState state;
public SelectionState State
{
get { return state; }
set
{
if (value == state) return;
state = value;
if (state == SelectionState.Selected)
selectionBox.FadeIn(transition_duration);
else
selectionBox.FadeOut(transition_duration);
StateChanged?.Invoke(State);
}
}
public event Action<SelectionState> StateChanged;
2018-04-13 17:19:50 +08:00
public DrawableRoom(Room room)
{
Room = room;
RelativeSizeAxes = Axes.X;
2018-05-11 09:48:07 +08:00
Height = height + selection_border_width * 2;
CornerRadius = corner_radius + selection_border_width / 2;
2018-04-13 17:19:50 +08:00
Masking = true;
2018-05-11 09:48:07 +08:00
// create selectionBox here so State can be set before being loaded
selectionBox = new Box
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Alpha = 0f,
};
Action += () => State = SelectionState.Selected;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation)
{
2018-05-11 09:48:07 +08:00
Box sideStrip;
Container coverContainer;
OsuSpriteText name, status, beatmapTitle, beatmapDash, beatmapArtist;
ParticipantInfo participantInfo;
ModeTypeInfo modeTypeInfo;
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
2018-05-11 09:48:07 +08:00
selectionBox,
2018-04-13 17:19:50 +08:00
new Container
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(selection_border_width),
Child = new Container
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = corner_radius,
EdgeEffect = new EdgeEffectParameters
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(40),
Radius = 5,
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
new Box
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"212121"),
},
sideStrip = new Box
{
RelativeSizeAxes = Axes.Y,
Width = side_strip_width,
},
new Container
{
Width = cover_width,
RelativeSizeAxes = Axes.Y,
Masking = true,
Margin = new MarginPadding { Left = side_strip_width },
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
coverContainer = new Container
{
RelativeSizeAxes = Axes.Both,
},
2018-04-13 17:19:50 +08:00
},
},
2018-05-11 09:48:07 +08:00
new Container
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
Vertical = content_padding,
Left = side_strip_width + cover_width + content_padding,
Right = content_padding,
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(5f),
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
name = new OsuSpriteText
{
TextSize = 18,
},
participantInfo = new ParticipantInfo(),
2018-04-13 17:19:50 +08:00
},
2018-05-11 09:48:07 +08:00
},
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
status = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-Bold",
},
new FillFlowContainer<OsuSpriteText>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Colour = colours.Gray9,
Direction = FillDirection.Horizontal,
Children = new[]
{
beatmapTitle = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-BoldItalic",
},
beatmapDash = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-BoldItalic",
},
beatmapArtist = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-RegularItalic",
},
},
},
2018-04-13 17:19:50 +08:00
},
},
2018-05-11 09:48:07 +08:00
modeTypeInfo = new ModeTypeInfo
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
},
2018-04-13 17:19:50 +08:00
},
},
},
},
},
};
2018-05-11 09:48:07 +08:00
nameBind.ValueChanged += n => name.Text = n;
hostBind.ValueChanged += h => participantInfo.Host = h;
typeBind.ValueChanged += m => modeTypeInfo.Type = m;
participantsBind.ValueChanged += p => participantInfo.Participants = p;
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
statusBind.ValueChanged += s =>
{
status.Text = s.Message;
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
foreach (Drawable d in new Drawable[] { selectionBox, sideStrip, status })
d.FadeColour(s.GetAppropriateColour(colours), 100);
};
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
beatmapBind.ValueChanged += b =>
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
modeTypeInfo.Beatmap = b;
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
if (b != null)
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
coverContainer.FadeIn(transition_duration);
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
LoadComponentAsync(new BeatmapSetCover(b.BeatmapSet)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
}, coverContainer.Add);
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
beatmapTitle.Current = localisation.GetUnicodePreference(b.Metadata.TitleUnicode, b.Metadata.Title);
beatmapDash.Text = @" - ";
beatmapArtist.Current = localisation.GetUnicodePreference(b.Metadata.ArtistUnicode, b.Metadata.Artist);
}
else
{
coverContainer.FadeOut(transition_duration);
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
beatmapTitle.Current = null;
beatmapArtist.Current = null;
2018-04-13 17:19:50 +08:00
2018-05-11 09:48:07 +08:00
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = string.Empty;
}
};
nameBind.BindTo(Room.Name);
hostBind.BindTo(Room.Host);
statusBind.BindTo(Room.Status);
typeBind.BindTo(Room.Type);
beatmapBind.BindTo(Room.Beatmap);
participantsBind.BindTo(Room.Participants);
2018-04-13 17:19:50 +08:00
}
}
}