diff --git a/osu.Game.Tests/Visual/TestCaseMatchResults.cs b/osu.Game.Tests/Visual/TestCaseMatchResults.cs index c34ad0fcbc..33469e74b7 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchResults.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchResults.cs @@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual { } - protected override IEnumerable CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap.Value, room) }; + protected override IEnumerable CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap.Value) }; } private class TestRoomLeaderboardPageInfo : RoomLeaderboardPageInfo diff --git a/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs b/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs index c66052052f..d1d30a7c29 100644 --- a/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs +++ b/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs @@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps.Drawables /// public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable { - public readonly IBindable Beatmap = new Bindable(); + public readonly Bindable Beatmap = new Bindable(); [Resolved] private BeatmapManager beatmaps { get; set; } diff --git a/osu.Game/Online/Multiplayer/Room.cs b/osu.Game/Online/Multiplayer/Room.cs index 0d5b168dcb..2dcc7369f9 100644 --- a/osu.Game/Online/Multiplayer/Room.cs +++ b/osu.Game/Online/Multiplayer/Room.cs @@ -31,6 +31,10 @@ namespace osu.Game.Online.Multiplayer [JsonProperty("playlist")] public BindableList Playlist { get; private set; } = new BindableList(); + [Cached] + [JsonIgnore] + public Bindable CurrentItem { get; private set; } = new Bindable(); + [Cached] [JsonProperty("channel_id")] public Bindable ChannelId { get; private set; } = new Bindable(); @@ -66,6 +70,18 @@ namespace osu.Game.Online.Multiplayer [Cached] public Bindable ParticipantCount { get; private set; } = new Bindable(); + public Room() + { + Playlist.ItemsAdded += updateCurrent; + Playlist.ItemsRemoved += updateCurrent; + updateCurrent(Playlist); + } + + private void updateCurrent(IEnumerable playlist) + { + CurrentItem.Value = playlist.FirstOrDefault(); + } + // todo: TEMPORARY [JsonProperty("participant_count")] private int? participantCount diff --git a/osu.Game/Screens/Multi/Components/BeatmapTitle.cs b/osu.Game/Screens/Multi/Components/BeatmapTitle.cs index dca0545035..ff1a1fb3a4 100644 --- a/osu.Game/Screens/Multi/Components/BeatmapTitle.cs +++ b/osu.Game/Screens/Multi/Components/BeatmapTitle.cs @@ -25,7 +25,7 @@ namespace osu.Game.Screens.Multi.Components [BackgroundDependencyLoader] private void load() { - CurrentBeatmap.BindValueChanged(v => updateText(), true); + CurrentItem.BindValueChanged(v => updateText(), true); } private float textSize = OsuSpriteText.FONT_SIZE; @@ -53,7 +53,9 @@ namespace osu.Game.Screens.Multi.Components textFlow.Clear(); - if (CurrentBeatmap.Value == null) + var beatmap = CurrentItem.Value?.Beatmap; + + if (beatmap == null) textFlow.AddText("No beatmap selected", s => { s.TextSize = TextSize; @@ -65,7 +67,7 @@ namespace osu.Game.Screens.Multi.Components { new OsuSpriteText { - Text = new LocalisedString((CurrentBeatmap.Value.Metadata.ArtistUnicode, CurrentBeatmap.Value.Metadata.Artist)), + Text = new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)), TextSize = TextSize, }, new OsuSpriteText @@ -75,10 +77,10 @@ namespace osu.Game.Screens.Multi.Components }, new OsuSpriteText { - Text = new LocalisedString((CurrentBeatmap.Value.Metadata.TitleUnicode, CurrentBeatmap.Value.Metadata.Title)), + Text = new LocalisedString((beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title)), TextSize = TextSize, } - }, null, LinkAction.OpenBeatmap, CurrentBeatmap.Value.OnlineBeatmapID.ToString(), "Open beatmap"); + }, null, LinkAction.OpenBeatmap, beatmap.OnlineBeatmapID.ToString(), "Open beatmap"); } } } diff --git a/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs b/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs index 3904df2069..4f432a232c 100644 --- a/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs +++ b/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs @@ -51,14 +51,16 @@ namespace osu.Game.Screens.Multi.Components } }; - CurrentBeatmap.BindValueChanged(v => + CurrentItem.BindValueChanged(item => { beatmapAuthor.Clear(); - if (v != null) + var beatmap = item?.Beatmap; + + if (beatmap != null) { beatmapAuthor.AddText("mapped by ", s => s.Colour = OsuColour.Gray(0.8f)); - beatmapAuthor.AddLink(v.Metadata.Author.Username, null, LinkAction.OpenUserProfile, v.Metadata.Author.Id.ToString(), "View Profile"); + beatmapAuthor.AddLink(beatmap.Metadata.Author.Username, null, LinkAction.OpenUserProfile, beatmap.Metadata.Author.Id.ToString(), "View Profile"); } }, true); } diff --git a/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs b/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs index 97ea1b5f36..0d49f75b46 100644 --- a/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs +++ b/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs @@ -5,6 +5,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps.Drawables; +using osu.Game.Online.Multiplayer; using osuTK; namespace osu.Game.Screens.Multi.Components @@ -45,17 +46,17 @@ namespace osu.Game.Screens.Multi.Components }, }; - CurrentBeatmap.BindValueChanged(_ => updateBeatmap()); - CurrentRuleset.BindValueChanged(_ => updateBeatmap(), true); + CurrentItem.BindValueChanged(updateBeatmap, true); + Type.BindValueChanged(v => gameTypeContainer.Child = new DrawableGameType(v) { Size = new Vector2(height) }, true); } - private void updateBeatmap() + private void updateBeatmap(PlaylistItem item) { - if (CurrentBeatmap.Value != null) + if (item?.Beatmap != null) { rulesetContainer.FadeIn(transition_duration); - rulesetContainer.Child = new DifficultyIcon(CurrentBeatmap.Value, CurrentRuleset.Value) { Size = new Vector2(height) }; + rulesetContainer.Child = new DifficultyIcon(item.Beatmap, item.Ruleset) { Size = new Vector2(height) }; } else rulesetContainer.FadeOut(transition_duration); diff --git a/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs b/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs index 8eff7b14af..06d5e585ab 100644 --- a/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs +++ b/osu.Game/Screens/Multi/Components/MultiplayerBackgroundSprite.cs @@ -16,7 +16,7 @@ namespace osu.Game.Screens.Multi.Components InternalChild = sprite = CreateBackgroundSprite(); - sprite.Beatmap.BindTo(CurrentBeatmap); + CurrentItem.BindValueChanged(i => sprite.Beatmap.Value = i?.Beatmap, true); } protected virtual UpdateableBeatmapBackgroundSprite CreateBackgroundSprite() => new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both }; diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index 1229d071ef..71205dc199 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; @@ -23,16 +22,13 @@ namespace osu.Game.Screens.Multi.Lounge protected readonly FilterControl Filter; private readonly Container content; - private readonly Action pushGameplayScreen; private readonly ProcessingOverlay processingOverlay; [Resolved] private Bindable currentRoom { get; set; } - public LoungeSubScreen(Action pushGameplayScreen) + public LoungeSubScreen() { - this.pushGameplayScreen = pushGameplayScreen; - InternalChildren = new Drawable[] { Filter = new FilterControl { Depth = -1 }, @@ -83,8 +79,8 @@ namespace osu.Game.Screens.Multi.Lounge content.Padding = new MarginPadding { Top = Filter.DrawHeight, - Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH + OsuScreen.HORIZONTAL_OVERFLOW_PADDING, - Right = SearchableListOverlay.WIDTH_PADDING + OsuScreen.HORIZONTAL_OVERFLOW_PADDING, + Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH + HORIZONTAL_OVERFLOW_PADDING, + Right = SearchableListOverlay.WIDTH_PADDING + HORIZONTAL_OVERFLOW_PADDING, }; } @@ -114,7 +110,7 @@ namespace osu.Game.Screens.Multi.Lounge private void joinRequested(Room room) { processingOverlay.Show(); - Manager?.JoinRoom(room, r => + RoomManager?.JoinRoom(room, r => { Open(room); processingOverlay.Hide(); @@ -132,7 +128,7 @@ namespace osu.Game.Screens.Multi.Lounge currentRoom.Value = room; - this.Push(new MatchSubScreen(room, s => pushGameplayScreen?.Invoke(s))); + this.Push(new MatchSubScreen(room)); } } } diff --git a/osu.Game/Screens/Multi/Match/Components/Header.cs b/osu.Game/Screens/Multi/Match/Components/Header.cs index 137c0aa939..9a0fdbd4e7 100644 --- a/osu.Game/Screens/Multi/Match/Components/Header.cs +++ b/osu.Game/Screens/Multi/Match/Components/Header.cs @@ -108,7 +108,7 @@ namespace osu.Game.Screens.Multi.Match.Components }, }; - CurrentMods.BindValueChanged(m => modDisplay.Current.Value = m, true); + CurrentItem.BindValueChanged(i => modDisplay.Current.Value = i?.RequiredMods, true); beatmapButton.Action = () => RequestBeatmapSelection?.Invoke(); } diff --git a/osu.Game/Screens/Multi/Match/Components/Info.cs b/osu.Game/Screens/Multi/Match/Components/Info.cs index ec6dbb6d12..b27c5b0ab4 100644 --- a/osu.Game/Screens/Multi/Match/Components/Info.cs +++ b/osu.Game/Screens/Multi/Match/Components/Info.cs @@ -92,8 +92,12 @@ namespace osu.Game.Screens.Multi.Match.Components }, }; - viewBeatmapButton.Beatmap.BindTo(CurrentBeatmap); - readyButton.Beatmap.BindTo(CurrentBeatmap); + CurrentItem.BindValueChanged(item => + { + viewBeatmapButton.Beatmap.Value = item?.Beatmap; + readyButton.Beatmap.Value = item?.Beatmap; + }, true); + hostInfo.Host.BindTo(Host); } } diff --git a/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs b/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs index 0f9c51af6a..50cf2addeb 100644 --- a/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs +++ b/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs @@ -14,7 +14,7 @@ namespace osu.Game.Screens.Multi.Match.Components { public class ReadyButton : HeaderButton { - public readonly IBindable Beatmap = new Bindable(); + public readonly Bindable Beatmap = new Bindable(); [Resolved(typeof(Room), nameof(Room.EndDate))] private Bindable endDate { get; set; } diff --git a/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs b/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs index 9970894ffc..e26a6b7e20 100644 --- a/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs +++ b/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs @@ -11,7 +11,7 @@ namespace osu.Game.Screens.Multi.Match.Components { public class ViewBeatmapButton : HeaderButton { - public readonly IBindable Beatmap = new Bindable(); + public readonly Bindable Beatmap = new Bindable(); [Resolved(CanBeNull = true)] private OsuGame osuGame { get; set; } diff --git a/osu.Game/Screens/Multi/Match/MatchSubScreen.cs b/osu.Game/Screens/Multi/Match/MatchSubScreen.cs index d252ddf0b9..41c498538f 100644 --- a/osu.Game/Screens/Multi/Match/MatchSubScreen.cs +++ b/osu.Game/Screens/Multi/Match/MatchSubScreen.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; @@ -11,11 +12,12 @@ using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer.GameTypes; -using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osu.Game.Screens.Multi.Match.Components; using osu.Game.Screens.Multi.Play; using osu.Game.Screens.Play; using osu.Game.Screens.Select; +using PlaylistItem = osu.Game.Online.Multiplayer.PlaylistItem; namespace osu.Game.Screens.Multi.Match { @@ -33,223 +35,208 @@ namespace osu.Game.Screens.Multi.Match [Resolved(typeof(Room), nameof(Room.Name))] private Bindable name { get; set; } - [Resolved(typeof(Room), nameof(Room.Playlist))] - private BindableList playlist { get; set; } + [Resolved(typeof(Room), nameof(Room.Type))] + private Bindable type { get; set; } - public MatchSubScreen(Room room, Action pushGameplayScreen) + [Resolved(typeof(Room))] + protected BindableList Playlist { get; private set; } + + [Resolved(typeof(Room))] + protected Bindable CurrentItem { get; private set; } + + [Resolved] + protected Bindable> CurrentMods { get; private set; } + + public MatchSubScreen(Room room) { Title = room.RoomID.Value == null ? "New room" : room.Name; + } - InternalChild = new Match(pushGameplayScreen) - { - RelativeSizeAxes = Axes.Both, - RequestBeatmapSelection = () => this.Push(new MatchSongSelect - { - Selected = item => - { - playlist.Clear(); - playlist.Add(item); - }, - }), - RequestExit = () => - { - if (this.IsCurrentScreen()) - this.Exit(); - } - }; + private readonly Action pushGameplayScreen; + + private MatchLeaderboard leaderboard; + + [Resolved] + private BeatmapManager beatmapManager { get; set; } + + [Resolved(CanBeNull = true)] + private OsuGame game { get; set; } + + protected override void LoadComplete() + { + base.LoadComplete(); + + CurrentItem.BindValueChanged(currentItemChanged, true); + } + + private void currentItemChanged(PlaylistItem item) + { + // Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info + var localBeatmap = item?.Beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == item.Beatmap.OnlineBeatmapID); + + Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap); + CurrentMods.Value = item?.RequiredMods ?? Enumerable.Empty(); + if (item?.Ruleset != null) + Ruleset.Value = item.Ruleset; } public override bool OnExiting(IScreen next) { - Manager?.PartRoom(); + RoomManager?.PartRoom(); return base.OnExiting(next); } - private class Match : MultiplayerComposite + [BackgroundDependencyLoader] + private void load() { - public Action RequestBeatmapSelection; - public Action RequestExit; + MatchChatDisplay chat; + Components.Header header; + Info info; + GridContainer bottomRow; + MatchSettingsOverlay settings; - private readonly Action pushGameplayScreen; - - private MatchLeaderboard leaderboard; - - [Resolved] - private IBindableBeatmap gameBeatmap { get; set; } - - [Resolved] - private BeatmapManager beatmapManager { get; set; } - - [Resolved(CanBeNull = true)] - private OsuGame game { get; set; } - - public Match(Action pushGameplayScreen) + InternalChildren = new Drawable[] { - this.pushGameplayScreen = pushGameplayScreen; - } - - [BackgroundDependencyLoader] - private void load() - { - MatchChatDisplay chat; - Components.Header header; - Info info; - GridContainer bottomRow; - MatchSettingsOverlay settings; - - InternalChildren = new Drawable[] + new GridContainer { - new GridContainer + RelativeSizeAxes = Axes.Both, + Content = new[] { - RelativeSizeAxes = Axes.Both, - Content = new[] + new Drawable[] { - new Drawable[] + header = new Components.Header { - header = new Components.Header + Depth = -1, + RequestBeatmapSelection = () => { - Depth = -1, - RequestBeatmapSelection = () => RequestBeatmapSelection?.Invoke() - } - }, - new Drawable[] { info = new Info { OnStart = onStart } }, - new Drawable[] - { - bottomRow = new GridContainer - { - RelativeSizeAxes = Axes.Both, - Content = new[] + this.Push(new MatchSongSelect { - new Drawable[] + Selected = item => { - leaderboard = new MatchLeaderboard + Playlist.Clear(); + Playlist.Add(item); + } + }); + } + } + }, + new Drawable[] { info = new Info { OnStart = onStart } }, + new Drawable[] + { + bottomRow = new GridContainer + { + RelativeSizeAxes = Axes.Both, + Content = new[] + { + new Drawable[] + { + leaderboard = new MatchLeaderboard + { + Padding = new MarginPadding + { + Left = 10 + HORIZONTAL_OVERFLOW_PADDING, + Right = 10, + Vertical = 10, + }, + RelativeSizeAxes = Axes.Both + }, + new Container + { + Padding = new MarginPadding + { + Left = 10, + Right = 10 + HORIZONTAL_OVERFLOW_PADDING, + Vertical = 10, + }, + RelativeSizeAxes = Axes.Both, + Child = chat = new MatchChatDisplay { - Padding = new MarginPadding - { - Left = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING, - Right = 10, - Vertical = 10, - }, RelativeSizeAxes = Axes.Both - }, - new Container - { - Padding = new MarginPadding - { - Left = 10, - Right = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING, - Vertical = 10, - }, - RelativeSizeAxes = Axes.Both, - Child = chat = new MatchChatDisplay - { - RelativeSizeAxes = Axes.Both - } - }, + } }, }, - } - }, + }, + } }, - RowDimensions = new[] - { - new Dimension(GridSizeMode.AutoSize), - new Dimension(GridSizeMode.AutoSize), - new Dimension(GridSizeMode.Distributed), - } }, - new Container + RowDimensions = new[] { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Top = Components.Header.HEIGHT }, - Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both }, - }, - }; - - header.Tabs.Current.BindValueChanged(t => - { - const float fade_duration = 500; - if (t is SettingsMatchPage) - { - settings.Show(); - info.FadeOut(fade_duration, Easing.OutQuint); - bottomRow.FadeOut(fade_duration, Easing.OutQuint); + new Dimension(GridSizeMode.AutoSize), + new Dimension(GridSizeMode.AutoSize), + new Dimension(GridSizeMode.Distributed), } - else - { - settings.Hide(); - info.FadeIn(fade_duration, Easing.OutQuint); - bottomRow.FadeIn(fade_duration, Easing.OutQuint); - } - }, true); - - chat.Exit += () => RequestExit?.Invoke(); - - beatmapManager.ItemAdded += beatmapAdded; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - CurrentBeatmap.BindValueChanged(setBeatmap, true); - CurrentRuleset.BindValueChanged(setRuleset, true); - } - - private void setBeatmap(BeatmapInfo beatmap) - { - // 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); - - game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap)); - } - - private void setRuleset(RulesetInfo ruleset) - { - if (ruleset == null) - return; - - game?.ForcefullySetRuleset(ruleset); - } - - private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() => - { - if (gameBeatmap.Value != beatmapManager.DefaultBeatmap) - return; - - if (CurrentBeatmap.Value == null) - return; - - // Try to retrieve the corresponding local beatmap - var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentBeatmap.Value.OnlineBeatmapID); - - if (localBeatmap != null) - game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap)); - }); - - private void onStart() - { - gameBeatmap.Value.Mods.Value = CurrentMods.Value.ToArray(); - - switch (Type.Value) + }, + new Container { - default: - case GameTypeTimeshift _: - pushGameplayScreen?.Invoke(new PlayerLoader(() => new TimeshiftPlayer(Playlist.First()) - { - Exited = () => leaderboard.RefreshScores() - })); - break; + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Top = Components.Header.HEIGHT }, + Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both }, + }, + }; + + header.Tabs.Current.BindValueChanged(t => + { + const float fade_duration = 500; + if (t is SettingsMatchPage) + { + settings.Show(); + info.FadeOut(fade_duration, Easing.OutQuint); + bottomRow.FadeOut(fade_duration, Easing.OutQuint); } - } + else + { + settings.Hide(); + info.FadeIn(fade_duration, Easing.OutQuint); + bottomRow.FadeIn(fade_duration, Easing.OutQuint); + } + }, true); - protected override void Dispose(bool isDisposing) + chat.Exit += () => { - base.Dispose(isDisposing); + if (this.IsCurrentScreen()) + this.Exit(); + }; - if (beatmapManager != null) - beatmapManager.ItemAdded -= beatmapAdded; + beatmapManager.ItemAdded += beatmapAdded; + } + + private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() => + { + if (Beatmap.Value != beatmapManager.DefaultBeatmap) + return; + + if (Beatmap.Value == null) + return; + + // Try to retrieve the corresponding local beatmap + var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentItem.Value.Beatmap.OnlineBeatmapID); + + if (localBeatmap != null) + Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap); + }); + + private void onStart() + { + //Beatmap.Value.Mods.Value = CurrentMods.Value.ToArray(); + + switch (type.Value) + { + default: + case GameTypeTimeshift _: + pushGameplayScreen?.Invoke(new PlayerLoader(() => new TimeshiftPlayer(CurrentItem) + { + Exited = () => leaderboard.RefreshScores() + })); + break; } } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (beatmapManager != null) + beatmapManager.ItemAdded -= beatmapAdded; + } } } diff --git a/osu.Game/Screens/Multi/Multiplayer.cs b/osu.Game/Screens/Multi/Multiplayer.cs index 42208a2165..7ea4736b04 100644 --- a/osu.Game/Screens/Multi/Multiplayer.cs +++ b/osu.Game/Screens/Multi/Multiplayer.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; using osu.Framework.Screens; -using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; @@ -16,9 +15,7 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Input; using osu.Game.Online.API; using osu.Game.Online.Multiplayer; -using osu.Game.Overlays; using osu.Game.Overlays.BeatmapSet.Buttons; -using osu.Game.Rulesets; using osu.Game.Screens.Menu; using osu.Game.Screens.Multi.Lounge; using osu.Game.Screens.Multi.Lounge.Components; @@ -28,19 +25,9 @@ using osuTK; namespace osu.Game.Screens.Multi { [Cached] - public class Multiplayer : CompositeDrawable, IOsuScreen, IOnlineComponent + public class Multiplayer : OsuScreen, IOnlineComponent { - public bool DisallowExternalBeatmapRulesetChanges => false; - - public bool CursorVisible => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.CursorVisible ?? true; - - public bool HideOverlaysOnEnter => false; - public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All; - - public float BackgroundParallaxAmount => 1; - - public bool ValidForResume { get; set; } = true; - public bool ValidForPush { get; set; } = true; + public override bool CursorVisible => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.CursorVisible ?? true; public override bool RemoveWhenNotAlive => false; @@ -70,20 +57,6 @@ namespace osu.Game.Screens.Multi [Resolved(CanBeNull = true)] private OsuLogo logo { get; set; } - public Bindable Beatmap { get; set; } - - public Bindable Ruleset { get; set; } - - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - var deps = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); - - Beatmap = deps.Beatmap; - Ruleset = deps.Ruleset; - - return deps; - } - public Multiplayer() { Anchor = Anchor.Centre; @@ -95,8 +68,8 @@ namespace osu.Game.Screens.Multi RelativeSizeAxes = Axes.Both, }; - screenStack = new ScreenStack(loungeSubScreen = new LoungeSubScreen(pushGameplayScreen)) { RelativeSizeAxes = Axes.Both }; - Padding = new MarginPadding { Horizontal = -OsuScreen.HORIZONTAL_OVERFLOW_PADDING }; + screenStack = new ScreenStack(loungeSubScreen = new LoungeSubScreen()) { RelativeSizeAxes = Axes.Both }; + Padding = new MarginPadding { Horizontal = -HORIZONTAL_OVERFLOW_PADDING }; waves.AddRange(new Drawable[] { @@ -136,7 +109,7 @@ namespace osu.Game.Screens.Multi Margin = new MarginPadding { Top = 10, - Right = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING, + Right = 10 + HORIZONTAL_OVERFLOW_PADDING, }, Text = "Create room", Action = () => loungeSubScreen.Open(new Room @@ -207,14 +180,14 @@ namespace osu.Game.Screens.Multi } } - public void OnEntering(IScreen last) + public override void OnEntering(IScreen last) { this.FadeIn(); waves.Show(); } - public bool OnExiting(IScreen next) + public override bool OnExiting(IScreen next) { waves.Hide(); @@ -233,17 +206,17 @@ namespace osu.Game.Screens.Multi return false; } - public void OnResuming(IScreen last) + public override void OnResuming(IScreen last) { this.FadeIn(250); this.ScaleTo(1, 250, Easing.OutSine); - logo?.AppendAnimatingAction(() => OsuScreen.ApplyLogoArrivingDefaults(logo), true); + logo?.AppendAnimatingAction(() => ApplyLogoArrivingDefaults(logo), true); updatePollingRate(isIdle.Value); } - public void OnSuspending(IScreen next) + public override void OnSuspending(IScreen next) { this.ScaleTo(1.1f, 250, Easing.InSine); this.FadeOut(250); @@ -254,7 +227,7 @@ namespace osu.Game.Screens.Multi private void cancelLooping() { - var track = beatmap?.Value?.Track; + var track = Beatmap?.Value?.Track; if (track != null) track.Looping = false; diff --git a/osu.Game/Screens/Multi/MultiplayerComposite.cs b/osu.Game/Screens/Multi/MultiplayerComposite.cs index 1a16db97a4..245a6ac358 100644 --- a/osu.Game/Screens/Multi/MultiplayerComposite.cs +++ b/osu.Game/Screens/Multi/MultiplayerComposite.cs @@ -3,14 +3,10 @@ using System; using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; -using osu.Game.Beatmaps; using osu.Game.Online.Multiplayer; -using osu.Game.Rulesets; -using osu.Game.Rulesets.Mods; using osu.Game.Users; namespace osu.Game.Screens.Multi @@ -35,6 +31,9 @@ namespace osu.Game.Screens.Multi [Resolved(typeof(Room))] protected BindableList Playlist { get; private set; } + [Resolved(typeof(Room))] + protected Bindable CurrentItem { get; private set; } + [Resolved(typeof(Room))] protected Bindable> Participants { get; private set; } @@ -52,35 +51,5 @@ namespace osu.Game.Screens.Multi [Resolved(typeof(Room))] protected Bindable Duration { get; private set; } - - private readonly Bindable currentBeatmap = new Bindable(); - protected IBindable CurrentBeatmap => currentBeatmap; - - private readonly Bindable> currentMods = new Bindable>(); - protected IBindable> CurrentMods => currentMods; - - private readonly Bindable currentRuleset = new Bindable(); - protected IBindable CurrentRuleset => currentRuleset; - - protected override void LoadComplete() - { - base.LoadComplete(); - - Playlist.ItemsAdded += _ => updatePlaylist(); - Playlist.ItemsRemoved += _ => updatePlaylist(); - - updatePlaylist(); - } - - private void updatePlaylist() - { - // Todo: We only ever have one playlist item for now. In the future, this will be user-settable - - var playlistItem = Playlist.FirstOrDefault(); - - currentBeatmap.Value = playlistItem?.Beatmap; - currentMods.Value = playlistItem?.RequiredMods ?? Enumerable.Empty(); - currentRuleset.Value = playlistItem?.Ruleset; - } } } diff --git a/osu.Game/Screens/Multi/MultiplayerSubScreen.cs b/osu.Game/Screens/Multi/MultiplayerSubScreen.cs index b0d89c9bba..ad72072981 100644 --- a/osu.Game/Screens/Multi/MultiplayerSubScreen.cs +++ b/osu.Game/Screens/Multi/MultiplayerSubScreen.cs @@ -2,57 +2,27 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Input.Bindings; using osu.Framework.Screens; -using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; using osu.Game.Input.Bindings; -using osu.Game.Overlays; -using osu.Game.Rulesets; namespace osu.Game.Screens.Multi { - public abstract class MultiplayerSubScreen : CompositeDrawable, IMultiplayerSubScreen, IKeyBindingHandler + public abstract class MultiplayerSubScreen : OsuScreen, IMultiplayerSubScreen, IKeyBindingHandler { - public virtual bool DisallowExternalBeatmapRulesetChanges => false; - - public bool CursorVisible => true; - - public bool HideOverlaysOnEnter => false; - public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All; - - public float BackgroundParallaxAmount => 1; - - public bool ValidForResume { get; set; } = true; - public bool ValidForPush { get; set; } = true; + public override bool DisallowExternalBeatmapRulesetChanges => false; public override bool RemoveWhenNotAlive => false; - public abstract string Title { get; } public virtual string ShortTitle => Title; - public Bindable Beatmap { get; set; } - - public Bindable Ruleset { get; set; } - - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - var deps = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); - - Beatmap = deps.Beatmap; - Ruleset = deps.Ruleset; - - return deps; - } - [Resolved(CanBeNull = true)] protected OsuGame Game { get; private set; } [Resolved(CanBeNull = true)] - protected IRoomManager Manager { get; private set; } + protected IRoomManager RoomManager { get; private set; } protected MultiplayerSubScreen() { @@ -61,14 +31,14 @@ namespace osu.Game.Screens.Multi RelativeSizeAxes = Axes.Both; } - public virtual void OnEntering(IScreen last) + public override void OnEntering(IScreen last) { this.FadeInFromZero(WaveContainer.APPEAR_DURATION, Easing.OutQuint); this.FadeInFromZero(WaveContainer.APPEAR_DURATION, Easing.OutQuint); this.MoveToX(200).MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint); } - public virtual bool OnExiting(IScreen next) + public override bool OnExiting(IScreen next) { this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); this.MoveToX(200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); @@ -76,19 +46,19 @@ namespace osu.Game.Screens.Multi return false; } - public virtual void OnResuming(IScreen last) + public override void OnResuming(IScreen last) { this.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint); this.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint); } - public virtual void OnSuspending(IScreen next) + public override void OnSuspending(IScreen next) { this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); this.MoveToX(-200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); } - public virtual bool OnPressed(GlobalAction action) + public override bool OnPressed(GlobalAction action) { if (!this.IsCurrentScreen()) return false;