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 @@ public class MainSettings : SettingsOverlay
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
protected override Drawable CreateFooter() => new SettingsFooter();
public MainSettings() : base(true)
{
}
}
}

View File

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

View File

@ -14,12 +14,12 @@
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 int EXPANDED_WIDTH = 200;
protected override Container<Drawable> Content => content;
protected override Container<SidebarButton> Content => content;
public Sidebar()
{
@ -35,7 +35,7 @@ public Sidebar()
{
Children = new[]
{
content = new FillFlowContainer
content = new FillFlowContainer<SidebarButton>
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,

View File

@ -6,6 +6,7 @@
using System.Linq;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -29,7 +30,6 @@ public abstract class SettingsOverlay : OsuFocusedOverlayContainer
private const float sidebar_padding = 10;
private Sidebar sidebar;
private SidebarButton[] sidebarButtons;
private SidebarButton selectedSidebarButton;
private SettingsSectionsContainer sectionsContainer;
@ -38,19 +38,20 @@ public abstract class SettingsOverlay : OsuFocusedOverlayContainer
private Func<float> getToolbarHeight;
protected SettingsOverlay()
private readonly bool showSidebar;
protected SettingsOverlay(bool showSidebar)
{
this.showSidebar = showSidebar;
RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X;
}
protected abstract IEnumerable<SettingsSection> CreateSections();
protected virtual IEnumerable<SettingsSection> CreateSections() => null;
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game)
{
var sections = CreateSections().ToList();
Children = new Drawable[]
{
new Box
@ -78,39 +79,53 @@ private void load(OsuGame game)
},
Exit = Hide,
},
Children = sections,
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];
selectedSidebarButton.Selected = true;
sectionsContainer.SelectedSection.ValueChanged += section =>
if (showSidebar)
{
selectedSidebarButton.Selected = false;
selectedSidebarButton = sidebarButtons.Single(b => b.Section == section);
selectedSidebarButton.Selected = true;
};
Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH });
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;
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();
@ -122,7 +137,7 @@ protected override void PopIn()
base.PopIn();
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);
searchTextBox.HoldFocus = true;
@ -133,7 +148,7 @@ protected override void PopOut()
base.PopOut();
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);
searchTextBox.HoldFocus = false;
@ -155,7 +170,7 @@ protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
sectionsContainer.Margin = new MarginPadding { Left = sidebar.DrawWidth };
sectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 };
sectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() };
}