1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:02:55 +08:00

Add filtering.

This commit is contained in:
DrabWeb 2018-05-22 00:33:41 -03:00
parent f7a4a4eeef
commit 6aac4269e6
2 changed files with 63 additions and 7 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
@ -24,7 +25,7 @@ using OpenTK.Graphics;
namespace osu.Game.Screens.Multi.Components
{
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>, IFilterable
{
public const float SELECTION_BORDER_WIDTH = 4;
private const float corner_radius = 5;
@ -63,6 +64,21 @@ namespace osu.Game.Screens.Multi.Components
}
}
public IEnumerable<string> FilterTerms => new[] { Room.Name.Value };
private bool matchingFilter;
public bool MatchingFilter
{
get { return matchingFilter; }
set
{
if (value == matchingFilter) return;
matchingFilter = value;
this.FadeTo(MatchingFilter ? 1 : 0, 200);
}
}
private Action<DrawableRoom> action;
public new Action<DrawableRoom> Action
{

View File

@ -20,7 +20,8 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
{
private readonly FilterControl filter;
private readonly Container content;
private readonly FillFlowContainer<DrawableRoom> roomsFlow;
private readonly SearchContainer search;
private readonly RoomsFilterContainer roomsFlow;
private readonly RoomInspector roomInspector;
protected override Container<Drawable> TransitionContent => content;
@ -46,6 +47,8 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
if (!enumerable.Contains(roomInspector.Room))
roomInspector.Room = null;
filterRooms();
}
}
@ -68,14 +71,17 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
Vertical = 35 - DrawableRoom.SELECTION_BORDER_WIDTH,
Right = 20 - DrawableRoom.SELECTION_BORDER_WIDTH
},
Child = roomsFlow = new FillFlowContainer<DrawableRoom>
Child = search = new SearchContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
LayoutEasing = Easing.OutQuint,
LayoutDuration = 200,
Spacing = new Vector2(10 - DrawableRoom.SELECTION_BORDER_WIDTH * 2),
Child = roomsFlow = new RoomsFilterContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10 - DrawableRoom.SELECTION_BORDER_WIDTH * 2),
},
},
},
roomInspector = new RoomInspector
@ -89,6 +95,8 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
},
};
filter.Search.Current.ValueChanged += s => filterRooms();
filter.Tabs.Current.ValueChanged += t => filterRooms();
filter.Search.Exit += Exit;
}
@ -133,6 +141,17 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
filter.Search.HoldFocus = false;
}
private void filterRooms()
{
search.SearchTerm = filter.Search.Current.Value ?? string.Empty;
foreach (DrawableRoom r in roomsFlow.Children)
{
r.MatchingFilter = r.MatchingFilter &&
r.Room.Availability.Value == (RoomAvailability)filter.Tabs.Current.Value;
}
}
private void didSelect(DrawableRoom room)
{
roomsFlow.Children.ForEach(c =>
@ -147,5 +166,26 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
if (room.State == SelectionState.Selected)
Push(new Match(room.Room));
}
private class RoomsFilterContainer : FillFlowContainer<DrawableRoom>, IHasFilterableChildren
{
public IEnumerable<string> FilterTerms => new string[] { };
public IEnumerable<IFilterable> FilterableChildren => Children;
public bool MatchingFilter
{
set
{
if (value)
InvalidateLayout();
}
}
public RoomsFilterContainer()
{
LayoutDuration = 200;
LayoutEasing = Easing.OutQuint;
}
}
}
}