1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 17:57:38 +08:00

add search box and the ability to search

This commit is contained in:
Jorolf 2017-05-07 20:35:57 +02:00
parent ef02f80881
commit 3c4faae554
3 changed files with 41 additions and 4 deletions

View File

@ -1,4 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. using System;
using System.Collections.Generic;
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK; using OpenTK;
@ -10,10 +12,11 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System.Linq;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public abstract class OptionsSection : Container public abstract class OptionsSection : Container, IHasFilterableChildren
{ {
protected FillFlowContainer FlowContent; protected FillFlowContainer FlowContent;
protected override Container<Drawable> Content => FlowContent; protected override Container<Drawable> Content => FlowContent;
@ -21,6 +24,16 @@ namespace osu.Game.Overlays.Options
public abstract FontAwesome Icon { get; } public abstract FontAwesome Icon { get; }
public abstract string Header { get; } public abstract string Header { get; }
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
public string[] FilterTerms => new[] { Header };
public bool MatchingCurrentFilter
{
set
{
FadeTo(value ? 1 : 0);
}
}
private readonly SpriteText headerLabel; private readonly SpriteText headerLabel;
protected OptionsSection() protected OptionsSection()

View File

@ -6,10 +6,12 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public abstract class OptionsSubsection : FillFlowContainer public abstract class OptionsSubsection : FillFlowContainer, IHasFilterableChildren
{ {
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
@ -17,6 +19,16 @@ namespace osu.Game.Overlays.Options
protected abstract string Header { get; } protected abstract string Header { get; }
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
public string[] FilterTerms => new[] { Header };
public bool MatchingCurrentFilter
{
set
{
FadeTo(value ? 1 : 0);
}
}
protected OptionsSubsection() protected OptionsSubsection()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;

View File

@ -13,6 +13,7 @@ using System;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Options.Sections; using osu.Game.Overlays.Options.Sections;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -32,6 +33,7 @@ namespace osu.Game.Overlays
private Sidebar sidebar; private Sidebar sidebar;
private SidebarButton[] sidebarButtons; private SidebarButton[] sidebarButtons;
private OptionsSection[] sections; private OptionsSection[] sections;
private SearchContainer searchContainer;
private float lastKnownScroll; private float lastKnownScroll;
public OptionsOverlay() public OptionsOverlay()
@ -43,6 +45,8 @@ namespace osu.Game.Overlays
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game, OsuColour colours) private void load(OsuGame game, OsuColour colours)
{ {
OsuTextBox textBox;
sections = new OptionsSection[] sections = new OptionsSection[]
{ {
new GeneralSection(), new GeneralSection(),
@ -92,7 +96,13 @@ namespace osu.Game.Overlays
TextSize = 18, TextSize = 18,
Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 }, Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 },
}, },
new FillFlowContainer textBox = new OsuTextBox
{
PlaceholderText = "Type to search!",
Width = width - CONTENT_MARGINS * 2,
Margin = new MarginPadding { Left = CONTENT_MARGINS },
},
searchContainer = new SearchContainer
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -118,6 +128,8 @@ namespace osu.Game.Overlays
} }
}; };
textBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue;
scrollContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 }; scrollContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 };
} }