mirror of
https://github.com/ppy/osu.git
synced 2025-03-19 01:17:19 +08:00
Merge pull request #18821 from ggliv/locked-room-filter
Add room access type filter to multiplayer lounge screen
This commit is contained in:
commit
6baccad058
@ -157,6 +157,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAccessTypeFiltering()
|
||||
{
|
||||
AddStep("add rooms", () =>
|
||||
{
|
||||
RoomManager.AddRooms(1, withPassword: true);
|
||||
RoomManager.AddRooms(1, withPassword: false);
|
||||
});
|
||||
|
||||
AddStep("apply default filter", () => container.Filter.SetDefault());
|
||||
|
||||
AddUntilStep("both rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
||||
|
||||
AddStep("filter public rooms", () => container.Filter.Value = new FilterCriteria { Permissions = RoomPermissionsFilter.Public });
|
||||
|
||||
AddUntilStep("private room hidden", () => container.Rooms.All(r => !r.Room.HasPassword.Value));
|
||||
|
||||
AddStep("filter private rooms", () => container.Filter.Value = new FilterCriteria { Permissions = RoomPermissionsFilter.Private });
|
||||
|
||||
AddUntilStep("public room hidden", () => container.Rooms.All(r => r.Room.HasPassword.Value));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPasswordProtectedRooms()
|
||||
{
|
||||
|
@ -13,5 +13,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
public RoomStatusFilter Status;
|
||||
public string Category;
|
||||
public RulesetInfo Ruleset;
|
||||
public RoomPermissionsFilter Permissions;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
// 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 RoomPermissionsFilter
|
||||
{
|
||||
All,
|
||||
Public,
|
||||
Private
|
||||
}
|
||||
}
|
@ -87,9 +87,29 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
matchingFilter &= r.FilterTerms.Any(term => term.ToString().Contains(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
matchingFilter &= matchPermissions(r, criteria.Permissions);
|
||||
|
||||
r.MatchingFilter = matchingFilter;
|
||||
}
|
||||
});
|
||||
|
||||
static bool matchPermissions(DrawableLoungeRoom room, RoomPermissionsFilter accessType)
|
||||
{
|
||||
switch (accessType)
|
||||
{
|
||||
case RoomPermissionsFilter.All:
|
||||
return true;
|
||||
|
||||
case RoomPermissionsFilter.Public:
|
||||
return !room.Room.HasPassword.Value;
|
||||
|
||||
case RoomPermissionsFilter.Private:
|
||||
return room.Room.HasPassword.Value;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(accessType), accessType, $"Unsupported {nameof(RoomPermissionsFilter)} in filter");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void roomsChanged(object sender, NotifyCollectionChangedEventArgs args)
|
||||
|
@ -3,11 +3,15 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
@ -27,6 +31,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[Resolved]
|
||||
private MultiplayerClient client { get; set; }
|
||||
|
||||
private Dropdown<RoomPermissionsFilter> roomAccessTypeDropdown;
|
||||
|
||||
public override void OnResuming(ScreenTransitionEvent e)
|
||||
{
|
||||
base.OnResuming(e);
|
||||
@ -40,10 +46,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<Drawable> CreateFilterControls()
|
||||
{
|
||||
roomAccessTypeDropdown = new SlimEnumDropdown<RoomPermissionsFilter>
|
||||
{
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Width = 160,
|
||||
};
|
||||
|
||||
roomAccessTypeDropdown.Current.BindValueChanged(_ => UpdateFilter());
|
||||
|
||||
return base.CreateFilterControls().Prepend(roomAccessTypeDropdown);
|
||||
}
|
||||
|
||||
protected override FilterCriteria CreateFilterCriteria()
|
||||
{
|
||||
var criteria = base.CreateFilterCriteria();
|
||||
criteria.Category = @"realtime";
|
||||
criteria.Permissions = roomAccessTypeDropdown.Current.Value;
|
||||
return criteria;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user