1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 10:47:25 +08:00

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.SidebarButton[] sidebarButtons;
private OptionsSection[] sections;
private float lastKnownScroll;
public OptionsOverlay()
{
@ -69,7 +70,6 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Y,
Width = width,
Margin = new MarginPadding { Left = sidebar_width },
Scrolled = ScrollContainer_Scrolled,
Children = new[]
{
new FlowContainer
@ -113,7 +113,7 @@ namespace osu.Game.Overlays
Selected = sections[0] == section,
Section = section,
Action = () => scrollContainer.ScrollTo(
scrollContainer.GetChildY(section) - scrollContainer.DrawSize.Y / 2),
scrollContainer.GetChildYInContent(section) - scrollContainer.DrawSize.Y / 2),
}
).ToArray()
}
@ -127,13 +127,16 @@ namespace osu.Game.Overlays
scrollContainer.Padding = new MarginPadding { Top = (game as OsuGame)?.Toolbar.DrawHeight ?? 0 };
}
private void ScrollContainer_Scrolled(float value)
protected override void Update()
{
base.Update();
if (scrollContainer.Current != lastKnownScroll)
{
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)
float y = scrollContainer.GetChildYInContent(section) - scrollContainer.Current;
if (y <= scrollContainer.DrawSize.Y / 2 + 25)
{
var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected);
var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section);
@ -146,6 +149,7 @@ namespace osu.Game.Overlays
}
}
}
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;