Store last opened settings subpanel rather than relying on LINQ

This commit is contained in:
Salman Ahmed 2021-08-06 18:38:14 +03:00
parent 4620ba8787
commit 067ff0e0ad
1 changed files with 8 additions and 5 deletions

View File

@ -9,7 +9,6 @@
using osu.Game.Overlays.Settings.Sections.Input;
using osuTK.Graphics;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Game.Localisation;
@ -38,6 +37,8 @@ public class SettingsOverlay : SettingsPanel, INamedOverlayComponent
private readonly List<SettingsSubPanel> subPanels = new List<SettingsSubPanel>();
private SettingsSubPanel lastOpenedSubPanel;
protected override Drawable CreateHeader() => new SettingsHeader(Title, Description);
protected override Drawable CreateFooter() => new SettingsFooter();
@ -46,21 +47,21 @@ public SettingsOverlay()
{
}
public override bool AcceptsFocus => subPanels.All(s => s.State.Value != Visibility.Visible);
public override bool AcceptsFocus => lastOpenedSubPanel == null || lastOpenedSubPanel.State.Value == Visibility.Hidden;
private T createSubPanel<T>(T subPanel)
where T : SettingsSubPanel
{
subPanel.Depth = 1;
subPanel.Anchor = Anchor.TopRight;
subPanel.State.ValueChanged += subPanelStateChanged;
subPanel.State.ValueChanged += e => subPanelStateChanged(subPanel, e);
subPanels.Add(subPanel);
return subPanel;
}
private void subPanelStateChanged(ValueChangedEvent<Visibility> state)
private void subPanelStateChanged(SettingsSubPanel panel, ValueChangedEvent<Visibility> state)
{
switch (state.NewValue)
{
@ -69,6 +70,8 @@ private void subPanelStateChanged(ValueChangedEvent<Visibility> state)
SectionsContainer.FadeOut(300, Easing.OutQuint);
ContentContainer.MoveToX(-WIDTH, 500, Easing.OutQuint);
lastOpenedSubPanel = panel;
break;
case Visibility.Hidden:
@ -80,7 +83,7 @@ private void subPanelStateChanged(ValueChangedEvent<Visibility> state)
}
}
protected override float ExpandedPosition => subPanels.Any(s => s.State.Value == Visibility.Visible) ? -WIDTH : base.ExpandedPosition;
protected override float ExpandedPosition => lastOpenedSubPanel?.State.Value == Visibility.Visible ? -WIDTH : base.ExpandedPosition;
[BackgroundDependencyLoader]
private void load()