From 3c4faae554d6f99bc1628fdec84d38ecd8f76f60 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Sun, 7 May 2017 20:35:57 +0200 Subject: [PATCH 1/7] add search box and the ability to search --- osu.Game/Overlays/Options/OptionsSection.cs | 17 +++++++++++++++-- osu.Game/Overlays/Options/OptionsSubsection.cs | 14 +++++++++++++- osu.Game/Overlays/OptionsOverlay.cs | 14 +++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Options/OptionsSection.cs b/osu.Game/Overlays/Options/OptionsSection.cs index d5dafad9ba..4069503a51 100644 --- a/osu.Game/Overlays/Options/OptionsSection.cs +++ b/osu.Game/Overlays/Options/OptionsSection.cs @@ -1,4 +1,6 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . +using System; +using System.Collections.Generic; +// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK; @@ -10,10 +12,11 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using System.Linq; namespace osu.Game.Overlays.Options { - public abstract class OptionsSection : Container + public abstract class OptionsSection : Container, IHasFilterableChildren { protected FillFlowContainer FlowContent; protected override Container Content => FlowContent; @@ -21,6 +24,16 @@ namespace osu.Game.Overlays.Options public abstract FontAwesome Icon { get; } public abstract string Header { get; } + public IEnumerable FilterableChildren => Children.OfType(); + public string[] FilterTerms => new[] { Header }; + public bool MatchingCurrentFilter + { + set + { + FadeTo(value ? 1 : 0); + } + } + private readonly SpriteText headerLabel; protected OptionsSection() diff --git a/osu.Game/Overlays/Options/OptionsSubsection.cs b/osu.Game/Overlays/Options/OptionsSubsection.cs index 9fd2e8fb1e..ff9e60c273 100644 --- a/osu.Game/Overlays/Options/OptionsSubsection.cs +++ b/osu.Game/Overlays/Options/OptionsSubsection.cs @@ -6,10 +6,12 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Game.Graphics.Sprites; +using System.Collections.Generic; +using System.Linq; namespace osu.Game.Overlays.Options { - public abstract class OptionsSubsection : FillFlowContainer + public abstract class OptionsSubsection : FillFlowContainer, IHasFilterableChildren { protected override Container Content => content; @@ -17,6 +19,16 @@ namespace osu.Game.Overlays.Options protected abstract string Header { get; } + public IEnumerable FilterableChildren => Children.OfType(); + public string[] FilterTerms => new[] { Header }; + public bool MatchingCurrentFilter + { + set + { + FadeTo(value ? 1 : 0); + } + } + protected OptionsSubsection() { RelativeSizeAxes = Axes.X; diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index dcbce80c69..afe998c208 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -13,6 +13,7 @@ using System; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Options.Sections; +using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays { @@ -32,6 +33,7 @@ namespace osu.Game.Overlays private Sidebar sidebar; private SidebarButton[] sidebarButtons; private OptionsSection[] sections; + private SearchContainer searchContainer; private float lastKnownScroll; public OptionsOverlay() @@ -43,6 +45,8 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuGame game, OsuColour colours) { + OsuTextBox textBox; + sections = new OptionsSection[] { new GeneralSection(), @@ -92,7 +96,13 @@ namespace osu.Game.Overlays TextSize = 18, 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, 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 }; } From 86f0173c6b476a203034e4b2dfc5483b4f0d72c1 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Mon, 8 May 2017 18:30:00 +0200 Subject: [PATCH 2/7] fix license header --- osu.Game/Overlays/Options/OptionsSection.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Options/OptionsSection.cs b/osu.Game/Overlays/Options/OptionsSection.cs index 4069503a51..5e36f79467 100644 --- a/osu.Game/Overlays/Options/OptionsSection.cs +++ b/osu.Game/Overlays/Options/OptionsSection.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -// Copyright (c) 2007-2017 ppy Pty Ltd . +// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK; @@ -12,6 +10,7 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using System.Collections.Generic; using System.Linq; namespace osu.Game.Overlays.Options From 7d8af5f1da4fd320c20b32ee5f76acf2d16e9bf6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 13:19:31 +0900 Subject: [PATCH 3/7] Use SearchTextBox Correctly handle focus. --- osu.Game/Overlays/OptionsOverlay.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index afe998c208..677c3f7c40 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -13,7 +13,7 @@ using System; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Options.Sections; -using osu.Game.Graphics.UserInterface; +using osu.Game.Screens.Select; namespace osu.Game.Overlays { @@ -33,7 +33,10 @@ namespace osu.Game.Overlays private Sidebar sidebar; private SidebarButton[] sidebarButtons; private OptionsSection[] sections; + private SearchContainer searchContainer; + private SearchTextBox searchTextBox; + private float lastKnownScroll; public OptionsOverlay() @@ -45,8 +48,6 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuGame game, OsuColour colours) { - OsuTextBox textBox; - sections = new OptionsSection[] { new GeneralSection(), @@ -96,11 +97,11 @@ namespace osu.Game.Overlays TextSize = 18, Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 }, }, - textBox = new OsuTextBox + searchTextBox = new SearchTextBox { - PlaceholderText = "Type to search!", Width = width - CONTENT_MARGINS * 2, Margin = new MarginPadding { Left = CONTENT_MARGINS }, + Exit = () => Hide(), }, searchContainer = new SearchContainer { @@ -128,7 +129,7 @@ namespace osu.Game.Overlays } }; - textBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue; + searchTextBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue; scrollContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 }; } @@ -169,6 +170,8 @@ namespace osu.Game.Overlays scrollContainer.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint); sidebar.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint); FadeTo(1, TRANSITION_LENGTH / 2); + + searchTextBox.HoldFocus = true; } protected override void PopOut() @@ -178,6 +181,9 @@ namespace osu.Game.Overlays scrollContainer.MoveToX(-width, TRANSITION_LENGTH, EasingTypes.OutQuint); sidebar.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, EasingTypes.OutQuint); FadeTo(0, TRANSITION_LENGTH / 2); + + searchTextBox.HoldFocus = false; + searchTextBox.TriggerFocusLost(); } } } From df4820440376e89f619752581d555814b3888767 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 13:56:21 +0900 Subject: [PATCH 4/7] Fix OptionsOverlay stealing focus itself. --- osu.Game/Overlays/OptionsOverlay.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 677c3f7c40..1176e91a36 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -14,6 +14,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Options.Sections; using osu.Game.Screens.Select; +using osu.Framework.Input; namespace osu.Game.Overlays { @@ -185,5 +186,11 @@ namespace osu.Game.Overlays searchTextBox.HoldFocus = false; searchTextBox.TriggerFocusLost(); } + + protected override bool OnFocus(InputState state) + { + searchTextBox.TriggerFocus(state); + return false; + } } } From ec67b617aea07053a8cecd7fd0e3140dfe065a7f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 May 2017 14:55:25 +0900 Subject: [PATCH 5/7] Add OptionsHeader class Makes search textbox anchor correctly. Also improves visual styling. --- osu.Game/Overlays/Options/OptionsHeader.cs | 108 +++++++++++++++++++++ osu.Game/Overlays/OptionsOverlay.cs | 72 ++++++-------- osu.Game/osu.Game.csproj | 1 + 3 files changed, 137 insertions(+), 44 deletions(-) create mode 100644 osu.Game/Overlays/Options/OptionsHeader.cs diff --git a/osu.Game/Overlays/Options/OptionsHeader.cs b/osu.Game/Overlays/Options/OptionsHeader.cs new file mode 100644 index 0000000000..1add9dc409 --- /dev/null +++ b/osu.Game/Overlays/Options/OptionsHeader.cs @@ -0,0 +1,108 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Screens.Select; +using OpenTK.Graphics; + +namespace osu.Game.Overlays.Options +{ + public class OptionsHeader : Container + { + public SearchTextBox SearchTextBox; + + private Box background; + + private readonly Func currentScrollOffset; + + public Action Exit; + + /// A reference to the current scroll position of the ScrollContainer we are contained within. + public OptionsHeader(Func currentScrollOffset) + { + this.currentScrollOffset = currentScrollOffset; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + Children = new Drawable[] + { + background = new Box + { + Colour = Color4.Black, + RelativeSizeAxes = Axes.Both, + }, + new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + new OsuSpriteText + { + Text = "settings", + TextSize = 40, + Margin = new MarginPadding { + Left = OptionsOverlay.CONTENT_MARGINS, + Top = Toolbar.Toolbar.TOOLTIP_HEIGHT + }, + }, + new OsuSpriteText + { + Colour = colours.Pink, + Text = "Change the way osu! behaves", + TextSize = 18, + Margin = new MarginPadding { + Left = OptionsOverlay.CONTENT_MARGINS, + Bottom = 30 + }, + }, + SearchTextBox = new SearchTextBox + { + RelativeSizeAxes = Axes.X, + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Width = 0.95f, + Margin = new MarginPadding { + Top = 20, + Bottom = 20 + }, + Exit = () => Exit(), + }, + } + } + }; + } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + // the point at which we will start anchoring to the top. + float anchorOffset = SearchTextBox.Y; + + float scrollPosition = currentScrollOffset(); + + // we want to anchor the search field to the top of the screen when scrolling. + Margin = new MarginPadding { Top = Math.Max(0, scrollPosition - anchorOffset) }; + + // we don't want the header to scroll when scrolling beyond the upper extent. + Y = Math.Min(0, scrollPosition); + + // we get darker as scroll progresses + background.Alpha = Math.Min(1, scrollPosition / anchorOffset) * 0.5f; + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 1176e91a36..6d1a3a64fc 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -10,10 +10,7 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Game.Overlays.Options; using System; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Options.Sections; -using osu.Game.Screens.Select; using osu.Framework.Input; namespace osu.Game.Overlays @@ -35,8 +32,11 @@ namespace osu.Game.Overlays private SidebarButton[] sidebarButtons; private OptionsSection[] sections; + private OptionsHeader header; + + private OptionsFooter footer; + private SearchContainer searchContainer; - private SearchTextBox searchTextBox; private float lastKnownScroll; @@ -47,7 +47,7 @@ namespace osu.Game.Overlays } [BackgroundDependencyLoader(permitNulls: true)] - private void load(OsuGame game, OsuColour colours) + private void load(OsuGame game) { sections = new OptionsSection[] { @@ -75,45 +75,20 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Width = width, Margin = new MarginPadding { Left = SIDEBAR_WIDTH }, - Children = new[] + Children = new Drawable[] { - new FillFlowContainer + searchContainer = new SearchContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, Direction = FillDirection.Vertical, - - Children = new Drawable[] - { - new OsuSpriteText - { - Text = "settings", - TextSize = 40, - Margin = new MarginPadding { Left = CONTENT_MARGINS, Top = Toolbar.Toolbar.TOOLTIP_HEIGHT }, - }, - new OsuSpriteText - { - Colour = colours.Pink, - Text = "Change the way osu! behaves", - TextSize = 18, - Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 }, - }, - searchTextBox = new SearchTextBox - { - Width = width - CONTENT_MARGINS * 2, - Margin = new MarginPadding { Left = CONTENT_MARGINS }, - Exit = () => Hide(), - }, - searchContainer = new SearchContainer - { - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - Direction = FillDirection.Vertical, - Children = sections, - }, - new OptionsFooter() - } - } + Children = sections, + }, + footer = new OptionsFooter(), + header = new OptionsHeader(() => scrollContainer.Current) + { + Exit = Hide, + }, } }, sidebar = new Sidebar @@ -130,11 +105,20 @@ namespace osu.Game.Overlays } }; - searchTextBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue; + header.SearchTextBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue; scrollContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 }; } + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + //we need to update these manually because we can't put the OptionsHeader inside the SearchContainer (due to its anchoring). + searchContainer.Y = header.DrawHeight; + footer.Y = searchContainer.Y + searchContainer.DrawHeight; + } + protected override void Update() { base.Update(); @@ -172,7 +156,7 @@ namespace osu.Game.Overlays sidebar.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint); FadeTo(1, TRANSITION_LENGTH / 2); - searchTextBox.HoldFocus = true; + header.SearchTextBox.HoldFocus = true; } protected override void PopOut() @@ -183,13 +167,13 @@ namespace osu.Game.Overlays sidebar.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, EasingTypes.OutQuint); FadeTo(0, TRANSITION_LENGTH / 2); - searchTextBox.HoldFocus = false; - searchTextBox.TriggerFocusLost(); + header.SearchTextBox.HoldFocus = false; + header.SearchTextBox.TriggerFocusLost(); } protected override bool OnFocus(InputState state) { - searchTextBox.TriggerFocus(state); + header.SearchTextBox.TriggerFocus(state); return false; } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index bd9f087cf7..904cf7f437 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -78,6 +78,7 @@ + From d2e066ca35f199d6e12f9da330b0f14ba83e6855 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 May 2017 19:57:06 +0900 Subject: [PATCH 6/7] Move SearchTextBox to better namespace Is being used in multiple places now. --- .../Select => Graphics/UserInterface}/SearchTextBox.cs | 6 ++---- osu.Game/Overlays/Options/OptionsHeader.cs | 1 + osu.Game/osu.Game.csproj | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) rename osu.Game/{Screens/Select => Graphics/UserInterface}/SearchTextBox.cs (91%) diff --git a/osu.Game/Screens/Select/SearchTextBox.cs b/osu.Game/Graphics/UserInterface/SearchTextBox.cs similarity index 91% rename from osu.Game/Screens/Select/SearchTextBox.cs rename to osu.Game/Graphics/UserInterface/SearchTextBox.cs index 4f2ab221cb..18148e9d31 100644 --- a/osu.Game/Screens/Select/SearchTextBox.cs +++ b/osu.Game/Graphics/UserInterface/SearchTextBox.cs @@ -1,14 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using OpenTK.Input; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osu.Framework.Input; -using osu.Game.Graphics; -using osu.Game.Graphics.UserInterface; +using OpenTK.Input; -namespace osu.Game.Screens.Select +namespace osu.Game.Graphics.UserInterface { /// /// A textbox which holds focus eagerly. diff --git a/osu.Game/Overlays/Options/OptionsHeader.cs b/osu.Game/Overlays/Options/OptionsHeader.cs index 1add9dc409..c173b8844d 100644 --- a/osu.Game/Overlays/Options/OptionsHeader.cs +++ b/osu.Game/Overlays/Options/OptionsHeader.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using osu.Game.Screens.Select; using OpenTK.Graphics; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 904cf7f437..a8f5c11a80 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -384,7 +384,7 @@ - + From 6c117f15afa03da81f62d9600331e107a22399d8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 May 2017 20:06:38 +0900 Subject: [PATCH 7/7] Remove unnecessary usings --- osu.Game/Overlays/Music/FilterControl.cs | 1 - osu.Game/Overlays/Options/OptionsHeader.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/osu.Game/Overlays/Music/FilterControl.cs b/osu.Game/Overlays/Music/FilterControl.cs index c6572c5ed2..0b4e067fff 100644 --- a/osu.Game/Overlays/Music/FilterControl.cs +++ b/osu.Game/Overlays/Music/FilterControl.cs @@ -10,7 +10,6 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; -using osu.Game.Screens.Select; using OpenTK; using OpenTK.Graphics; using System; diff --git a/osu.Game/Overlays/Options/OptionsHeader.cs b/osu.Game/Overlays/Options/OptionsHeader.cs index c173b8844d..8b97a607a2 100644 --- a/osu.Game/Overlays/Options/OptionsHeader.cs +++ b/osu.Game/Overlays/Options/OptionsHeader.cs @@ -10,7 +10,6 @@ using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; -using osu.Game.Screens.Select; using OpenTK.Graphics; namespace osu.Game.Overlays.Options