1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 13:27:23 +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 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,13 +127,16 @@ 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()
{
base.Update();
if (scrollContainer.Current != lastKnownScroll)
{ {
for (int i = sections.Length - 1; i >= 0; i--) for (int i = sections.Length - 1; i >= 0; i--)
{ {
var section = sections[i]; var section = sections[i];
float y = scrollContainer.GetChildY(section) - value; float y = scrollContainer.GetChildYInContent(section) - scrollContainer.Current;
if (y <= scrollContainer.DrawSize.Y / 2) if (y <= scrollContainer.DrawSize.Y / 2 + 25)
{ {
var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected);
var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section); 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; protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;