mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 09:03:50 +09:00
Merge pull request #7740 from peppy/lounge-ruleset-filtering
Make multiplayer room listing filter by current ruleset
This commit is contained in:
@ -8,8 +8,12 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.Multiplayer;
|
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;
|
||||||
using osu.Game.Screens.Multi.Lounge.Components;
|
using osu.Game.Screens.Multi.Lounge.Components;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
@ -52,21 +56,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestBasicListChanges()
|
public void TestBasicListChanges()
|
||||||
{
|
{
|
||||||
AddStep("add rooms", () =>
|
addRooms(3);
|
||||||
{
|
|
||||||
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) }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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()));
|
AddStep("remove first room", () => roomManager.Rooms.Remove(roomManager.Rooms.FirstOrDefault()));
|
||||||
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
|
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
|
||||||
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
|
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);
|
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 void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
|
||||||
|
|
||||||
private class TestRoomManager : IRoomManager
|
private class TestRoomManager : IRoomManager
|
||||||
|
@ -75,8 +75,13 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
{
|
{
|
||||||
matchingFilter = value;
|
matchingFilter = value;
|
||||||
|
|
||||||
if (IsLoaded)
|
if (!IsLoaded)
|
||||||
this.FadeTo(MatchingFilter ? 1 : 0, 200);
|
return;
|
||||||
|
|
||||||
|
if (matchingFilter)
|
||||||
|
this.FadeIn(200);
|
||||||
|
else
|
||||||
|
Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Overlays.SearchableList;
|
using osu.Game.Overlays.SearchableList;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Lounge.Components
|
namespace osu.Game.Screens.Multi.Lounge.Components
|
||||||
@ -22,6 +23,9 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private Bindable<FilterCriteria> filter { get; set; }
|
private Bindable<FilterCriteria> filter { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
public FilterControl()
|
public FilterControl()
|
||||||
{
|
{
|
||||||
DisplayStyleControl.Hide();
|
DisplayStyleControl.Hide();
|
||||||
@ -38,6 +42,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
ruleset.BindValueChanged(_ => updateFilter());
|
||||||
Search.Current.BindValueChanged(_ => scheduleUpdateFilter());
|
Search.Current.BindValueChanged(_ => scheduleUpdateFilter());
|
||||||
Tabs.Current.BindValueChanged(_ => updateFilter(), true);
|
Tabs.Current.BindValueChanged(_ => updateFilter(), true);
|
||||||
}
|
}
|
||||||
@ -58,7 +63,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
{
|
{
|
||||||
SearchString = Search.Current.Value ?? string.Empty,
|
SearchString = Search.Current.Value ?? string.Empty,
|
||||||
PrimaryFilter = Tabs.Current.Value,
|
PrimaryFilter = Tabs.Current.Value,
|
||||||
SecondaryFilter = DisplayStyleControl.Dropdown.Current.Value
|
SecondaryFilter = DisplayStyleControl.Dropdown.Current.Value,
|
||||||
|
Ruleset = ruleset.Value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Lounge.Components
|
namespace osu.Game.Screens.Multi.Lounge.Components
|
||||||
{
|
{
|
||||||
public class FilterCriteria
|
public class FilterCriteria
|
||||||
@ -8,5 +10,6 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
public string SearchString;
|
public string SearchString;
|
||||||
public PrimaryFilter PrimaryFilter;
|
public PrimaryFilter PrimaryFilter;
|
||||||
public SecondaryFilter SecondaryFilter;
|
public SecondaryFilter SecondaryFilter;
|
||||||
|
public RulesetInfo Ruleset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
roomManager.RoomsUpdated += updateSorting;
|
roomManager.RoomsUpdated += updateSorting;
|
||||||
|
|
||||||
rooms.BindTo(roomManager.Rooms);
|
rooms.BindTo(roomManager.Rooms);
|
||||||
|
|
||||||
|
filter?.BindValueChanged(criteria => Filter(criteria.NewValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Filter(FilterCriteria criteria)
|
public void Filter(FilterCriteria criteria)
|
||||||
@ -65,6 +67,10 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool matchingFilter = true;
|
bool matchingFilter = true;
|
||||||
|
|
||||||
|
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);
|
matchingFilter &= r.FilterTerms.Any(term => term.IndexOf(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase) >= 0);
|
||||||
|
|
||||||
switch (criteria.SecondaryFilter)
|
switch (criteria.SecondaryFilter)
|
||||||
|
Reference in New Issue
Block a user