Skip to content

Commit

Permalink
Add ability to filter out currently playing rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Dec 11, 2024
1 parent 637fe07 commit 84cf638
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
17 changes: 11 additions & 6 deletions osu.Game/Online/Rooms/GetRoomsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,32 @@ namespace osu.Game.Online.Rooms
public class GetRoomsRequest : APIRequest<List<Room>>
{
private readonly RoomModeFilter mode;
private readonly RoomStatusFilter? status;
private readonly string category;

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

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

if (mode != RoomModeFilter.Open)
req.AddParameter("mode", mode.ToString().ToSnakeCase().ToLowerInvariant());
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.Mode, 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 @@ -9,6 +9,7 @@ public class FilterCriteria
{
public string SearchString = string.Empty;
public RoomModeFilter Mode;
public RoomStatusFilter? Status;
public string Category = string.Empty;
public RulesetInfo? Ruleset;
public RoomPermissionsFilter Permissions;
Expand Down
11 changes: 11 additions & 0 deletions osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public enum RoomStatusFilter
{
Idle,
Playing,
}
}
4 changes: 2 additions & 2 deletions osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ private void load()
Spacing = new Vector2(10),
ChildrenEnumerable = CreateFilterControls().Select(f => f.With(d =>
{
d.Anchor = Anchor.TopRight;
d.Origin = Anchor.TopRight;
d.Anchor = Anchor.CentreRight;
d.Origin = Anchor.CentreRight;
}))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -56,14 +57,24 @@ protected override IEnumerable<Drawable> CreateFilterControls()

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

return base.CreateFilterControls().Append(roomAccessTypeDropdown);
showInProgress = new OsuCheckbox
{
LabelText = "Show playing rooms",
RelativeSizeAxes = Axes.None,
Width = 200,
Current = { Value = true }
};
showInProgress.Current.BindValueChanged(_ => UpdateFilter());

return base.CreateFilterControls().Concat([roomAccessTypeDropdown, showInProgress]);
}

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

Expand Down

0 comments on commit 84cf638

Please sign in to comment.