1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 15:12:57 +08:00

Merge pull request #7740 from peppy/lounge-ruleset-filtering

Make multiplayer room listing filter by current ruleset
This commit is contained in:
Dan Balasescu 2020-02-06 15:53:50 +09:00 committed by GitHub
commit bb0990d805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 18 deletions

View File

@ -8,8 +8,12 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Multi;
using osu.Game.Screens.Multi.Lounge.Components;
using osu.Game.Users;
@ -52,21 +56,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestBasicListChanges()
{
AddStep("add rooms", () =>
{
for (int i = 0; i < 3; i++)
{
roomManager.Rooms.Add(new Room
{
RoomID = { Value = i },
Name = { Value = $"Room {i}" },
Host = { Value = new User { Username = "Host" } },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
});
}
});
addRooms(3);
AddAssert("has 2 rooms", () => container.Rooms.Count == 3);
AddAssert("has 3 rooms", () => container.Rooms.Count == 3);
AddStep("remove first room", () => roomManager.Rooms.Remove(roomManager.Rooms.FirstOrDefault()));
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
@ -78,6 +70,70 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddAssert("first room joined", () => roomManager.Rooms.First().Status.Value is JoinedRoomStatus);
}
[Test]
public void TestStringFiltering()
{
addRooms(4);
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
AddStep("filter one room", () => container.Filter(new FilterCriteria { SearchString = "1" }));
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
AddStep("remove filter", () => container.Filter(null));
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
}
[Test]
public void TestRulesetFiltering()
{
addRooms(2, new OsuRuleset().RulesetInfo);
addRooms(3, new CatchRuleset().RulesetInfo);
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
AddStep("filter osu! rooms", () => container.Filter(new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo }));
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
AddStep("filter catch rooms", () => container.Filter(new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo }));
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
}
private void addRooms(int count, RulesetInfo ruleset = null)
{
AddStep("add rooms", () =>
{
for (int i = 0; i < count; i++)
{
var room = new Room
{
RoomID = { Value = i },
Name = { Value = $"Room {i}" },
Host = { Value = new User { Username = "Host" } },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
};
if (ruleset != null)
{
room.Playlist.Add(new PlaylistItem
{
Ruleset = ruleset,
Beatmap = new BeatmapInfo
{
Metadata = new BeatmapMetadata()
}
});
}
roomManager.Rooms.Add(room);
}
});
}
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
private class TestRoomManager : IRoomManager

View File

@ -75,8 +75,13 @@ namespace osu.Game.Screens.Multi.Lounge.Components
{
matchingFilter = value;
if (IsLoaded)
this.FadeTo(MatchingFilter ? 1 : 0, 200);
if (!IsLoaded)
return;
if (matchingFilter)
this.FadeIn(200);
else
Hide();
}
}

View File

@ -7,6 +7,7 @@ using osu.Framework.Bindables;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Overlays.SearchableList;
using osu.Game.Rulesets;
using osuTK.Graphics;
namespace osu.Game.Screens.Multi.Lounge.Components
@ -22,6 +23,9 @@ namespace osu.Game.Screens.Multi.Lounge.Components
[Resolved(CanBeNull = true)]
private Bindable<FilterCriteria> filter { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
public FilterControl()
{
DisplayStyleControl.Hide();
@ -38,6 +42,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
{
base.LoadComplete();
ruleset.BindValueChanged(_ => updateFilter());
Search.Current.BindValueChanged(_ => scheduleUpdateFilter());
Tabs.Current.BindValueChanged(_ => updateFilter(), true);
}
@ -58,7 +63,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
{
SearchString = Search.Current.Value ?? string.Empty,
PrimaryFilter = Tabs.Current.Value,
SecondaryFilter = DisplayStyleControl.Dropdown.Current.Value
SecondaryFilter = DisplayStyleControl.Dropdown.Current.Value,
Ruleset = ruleset.Value
};
}
}

View File

@ -1,6 +1,8 @@
// 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.Game.Rulesets;
namespace osu.Game.Screens.Multi.Lounge.Components
{
public class FilterCriteria
@ -8,5 +10,6 @@ namespace osu.Game.Screens.Multi.Lounge.Components
public string SearchString;
public PrimaryFilter PrimaryFilter;
public SecondaryFilter SecondaryFilter;
public RulesetInfo Ruleset;
}
}

View File

@ -54,6 +54,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
roomManager.RoomsUpdated += updateSorting;
rooms.BindTo(roomManager.Rooms);
filter?.BindValueChanged(criteria => Filter(criteria.NewValue));
}
public void Filter(FilterCriteria criteria)
@ -65,7 +67,11 @@ namespace osu.Game.Screens.Multi.Lounge.Components
else
{
bool matchingFilter = true;
matchingFilter &= r.FilterTerms.Any(term => term.IndexOf(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase) >= 0);
matchingFilter &= r.Room.Playlist.Count == 0 || r.Room.Playlist.Any(i => i.Ruleset.Equals(criteria.Ruleset));
if (!string.IsNullOrEmpty(criteria.SearchString))
matchingFilter &= r.FilterTerms.Any(term => term.IndexOf(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase) >= 0);
switch (criteria.SecondaryFilter)
{