2019-05-14 09:45:05 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-05-14 09:45:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-08-17 11:31:33 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Framework.Allocation;
|
2021-08-19 00:27:14 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-26 18:25:05 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-08-19 00:27:14 +08:00
|
|
|
|
[Cached]
|
2019-05-14 09:45:05 +08:00
|
|
|
|
public abstract partial class SettingsPanel : OsuFocusedOverlayContainer
|
|
|
|
|
{
|
2021-10-10 01:18:29 +08:00
|
|
|
|
public const float CONTENT_MARGINS = 20;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
|
|
|
|
public const float TRANSITION_LENGTH = 600;
|
|
|
|
|
|
2022-01-06 16:15:42 +08:00
|
|
|
|
private const float sidebar_width = SettingsSidebar.DEFAULT_WIDTH;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
2021-08-08 00:56:51 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The width of the settings panel content, excluding the sidebar.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const float PANEL_WIDTH = 400;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The full width of the settings panel, including the sidebar.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const float WIDTH = sidebar_width + PANEL_WIDTH;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
|
|
|
|
protected Container<Drawable> ContentContainer;
|
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => ContentContainer;
|
|
|
|
|
|
2022-01-06 16:15:42 +08:00
|
|
|
|
protected SettingsSidebar Sidebar;
|
2021-10-10 02:43:18 +08:00
|
|
|
|
private SidebarIconButton selectedSidebarButton;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
2021-08-19 00:27:14 +08:00
|
|
|
|
public SettingsSectionsContainer SectionsContainer { get; private set; }
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
2019-10-22 07:00:09 +08:00
|
|
|
|
private SeekLimitedSearchTextBox searchTextBox;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
2021-01-15 13:57:46 +08:00
|
|
|
|
protected override string PopInSampleName => "UI/settings-pop-in";
|
|
|
|
|
|
2019-05-14 09:45:05 +08:00
|
|
|
|
private readonly bool showSidebar;
|
|
|
|
|
|
2021-08-16 18:18:39 +08:00
|
|
|
|
private LoadingLayer loading;
|
|
|
|
|
|
2021-08-17 11:31:33 +08:00
|
|
|
|
private readonly List<SettingsSection> loadableSections = new List<SettingsSection>();
|
|
|
|
|
|
|
|
|
|
private Task sectionsLoadingTask;
|
|
|
|
|
|
2021-08-19 00:27:14 +08:00
|
|
|
|
public IBindable<SettingsSection> CurrentSection = new Bindable<SettingsSection>();
|
|
|
|
|
|
2021-10-03 23:30:22 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
|
|
|
|
|
2019-05-14 09:45:05 +08:00
|
|
|
|
protected SettingsPanel(bool showSidebar)
|
|
|
|
|
{
|
|
|
|
|
this.showSidebar = showSidebar;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual IEnumerable<SettingsSection> CreateSections() => null;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2021-05-26 18:25:05 +08:00
|
|
|
|
InternalChild = ContentContainer = new NonMaskedContent
|
2019-05-14 09:45:05 +08:00
|
|
|
|
{
|
2021-08-06 23:36:43 +08:00
|
|
|
|
X = -WIDTH + ExpandedPosition,
|
2021-08-08 00:56:51 +08:00
|
|
|
|
Width = PANEL_WIDTH,
|
2019-05-14 09:45:05 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-05-26 18:25:05 +08:00
|
|
|
|
new Box
|
2019-05-14 09:45:05 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Scale = new Vector2(2, 1), // over-extend to the left for transitions
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-10-03 23:30:22 +08:00
|
|
|
|
Colour = colourProvider.Background4,
|
2020-11-30 16:18:29 +08:00
|
|
|
|
Alpha = 1,
|
2019-05-14 09:45:05 +08:00
|
|
|
|
},
|
2021-08-16 18:18:39 +08:00
|
|
|
|
loading = new LoadingLayer
|
2019-05-14 09:45:05 +08:00
|
|
|
|
{
|
2021-08-16 18:18:39 +08:00
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
|
}
|
2019-05-14 09:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-17 11:31:33 +08:00
|
|
|
|
Add(SectionsContainer = new SettingsSectionsContainer
|
2021-08-16 18:18:39 +08:00
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ExpandableHeader = CreateHeader(),
|
2021-08-19 00:27:14 +08:00
|
|
|
|
SelectedSection = { BindTarget = CurrentSection },
|
2021-10-10 01:18:29 +08:00
|
|
|
|
FixedHeader = new Container
|
2021-08-16 18:18:39 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-10-10 01:18:29 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding
|
2021-08-16 18:18:39 +08:00
|
|
|
|
{
|
2021-10-10 01:18:29 +08:00
|
|
|
|
Vertical = 20,
|
|
|
|
|
Horizontal = CONTENT_MARGINS
|
2021-08-16 18:18:39 +08:00
|
|
|
|
},
|
2021-10-10 01:18:29 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Child = searchTextBox = new SeekLimitedSearchTextBox
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
}
|
2021-08-16 18:18:39 +08:00
|
|
|
|
},
|
2021-08-17 11:31:33 +08:00
|
|
|
|
Footer = CreateFooter().With(f => f.Alpha = 0)
|
|
|
|
|
});
|
2021-08-16 18:18:39 +08:00
|
|
|
|
|
2019-05-14 09:45:05 +08:00
|
|
|
|
if (showSidebar)
|
|
|
|
|
{
|
2022-01-06 16:15:42 +08:00
|
|
|
|
AddInternal(Sidebar = new SettingsSidebar { Width = sidebar_width });
|
2019-05-14 09:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreateSections()?.ForEach(AddSection);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 18:47:27 +08:00
|
|
|
|
protected void AddSection(SettingsSection section)
|
|
|
|
|
{
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
// just to keep things simple. can be accommodated for if we ever need it.
|
|
|
|
|
throw new InvalidOperationException("All sections must be added before the panel is loaded.");
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
2021-08-17 11:31:33 +08:00
|
|
|
|
loadableSections.Add(section);
|
2019-05-14 09:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual Drawable CreateHeader() => new Container();
|
|
|
|
|
|
|
|
|
|
protected virtual Drawable CreateFooter() => new Container();
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
|
2021-08-16 18:51:13 +08:00
|
|
|
|
ContentContainer.MoveToX(ExpandedPosition, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
// delay load enough to ensure it doesn't overlap with the initial animation.
|
|
|
|
|
// this is done as there is still a brief stutter during load completion which is more visible if the transition is in progress.
|
|
|
|
|
// the eventual goal would be to remove the need for this by splitting up load into smaller work pieces, or fixing the remaining
|
|
|
|
|
// load complete overheads.
|
2021-08-17 11:31:33 +08:00
|
|
|
|
Scheduler.AddDelayed(loadSections, TRANSITION_LENGTH / 3);
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
|
|
|
|
Sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
this.FadeTo(1, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
2022-04-14 19:06:00 +08:00
|
|
|
|
searchTextBox.TakeFocus();
|
2019-05-14 09:45:05 +08:00
|
|
|
|
searchTextBox.HoldFocus = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual float ExpandedPosition => 0;
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
|
|
|
|
|
2021-05-26 18:25:05 +08:00
|
|
|
|
ContentContainer.MoveToX(-WIDTH + ExpandedPosition, TRANSITION_LENGTH, Easing.OutQuint);
|
2019-05-14 09:45:05 +08:00
|
|
|
|
|
|
|
|
|
Sidebar?.MoveToX(-sidebar_width, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
searchTextBox.HoldFocus = false;
|
|
|
|
|
if (searchTextBox.HasFocus)
|
|
|
|
|
GetContainingInputManager().ChangeFocus(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool AcceptsFocus => true;
|
|
|
|
|
|
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
|
|
|
|
{
|
2021-08-18 11:45:08 +08:00
|
|
|
|
searchTextBox.TakeFocus();
|
2019-05-14 09:45:05 +08:00
|
|
|
|
base.OnFocus(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
ContentContainer.Margin = new MarginPadding { Left = Sidebar?.DrawWidth ?? 0 };
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 20:17:06 +08:00
|
|
|
|
private const double fade_in_duration = 500;
|
2021-08-17 11:31:33 +08:00
|
|
|
|
|
|
|
|
|
private void loadSections()
|
|
|
|
|
{
|
|
|
|
|
if (sectionsLoadingTask != null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
sectionsLoadingTask = LoadComponentsAsync(loadableSections, sections =>
|
|
|
|
|
{
|
|
|
|
|
SectionsContainer.AddRange(sections);
|
|
|
|
|
SectionsContainer.Footer.FadeInFromZero(fade_in_duration, Easing.OutQuint);
|
|
|
|
|
SectionsContainer.SearchContainer.FadeInFromZero(fade_in_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
loading.Hide();
|
|
|
|
|
|
2021-08-24 00:13:25 +08:00
|
|
|
|
searchTextBox.Current.BindValueChanged(term => SectionsContainer.SearchTerm = term.NewValue, true);
|
2021-08-17 11:31:33 +08:00
|
|
|
|
|
|
|
|
|
loadSidebarButtons();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadSidebarButtons()
|
|
|
|
|
{
|
|
|
|
|
if (Sidebar == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LoadComponentsAsync(createSidebarButtons(), buttons =>
|
|
|
|
|
{
|
|
|
|
|
float delay = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var button in buttons)
|
|
|
|
|
{
|
|
|
|
|
Sidebar.Add(button);
|
|
|
|
|
|
|
|
|
|
button.FadeOut()
|
|
|
|
|
.Delay(delay)
|
|
|
|
|
.FadeInFromZero(fade_in_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
delay += 40;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SectionsContainer.SelectedSection.BindValueChanged(section =>
|
|
|
|
|
{
|
|
|
|
|
if (selectedSidebarButton != null)
|
|
|
|
|
selectedSidebarButton.Selected = false;
|
|
|
|
|
|
2022-01-06 16:15:42 +08:00
|
|
|
|
selectedSidebarButton = Sidebar.Children.OfType<SidebarIconButton>().FirstOrDefault(b => b.Section == section.NewValue);
|
2021-08-19 00:27:14 +08:00
|
|
|
|
|
|
|
|
|
if (selectedSidebarButton != null)
|
|
|
|
|
selectedSidebarButton.Selected = true;
|
2021-08-17 11:31:33 +08:00
|
|
|
|
}, true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-10 02:43:18 +08:00
|
|
|
|
private IEnumerable<SidebarIconButton> createSidebarButtons()
|
2021-08-17 11:31:33 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var section in SectionsContainer)
|
|
|
|
|
{
|
2021-10-10 02:43:18 +08:00
|
|
|
|
yield return new SidebarIconButton
|
2021-08-17 11:31:33 +08:00
|
|
|
|
{
|
|
|
|
|
Section = section,
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
if (!SectionsContainer.IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SectionsContainer.ScrollTo(section);
|
2022-01-21 22:41:45 +08:00
|
|
|
|
Sidebar.Expanded.Value = false;
|
2021-08-17 11:31:33 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 18:25:05 +08:00
|
|
|
|
private partial class NonMaskedContent : Container<Drawable>
|
|
|
|
|
{
|
|
|
|
|
// masking breaks the pan-out transform with nested sub-settings panels.
|
|
|
|
|
protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 20:56:47 +08:00
|
|
|
|
public partial class SettingsSectionsContainer : SectionsContainer<SettingsSection>
|
2019-05-14 09:45:05 +08:00
|
|
|
|
{
|
|
|
|
|
public SearchContainer<SettingsSection> SearchContainer;
|
|
|
|
|
|
2021-08-19 00:25:57 +08:00
|
|
|
|
public string SearchTerm
|
|
|
|
|
{
|
|
|
|
|
get => SearchContainer.SearchTerm;
|
2022-04-21 23:48:41 +08:00
|
|
|
|
set => SearchContainer.SearchTerm = value;
|
2021-08-19 00:25:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 09:45:05 +08:00
|
|
|
|
protected override FlowContainer<SettingsSection> CreateScrollContentContainer()
|
|
|
|
|
=> SearchContainer = new SearchContainer<SettingsSection>
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-03 23:30:22 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2019-05-14 09:45:05 +08:00
|
|
|
|
{
|
|
|
|
|
HeaderBackground = new Box
|
|
|
|
|
{
|
2021-10-03 23:30:22 +08:00
|
|
|
|
Colour = colourProvider.Background4,
|
2019-05-14 09:45:05 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
};
|
2022-04-21 23:48:41 +08:00
|
|
|
|
|
|
|
|
|
SearchContainer.FilterCompleted += InvalidateScrollPosition;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
// no null check because the usage of this class is strict
|
2020-11-30 16:56:04 +08:00
|
|
|
|
HeaderBackground.Alpha = -ExpandableHeader.Y / ExpandableHeader.LayoutSize.Y;
|
2019-05-14 09:45:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|