Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to filter out currently playing rooms #31073

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions osu.Game/Online/Rooms/GetRoomsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@ namespace osu.Game.Online.Rooms
{
public class GetRoomsRequest : APIRequest<List<Room>>
{
private readonly RoomStatusFilter status;
private readonly RoomModeFilter mode;
private readonly RoomStatusFilter? status;
private readonly string category;

public GetRoomsRequest(RoomStatusFilter status, string category)
public GetRoomsRequest(FilterCriteria filterCriteria)
{
this.status = status;
this.category = category;
mode = filterCriteria.Mode;
category = filterCriteria.Category;
status = filterCriteria.Status;
}

protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();

if (status != RoomStatusFilter.Open)
req.AddParameter("mode", status.ToString().ToSnakeCase().ToLowerInvariant());
if (mode != RoomModeFilter.Open)
req.AddParameter(@"mode", mode.ToString().ToSnakeCase().ToLowerInvariant());

if (status != null)
req.AddParameter(@"status", status.Value.ToString().ToSnakeCase().ToLowerInvariant());

if (!string.IsNullOrEmpty(category))
req.AddParameter("category", category);
req.AddParameter(@"category", category);

return req;
}

protected override string Target => "rooms";
protected override string Target => @"rooms";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override Task Poll()

lastPollRequest?.Cancel();

var req = new GetRoomsRequest(Filter.Value.Status, Filter.Value.Category);
var req = new GetRoomsRequest(Filter.Value);

req.Success += result =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
public class FilterCriteria
{
public string SearchString = string.Empty;
public RoomStatusFilter Status;
public RoomModeFilter Mode;
public RoomStatusFilter? Status;
public string Category = string.Empty;
public RulesetInfo? Ruleset;
public RoomPermissionsFilter Permissions;
Expand Down
17 changes: 17 additions & 0 deletions osu.Game/Screens/OnlinePlay/Lounge/Components/RoomModeFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 System.ComponentModel;

namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public enum RoomModeFilter
{
Open,

[Description("Recently Ended")]
Ended,
Participated,
Owned,
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// 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 System.ComponentModel;

namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public enum RoomStatusFilter
{
Open,

[Description("Recently Ended")]
Ended,
Participated,
Owned,
Idle,
Playing,
}
}
11 changes: 6 additions & 5 deletions osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public abstract partial class LoungeSubScreen : OnlinePlaySubScreen
private LoadingLayer loadingLayer = null!;
private RoomsContainer roomsContainer = null!;
private SearchTextBox searchTextBox = null!;
private Dropdown<RoomStatusFilter> statusDropdown = null!;

protected Dropdown<RoomModeFilter> StatusDropdown { get; private set; } = null!;

[BackgroundDependencyLoader(true)]
private void load()
Expand Down Expand Up @@ -223,20 +224,20 @@ private void updateFilter()
{
SearchString = searchTextBox.Current.Value,
Ruleset = ruleset.Value,
Status = statusDropdown.Current.Value
Mode = StatusDropdown.Current.Value
};

protected virtual IEnumerable<Drawable> CreateFilterControls()
{
statusDropdown = new SlimEnumDropdown<RoomStatusFilter>
StatusDropdown = new SlimEnumDropdown<RoomModeFilter>
{
RelativeSizeAxes = Axes.None,
Width = 160,
};

statusDropdown.Current.BindValueChanged(_ => UpdateFilter());
StatusDropdown.Current.BindValueChanged(_ => UpdateFilter());

yield return statusDropdown;
yield return StatusDropdown;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand Down Expand Up @@ -31,6 +30,7 @@ public partial class MultiplayerLoungeSubScreen : LoungeSubScreen
private MultiplayerClient client { get; set; } = null!;

private Dropdown<RoomPermissionsFilter> roomAccessTypeDropdown = null!;
private OsuCheckbox showInProgress = null!;

public override void OnResuming(ScreenTransitionEvent e)
{
Expand All @@ -47,7 +47,10 @@ public override void OnResuming(ScreenTransitionEvent e)

protected override IEnumerable<Drawable> CreateFilterControls()
{
roomAccessTypeDropdown = new SlimEnumDropdown<RoomPermissionsFilter>
foreach (var control in base.CreateFilterControls())
yield return control;

yield return roomAccessTypeDropdown = new SlimEnumDropdown<RoomPermissionsFilter>
{
RelativeSizeAxes = Axes.None,
Current = Config.GetBindable<RoomPermissionsFilter>(OsuSetting.MultiplayerRoomFilter),
Expand All @@ -56,14 +59,25 @@ protected override IEnumerable<Drawable> CreateFilterControls()

roomAccessTypeDropdown.Current.BindValueChanged(_ => UpdateFilter());

return base.CreateFilterControls().Append(roomAccessTypeDropdown);
yield return showInProgress = new OsuCheckbox
{
LabelText = "Show playing rooms",
RelativeSizeAxes = Axes.None,
Width = 200,
Padding = new MarginPadding { Vertical = 5, },
Current = { Value = true }
};

showInProgress.Current.BindValueChanged(_ => UpdateFilter());
StatusDropdown.Current.BindValueChanged(_ => showInProgress.Alpha = StatusDropdown.Current.Value == RoomModeFilter.Open ? 1 : 0, true);
}

protected override FilterCriteria CreateFilterCriteria()
{
var criteria = base.CreateFilterCriteria();
criteria.Category = @"realtime";
criteria.Permissions = roomAccessTypeDropdown.Current.Value;
criteria.Status = showInProgress.Current.Value && criteria.Mode == RoomModeFilter.Open ? null : RoomStatusFilter.Idle;
return criteria;
}

Expand Down
Loading