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
|
|
|
|
|
|
2018-12-18 11:56:16 +08:00
|
|
|
|
using System;
|
2018-05-29 13:42:52 +08:00
|
|
|
|
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;
|
2018-05-29 13:42:52 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-12-17 10:51:28 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2018-05-29 09:11:01 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-12-10 17:00:57 +08:00
|
|
|
|
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;
|
2018-12-11 16:32:01 +08:00
|
|
|
|
using osu.Game.Screens.Multi.Play;
|
|
|
|
|
using osu.Game.Screens.Play;
|
2018-05-29 09:11:01 +08:00
|
|
|
|
using osu.Game.Screens.Select;
|
2018-05-29 13:42:52 +08:00
|
|
|
|
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
|
|
|
|
{
|
2018-05-29 13:42:52 +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>();
|
2018-05-29 13:42:52 +08:00
|
|
|
|
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-05-29 13:42:52 +08:00
|
|
|
|
|
2018-12-18 13:17:20 +08:00
|
|
|
|
public override bool AllowBeatmapRulesetChange => false;
|
2018-05-29 08:01:56 +08:00
|
|
|
|
|
2018-12-18 13:17:20 +08:00
|
|
|
|
protected override Drawable TransitionContent => participants;
|
2018-12-14 16:35:18 +08:00
|
|
|
|
|
2018-05-29 08:01:56 +08:00
|
|
|
|
public override string Title => room.Name.Value;
|
|
|
|
|
|
2018-12-04 16:43:44 +08:00
|
|
|
|
public override string ShortTitle => "room";
|
|
|
|
|
|
2018-12-13 17:38:03 +08:00
|
|
|
|
private readonly Components.Header header;
|
|
|
|
|
private readonly Info info;
|
2018-12-17 10:51:28 +08:00
|
|
|
|
private readonly MatchLeaderboard leaderboard;
|
2018-12-18 11:56:16 +08:00
|
|
|
|
private readonly Action<Screen> pushGameplayScreen;
|
2018-12-13 17:38:03 +08:00
|
|
|
|
|
2018-12-10 17:00:57 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private readonly Room room;
|
|
|
|
|
|
2018-12-06 11:21:30 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
|
2018-12-10 17:00:57 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private APIAccess api { get; set; }
|
|
|
|
|
|
2018-12-18 11:56:16 +08:00
|
|
|
|
public MatchScreen(Room room, Action<Screen> pushGameplayScreen)
|
2018-05-29 08:01:56 +08:00
|
|
|
|
{
|
|
|
|
|
this.room = room;
|
2018-12-18 11:56:16 +08:00
|
|
|
|
this.pushGameplayScreen = pushGameplayScreen;
|
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);
|
|
|
|
|
|
2018-06-06 15:27:53 +08:00
|
|
|
|
RoomSettingsOverlay settings;
|
2018-05-29 09:11:01 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-12-14 13:20:03 +08:00
|
|
|
|
new GridContainer
|
2018-05-29 13:42:52 +08:00
|
|
|
|
{
|
|
|
|
|
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 } },
|
2018-12-14 18:52:03 +08:00
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
participants = new Participants { RelativeSizeAxes = Axes.Both },
|
2018-12-17 10:51:28 +08:00
|
|
|
|
leaderboard = new MatchLeaderboard(room) { RelativeSizeAxes = Axes.Both }
|
2018-12-14 18:52:03 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Distributed),
|
|
|
|
|
new Dimension(GridSizeMode.Relative, 0.5f),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-12-14 13:20:03 +08:00
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension(GridSizeMode.Distributed),
|
|
|
|
|
}
|
2018-05-29 13:42:52 +08:00
|
|
|
|
},
|
2018-06-06 15:27:53 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-12-10 18:20:41 +08:00
|
|
|
|
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
|
2018-12-17 13:44:54 +08:00
|
|
|
|
Child = settings = new RoomSettingsOverlay(room)
|
2018-06-06 15:27:53 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0.9f,
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-05-29 09:11:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-12-14 12:38:27 +08:00
|
|
|
|
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect { Selected = addPlaylistItem });
|
2018-05-29 09:11:01 +08:00
|
|
|
|
|
2018-06-06 15:27:53 +08:00
|
|
|
|
header.Tabs.Current.ValueChanged += t =>
|
|
|
|
|
{
|
2018-12-10 17:00:57 +08:00
|
|
|
|
if (t is SettingsMatchPage)
|
2018-06-06 15:27:53 +08:00
|
|
|
|
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-06-20 16:06:02 +08:00
|
|
|
|
|
2018-12-07 15:20:05 +08:00
|
|
|
|
participants.Users.BindTo(participantsBind);
|
|
|
|
|
participants.MaxParticipants.BindTo(maxParticipantsBind);
|
2018-12-13 17:38:03 +08:00
|
|
|
|
|
2018-12-14 12:38:27 +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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 12:38:27 +08:00
|
|
|
|
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;
|
2018-12-14 12:38:27 +08:00
|
|
|
|
info.Mods.Value = item.RequiredMods;
|
2018-12-13 17:38:03 +08:00
|
|
|
|
|
2018-12-14 14:04:04 +08:00
|
|
|
|
// Todo: item.Beatmap can be null here...
|
2018-12-14 15:11:00 +08:00
|
|
|
|
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == item.BeatmapID) ?? item.Beatmap;
|
2018-12-14 16:35:18 +08:00
|
|
|
|
|
2018-12-18 13:17:20 +08:00
|
|
|
|
// Bypass any beatmap and ruleset restrictions
|
|
|
|
|
var beatmapDisabled = Beatmap.Disabled;
|
|
|
|
|
var rulesetDisabled = Ruleset.Disabled;
|
|
|
|
|
Beatmap.Disabled = false;
|
|
|
|
|
Ruleset.Disabled = false;
|
|
|
|
|
|
|
|
|
|
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
|
|
|
|
|
Beatmap.Value.Mods.Value = item.RequiredMods.ToArray();
|
|
|
|
|
Ruleset.Value = item.Ruleset;
|
2018-12-14 16:35:18 +08:00
|
|
|
|
|
2018-12-18 13:17:20 +08:00
|
|
|
|
Beatmap.Disabled = beatmapDisabled;
|
|
|
|
|
Ruleset.Disabled = rulesetDisabled;
|
2018-12-06 11:21:30 +08:00
|
|
|
|
}
|
2018-12-11 16:32:01 +08:00
|
|
|
|
|
|
|
|
|
private void onStart()
|
|
|
|
|
{
|
|
|
|
|
switch (typeBind.Value)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case GameTypeTimeshift _:
|
2018-12-18 11:56:16 +08:00
|
|
|
|
var player = new TimeshiftPlayer(room.RoomID.Value ?? 0, room.Playlist.First().ID);
|
|
|
|
|
player.Exited += _ => leaderboard.RefreshScores();
|
|
|
|
|
|
|
|
|
|
pushGameplayScreen?.Invoke(new PlayerLoader(player));
|
2018-12-11 16:32:01 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-29 08:01:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|