1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Make sidebar buttons working.

This commit is contained in:
Huo Yaoyuan 2017-05-21 04:32:15 +08:00
parent aa409ac1a9
commit f06f8b4dcd
2 changed files with 16 additions and 6 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Overlays.Settings
private readonly Box backgroundBox;
private readonly Box selectionIndicator;
private readonly Container text;
public Action Action;
public Action<SettingsSection> Action;
private SettingsSection section;
public SettingsSection Section
@ -75,6 +75,7 @@ namespace osu.Game.Overlays.Settings
{
Width = Sidebar.DEFAULT_WIDTH,
RelativeSizeAxes = Axes.Y,
Colour = OsuColour.Gray(0.6f),
Children = new[]
{
headerText = new OsuSpriteText
@ -110,7 +111,7 @@ namespace osu.Game.Overlays.Settings
protected override bool OnClick(InputState state)
{
Action?.Invoke();
Action?.Invoke(section);
backgroundBox.FlashColour(Color4.White, 400);
return true;
}

View File

@ -29,7 +29,7 @@ namespace osu.Game.Overlays
private Sidebar sidebar;
private SidebarButton[] sidebarButtons;
private SettingsSection[] sections;
private SidebarButton selectedSidebarButton;
private SettingsSectionsContainer sectionsContainer;
@ -44,7 +44,7 @@ namespace osu.Game.Overlays
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game)
{
sections = new SettingsSection[]
var sections = new SettingsSection[]
{
new GeneralSection(),
new GraphicsSection(),
@ -92,14 +92,23 @@ namespace osu.Game.Overlays
Children = sidebarButtons = sections.Select(section =>
new SidebarButton
{
Selected = sections[0] == section,
Section = section,
Action = () => sectionsContainer.ScrollContainer.ScrollIntoView(section),
Action = sectionsContainer.ScrollContainer.ScrollIntoView,
}
).ToArray()
}
};
selectedSidebarButton = sidebarButtons[0];
selectedSidebarButton.Selected = true;
sectionsContainer.SelectedSection.ValueChanged += section =>
{
selectedSidebarButton.Selected = false;
selectedSidebarButton = sidebarButtons.Single(b => b.Section == section);
selectedSidebarButton.Selected = true;
};
searchTextBox.Current.ValueChanged += newValue => sectionsContainer.SearchContainer.SearchTerm = newValue;
sectionsContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 };