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 @@ public class SidebarButton : Container
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 @@ public SidebarButton()
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)
}
};
}

View File

@ -33,10 +33,12 @@ public class OptionsOverlay : OverlayContainer
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 @@ public OptionsOverlay()
RelativeSizeAxes = Axes.Y,
Width = width,
Margin = new MarginPadding { Left = sidebar_width },
Scrolled = ScrollContainer_Scrolled,
Children = new[]
{
new FlowContainer
@ -104,14 +107,15 @@ public OptionsOverlay()
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 @@ protected override void Load(BaseGame game)
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)