1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Tidy up how subpanels are handled in SettingsOverlay

This commit is contained in:
Dean Herbert 2019-05-27 01:45:37 +09:00
parent 53b2245330
commit 02e2fb963a

View File

@ -8,13 +8,12 @@ using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections; using osu.Game.Overlays.Settings.Sections;
using osuTK.Graphics; using osuTK.Graphics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class SettingsOverlay : SettingsPanel public class SettingsOverlay : SettingsPanel
{ {
private readonly KeyBindingPanel keyBindingPanel;
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[] protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
{ {
new GeneralSection(), new GeneralSection(),
@ -22,29 +21,37 @@ namespace osu.Game.Overlays
new GameplaySection(), new GameplaySection(),
new AudioSection(), new AudioSection(),
new SkinSection(), new SkinSection(),
new InputSection(keyBindingPanel), new InputSection(createSubPanel(new KeyBindingPanel())),
new OnlineSection(), new OnlineSection(),
new MaintenanceSection(), new MaintenanceSection(),
new DebugSection(), new DebugSection(),
}; };
private readonly List<SettingsSubPanel> subPanels = new List<SettingsSubPanel>();
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 SettingsOverlay() public SettingsOverlay()
: base(true) : base(true)
{ {
keyBindingPanel = new KeyBindingPanel
{
Depth = 1,
Anchor = Anchor.TopRight,
};
keyBindingPanel.StateChanged += keyBindingPanelStateChanged;
} }
public override bool AcceptsFocus => keyBindingPanel.State != Visibility.Visible; public override bool AcceptsFocus => subPanels.All(s => s.State != Visibility.Visible);
private void keyBindingPanelStateChanged(Visibility visibility) private T createSubPanel<T>(T subPanel)
where T : SettingsSubPanel
{
subPanel.Depth = 1;
subPanel.Anchor = Anchor.TopRight;
subPanel.StateChanged += subPanelStateChanged;
subPanels.Add(subPanel);
return subPanel;
}
private void subPanelStateChanged(Visibility visibility)
{ {
switch (visibility) switch (visibility)
{ {
@ -66,12 +73,13 @@ namespace osu.Game.Overlays
} }
} }
protected override float ExpandedPosition => keyBindingPanel.State == Visibility.Visible ? -WIDTH : base.ExpandedPosition; protected override float ExpandedPosition => subPanels.Any(s => s.State == Visibility.Visible) ? -WIDTH : base.ExpandedPosition;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
ContentContainer.Add(keyBindingPanel); foreach (var s in subPanels)
ContentContainer.Add(s);
} }
} }
} }