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

198 lines
7.2 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;
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;
using osu.Framework.Screens;
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>();
public override bool AllowBeatmapRulesetChange => false;
2018-05-29 08:01:56 +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;
public override string ShortTitle => "room";
2018-12-13 17:38:03 +08:00
private readonly Components.Header header;
private readonly Info info;
private readonly MatchLeaderboard leaderboard;
private readonly Action<Screen> pushGameplayScreen;
2018-12-13 17:38:03 +08:00
[Cached]
private readonly Room room;
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved]
private APIAccess api { get; set; }
public MatchScreen(Room room, Action<Screen> pushGameplayScreen)
2018-05-29 08:01:56 +08:00
{
this.room = room;
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);
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 } },
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 },
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),
}
},
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)
{
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...
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == item.BeatmapID) ?? item.Beatmap;
2018-12-14 16:35:18 +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
Beatmap.Disabled = beatmapDisabled;
Ruleset.Disabled = rulesetDisabled;
2018-12-06 11:21:30 +08:00
}
private void onStart()
{
switch (typeBind.Value)
{
default:
case GameTypeTimeshift _:
var player = new TimeshiftPlayer(room.RoomID.Value ?? 0, room.Playlist.First().ID);
player.Exited += _ => leaderboard.RefreshScores();
pushGameplayScreen?.Invoke(new PlayerLoader(player));
break;
}
}
2018-05-29 08:01:56 +08:00
}
}