diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index 450470fcf1..30f5e8e432 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -2,12 +2,10 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; using osu.Framework.Screens; -using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Multiplayer; using osu.Game.Overlays.SearchableList; @@ -16,19 +14,9 @@ using osu.Game.Screens.Multi.Match; namespace osu.Game.Screens.Multi.Lounge { - public class LoungeSubScreen : CompositeDrawable, IMultiplayerSubScreen + public class LoungeSubScreen : MultiplayerSubScreen { - public bool AllowBeatmapRulesetChange => true; - public bool AllowExternalScreenChange => true; - public bool CursorVisible => true; - - public string Title => "Lounge"; - public string ShortTitle => Title; - - public bool ValidForResume { get; set; } = true; - public bool ValidForPush { get; set; } = true; - - public override bool RemoveWhenNotAlive => false; + public override string Title => "Lounge"; protected readonly FilterControl Filter; @@ -37,15 +25,10 @@ namespace osu.Game.Screens.Multi.Lounge private readonly Action pushGameplayScreen; private readonly ProcessingOverlay processingOverlay; - [Resolved(CanBeNull = true)] - private IRoomManager roomManager { get; set; } - public LoungeSubScreen(Action pushGameplayScreen) { this.pushGameplayScreen = pushGameplayScreen; - RelativeSizeAxes = Axes.Both; - RoomInspector inspector; InternalChildren = new Drawable[] @@ -112,49 +95,34 @@ namespace osu.Game.Screens.Multi.Lounge GetContainingInputManager().ChangeFocus(Filter.Search); } - public 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); - + base.OnEntering(last); Filter.Search.HoldFocus = true; } - public 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); - Filter.Search.HoldFocus = false; - - return false; + return base.OnExiting(next); } - public void OnResuming(IScreen last) + public override void OnSuspending(IScreen next) { - this.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint); - this.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint); - } - - public void OnSuspending(IScreen next) - { - this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); - this.MoveToX(-200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); - + base.OnSuspending(next); Filter.Search.HoldFocus = false; } private void filterRooms() { rooms.Filter(Filter.CreateCriteria()); - roomManager?.Filter(Filter.CreateCriteria()); + Manager?.Filter(Filter.CreateCriteria()); } private void joinRequested(Room room) { processingOverlay.Show(); - roomManager?.JoinRoom(room, r => + Manager?.JoinRoom(room, r => { Push(room); processingOverlay.Hide(); @@ -172,7 +140,5 @@ namespace osu.Game.Screens.Multi.Lounge this.Push(new MatchSubScreen(room, s => pushGameplayScreen?.Invoke(s))); } - - public override string ToString() => Title; } } diff --git a/osu.Game/Screens/Multi/Match/MatchSubScreen.cs b/osu.Game/Screens/Multi/Match/MatchSubScreen.cs index 95ce57cd53..19b33f70d3 100644 --- a/osu.Game/Screens/Multi/Match/MatchSubScreen.cs +++ b/osu.Game/Screens/Multi/Match/MatchSubScreen.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Screens; using osu.Game.Beatmaps; -using osu.Game.Graphics.Containers; using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer.GameTypes; using osu.Game.Rulesets; @@ -19,19 +18,11 @@ using osu.Game.Screens.Select; namespace osu.Game.Screens.Multi.Match { - public class MatchSubScreen : CompositeDrawable, IMultiplayerSubScreen + public class MatchSubScreen : MultiplayerSubScreen { public bool AllowBeatmapRulesetChange => false; - public bool AllowExternalScreenChange => true; - public bool CursorVisible => true; - - public string Title => room.RoomID.Value == null ? "New room" : room.Name.Value; - public string ShortTitle => "room"; - - public bool ValidForResume { get; set; } = true; - public bool ValidForPush { get; set; } = true; - - public override bool RemoveWhenNotAlive => false; + public override string Title => room.RoomID.Value == null ? "New room" : room.Name.Value; + public override string ShortTitle => "room"; private readonly RoomBindings bindings = new RoomBindings(); @@ -42,25 +33,14 @@ namespace osu.Game.Screens.Multi.Match [Cached] private readonly Room room; - [Resolved] - private IBindableBeatmap beatmap { get; set; } - [Resolved] private BeatmapManager beatmapManager { get; set; } - [Resolved(CanBeNull = true)] - private OsuGame game { get; set; } - - [Resolved(CanBeNull = true)] - private IRoomManager manager { get; set; } - public MatchSubScreen(Room room, Action pushGameplayScreen) { this.room = room; this.pushGameplayScreen = pushGameplayScreen; - RelativeSizeAxes = Axes.Both; - bindings.Room = room; MatchChatDisplay chat; @@ -149,33 +129,10 @@ namespace osu.Game.Screens.Multi.Match beatmapManager.ItemAdded += beatmapAdded; } - public void OnEntering(IScreen last) + public override bool OnExiting(IScreen next) { - 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 bool OnExiting(IScreen next) - { - manager?.PartRoom(); - - this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); - this.MoveToX(200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); - - return false; - } - - public void OnResuming(IScreen last) - { - this.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint); - this.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint); - } - - public void OnSuspending(IScreen next) - { - this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); - this.MoveToX(-200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); + Manager?.PartRoom(); + return base.OnExiting(next); } protected override void LoadComplete() @@ -191,7 +148,7 @@ namespace osu.Game.Screens.Multi.Match // 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)); + Game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap)); } private void setRuleset(RulesetInfo ruleset) @@ -199,12 +156,12 @@ namespace osu.Game.Screens.Multi.Match if (ruleset == null) return; - game?.ForcefullySetRuleset(ruleset); + Game?.ForcefullySetRuleset(ruleset); } private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() => { - if (beatmap.Value != beatmapManager.DefaultBeatmap) + if (Beatmap.Value != beatmapManager.DefaultBeatmap) return; if (bindings.CurrentBeatmap.Value == null) @@ -214,7 +171,7 @@ namespace osu.Game.Screens.Multi.Match var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == bindings.CurrentBeatmap.Value.OnlineBeatmapID); if (localBeatmap != null) - game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap)); + Game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap)); }); private void addPlaylistItem(PlaylistItem item) @@ -225,7 +182,7 @@ namespace osu.Game.Screens.Multi.Match private void onStart() { - beatmap.Value.Mods.Value = bindings.CurrentMods.Value.ToArray(); + Beatmap.Value.Mods.Value = bindings.CurrentMods.Value.ToArray(); switch (bindings.Type.Value) { @@ -239,8 +196,6 @@ namespace osu.Game.Screens.Multi.Match } } - public override string ToString() => Title; - protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); diff --git a/osu.Game/Screens/Multi/MultiplayerSubScreen.cs b/osu.Game/Screens/Multi/MultiplayerSubScreen.cs new file mode 100644 index 0000000000..91411da65f --- /dev/null +++ b/osu.Game/Screens/Multi/MultiplayerSubScreen.cs @@ -0,0 +1,87 @@ +// Copyright (c) 2007-2019 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +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; + +namespace osu.Game.Screens.Multi +{ + public abstract class MultiplayerSubScreen : CompositeDrawable, IMultiplayerSubScreen, IKeyBindingHandler + { + public bool AllowBeatmapRulesetChange => true; + public bool AllowExternalScreenChange => true; + public bool CursorVisible => true; + + public bool ValidForResume { get; set; } = true; + public bool ValidForPush { get; set; } = true; + + public override bool RemoveWhenNotAlive => false; + + public abstract string Title { get; } + public virtual string ShortTitle => Title; + + [Resolved] + protected IBindableBeatmap Beatmap { get; private set; } + + [Resolved(CanBeNull = true)] + protected OsuGame Game { get; private set; } + + [Resolved(CanBeNull = true)] + protected IRoomManager Manager { get; private set; } + + protected MultiplayerSubScreen() + { + RelativeSizeAxes = Axes.Both; + } + + public virtual 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) + { + this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); + this.MoveToX(200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); + + return false; + } + + public virtual 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) + { + this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); + this.MoveToX(-200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); + } + + public virtual bool OnPressed(GlobalAction action) + { + if (!this.IsCurrentScreen()) return false; + + if (action == GlobalAction.Back) + { + this.Exit(); + return true; + } + + return false; + } + + public bool OnReleased(GlobalAction action) => action == GlobalAction.Back; + + public override string ToString() => Title; + } +}