1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

refactor to use enum dropdown

This commit is contained in:
Gabe Livengood 2022-06-23 11:02:27 -04:00
parent a03cfbc2d4
commit 2def6d809b
No known key found for this signature in database
GPG Key ID: 70321B78DAECE683
5 changed files with 26 additions and 16 deletions

View File

@ -158,7 +158,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
}
[Test]
public void TestLockedFiltering()
public void TestPublicityFiltering()
{
AddStep("add rooms", () =>
{
@ -166,15 +166,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
RoomManager.AddRooms(1, withPassword: false);
});
AddUntilStep("both rooms shown", () => container.Rooms.Count(r => r.IsPresent) == 2);
AddStep("filter public rooms", () => container.Filter.Value = new FilterCriteria { Publicity = RoomPublicityFilter.Public });
AddStep("filter locked rooms", () => container.Filter.Value = new FilterCriteria { Locked = false });
AddUntilStep("private room hidden", () => container.Rooms.All(r => !r.Room.HasPassword.Value));
AddUntilStep("locked room hidden", () => container.Rooms.All(r => !r.Room.HasPassword.Value));
AddStep("filter private rooms", () => container.Filter.Value = new FilterCriteria { Publicity = RoomPublicityFilter.Private });
AddStep("unfilter locked rooms", () => container.Filter.SetDefault());
AddUntilStep("both rooms shown", () => container.Rooms.Count(r => r.IsPresent) == 2);
AddUntilStep("public room hidden", () => container.Rooms.All(r => r.Room.HasPassword.Value));
}
[Test]

View File

@ -13,6 +13,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
public RoomStatusFilter Status;
public string Category;
public RulesetInfo Ruleset;
public bool Locked = true;
public RoomPublicityFilter Publicity;
}
}

View File

@ -0,0 +1,13 @@
// 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.
#nullable disable
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public enum RoomPublicityFilter
{
Public,
Private
}
}

View File

@ -87,7 +87,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
matchingFilter &= r.FilterTerms.Any(term => term.ToString().Contains(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase));
}
matchingFilter &= criteria.Locked || !r.Room.HasPassword.Value;
matchingFilter &= (criteria.Publicity == RoomPublicityFilter.Public && !r.Room.HasPassword.Value) || (criteria.Publicity == RoomPublicityFilter.Private && r.Room.HasPassword.Value);
r.MatchingFilter = matchingFilter;
}

View File

@ -85,7 +85,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private RoomsContainer roomsContainer;
private SearchTextBox searchTextBox;
private Dropdown<RoomStatusFilter> statusDropdown;
private Checkbox lockedCheckbox;
private Dropdown<RoomPublicityFilter> publicityDropdown;
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] IdleTracker idleTracker)
@ -226,7 +226,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
SearchString = searchTextBox.Current.Value,
Ruleset = ruleset.Value,
Status = statusDropdown.Current.Value,
Locked = lockedCheckbox.Current.Value,
Publicity = publicityDropdown.Current.Value,
};
#endregion
@ -241,16 +241,15 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
statusDropdown.Current.BindValueChanged(_ => UpdateFilter());
lockedCheckbox = new OsuTabControlCheckbox
publicityDropdown = new SlimEnumDropdown<RoomPublicityFilter>
{
Current = new Bindable<bool>(true),
RelativeSizeAxes = Axes.None,
Text = @"Show Locked",
Width = 160,
};
lockedCheckbox.Current.BindValueChanged(_ => UpdateFilter());
publicityDropdown.Current.BindValueChanged(_ => UpdateFilter());
return new Drawable[] { lockedCheckbox, statusDropdown, };
return new Drawable[] { publicityDropdown, statusDropdown, };
}
public override void OnEntering(ScreenTransitionEvent e)