1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 01:33:21 +08:00

Dim all but the current section

This commit is contained in:
Dean Herbert 2021-08-19 01:27:14 +09:00
parent e87accafc8
commit 6637c64501
2 changed files with 58 additions and 4 deletions

View File

@ -4,9 +4,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
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.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -19,6 +21,10 @@ namespace osu.Game.Overlays.Settings
protected FillFlowContainer FlowContent; protected FillFlowContainer FlowContent;
protected override Container<Drawable> Content => FlowContent; protected override Container<Drawable> Content => FlowContent;
private IBindable<SettingsSection> selectedSection;
private Container content;
public abstract Drawable CreateIcon(); public abstract Drawable CreateIcon();
public abstract LocalisableString Header { get; } public abstract LocalisableString Header { get; }
@ -36,6 +42,9 @@ namespace osu.Game.Overlays.Settings
public bool FilteringActive { get; set; } public bool FilteringActive { get; set; }
[Resolved]
private SettingsPanel settingsPanel { get; set; }
protected SettingsSection() protected SettingsSection()
{ {
Margin = new MarginPadding { Top = margin }; Margin = new MarginPadding { Top = margin };
@ -65,7 +74,7 @@ namespace osu.Game.Overlays.Settings
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = border_size, Height = border_size,
}, },
new Container content = new Container
{ {
Padding = new MarginPadding Padding = new MarginPadding
{ {
@ -91,6 +100,44 @@ namespace osu.Game.Overlays.Settings
} }
}, },
}); });
selectedSection = settingsPanel.CurrentSection.GetBoundCopy();
selectedSection.BindValueChanged(selected =>
{
if (selected.NewValue == this)
content.FadeIn(500, Easing.OutQuint);
else
content.FadeTo(0.25f, 500, Easing.OutQuint);
}, true);
}
private bool isCurrentSection => selectedSection.Value == this;
protected override bool OnHover(HoverEvent e)
{
if (!isCurrentSection)
content.FadeTo(0.6f, 500, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
if (!isCurrentSection)
content.FadeTo(0.25f, 500, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override bool OnClick(ClickEvent e)
{
if (!isCurrentSection)
settingsPanel.SectionsContainer.ScrollTo(this);
return base.OnClick(e);
}
protected override bool ShouldBeConsideredForInput(Drawable child)
{
return isCurrentSection;
} }
} }
} }

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -21,6 +22,7 @@ using osu.Game.Overlays.Settings;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
[Cached]
public abstract class SettingsPanel : OsuFocusedOverlayContainer public abstract class SettingsPanel : OsuFocusedOverlayContainer
{ {
public const float CONTENT_MARGINS = 15; public const float CONTENT_MARGINS = 15;
@ -46,7 +48,7 @@ namespace osu.Game.Overlays
protected Sidebar Sidebar; protected Sidebar Sidebar;
private SidebarButton selectedSidebarButton; private SidebarButton selectedSidebarButton;
protected SettingsSectionsContainer SectionsContainer; public SettingsSectionsContainer SectionsContainer { get; private set; }
private SeekLimitedSearchTextBox searchTextBox; private SeekLimitedSearchTextBox searchTextBox;
@ -65,6 +67,8 @@ namespace osu.Game.Overlays
private Task sectionsLoadingTask; private Task sectionsLoadingTask;
public IBindable<SettingsSection> CurrentSection = new Bindable<SettingsSection>();
protected SettingsPanel(bool showSidebar) protected SettingsPanel(bool showSidebar)
{ {
this.showSidebar = showSidebar; this.showSidebar = showSidebar;
@ -105,6 +109,7 @@ namespace osu.Game.Overlays
Masking = true, Masking = true,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ExpandableHeader = CreateHeader(), ExpandableHeader = CreateHeader(),
SelectedSection = { BindTarget = CurrentSection },
FixedHeader = searchTextBox = new SeekLimitedSearchTextBox FixedHeader = searchTextBox = new SeekLimitedSearchTextBox
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -238,7 +243,9 @@ namespace osu.Game.Overlays
if (selectedSidebarButton != null) if (selectedSidebarButton != null)
selectedSidebarButton.Selected = false; selectedSidebarButton.Selected = false;
selectedSidebarButton = Sidebar.Children.Single(b => b.Section == section.NewValue); selectedSidebarButton = Sidebar.Children.FirstOrDefault(b => b.Section == section.NewValue);
if (selectedSidebarButton != null)
selectedSidebarButton.Selected = true; selectedSidebarButton.Selected = true;
}, true); }, true);
}); });