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

260 lines
9.9 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;
2018-05-22 11:33:41 +08:00
using System.Collections.Generic;
2018-12-13 17:38:03 +08:00
using System.Linq;
2018-05-11 09:48:07 +08:00
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.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;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Components;
2018-04-13 17:19:50 +08:00
using osu.Game.Users;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2018-12-10 18:20:41 +08:00
namespace osu.Game.Screens.Multi.Lounge.Components
2018-04-13 17:19:50 +08:00
{
2018-05-22 11:33:41 +08:00
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>, IFilterable
2018-04-13 17:19:50 +08:00
{
2018-05-22 11:07:04 +08:00
public const float SELECTION_BORDER_WIDTH = 4;
2018-05-11 09:48:07 +08:00
private const float corner_radius = 5;
2018-05-28 12:02:15 +08:00
private const float transition_duration = 60;
2018-04-13 17:19:50 +08:00
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-12-04 14:26:06 +08:00
public event Action<SelectionState> StateChanged;
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<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
2018-12-13 17:38:03 +08:00
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
2018-04-13 17:19:50 +08:00
2018-12-06 11:21:30 +08:00
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2018-12-13 17:38:03 +08:00
private UpdateableBeatmapBackgroundSprite background;
private BeatmapTitle beatmapTitle;
private ModeTypeInfo modeTypeInfo;
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
2018-04-13 17:19:50 +08:00
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);
}
}
2018-05-22 11:33:41 +08:00
public IEnumerable<string> FilterTerms => new[] { Room.Name.Value };
private bool matchingFilter;
public bool MatchingFilter
{
get { return matchingFilter; }
set
{
matchingFilter = value;
this.FadeTo(MatchingFilter ? 1 : 0, 200);
}
}
2018-04-13 17:19:50 +08:00
public DrawableRoom(Room room)
{
Room = room;
RelativeSizeAxes = Axes.X;
2018-05-22 11:07:04 +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,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2018-05-11 09:48:07 +08:00
Box sideStrip;
OsuSpriteText status;
2018-05-11 09:48:07 +08:00
ParticipantInfo participantInfo;
2018-12-13 17:38:03 +08:00
OsuSpriteText name;
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,
2018-05-22 11:07:04 +08:00
Padding = new MarginPadding(SELECTION_BORDER_WIDTH),
2018-05-11 09:48:07 +08:00
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,
},
2018-12-06 11:21:30 +08:00
new Container
2018-05-11 09:48:07 +08:00
{
RelativeSizeAxes = Axes.Y,
2018-12-06 11:21:30 +08:00
Width = cover_width,
2018-05-11 09:48:07 +08:00
Masking = true,
Margin = new MarginPadding { Left = side_strip_width },
2018-12-06 11:21:30 +08:00
Child = background = new UpdateableBeatmapBackgroundSprite { 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
{
name = new OsuSpriteText { TextSize = 18 },
2018-05-11 09:48:07 +08:00
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",
},
beatmapTitle = new BeatmapTitle
2018-05-11 09:48:07 +08:00
{
TextSize = 14,
Colour = colours.Gray9
2018-05-11 09:48:07 +08:00
},
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
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 })
2018-05-28 12:02:15 +08:00
d.FadeColour(s.GetAppropriateColour(colours), transition_duration);
2018-05-11 09:48:07 +08:00
};
2018-04-13 17:19:50 +08:00
nameBind.BindValueChanged(n => name.Text = n);
2018-05-11 09:48:07 +08:00
nameBind.BindTo(Room.Name);
hostBind.BindTo(Room.Host);
statusBind.BindTo(Room.Status);
typeBind.BindTo(Room.Type);
2018-12-13 17:38:03 +08:00
playlistBind.BindTo(Room.Playlist);
2018-05-11 09:48:07 +08:00
participantsBind.BindTo(Room.Participants);
modeTypeInfo.Type.BindTo(typeBind);
participantInfo.Host.BindTo(hostBind);
participantInfo.Participants.BindTo(participantsBind);
2018-12-13 17:38:03 +08:00
playlistBind.ItemsAdded += _ => updatePlaylist();
playlistBind.ItemsRemoved += _ => updatePlaylist();
updatePlaylist();
2018-04-13 17:19:50 +08:00
}
2018-05-22 11:07:04 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
this.FadeInFromZero(transition_duration);
}
2018-12-13 17:38:03 +08:00
private void updatePlaylist()
{
2018-12-14 11:35:05 +08:00
if (playlistBind.Count == 0)
return;
2018-12-13 17:38:03 +08:00
// For now, only the first playlist item is supported
var item = playlistBind.First();
beatmap.Value = beatmaps.GetWorkingBeatmap(item.Beatmap);
background.Beatmap.Value = item.Beatmap;
modeTypeInfo.Beatmap.Value = item.Beatmap;
beatmapTitle.Beatmap.Value = item.Beatmap;
}
2018-04-13 17:19:50 +08:00
}
}