mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:17:26 +08:00
Merge pull request #14117 from peppy/multiplayer-create-with-enter
Add the ability to create multiplayer games using only the keyboard
This commit is contained in:
commit
f0d11ebd89
@ -8,6 +8,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
@ -88,6 +89,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
// used to test the flow of multiplayer from visual tests.
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRoomViaKeyboard()
|
||||
{
|
||||
// create room dialog
|
||||
AddStep("Press new document", () => InputManager.Keys(PlatformAction.DocumentNew));
|
||||
AddUntilStep("wait for settings", () => InputManager.ChildrenOfType<MultiplayerMatchSettingsOverlay>().FirstOrDefault() != null);
|
||||
|
||||
// edit playlist item
|
||||
AddStep("Press select", () => InputManager.Key(Key.Enter));
|
||||
AddUntilStep("wait for song select", () => InputManager.ChildrenOfType<MultiplayerMatchSongSelect>().FirstOrDefault() != null);
|
||||
|
||||
// select beatmap
|
||||
AddStep("Press select", () => InputManager.Key(Key.Enter));
|
||||
AddUntilStep("wait for return to screen", () => InputManager.ChildrenOfType<MultiplayerMatchSongSelect>().FirstOrDefault() == null);
|
||||
|
||||
// create room
|
||||
AddStep("Press select", () => InputManager.Key(Key.Enter));
|
||||
|
||||
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
||||
AddUntilStep("wait for join", () => client.Room != null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRoomWithoutPassword()
|
||||
{
|
||||
|
@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
{
|
||||
public abstract class CreateRoomButton : PurpleTriangleButton, IKeyBindingHandler<PlatformAction>
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Triangles.TriangleScale = 1.5f;
|
||||
}
|
||||
|
||||
public bool OnPressed(PlatformAction action)
|
||||
{
|
||||
if (!Enabled.Value)
|
||||
return false;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case PlatformAction.DocumentNew:
|
||||
// might as well also handle new tab. it's a bit of an undefined flow on this screen.
|
||||
case PlatformAction.TabNew:
|
||||
TriggerClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(PlatformAction action)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -4,15 +4,17 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
{
|
||||
public abstract class MatchSettingsOverlay : FocusedOverlayContainer
|
||||
public abstract class MatchSettingsOverlay : FocusedOverlayContainer, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
protected const float TRANSITION_DURATION = 350;
|
||||
protected const float FIELD_PADDING = 45;
|
||||
@ -21,6 +23,10 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
|
||||
protected override bool BlockScrollInput => false;
|
||||
|
||||
protected abstract OsuButton SubmitButton { get; }
|
||||
|
||||
protected abstract bool IsLoading { get; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -29,6 +35,8 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
Add(Settings = CreateSettings());
|
||||
}
|
||||
|
||||
protected abstract void SelectBeatmap();
|
||||
|
||||
protected abstract OnlinePlayComposite CreateSettings();
|
||||
|
||||
protected override void PopIn()
|
||||
@ -41,6 +49,33 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
Settings.MoveToY(-1, TRANSITION_DURATION, Easing.InSine);
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.Select:
|
||||
if (IsLoading)
|
||||
return true;
|
||||
|
||||
if (SubmitButton.Enabled.Value)
|
||||
{
|
||||
SubmitButton.TriggerClick();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectBeatmap();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(GlobalAction action)
|
||||
{
|
||||
}
|
||||
|
||||
protected class SettingsTextBox : OsuTextBox
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -8,7 +8,7 @@ using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
public class CreateMultiplayerMatchButton : PurpleTriangleButton
|
||||
public class CreateMultiplayerMatchButton : CreateRoomButton
|
||||
{
|
||||
private IBindable<bool> isConnected;
|
||||
private IBindable<bool> operationInProgress;
|
||||
@ -22,8 +22,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Triangles.TriangleScale = 1.5f;
|
||||
|
||||
Text = "Create room";
|
||||
|
||||
isConnected = multiplayerClient.IsConnected.GetBoundCopy();
|
||||
|
@ -47,7 +47,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 40,
|
||||
Text = "Select beatmap",
|
||||
Action = () => matchSubScreen.Push(new MultiplayerMatchSongSelect()),
|
||||
Action = () =>
|
||||
{
|
||||
if (matchSubScreen.IsCurrentScreen())
|
||||
matchSubScreen.Push(new MultiplayerMatchSongSelect());
|
||||
},
|
||||
Alpha = 0
|
||||
}
|
||||
}
|
||||
@ -68,6 +72,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
}, true);
|
||||
}
|
||||
|
||||
public void BeginSelection() => selectButton.TriggerClick();
|
||||
|
||||
private void updateBeatmap()
|
||||
{
|
||||
if (SelectedItem.Value == null)
|
||||
|
@ -28,8 +28,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class MultiplayerMatchSettingsOverlay : MatchSettingsOverlay
|
||||
{
|
||||
private MatchSettings settings;
|
||||
|
||||
protected override OsuButton SubmitButton => settings.ApplyButton;
|
||||
|
||||
[Resolved]
|
||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||
|
||||
protected override bool IsLoading => ongoingOperationTracker.InProgress.Value;
|
||||
|
||||
protected override void SelectBeatmap() => settings.SelectBeatmap();
|
||||
|
||||
protected override OnlinePlayComposite CreateSettings()
|
||||
=> new MatchSettings
|
||||
=> settings = new MatchSettings
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
@ -54,6 +65,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
private LoadingLayer loadingLayer;
|
||||
private BeatmapSelectionControl initialBeatmapControl;
|
||||
|
||||
public void SelectBeatmap() => initialBeatmapControl.BeginSelection();
|
||||
|
||||
[Resolved]
|
||||
private IRoomManager manager { get; set; }
|
||||
|
||||
|
@ -6,13 +6,11 @@ using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public class CreatePlaylistsRoomButton : PurpleTriangleButton
|
||||
public class CreatePlaylistsRoomButton : CreateRoomButton
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Triangles.TriangleScale = 1.5f;
|
||||
|
||||
Text = "Create playlist";
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,16 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public Action EditPlaylist;
|
||||
|
||||
private MatchSettings settings;
|
||||
|
||||
protected override OsuButton SubmitButton => settings.ApplyButton;
|
||||
|
||||
protected override bool IsLoading => settings.IsLoading; // should probably be replaced with an OngoingOperationTracker.
|
||||
|
||||
protected override void SelectBeatmap() => settings.SelectBeatmap();
|
||||
|
||||
protected override OnlinePlayComposite CreateSettings()
|
||||
=> new MatchSettings
|
||||
=> settings = new MatchSettings
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
@ -45,12 +53,16 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
public RoomAvailabilityPicker AvailabilityPicker;
|
||||
public TriangleButton ApplyButton;
|
||||
|
||||
public bool IsLoading => loadingLayer.State.Value == Visibility.Visible;
|
||||
|
||||
public OsuSpriteText ErrorText;
|
||||
|
||||
private LoadingLayer loadingLayer;
|
||||
private DrawableRoomPlaylist playlist;
|
||||
private OsuSpriteText playlistLength;
|
||||
|
||||
private PurpleTriangleButton editPlaylistButton;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IRoomManager manager { get; set; }
|
||||
|
||||
@ -199,7 +211,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
new PurpleTriangleButton
|
||||
editPlaylistButton = new PurpleTriangleButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 40,
|
||||
@ -292,6 +304,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
ApplyButton.Enabled.Value = hasValidSettings;
|
||||
}
|
||||
|
||||
public void SelectBeatmap() => editPlaylistButton.TriggerClick();
|
||||
|
||||
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) =>
|
||||
playlistLength.Text = $"Length: {Playlist.GetTotalDuration()}";
|
||||
|
||||
|
@ -230,7 +230,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
settingsOverlay = new PlaylistsMatchSettingsOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
EditPlaylist = () => this.Push(new PlaylistsSongSelect()),
|
||||
EditPlaylist = () =>
|
||||
{
|
||||
if (this.IsCurrentScreen())
|
||||
this.Push(new PlaylistsSongSelect());
|
||||
},
|
||||
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user