2019-01-24 08:43:03 +00: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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-11-30 08:57:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-04-22 09:04:07 +00:00
|
|
|
|
using System.Diagnostics;
|
2020-11-30 08:57:25 +00:00
|
|
|
|
using System.Linq;
|
2017-01-13 04:49:05 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-08-18 16:27:14 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2016-11-03 04:45:16 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-08-18 16:27:14 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-08-11 03:23:12 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2016-11-07 23:04:49 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2017-01-31 09:53:52 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-10-09 17:54:20 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-15 01:55:29 +00:00
|
|
|
|
namespace osu.Game.Overlays.Settings
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
2017-05-15 01:55:29 +00:00
|
|
|
|
public abstract class SettingsSection : Container, IHasFilterableChildren
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
2017-03-01 18:33:01 +00:00
|
|
|
|
protected FillFlowContainer FlowContent;
|
2017-02-07 07:15:45 +00:00
|
|
|
|
protected override Container<Drawable> Content => FlowContent;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-08-18 16:27:14 +00:00
|
|
|
|
private IBindable<SettingsSection> selectedSection;
|
|
|
|
|
|
2022-04-14 10:43:09 +00:00
|
|
|
|
private Box dim;
|
|
|
|
|
|
2022-04-14 12:16:54 +00:00
|
|
|
|
private const float inactive_alpha = 0.8f;
|
2021-08-18 16:27:14 +00:00
|
|
|
|
|
2020-04-25 18:35:46 +00:00
|
|
|
|
public abstract Drawable CreateIcon();
|
2021-08-11 03:23:12 +00:00
|
|
|
|
public abstract LocalisableString Header { get; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-07 18:35:57 +00:00
|
|
|
|
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
|
2022-05-16 05:09:37 +00:00
|
|
|
|
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Header };
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-09 17:54:20 +00:00
|
|
|
|
public const int ITEM_SPACING = 14;
|
|
|
|
|
|
2021-10-09 17:25:24 +00:00
|
|
|
|
private const int header_size = 24;
|
2021-10-03 15:30:22 +00:00
|
|
|
|
private const int border_size = 4;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-04-22 20:50:58 +00:00
|
|
|
|
private bool matchingFilter = true;
|
2022-04-22 17:34:00 +00:00
|
|
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
|
|
|
|
get => matchingFilter;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
bool wasPresent = IsPresent;
|
|
|
|
|
|
|
|
|
|
matchingFilter = value;
|
|
|
|
|
|
|
|
|
|
if (IsPresent != wasPresent)
|
|
|
|
|
Invalidate(Invalidation.Presence);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsPresent => base.IsPresent && MatchingFilter;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-28 15:29:07 +00:00
|
|
|
|
public bool FilteringActive { get; set; }
|
|
|
|
|
|
2022-04-22 09:04:07 +00:00
|
|
|
|
[Resolved(canBeNull: true)]
|
2021-08-18 16:27:14 +00:00
|
|
|
|
private SettingsPanel settingsPanel { get; set; }
|
|
|
|
|
|
2017-05-15 01:55:29 +00:00
|
|
|
|
protected SettingsSection()
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-14 05:40:48 +00:00
|
|
|
|
FlowContent = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
2021-10-09 17:54:20 +00:00
|
|
|
|
Top = 36
|
2017-08-14 05:40:48 +00:00
|
|
|
|
},
|
2021-10-09 17:54:20 +00:00
|
|
|
|
Spacing = new Vector2(0, ITEM_SPACING),
|
2017-08-14 05:40:48 +00:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-14 05:40:48 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 00:06:39 +00:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2017-08-14 05:40:48 +00:00
|
|
|
|
{
|
2017-07-11 13:58:06 +00:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2021-08-20 08:40:03 +00:00
|
|
|
|
Name = "separator",
|
2021-10-03 15:30:22 +00:00
|
|
|
|
Colour = colourProvider.Background6,
|
2016-11-03 04:45:16 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-02-07 07:15:45 +00:00
|
|
|
|
Height = border_size,
|
2016-11-03 04:45:16 +00:00
|
|
|
|
},
|
2021-08-20 08:40:03 +00:00
|
|
|
|
new Container
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
2022-04-14 10:43:09 +00:00
|
|
|
|
Padding = new MarginPadding { Top = border_size },
|
2016-11-03 04:45:16 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-09-05 05:59:37 +00:00
|
|
|
|
Children = new Drawable[]
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
2022-04-14 10:43:09 +00:00
|
|
|
|
new Container
|
2016-11-03 04:45:16 +00:00
|
|
|
|
{
|
2022-04-14 10:43:09 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 24,
|
|
|
|
|
Bottom = 40,
|
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
2020-11-30 08:43:53 +00:00
|
|
|
|
{
|
2022-04-14 12:04:52 +00:00
|
|
|
|
new OsuSpriteText
|
2022-04-14 10:43:09 +00:00
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.TorusAlternate.With(size: header_size),
|
|
|
|
|
Text = Header,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Horizontal = SettingsPanel.CONTENT_MARGINS
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
FlowContent
|
2020-11-30 08:43:53 +00:00
|
|
|
|
}
|
2016-11-03 04:45:16 +00:00
|
|
|
|
},
|
2022-04-14 12:04:52 +00:00
|
|
|
|
dim = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colourProvider.Background5,
|
2022-04-14 12:16:54 +00:00
|
|
|
|
Alpha = inactive_alpha,
|
2022-04-14 12:04:52 +00:00
|
|
|
|
},
|
2016-11-03 04:45:16 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-08-18 16:27:14 +00:00
|
|
|
|
|
2022-04-22 09:04:07 +00:00
|
|
|
|
selectedSection = settingsPanel?.CurrentSection.GetBoundCopy() ?? new Bindable<SettingsSection>(this);
|
2021-08-20 07:50:27 +00:00
|
|
|
|
selectedSection.BindValueChanged(_ => updateContentFade(), true);
|
2021-08-18 16:27:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isCurrentSection => selectedSection.Value == this;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2021-08-20 07:50:27 +00:00
|
|
|
|
updateContentFade();
|
2021-08-18 16:27:14 +00:00
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
2021-08-20 07:50:27 +00:00
|
|
|
|
updateContentFade();
|
2021-08-18 16:27:14 +00:00
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (!isCurrentSection)
|
2022-04-22 09:04:07 +00:00
|
|
|
|
{
|
|
|
|
|
Debug.Assert(settingsPanel != null);
|
2021-08-18 16:27:14 +00:00
|
|
|
|
settingsPanel.SectionsContainer.ScrollTo(this);
|
2022-04-22 09:04:07 +00:00
|
|
|
|
}
|
2021-08-18 16:27:14 +00:00
|
|
|
|
|
|
|
|
|
return base.OnClick(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 07:50:27 +00:00
|
|
|
|
protected override bool ShouldBeConsideredForInput(Drawable child) =>
|
|
|
|
|
// only the current section should accept input.
|
|
|
|
|
// this provides the behaviour of the first click scrolling the target section to the centre of the screen.
|
|
|
|
|
isCurrentSection;
|
|
|
|
|
|
|
|
|
|
private void updateContentFade()
|
2021-08-18 16:27:14 +00:00
|
|
|
|
{
|
2022-04-14 10:43:09 +00:00
|
|
|
|
float dimFade = 0;
|
2021-08-20 07:50:27 +00:00
|
|
|
|
|
|
|
|
|
if (!isCurrentSection)
|
2021-08-20 08:40:03 +00:00
|
|
|
|
{
|
2022-04-14 12:16:54 +00:00
|
|
|
|
dimFade = IsHovered ? 0.5f : inactive_alpha;
|
2021-08-20 08:40:03 +00:00
|
|
|
|
}
|
2021-08-20 07:50:27 +00:00
|
|
|
|
|
2022-04-14 12:04:52 +00:00
|
|
|
|
dim.FadeTo(dimFade, 300, Easing.OutQuint);
|
2016-11-03 04:45:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-14 05:40:48 +00:00
|
|
|
|
}
|