mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Track the visible section in options
This commit is contained in:
parent
226d1aa0da
commit
32196c57af
@ -77,18 +77,36 @@ namespace osu.Game.Overlays.Options
|
||||
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 @@ namespace osu.Game.Overlays.Options
|
||||
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)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -33,10 +33,12 @@ namespace osu.Game.Overlays
|
||||
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Width = width,
|
||||
Margin = new MarginPadding { Left = sidebar_width },
|
||||
Scrolled = ScrollContainer_Scrolled,
|
||||
Children = new[]
|
||||
{
|
||||
new FlowContainer
|
||||
@ -104,14 +107,15 @@ namespace osu.Game.Overlays
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user