Move scroll logic into Update

This commit is contained in:
Drew DeVault 2016-11-10 18:04:39 -05:00
parent 32196c57af
commit a8bba445db

View File

@ -35,6 +35,7 @@ namespace osu.Game.Overlays
private OptionsSidebar sidebar; private OptionsSidebar sidebar;
private OptionsSidebar.SidebarButton[] sidebarButtons; private OptionsSidebar.SidebarButton[] sidebarButtons;
private OptionsSection[] sections; private OptionsSection[] sections;
private float lastKnownScroll;
public OptionsOverlay() public OptionsOverlay()
{ {
@ -69,7 +70,6 @@ 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
@ -113,7 +113,7 @@ namespace osu.Game.Overlays
Selected = sections[0] == section, Selected = sections[0] == section,
Section = section, Section = section,
Action = () => scrollContainer.ScrollTo( Action = () => scrollContainer.ScrollTo(
scrollContainer.GetChildY(section) - scrollContainer.DrawSize.Y / 2), scrollContainer.GetChildYInContent(section) - scrollContainer.DrawSize.Y / 2),
} }
).ToArray() ).ToArray()
} }
@ -127,22 +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) protected override void Update()
{ {
for (int i = sections.Length - 1; i >= 0; i--) base.Update();
if (scrollContainer.Current != lastKnownScroll)
{ {
var section = sections[i]; for (int i = sections.Length - 1; i >= 0; i--)
float y = scrollContainer.GetChildY(section) - value;
if (y <= scrollContainer.DrawSize.Y / 2)
{ {
var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); var section = sections[i];
var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section); float y = scrollContainer.GetChildYInContent(section) - scrollContainer.Current;
if (next != null) if (y <= scrollContainer.DrawSize.Y / 2 + 25)
{ {
previous.Selected = false; var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected);
next.Selected = true; var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section);
if (next != null)
{
previous.Selected = false;
next.Selected = true;
}
break;
} }
break;
} }
} }
} }