Re-implement MultiplayerSubScreen

This commit is contained in:
smoogipoo
2019-01-25 19:32:37 +09:00
parent 3fb17ead06
commit e1e7759e0f
3 changed files with 108 additions and 100 deletions

View File

@ -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<Screen> pushGameplayScreen;
private readonly ProcessingOverlay processingOverlay;
[Resolved(CanBeNull = true)]
private IRoomManager roomManager { get; set; }
public LoungeSubScreen(Action<Screen> 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;
}
}

View File

@ -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<Screen> 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);

View File

@ -0,0 +1,87 @@
// Copyright (c) 2007-2019 ppy Pty Ltd <contact@ppy.sh>.
// 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<GlobalAction>
{
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;
}
}