mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:07:52 +08:00
Make the settings sidebar optional
Also removes an unnecessary secondary list of SidebarButtons by using generic containers.
This commit is contained in:
parent
66fa84a451
commit
dccefe1c0e
@ -25,5 +25,9 @@ namespace osu.Game.Overlays
|
||||
|
||||
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
|
||||
protected override Drawable CreateFooter() => new SettingsFooter();
|
||||
|
||||
public MainSettings() : base(true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ using osu.Framework.Allocation;
|
||||
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 @@ namespace osu.Game.Overlays.Settings
|
||||
|
||||
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 @@ namespace osu.Game.Overlays.Settings
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ using osu.Game.Overlays.Toolbar;
|
||||
|
||||
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 @@ namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
content = new FillFlowContainer
|
||||
content = new FillFlowContainer<SidebarButton>
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
private const float sidebar_padding = 10;
|
||||
|
||||
private Sidebar sidebar;
|
||||
private SidebarButton[] sidebarButtons;
|
||||
private SidebarButton selectedSidebarButton;
|
||||
|
||||
private SettingsSectionsContainer sectionsContainer;
|
||||
@ -38,19 +38,20 @@ namespace osu.Game.Overlays
|
||||
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
},
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
|
||||
sectionsContainer.Margin = new MarginPadding { Left = sidebar.DrawWidth };
|
||||
sectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 };
|
||||
sectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user