1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 10:47:24 +08:00
osu-lazer/osu.Game/Screens/Multi/Match/MatchSubScreen.cs

247 lines
10 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-05-29 08:01:56 +08:00
using System;
using System.Linq;
2018-12-06 11:21:30 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-05-29 09:11:01 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Audio;
2018-05-29 09:11:01 +08:00
using osu.Game.Beatmaps;
2018-05-29 08:01:56 +08:00
using osu.Game.Online.Multiplayer;
2018-12-26 15:46:50 +08:00
using osu.Game.Online.Multiplayer.GameTypes;
2019-02-11 18:11:34 +08:00
using osu.Game.Rulesets.Mods;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Multi.Play;
2020-02-14 19:48:09 +08:00
using osu.Game.Screens.Select;
using Footer = osu.Game.Screens.Multi.Match.Components.Footer;
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
{
2019-08-13 16:38:21 +08:00
[Cached(typeof(IPreviewTrackOwner))]
public class MatchSubScreen : MultiplayerSubScreen, IPreviewTrackOwner
2018-05-29 08:01:56 +08:00
{
2019-02-01 14:42:15 +08:00
public override bool DisallowExternalBeatmapRulesetChanges => true;
2019-02-07 18:52:33 +08:00
public override string Title { get; }
2019-02-05 18:00:01 +08:00
2019-01-25 18:32:37 +08:00
public override string ShortTitle => "room";
2019-02-05 18:00:01 +08:00
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<int?> roomId { get; set; }
2018-12-22 13:01:06 +08:00
2019-02-11 18:11:34 +08:00
[Resolved(typeof(Room), nameof(Room.Type))]
private Bindable<GameType> type { get; set; }
2018-12-13 17:38:03 +08:00
2020-02-14 19:48:09 +08:00
[Resolved(typeof(Room), nameof(Room.Playlist))]
private BindableList<PlaylistItem> playlist { get; set; }
2019-02-11 18:11:34 +08:00
[Resolved]
private BeatmapManager beatmapManager { get; set; }
2018-05-29 09:11:01 +08:00
2020-02-14 19:48:09 +08:00
[Resolved(canBeNull: true)]
private Multiplayer multiplayer { get; set; }
2018-12-07 15:20:05 +08:00
protected readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
2020-02-14 19:48:09 +08:00
private LeaderboardChatDisplay leaderboardChatDisplay;
private MatchSettingsOverlay settingsOverlay;
2019-02-11 18:11:34 +08:00
2019-02-12 12:02:33 +08:00
public MatchSubScreen(Room room)
2019-02-11 18:11:34 +08:00
{
2019-02-21 17:56:34 +08:00
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
2019-02-11 18:11:34 +08:00
}
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
new GridContainer
{
2019-02-11 18:11:34 +08:00
RelativeSizeAxes = Axes.Both,
Content = new[]
2018-12-14 13:20:03 +08:00
{
2019-02-11 18:11:34 +08:00
new Drawable[]
2018-12-14 18:52:03 +08:00
{
2020-02-14 19:48:09 +08:00
new Container
2018-12-14 18:52:03 +08:00
{
2019-02-11 18:11:34 +08:00
RelativeSizeAxes = Axes.Both,
2020-02-14 19:48:09 +08:00
Padding = new MarginPadding
2018-12-14 18:52:03 +08:00
{
2020-02-14 19:48:09 +08:00
Horizontal = 105,
Vertical = 20
},
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
2018-12-14 18:52:03 +08:00
{
2020-02-14 19:48:09 +08:00
new Drawable[] { new Components.Header() },
new Drawable[]
2019-02-11 18:11:34 +08:00
{
2020-02-14 19:48:09 +08:00
new Container
{
2020-02-14 19:48:09 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 65 },
Child = new GridContainer
{
ColumnDimensions = new[]
{
new Dimension(minSize: 160),
new Dimension(minSize: 360),
new Dimension(minSize: 400),
},
2020-02-14 19:48:09 +08:00
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 5 },
Child = new OverlinedParticipants(Direction.Vertical) { RelativeSizeAxes = Axes.Both }
2020-02-14 19:48:09 +08:00
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 },
Child = new OverlinedPlaylist(true) // Temporarily always allow selection
{
RelativeSizeAxes = Axes.Both,
SelectedItem = { BindTarget = SelectedItem }
2020-02-14 19:48:09 +08:00
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 5 },
Child = leaderboardChatDisplay = new LeaderboardChatDisplay()
}
},
}
}
2019-02-11 18:11:34 +08:00
}
2020-02-14 19:48:09 +08:00
}
2018-12-14 18:52:03 +08:00
},
2020-02-14 19:48:09 +08:00
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
}
}
2019-02-11 18:11:34 +08:00
}
2018-12-14 18:52:03 +08:00
},
2020-02-14 19:48:09 +08:00
new Drawable[]
{
new Footer
{
OnStart = onStart,
SelectedItem = { BindTarget = SelectedItem }
2020-02-14 19:48:09 +08:00
}
}
2019-02-05 18:00:01 +08:00
},
2019-02-11 18:11:34 +08:00
RowDimensions = new[]
2019-02-05 18:00:01 +08:00
{
2020-02-14 19:48:09 +08:00
new Dimension(),
2019-02-11 18:11:34 +08:00
new Dimension(GridSizeMode.AutoSize),
2019-02-05 18:00:01 +08:00
}
2019-02-11 18:11:34 +08:00
},
2020-02-14 19:48:09 +08:00
settingsOverlay = new MatchSettingsOverlay
2019-02-11 18:11:34 +08:00
{
RelativeSizeAxes = Axes.Both,
2020-02-14 19:48:09 +08:00
EditPlaylist = () => this.Push(new MatchSongSelect()),
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
}
2019-02-11 18:11:34 +08:00
};
}
2018-12-27 17:10:49 +08:00
2019-02-12 12:02:33 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
2020-02-14 19:48:09 +08:00
roomId.BindValueChanged(id =>
{
if (id.NewValue == null)
settingsOverlay.Show();
else
{
2020-02-14 19:48:09 +08:00
settingsOverlay.Hide();
// Set the first playlist item.
// This is scheduled since updating the room and playlist may happen in an arbitrary order (via Room.CopyFrom()).
Schedule(() => SelectedItem.Value = playlist.FirstOrDefault());
}
2020-02-14 19:48:09 +08:00
}, true);
2020-02-13 17:48:28 +08:00
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged));
SelectedItem.Value = playlist.FirstOrDefault();
2020-02-13 17:48:28 +08:00
2020-02-14 19:48:09 +08:00
beatmapManager.ItemAdded += beatmapAdded;
2019-02-12 12:02:33 +08:00
}
public override bool OnExiting(IScreen next)
{
RoomManager?.PartRoom();
Mods.Value = Array.Empty<Mod>();
return base.OnExiting(next);
}
private void selectedItemChanged()
2019-02-12 12:02:33 +08:00
{
2020-02-14 19:48:09 +08:00
updateWorkingBeatmap();
2020-02-13 17:48:28 +08:00
var item = SelectedItem.Value;
2019-02-12 12:02:33 +08:00
2020-02-13 17:48:28 +08:00
Mods.Value = item?.RequiredMods?.ToArray() ?? Array.Empty<Mod>();
2019-06-24 07:09:00 +08:00
2020-02-13 17:48:28 +08:00
if (item?.Ruleset != null)
Ruleset.Value = item.Ruleset.Value;
2020-02-14 19:48:09 +08:00
}
private void updateWorkingBeatmap()
{
var beatmap = SelectedItem.Value?.Beatmap.Value;
2019-06-24 07:09:00 +08:00
2020-02-14 19:48:09 +08:00
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
var localBeatmap = beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID);
2019-08-08 17:25:46 +08:00
2020-02-14 19:48:09 +08:00
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
2019-02-12 12:02:33 +08:00
}
private void beatmapAdded(BeatmapSetInfo model) => Schedule(() =>
2019-02-11 18:11:34 +08:00
{
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
return;
2018-12-27 17:10:49 +08:00
2020-02-14 19:48:09 +08:00
updateWorkingBeatmap();
2019-02-11 18:11:34 +08:00
});
2019-02-11 18:11:34 +08:00
private void onStart()
{
switch (type.Value)
{
2019-02-11 18:11:34 +08:00
default:
case GameTypeTimeshift _:
multiplayer?.Start(() => new TimeshiftPlayer(SelectedItem.Value)
2019-02-11 18:11:34 +08:00
{
2020-02-14 19:48:09 +08:00
Exited = () => leaderboardChatDisplay.RefreshScores()
2019-02-12 10:19:34 +08:00
});
2019-02-11 18:11:34 +08:00
break;
}
2019-02-11 18:11:34 +08:00
}
2018-12-27 17:10:49 +08:00
2019-02-11 18:11:34 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2018-12-27 17:10:49 +08:00
2019-02-11 18:11:34 +08:00
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
2018-12-27 17:10:49 +08:00
}
2018-05-29 08:01:56 +08:00
}
}