Add the ability to deselect the currently selected room via clicking away

Always felt wrong that you couldn't do this until now.
This commit is contained in:
Dean Herbert 2021-02-16 13:44:36 +09:00
parent 335af04764
commit e82922f8c5
2 changed files with 24 additions and 0 deletions

View File

@ -69,6 +69,20 @@ public void TestKeyboardNavigation()
AddAssert("last room joined", () => RoomManager.Rooms.Last().Status.Value is JoinedRoomStatus);
}
[Test]
public void TestClickDeselection()
{
AddRooms(1);
AddAssert("no selection", () => checkRoomSelected(null));
press(Key.Down);
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
AddStep("click away", () => InputManager.Click(MouseButton.Left));
AddAssert("no selection", () => checkRoomSelected(null));
}
private void press(Key down)
{
AddStep($"press {down}", () => InputManager.Key(down));

View File

@ -11,6 +11,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Game.Extensions;
using osu.Game.Graphics.Cursor;
@ -42,6 +43,9 @@ public class RoomsContainer : CompositeDrawable, IKeyBindingHandler<GlobalAction
[Resolved(CanBeNull = true)]
private LoungeSubScreen loungeSubScreen { get; set; }
// handle deselection
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
public RoomsContainer()
{
RelativeSizeAxes = Axes.X;
@ -159,6 +163,12 @@ private void joinSelected()
JoinRequested?.Invoke(selectedRoom.Value);
}
protected override bool OnClick(ClickEvent e)
{
selectRoom(null);
return base.OnClick(e);
}
#region Key selection logic (shared with BeatmapCarousel)
public bool OnPressed(GlobalAction action)