Make the settings sidebar optional

Also removes an unnecessary secondary list of SidebarButtons by using generic containers.
This commit is contained in:
Dean Herbert 2017-08-14 14:40:48 +09:00
parent 66fa84a451
commit dccefe1c0e
4 changed files with 81 additions and 62 deletions

View File

@ -25,5 +25,9 @@ namespace osu.Game.Overlays
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves"); protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
protected override Drawable CreateFooter() => new SettingsFooter(); protected override Drawable CreateFooter() => new SettingsFooter();
public MainSettings() : base(true)
{
}
} }
} }

View File

@ -7,7 +7,6 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System.Collections.Generic; using System.Collections.Generic;
@ -25,25 +24,38 @@ namespace osu.Game.Overlays.Settings
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>(); public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
public string[] FilterTerms => new[] { Header }; public string[] FilterTerms => new[] { Header };
private const int header_size = 26;
private const int header_margin = 25;
private const int border_size = 2;
public bool MatchingFilter public bool MatchingFilter
{ {
set set { this.FadeTo(value ? 1 : 0); }
{
this.FadeTo(value ? 1 : 0);
}
} }
private readonly SpriteText headerLabel;
protected SettingsSection() protected SettingsSection()
{ {
Margin = new MarginPadding { Top = 20 }; Margin = new MarginPadding { Top = 20 };
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
const int header_size = 26; FlowContent = new FillFlowContainer
const int header_margin = 25; {
const int border_size = 2; Margin = new MarginPadding
{
Top = header_size + header_margin
},
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 30),
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddRangeInternal(new Drawable[] AddRangeInternal(new Drawable[]
{ {
new Box new Box
@ -65,28 +77,16 @@ namespace osu.Game.Overlays.Settings
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Children = new[] Children = new[]
{ {
headerLabel = new OsuSpriteText new OsuSpriteText
{ {
TextSize = header_size, TextSize = header_size,
Text = Header, Text = Header,
Colour = colours.Yellow
}, },
FlowContent = new FillFlowContainer FlowContent
{
Margin = new MarginPadding { Top = header_size + header_margin },
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 30),
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
} }
}, },
}); });
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
headerLabel.Colour = colours.Yellow;
}
} }
} }

View File

@ -14,12 +14,12 @@ using osu.Game.Overlays.Toolbar;
namespace osu.Game.Overlays.Settings namespace osu.Game.Overlays.Settings
{ {
public class Sidebar : Container, IStateful<ExpandedState> public class Sidebar : Container<SidebarButton>, IStateful<ExpandedState>
{ {
private readonly FillFlowContainer content; private readonly FillFlowContainer<SidebarButton> content;
internal const float DEFAULT_WIDTH = ToolbarButton.WIDTH; internal const float DEFAULT_WIDTH = ToolbarButton.WIDTH;
internal const int EXPANDED_WIDTH = 200; internal const int EXPANDED_WIDTH = 200;
protected override Container<Drawable> Content => content; protected override Container<SidebarButton> Content => content;
public Sidebar() public Sidebar()
{ {
@ -35,7 +35,7 @@ namespace osu.Game.Overlays.Settings
{ {
Children = new[] Children = new[]
{ {
content = new FillFlowContainer content = new FillFlowContainer<SidebarButton>
{ {
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -29,7 +30,6 @@ namespace osu.Game.Overlays
private const float sidebar_padding = 10; private const float sidebar_padding = 10;
private Sidebar sidebar; private Sidebar sidebar;
private SidebarButton[] sidebarButtons;
private SidebarButton selectedSidebarButton; private SidebarButton selectedSidebarButton;
private SettingsSectionsContainer sectionsContainer; private SettingsSectionsContainer sectionsContainer;
@ -38,19 +38,20 @@ namespace osu.Game.Overlays
private Func<float> getToolbarHeight; private Func<float> getToolbarHeight;
protected SettingsOverlay() private readonly bool showSidebar;
protected SettingsOverlay(bool showSidebar)
{ {
this.showSidebar = showSidebar;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
} }
protected abstract IEnumerable<SettingsSection> CreateSections(); protected virtual IEnumerable<SettingsSection> CreateSections() => null;
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game) private void load(OsuGame game)
{ {
var sections = CreateSections().ToList();
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -78,39 +79,53 @@ namespace osu.Game.Overlays
}, },
Exit = Hide, Exit = Hide,
}, },
Children = sections,
Footer = CreateFooter() Footer = CreateFooter()
},
sidebar = new Sidebar
{
Width = SIDEBAR_WIDTH,
Children = sidebarButtons = sections.Select(section =>
new SidebarButton
{
Section = section,
Action = s =>
{
sectionsContainer.ScrollTo(s);
sidebar.State = ExpandedState.Contracted;
},
}
).ToArray()
} }
}; };
selectedSidebarButton = sidebarButtons[0]; if (showSidebar)
selectedSidebarButton.Selected = true;
sectionsContainer.SelectedSection.ValueChanged += section =>
{ {
selectedSidebarButton.Selected = false; Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH });
selectedSidebarButton = sidebarButtons.Single(b => b.Section == section);
selectedSidebarButton.Selected = true; sectionsContainer.SelectedSection.ValueChanged += section =>
}; {
selectedSidebarButton.Selected = false;
selectedSidebarButton = sidebar.Children.Single(b => b.Section == section);
selectedSidebarButton.Selected = true;
};
}
searchTextBox.Current.ValueChanged += newValue => sectionsContainer.SearchContainer.SearchTerm = newValue; searchTextBox.Current.ValueChanged += newValue => sectionsContainer.SearchContainer.SearchTerm = newValue;
getToolbarHeight = () => game?.ToolbarOffset ?? 0; getToolbarHeight = () => game?.ToolbarOffset ?? 0;
CreateSections()?.ForEach(AddSection);
}
protected void AddSection(SettingsSection section)
{
sectionsContainer.Add(section);
if (sidebar != null)
{
var button = new SidebarButton
{
Section = section,
Action = s =>
{
sectionsContainer.ScrollTo(s);
sidebar.State = ExpandedState.Contracted;
},
};
sidebar.Add(button);
if (selectedSidebarButton == null)
{
selectedSidebarButton = sidebar.Children.First();
selectedSidebarButton.Selected = true;
}
}
} }
protected virtual Drawable CreateHeader() => new Container(); protected virtual Drawable CreateHeader() => new Container();
@ -122,7 +137,7 @@ namespace osu.Game.Overlays
base.PopIn(); base.PopIn();
sectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); sectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
sidebar.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
this.FadeTo(1, TRANSITION_LENGTH / 2); this.FadeTo(1, TRANSITION_LENGTH / 2);
searchTextBox.HoldFocus = true; searchTextBox.HoldFocus = true;
@ -133,7 +148,7 @@ namespace osu.Game.Overlays
base.PopOut(); base.PopOut();
sectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); sectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint);
sidebar.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint);
this.FadeTo(0, TRANSITION_LENGTH / 2); this.FadeTo(0, TRANSITION_LENGTH / 2);
searchTextBox.HoldFocus = false; searchTextBox.HoldFocus = false;
@ -155,7 +170,7 @@ namespace osu.Game.Overlays
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
sectionsContainer.Margin = new MarginPadding { Left = sidebar.DrawWidth }; sectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 };
sectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; sectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() };
} }