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

Use SearchContainer instead of manual search implementation

This commit is contained in:
Bartłomiej Dach 2024-10-22 11:36:00 +02:00
parent 256d8c6559
commit 826b35e031
No known key found for this signature in database
2 changed files with 29 additions and 24 deletions

View File

@ -37,7 +37,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
private readonly Dictionary<Channel, ChannelListItem> channelMap = new Dictionary<Channel, ChannelListItem>(); private readonly Dictionary<Channel, ChannelListItem> channelMap = new Dictionary<Channel, ChannelListItem>();
private OsuScrollContainer scroll = null!; private OsuScrollContainer scroll = null!;
private FillFlowContainer groupFlow = null!; private SearchContainer groupFlow = null!;
private ChannelGroup announceChannelGroup = null!; private ChannelGroup announceChannelGroup = null!;
private ChannelGroup publicChannelGroup = null!; private ChannelGroup publicChannelGroup = null!;
private ChannelGroup privateChannelGroup = null!; private ChannelGroup privateChannelGroup = null!;
@ -59,7 +59,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarAnchor = Anchor.TopRight, ScrollbarAnchor = Anchor.TopRight,
ScrollDistance = 35f, ScrollDistance = 35f,
Child = groupFlow = new FillFlowContainer Child = groupFlow = new SearchContainer
{ {
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -87,10 +87,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
}, },
}; };
searchTextBox.OnUpdate += (newText) => searchTextBox.Current.BindValueChanged(_ => groupFlow.SearchTerm = searchTextBox.Current.Value, true);
{
privateChannelGroup.FilterChannels(searchTextBox.Text);
};
selector.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan); selector.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan);
} }
@ -188,23 +185,6 @@ namespace osu.Game.Overlays.Chat.ChannelList
}, },
}; };
} }
public void FilterChannels(string searchTerm)
{
foreach (var item in ItemFlow.Children)
{
if (string.IsNullOrEmpty(searchTerm))
{
item.Show();
continue;
}
if (item.Channel.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase))
item.Show();
else
item.Hide();
}
}
} }
} }
} }

View File

@ -2,6 +2,7 @@
// 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 System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -9,6 +10,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -19,7 +21,7 @@ using osuTK;
namespace osu.Game.Overlays.Chat.ChannelList namespace osu.Game.Overlays.Chat.ChannelList
{ {
public partial class ChannelListItem : OsuClickableContainer public partial class ChannelListItem : OsuClickableContainer, IFilterable
{ {
public event Action<Channel>? OnRequestSelect; public event Action<Channel>? OnRequestSelect;
public event Action<Channel>? OnRequestLeave; public event Action<Channel>? OnRequestLeave;
@ -186,5 +188,28 @@ namespace osu.Game.Overlays.Chat.ChannelList
} }
private bool isSelector => Channel is ChannelListing.ChannelListingChannel; private bool isSelector => Channel is ChannelListing.ChannelListingChannel;
#region Filtering support
public IEnumerable<LocalisableString> FilterTerms => isSelector ? Enumerable.Empty<LocalisableString>() : [Channel.Name];
private bool matchingFilter = true;
public bool MatchingFilter
{
get => matchingFilter;
set
{
if (matchingFilter == value)
return;
matchingFilter = value;
Alpha = matchingFilter ? 1 : 0;
}
}
public bool FilteringActive { get; set; }
#endregion
} }
} }