From 32196c57af1b0b5a368a90af0d8ff09d1e88cf76 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 9 Nov 2016 00:17:48 -0500 Subject: [PATCH] Track the visible section in options --- osu.Game/Overlays/Options/OptionsSidebar.cs | 41 +++++++++++++++++---- osu.Game/Overlays/OptionsOverlay.cs | 36 +++++++++++++++--- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/Options/OptionsSidebar.cs b/osu.Game/Overlays/Options/OptionsSidebar.cs index 6f1cb4a48c..111aad5ecd 100644 --- a/osu.Game/Overlays/Options/OptionsSidebar.cs +++ b/osu.Game/Overlays/Options/OptionsSidebar.cs @@ -77,18 +77,36 @@ namespace osu.Game.Overlays.Options private TextAwesome drawableIcon; private SpriteText headerText; private Box backgroundBox; + private Box selectionIndicator; public Action Action; - public FontAwesome Icon + private OptionsSection section; + public OptionsSection Section { - get { return drawableIcon.Icon; } - set { drawableIcon.Icon = value; } + get + { + return section; + } + set + { + section = value; + headerText.Text = value.Header; + drawableIcon.Icon = value.Icon; + } } - - public string Header + + private bool selected; + public bool Selected { - get { return headerText.Text; } - set { headerText.Text = value; } + get { return selected; } + set + { + selected = value; + if (selected) + selectionIndicator.FadeIn(50); + else + selectionIndicator.FadeOut(50); + } } public SidebarButton() @@ -122,6 +140,15 @@ namespace osu.Game.Overlays.Options Position = new Vector2(default_width + 10, 0), Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, + }, + selectionIndicator = new Box + { + Alpha = 0, + RelativeSizeAxes = Axes.Y, + Width = 5, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Colour = new Color4(233, 103, 161, 255) } }; } diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 2e00bef970..b72c2293c9 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -33,10 +33,12 @@ namespace osu.Game.Overlays private ScrollContainer scrollContainer; private OptionsSidebar sidebar; + private OptionsSidebar.SidebarButton[] sidebarButtons; + private OptionsSection[] sections; public OptionsOverlay() { - var sections = new OptionsSection[] + sections = new OptionsSection[] { new GeneralSection(), new GraphicsSection(), @@ -67,6 +69,7 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Width = width, Margin = new MarginPadding { Left = sidebar_width }, + Scrolled = ScrollContainer_Scrolled, Children = new[] { new FlowContainer @@ -104,14 +107,15 @@ namespace osu.Game.Overlays sidebar = new OptionsSidebar { Width = sidebar_width, - Children = sections.Select(section => + Children = sidebarButtons = sections.Select(section => new OptionsSidebar.SidebarButton { - Icon = section.Icon, - Header = section.Header, - Action = () => scrollContainer.ScrollIntoView(section), + Selected = sections[0] == section, + Section = section, + Action = () => scrollContainer.ScrollTo( + scrollContainer.GetChildY(section) - scrollContainer.DrawSize.Y / 2), } - ) + ).ToArray() } }; } @@ -123,6 +127,26 @@ namespace osu.Game.Overlays scrollContainer.Padding = new MarginPadding { Top = (game as OsuGame)?.Toolbar.DrawHeight ?? 0 }; } + private void ScrollContainer_Scrolled(float value) + { + for (int i = sections.Length - 1; i >= 0; i--) + { + var section = sections[i]; + float y = scrollContainer.GetChildY(section) - value; + if (y <= scrollContainer.DrawSize.Y / 2) + { + var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); + var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section); + if (next != null) + { + previous.Selected = false; + next.Selected = true; + } + break; + } + } + } + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)