2021-10-09 18:43:18 +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.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-10-09 18:43:18 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings
|
|
|
|
|
{
|
|
|
|
|
public partial class SidebarIconButton : SidebarButton
|
|
|
|
|
{
|
2021-10-10 02:34:01 +00:00
|
|
|
|
private const float selection_indicator_height_active = 18;
|
|
|
|
|
private const float selection_indicator_height_inactive = 4;
|
2021-10-09 18:43:18 +00:00
|
|
|
|
|
|
|
|
|
private readonly ConstrainedIconContainer iconContainer;
|
|
|
|
|
private readonly SpriteText headerText;
|
|
|
|
|
private readonly CircularContainer selectionIndicator;
|
2021-10-10 02:55:45 +00:00
|
|
|
|
private readonly Container textIconContent;
|
2021-10-09 18:43:18 +00:00
|
|
|
|
|
|
|
|
|
// always consider as part of flow, even when not visible (for the sake of the initial animation).
|
|
|
|
|
public override bool IsPresent => true;
|
|
|
|
|
|
|
|
|
|
private SettingsSection section;
|
|
|
|
|
|
|
|
|
|
public SettingsSection Section
|
|
|
|
|
{
|
|
|
|
|
get => section;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
section = value;
|
|
|
|
|
headerText.Text = value.Header;
|
|
|
|
|
iconContainer.Icon = value.CreateIcon();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool selected;
|
|
|
|
|
|
|
|
|
|
public bool Selected
|
|
|
|
|
{
|
|
|
|
|
get => selected;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
selected = value;
|
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
UpdateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SidebarIconButton()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = 46;
|
|
|
|
|
|
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
2021-10-10 02:55:45 +00:00
|
|
|
|
textIconContent = new Container
|
2021-10-09 18:43:18 +00:00
|
|
|
|
{
|
2022-01-06 08:15:42 +00:00
|
|
|
|
Width = SettingsSidebar.DEFAULT_WIDTH,
|
2021-10-09 18:43:18 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Colour = OsuColour.Gray(0.6f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
headerText = new OsuSpriteText
|
|
|
|
|
{
|
2022-01-06 08:15:42 +00:00
|
|
|
|
Position = new Vector2(SettingsSidebar.DEFAULT_WIDTH + 10, 0),
|
2021-10-09 18:43:18 +00:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
|
|
|
|
iconContainer = new ConstrainedIconContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(20),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
selectionIndicator = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
2021-10-10 02:34:01 +00:00
|
|
|
|
Width = 4,
|
|
|
|
|
Height = selection_indicator_height_inactive,
|
2021-10-09 18:43:18 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 1.5f,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Left = 9,
|
|
|
|
|
},
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Colour4.White
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
selectionIndicator.Colour = ColourProvider.Highlight1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState()
|
|
|
|
|
{
|
|
|
|
|
if (Selected)
|
|
|
|
|
{
|
2021-10-10 02:55:45 +00:00
|
|
|
|
textIconContent.FadeColour(ColourProvider.Content1, FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
selectionIndicator.FadeIn(FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
selectionIndicator.ResizeHeightTo(selection_indicator_height_active, FADE_DURATION, Easing.OutElasticHalf);
|
2021-10-09 18:43:18 +00:00
|
|
|
|
}
|
2021-10-10 02:55:45 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
textIconContent.FadeColour(IsHovered ? ColourProvider.Light1 : ColourProvider.Light3, FADE_DURATION, Easing.OutQuint);
|
2021-10-09 18:43:18 +00:00
|
|
|
|
|
2021-10-10 02:55:45 +00:00
|
|
|
|
selectionIndicator.FadeOut(FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
selectionIndicator.ResizeHeightTo(selection_indicator_height_inactive, FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
}
|
2021-10-09 18:43:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|