2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-11-30 16:57:25 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-08-19 00:27:14 +08:00
|
|
|
|
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.Shapes;
|
2021-08-19 00:27:14 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-08-11 11:23:12 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-10-10 01:54:20 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings
|
|
|
|
|
{
|
|
|
|
|
public abstract class SettingsSection : Container, IHasFilterableChildren
|
|
|
|
|
{
|
|
|
|
|
protected FillFlowContainer FlowContent;
|
|
|
|
|
protected override Container<Drawable> Content => FlowContent;
|
|
|
|
|
|
2021-08-19 00:27:14 +08:00
|
|
|
|
private IBindable<SettingsSection> selectedSection;
|
|
|
|
|
|
2021-08-20 16:40:03 +08:00
|
|
|
|
private OsuSpriteText header;
|
2021-08-19 00:27:14 +08:00
|
|
|
|
|
2020-04-26 02:35:46 +08:00
|
|
|
|
public abstract Drawable CreateIcon();
|
2021-08-11 11:23:12 +08:00
|
|
|
|
public abstract LocalisableString Header { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
|
2021-08-11 11:23:12 +08:00
|
|
|
|
public virtual IEnumerable<string> FilterTerms => new[] { Header.ToString() };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-10 01:54:20 +08:00
|
|
|
|
public const int ITEM_SPACING = 14;
|
|
|
|
|
|
2021-10-10 01:25:24 +08:00
|
|
|
|
private const int header_size = 24;
|
2021-10-03 23:30:22 +08:00
|
|
|
|
private const int border_size = 4;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
set => this.FadeTo(value ? 1 : 0);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 23:29:07 +08:00
|
|
|
|
public bool FilteringActive { get; set; }
|
|
|
|
|
|
2021-08-19 00:27:14 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private SettingsPanel settingsPanel { get; set; }
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected SettingsSection()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
FlowContent = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
2021-10-10 01:54:20 +08:00
|
|
|
|
Top = 36
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2021-10-10 01:54:20 +08:00
|
|
|
|
Spacing = new Vector2(0, ITEM_SPACING),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 08:06:39 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2021-08-20 16:40:03 +08:00
|
|
|
|
Name = "separator",
|
2021-10-03 23:30:22 +08:00
|
|
|
|
Colour = colourProvider.Background6,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = border_size,
|
|
|
|
|
},
|
2021-08-20 16:40:03 +08:00
|
|
|
|
new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
2021-10-10 01:25:24 +08:00
|
|
|
|
Top = 28,
|
|
|
|
|
Bottom = 40,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-09-05 13:59:37 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-08-20 16:40:03 +08:00
|
|
|
|
header = new OsuSpriteText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-10 01:25:24 +08:00
|
|
|
|
Font = OsuFont.TorusAlternate.With(size: header_size),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Text = Header,
|
2020-11-30 16:43:53 +08:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
2021-10-10 01:25:24 +08:00
|
|
|
|
Horizontal = SettingsPanel.CONTENT_MARGINS
|
2020-11-30 16:43:53 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
FlowContent
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-08-19 00:27:14 +08:00
|
|
|
|
|
|
|
|
|
selectedSection = settingsPanel.CurrentSection.GetBoundCopy();
|
2021-08-20 15:50:27 +08:00
|
|
|
|
selectedSection.BindValueChanged(_ => updateContentFade(), true);
|
2021-08-19 00:27:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isCurrentSection => selectedSection.Value == this;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2021-08-20 15:50:27 +08:00
|
|
|
|
updateContentFade();
|
2021-08-19 00:27:14 +08:00
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
2021-08-20 15:50:27 +08:00
|
|
|
|
updateContentFade();
|
2021-08-19 00:27:14 +08:00
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (!isCurrentSection)
|
|
|
|
|
settingsPanel.SectionsContainer.ScrollTo(this);
|
|
|
|
|
|
|
|
|
|
return base.OnClick(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 15:50:27 +08: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-19 00:27:14 +08:00
|
|
|
|
{
|
2021-08-20 16:40:03 +08:00
|
|
|
|
float contentFade = 1;
|
|
|
|
|
float headerFade = 1;
|
2021-08-20 15:50:27 +08:00
|
|
|
|
|
|
|
|
|
if (!isCurrentSection)
|
2021-08-20 16:40:03 +08:00
|
|
|
|
{
|
|
|
|
|
contentFade = 0.25f;
|
|
|
|
|
headerFade = IsHovered ? 0.5f : 0.25f;
|
|
|
|
|
}
|
2021-08-20 15:50:27 +08:00
|
|
|
|
|
2021-08-20 16:40:03 +08:00
|
|
|
|
header.FadeTo(headerFade, 500, Easing.OutQuint);
|
|
|
|
|
FlowContent.FadeTo(contentFade, 500, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|