Track the visible section in options

This commit is contained in:
Drew DeVault 2016-11-09 00:17:48 -05:00
parent 226d1aa0da
commit 32196c57af
2 changed files with 64 additions and 13 deletions

View File

@ -77,18 +77,36 @@ namespace osu.Game.Overlays.Options
private TextAwesome drawableIcon; private TextAwesome drawableIcon;
private SpriteText headerText; private SpriteText headerText;
private Box backgroundBox; private Box backgroundBox;
private Box selectionIndicator;
public Action Action; public Action Action;
public FontAwesome Icon private OptionsSection section;
public OptionsSection Section
{ {
get { return drawableIcon.Icon; } get
set { drawableIcon.Icon = value; } {
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; } get { return selected; }
set { headerText.Text = value; } set
{
selected = value;
if (selected)
selectionIndicator.FadeIn(50);
else
selectionIndicator.FadeOut(50);
}
} }
public SidebarButton() public SidebarButton()
@ -122,6 +140,15 @@ namespace osu.Game.Overlays.Options
Position = new Vector2(default_width + 10, 0), Position = new Vector2(default_width + 10, 0),
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = 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)
} }
}; };
} }

View File

@ -33,10 +33,12 @@ namespace osu.Game.Overlays
private ScrollContainer scrollContainer; private ScrollContainer scrollContainer;
private OptionsSidebar sidebar; private OptionsSidebar sidebar;
private OptionsSidebar.SidebarButton[] sidebarButtons;
private OptionsSection[] sections;
public OptionsOverlay() public OptionsOverlay()
{ {
var sections = new OptionsSection[] sections = new OptionsSection[]
{ {
new GeneralSection(), new GeneralSection(),
new GraphicsSection(), new GraphicsSection(),
@ -67,6 +69,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = width, Width = width,
Margin = new MarginPadding { Left = sidebar_width }, Margin = new MarginPadding { Left = sidebar_width },
Scrolled = ScrollContainer_Scrolled,
Children = new[] Children = new[]
{ {
new FlowContainer new FlowContainer
@ -104,14 +107,15 @@ namespace osu.Game.Overlays
sidebar = new OptionsSidebar sidebar = new OptionsSidebar
{ {
Width = sidebar_width, Width = sidebar_width,
Children = sections.Select(section => Children = sidebarButtons = sections.Select(section =>
new OptionsSidebar.SidebarButton new OptionsSidebar.SidebarButton
{ {
Icon = section.Icon, Selected = sections[0] == section,
Header = section.Header, Section = section,
Action = () => scrollContainer.ScrollIntoView(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 }; 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 OnMouseDown(InputState state, MouseDownEventArgs args) => true;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)