1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 13:27:25 +08:00
osu-lazer/osu.Game/Screens/Multi/Match/MatchScreen.cs

159 lines
5.3 KiB
C#
Raw Normal View History

2018-05-29 08:01:56 +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
using System.Collections.Generic;
2018-12-12 13:38:03 +08:00
using System.Linq;
2018-12-06 11:21:30 +08:00
using osu.Framework.Allocation;
2018-05-29 09:11:01 +08:00
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-05-29 09:11:01 +08:00
using osu.Game.Beatmaps;
using osu.Game.Online.API;
2018-05-29 08:01:56 +08:00
using osu.Game.Online.Multiplayer;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Multi.Play;
using osu.Game.Screens.Play;
2018-05-29 09:11:01 +08:00
using osu.Game.Screens.Select;
using osu.Game.Users;
2018-05-29 08:01:56 +08:00
2018-12-10 18:20:41 +08:00
namespace osu.Game.Screens.Multi.Match
2018-05-29 08:01:56 +08:00
{
2018-12-10 18:20:41 +08:00
public class MatchScreen : MultiplayerScreen
2018-05-29 08:01:56 +08:00
{
private readonly Participants participants;
2018-05-29 12:51:04 +08:00
private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
2018-12-13 17:38:03 +08:00
private readonly BindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
2018-12-07 15:20:05 +08:00
protected override Drawable TransitionContent => participants;
2018-05-29 08:01:56 +08:00
public override string Title => room.Name.Value;
public override string ShortTitle => "room";
2018-12-13 17:38:03 +08:00
private readonly Components.Header header;
private readonly Info info;
[Cached]
private readonly Room room;
[Resolved]
private Multiplayer multiplayer { get; set; }
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved]
private APIAccess api { get; set; }
2018-12-10 18:20:41 +08:00
public MatchScreen(Room room)
2018-05-29 08:01:56 +08:00
{
this.room = room;
2018-12-06 11:21:30 +08:00
2018-12-07 15:20:05 +08:00
nameBind.BindTo(room.Name);
statusBind.BindTo(room.Status);
availabilityBind.BindTo(room.Availability);
typeBind.BindTo(room.Type);
participantsBind.BindTo(room.Participants);
maxParticipantsBind.BindTo(room.MaxParticipants);
RoomSettingsOverlay settings;
2018-05-29 09:11:01 +08:00
Children = new Drawable[]
{
2018-12-14 13:20:03 +08:00
new GridContainer
{
RelativeSizeAxes = Axes.Both,
2018-12-14 13:20:03 +08:00
Content = new[]
{
new Drawable[] { header = new Components.Header { Depth = -1 } },
new Drawable[] { info = new Info { OnStart = onStart } },
new Drawable[] { participants = new Participants { RelativeSizeAxes = Axes.Both } },
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
2018-12-10 18:20:41 +08:00
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
Child = settings = new RoomSettingsOverlay
{
RelativeSizeAxes = Axes.Both,
Height = 0.9f,
},
},
2018-05-29 09:11:01 +08:00
};
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect { Selected = addPlaylistItem });
2018-05-29 09:11:01 +08:00
header.Tabs.Current.ValueChanged += t =>
{
if (t is SettingsMatchPage)
settings.Show();
else
settings.Hide();
};
2018-12-07 15:20:05 +08:00
info.Name.BindTo(nameBind);
info.Status.BindTo(statusBind);
info.Availability.BindTo(availabilityBind);
info.Type.BindTo(typeBind);
2018-12-07 15:20:05 +08:00
participants.Users.BindTo(participantsBind);
participants.MaxParticipants.BindTo(maxParticipantsBind);
2018-12-13 17:38:03 +08:00
playlistBind.ItemsAdded += _ => setFromPlaylist();
playlistBind.ItemsRemoved += _ => setFromPlaylist();
2018-05-29 08:01:56 +08:00
}
2018-12-06 11:21:30 +08:00
[BackgroundDependencyLoader]
private void load()
{
2018-12-13 17:38:03 +08:00
playlistBind.BindTo(room.Playlist);
}
private void addPlaylistItem(PlaylistItem item)
{
playlistBind.Clear();
playlistBind.Add(item);
}
private void setFromPlaylist()
2018-12-13 17:38:03 +08:00
{
if (playlistBind.Count == 0)
return;
// For now, only the first playlist item is supported
var item = playlistBind.First();
header.Beatmap.Value = item.Beatmap;
info.Beatmap.Value = item.Beatmap;
info.Mods.Value = item.RequiredMods;
2018-12-13 17:38:03 +08:00
// Todo: item.Beatmap can be null here...
Beatmap.Value = beatmapManager.GetWorkingBeatmap(item.Beatmap);
2018-12-06 11:21:30 +08:00
}
private void onStart()
{
switch (typeBind.Value)
{
default:
case GameTypeTimeshift _:
multiplayer.Push(new PlayerLoader(new TimeshiftPlayer()));
break;
}
}
2018-05-29 08:01:56 +08:00
}
}