osu/osu.Game/Screens/Multi/Match/MatchSubScreen.cs

250 lines
9.2 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 00:01:56 +00:00
using System;
2018-12-06 03:21:30 +00:00
using osu.Framework.Allocation;
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables;
2018-05-29 01:11:01 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Audio;
2018-05-29 01:11:01 +00:00
using osu.Game.Beatmaps;
2018-05-29 00:01:56 +00:00
using osu.Game.Online.Multiplayer;
2018-12-26 07:46:50 +00:00
using osu.Game.Online.Multiplayer.GameTypes;
2019-02-11 10:11:34 +00:00
using osu.Game.Rulesets.Mods;
2018-12-10 10:20:41 +00:00
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Multi.Play;
2018-05-29 01:11:01 +00:00
using osu.Game.Screens.Select;
2019-02-11 10:11:34 +00:00
using PlaylistItem = osu.Game.Online.Multiplayer.PlaylistItem;
2018-05-29 00:01:56 +00:00
2018-12-10 10:20:41 +00:00
namespace osu.Game.Screens.Multi.Match
2018-05-29 00:01:56 +00:00
{
2019-08-13 08:38:21 +00:00
[Cached(typeof(IPreviewTrackOwner))]
public class MatchSubScreen : MultiplayerSubScreen, IPreviewTrackOwner
2018-05-29 00:01:56 +00:00
{
2019-02-01 06:42:15 +00:00
public override bool DisallowExternalBeatmapRulesetChanges => true;
2019-02-07 10:52:33 +00:00
public override string Title { get; }
2019-02-05 10:00:01 +00:00
2019-01-25 10:32:37 +00:00
public override string ShortTitle => "room";
2019-02-05 10:00:01 +00:00
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<int?> roomId { get; set; }
2018-12-22 05:01:06 +00:00
2019-02-05 10:00:01 +00:00
[Resolved(typeof(Room), nameof(Room.Name))]
private Bindable<string> name { get; set; }
2018-12-25 08:14:56 +00:00
2019-02-11 10:11:34 +00:00
[Resolved(typeof(Room), nameof(Room.Type))]
private Bindable<GameType> type { get; set; }
2018-12-13 09:38:03 +00:00
2019-02-11 10:11:34 +00:00
[Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; }
2019-02-11 10:11:34 +00:00
[Resolved(typeof(Room))]
protected Bindable<PlaylistItem> CurrentItem { get; private set; }
2018-12-06 03:21:30 +00:00
2019-02-11 10:11:34 +00:00
[Resolved]
private BeatmapManager beatmapManager { get; set; }
2018-05-29 01:11:01 +00:00
[Resolved]
private PreviewTrackManager previewTrackManager { get; set; }
2019-02-11 10:11:34 +00:00
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
2018-12-07 07:20:05 +00:00
2019-02-12 04:02:33 +00:00
private MatchLeaderboard leaderboard;
2019-02-11 10:11:34 +00:00
2019-02-12 04:02:33 +00:00
public MatchSubScreen(Room room)
2019-02-11 10:11:34 +00:00
{
2019-02-21 09:56:34 +00:00
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
2019-02-11 10:11:34 +00:00
}
[BackgroundDependencyLoader]
private void load()
{
MatchChatDisplay chat;
Components.Header header;
Info info;
GridContainer bottomRow;
MatchSettingsOverlay settings;
2019-02-05 10:00:01 +00:00
2019-02-11 10:11:34 +00:00
InternalChildren = new Drawable[]
{
new GridContainer
{
2019-02-11 10:11:34 +00:00
RelativeSizeAxes = Axes.Both,
Content = new[]
2018-12-14 05:20:03 +00:00
{
2019-02-11 10:11:34 +00:00
new Drawable[]
2018-12-14 10:52:03 +00:00
{
2019-02-11 10:11:34 +00:00
header = new Components.Header
2018-12-14 10:52:03 +00:00
{
2019-02-11 10:11:34 +00:00
Depth = -1,
RequestBeatmapSelection = () =>
2018-12-14 10:52:03 +00:00
{
2019-02-11 10:11:34 +00:00
this.Push(new MatchSongSelect
{
Selected = item =>
{
Playlist.Clear();
Playlist.Add(item);
}
});
2019-02-05 10:00:01 +00:00
}
2019-02-11 10:11:34 +00:00
}
},
new Drawable[] { info = new Info { OnStart = onStart } },
new Drawable[]
{
bottomRow = new GridContainer
2018-12-14 10:52:03 +00:00
{
2019-02-11 10:11:34 +00:00
RelativeSizeAxes = Axes.Both,
Content = new[]
2018-12-14 10:52:03 +00:00
{
2019-02-11 10:11:34 +00:00
new Drawable[]
2018-12-14 10:52:03 +00:00
{
2019-02-11 10:11:34 +00:00
leaderboard = new MatchLeaderboard
{
2019-02-11 10:11:34 +00:00
Padding = new MarginPadding
{
2019-02-11 10:11:34 +00:00
Left = 10 + HORIZONTAL_OVERFLOW_PADDING,
Right = 10,
Vertical = 10,
},
2019-02-11 10:11:34 +00:00
RelativeSizeAxes = Axes.Both
},
new Container
{
Padding = new MarginPadding
{
2019-02-11 10:11:34 +00:00
Left = 10,
Right = 10 + HORIZONTAL_OVERFLOW_PADDING,
Vertical = 10,
},
2019-02-11 10:11:34 +00:00
RelativeSizeAxes = Axes.Both,
Child = chat = new MatchChatDisplay
{
RelativeSizeAxes = Axes.Both
}
},
2018-12-14 10:52:03 +00:00
},
2019-02-11 10:11:34 +00:00
},
}
2018-12-14 10:52:03 +00:00
},
2019-02-05 10:00:01 +00:00
},
2019-02-11 10:11:34 +00:00
RowDimensions = new[]
2019-02-05 10:00:01 +00:00
{
2019-02-11 10:11:34 +00:00
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
2019-02-05 10:00:01 +00:00
}
2019-02-11 10:11:34 +00:00
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both },
},
};
2018-12-13 09:38:03 +00:00
header.Tabs.Current.BindValueChanged(tab =>
2019-02-05 10:00:01 +00:00
{
2019-02-11 10:11:34 +00:00
const float fade_duration = 500;
2019-04-01 03:16:05 +00:00
2019-08-12 07:02:45 +00:00
var settingsDisplayed = tab.NewValue is SettingsMatchPage;
header.ShowBeatmapPanel.Value = !settingsDisplayed;
settings.State.Value = settingsDisplayed ? Visibility.Visible : Visibility.Hidden;
info.FadeTo(settingsDisplayed ? 0 : 1, fade_duration, Easing.OutQuint);
bottomRow.FadeTo(settingsDisplayed ? 0 : 1, fade_duration, Easing.OutQuint);
2019-02-11 10:11:34 +00:00
}, true);
2018-12-22 05:01:06 +00:00
2019-02-11 10:11:34 +00:00
chat.Exit += () =>
2019-02-05 10:00:01 +00:00
{
2019-02-11 10:11:34 +00:00
if (this.IsCurrentScreen())
this.Exit();
};
2018-12-14 08:35:18 +00:00
2019-02-11 10:11:34 +00:00
beatmapManager.ItemAdded += beatmapAdded;
}
2018-12-27 09:10:49 +00:00
2019-02-12 04:02:33 +00:00
protected override void LoadComplete()
{
base.LoadComplete();
CurrentItem.BindValueChanged(currentItemChanged, true);
}
public override bool OnExiting(IScreen next)
{
RoomManager?.PartRoom();
Mods.Value = Array.Empty<Mod>();
previewTrackManager.StopAnyPlaying(this);
return base.OnExiting(next);
}
/// <summary>
/// Handles propagation of the current playlist item's content to game-wide mechanisms.
/// </summary>
2019-02-21 09:56:34 +00:00
private void currentItemChanged(ValueChangedEvent<PlaylistItem> e)
2019-02-12 04:02:33 +00:00
{
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
2019-02-21 09:56:34 +00:00
var localBeatmap = e.NewValue?.Beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == e.NewValue.Beatmap.OnlineBeatmapID);
2019-02-12 04:02:33 +00:00
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
Mods.Value = e.NewValue?.RequiredMods?.ToArray() ?? Array.Empty<Mod>();
2019-06-23 23:09:00 +00:00
2019-02-21 09:56:34 +00:00
if (e.NewValue?.Ruleset != null)
Ruleset.Value = e.NewValue.Ruleset;
2019-08-08 09:25:46 +00:00
previewTrackManager.StopAnyPlaying(this);
2019-02-12 04:02:33 +00:00
}
2019-02-12 02:19:34 +00:00
/// <summary>
/// Handle the case where a beatmap is imported (and can be used by this match).
/// </summary>
private void beatmapAdded(BeatmapSetInfo model) => Schedule(() =>
2019-02-11 10:11:34 +00:00
{
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
return;
2018-12-27 09:10:49 +00:00
if (CurrentItem.Value == null)
2019-02-11 10:11:34 +00:00
return;
2018-12-27 09:10:49 +00:00
2019-02-11 10:11:34 +00:00
// Try to retrieve the corresponding local beatmap
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentItem.Value.Beatmap.OnlineBeatmapID);
2018-12-27 09:10:49 +00:00
2019-02-11 10:11:34 +00:00
if (localBeatmap != null)
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
});
2019-02-12 02:19:34 +00:00
[Resolved(canBeNull: true)]
private Multiplayer multiplayer { get; set; }
2019-02-11 10:11:34 +00:00
private void onStart()
{
previewTrackManager.StopAnyPlaying(this);
2019-08-08 06:52:42 +00:00
2019-02-11 10:11:34 +00:00
switch (type.Value)
{
2019-02-11 10:11:34 +00:00
default:
case GameTypeTimeshift _:
2019-02-21 09:56:34 +00:00
multiplayer?.Start(() => new TimeshiftPlayer(CurrentItem.Value)
2019-02-11 10:11:34 +00:00
{
Exited = () => leaderboard.RefreshScores()
2019-02-12 02:19:34 +00:00
});
2019-02-11 10:11:34 +00:00
break;
}
2019-02-11 10:11:34 +00:00
}
2018-12-27 09:10:49 +00:00
2019-02-11 10:11:34 +00:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2018-12-27 09:10:49 +00:00
2019-02-11 10:11:34 +00:00
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
2018-12-27 09:10:49 +00:00
}
2018-05-29 00:01:56 +00:00
}
}