1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 08:32:54 +08:00
osu-lazer/osu.Game/Overlays/Settings/SettingsSection.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

184 lines
5.8 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
2020-11-30 16:57:25 +08:00
using System.Collections.Generic;
using System.Diagnostics;
2020-11-30 16:57:25 +08:00
using System.Linq;
using osu.Framework.Allocation;
2021-08-19 00:27:14 +08:00
using osu.Framework.Bindables;
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;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Settings
{
public abstract class SettingsSection : Container, IHasFilterableChildren
{
2017-03-02 02:33:01 +08:00
protected FillFlowContainer FlowContent;
2017-02-07 15:15:45 +08:00
protected override Container<Drawable> Content => FlowContent;
2018-04-13 17:19:50 +08:00
2021-08-19 00:27:14 +08:00
private IBindable<SettingsSection> selectedSection;
private Box dim;
2022-04-14 20:16:54 +08:00
private const float inactive_alpha = 0.8f;
2021-08-19 00:27:14 +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>();
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Header };
2018-04-13 17:19:50 +08:00
public const int ITEM_SPACING = 14;
private const int header_size = 24;
private const int border_size = 4;
2018-04-13 17:19:50 +08:00
private bool matchingFilter = true;
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 17:19:50 +08:00
2019-03-28 23:29:07 +08:00
public bool FilteringActive { get; set; }
[Resolved(canBeNull: true)]
2021-08-19 00:27:14 +08:00
private SettingsPanel settingsPanel { get; set; }
protected SettingsSection()
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
2018-04-13 17:19:50 +08:00
FlowContent = new FillFlowContainer
{
Margin = new MarginPadding
{
Top = 36
},
Spacing = new Vector2(0, ITEM_SPACING),
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
};
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load(OverlayColourProvider colourProvider)
{
2017-07-11 21:58:06 +08:00
AddRangeInternal(new Drawable[]
{
new Box
{
Name = "separator",
Colour = colourProvider.Background6,
RelativeSizeAxes = Axes.X,
2017-02-07 15:15:45 +08:00
Height = border_size,
},
new Container
{
Padding = new MarginPadding { Top = border_size },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding
{
Top = 24,
Bottom = 40,
},
Children = new Drawable[]
{
new OsuSpriteText
{
Font = OsuFont.TorusAlternate.With(size: header_size),
Text = Header,
Margin = new MarginPadding
{
Horizontal = SettingsPanel.CONTENT_MARGINS
}
},
FlowContent
}
},
dim = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
2022-04-14 20:16:54 +08:00
Alpha = inactive_alpha,
},
}
},
});
2021-08-19 00:27:14 +08:00
selectedSection = settingsPanel?.CurrentSection.GetBoundCopy() ?? new Bindable<SettingsSection>(this);
selectedSection.BindValueChanged(_ => updateContentFade(), true);
2021-08-19 00:27:14 +08:00
}
private bool isCurrentSection => selectedSection.Value == this;
protected override bool OnHover(HoverEvent e)
{
updateContentFade();
2021-08-19 00:27:14 +08:00
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateContentFade();
2021-08-19 00:27:14 +08:00
base.OnHoverLost(e);
}
protected override bool OnClick(ClickEvent e)
{
if (!isCurrentSection)
{
Debug.Assert(settingsPanel != null);
2021-08-19 00:27:14 +08:00
settingsPanel.SectionsContainer.ScrollTo(this);
}
2021-08-19 00:27:14 +08:00
return base.OnClick(e);
}
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
{
float dimFade = 0;
if (!isCurrentSection)
{
2022-04-14 20:16:54 +08:00
dimFade = IsHovered ? 0.5f : inactive_alpha;
}
dim.FadeTo(dimFade, 300, Easing.OutQuint);
}
}
}