1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 14:17:27 +08:00
osu-lazer/osu.Game/Overlays/SettingsOverlay.cs

122 lines
4.0 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Game.Graphics;
using osu.Game.Localisation;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Overlays.Settings.Sections.Input;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays
{
2022-11-24 13:32:20 +08:00
public partial class SettingsOverlay : SettingsPanel, INamedOverlayComponent
2018-04-13 17:19:50 +08:00
{
public IconUsage Icon => OsuIcon.Settings;
public LocalisableString Title => SettingsStrings.HeaderTitle;
public LocalisableString Description => SettingsStrings.HeaderDescription;
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
2018-04-13 17:19:50 +08:00
{
// This list should be kept in sync with ScreenBehaviour.
new GeneralSection(),
new SkinSection(),
new InputSection(createSubPanel(new KeyBindingPanel())),
new UserInterfaceSection(),
new GameplaySection(),
2021-10-12 13:31:08 +08:00
new RulesetSection(),
new AudioSection(),
new GraphicsSection(),
new OnlineSection(),
new MaintenanceSection(),
new DebugSection(),
};
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();
public SettingsOverlay()
: base(false)
2018-04-13 17:19:50 +08:00
{
}
public override bool AcceptsFocus => lastOpenedSubPanel == null || lastOpenedSubPanel.State.Value == Visibility.Hidden;
public void ShowAtControl<T>()
where T : Drawable
{
Show();
// wait for load of sections
if (!SectionsContainer.Any())
{
Scheduler.Add(ShowAtControl<T>);
return;
}
SectionsContainer.ScrollTo(SectionsContainer.ChildrenOfType<T>().Single());
}
private T createSubPanel<T>(T subPanel)
where T : SettingsSubPanel
{
subPanel.Depth = 1;
subPanel.Anchor = Anchor.TopRight;
subPanel.State.ValueChanged += e => subPanelStateChanged(subPanel, e);
subPanels.Add(subPanel);
return subPanel;
}
2018-04-13 17:19:50 +08:00
private void subPanelStateChanged(SettingsSubPanel panel, ValueChangedEvent<Visibility> state)
2018-04-13 17:19:50 +08:00
{
switch (state.NewValue)
{
case Visibility.Visible:
Sidebar.Expanded.Value = false;
Sidebar.FadeColour(Color4.DarkGray, 300, Easing.OutQuint);
2018-04-13 17:19:50 +08:00
SectionsContainer.FadeOut(300, Easing.OutQuint);
ContentContainer.MoveToX(-PANEL_WIDTH, 500, Easing.OutQuint);
lastOpenedSubPanel = panel;
break;
2018-04-13 17:19:50 +08:00
case Visibility.Hidden:
Sidebar.Expanded.Value = true;
Sidebar.FadeColour(Color4.White, 300, Easing.OutQuint);
2018-04-13 17:19:50 +08:00
SectionsContainer.FadeIn(500, Easing.OutQuint);
ContentContainer.MoveToX(0, 500, Easing.OutQuint);
break;
}
2018-04-13 17:19:50 +08:00
}
protected override float ExpandedPosition => lastOpenedSubPanel?.State.Value == Visibility.Visible ? -PANEL_WIDTH : base.ExpandedPosition;
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load()
2018-04-13 17:19:50 +08:00
{
foreach (var s in subPanels)
ContentContainer.Add(s);
2018-04-13 17:19:50 +08:00
}
}
}