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
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-10-03 23:30:22 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-04-26 02:35:46 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings
|
|
|
|
|
{
|
2019-11-06 13:08:52 +08:00
|
|
|
|
public class SidebarButton : OsuButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-03 23:30:22 +08:00
|
|
|
|
private const double fade_duration = 50;
|
|
|
|
|
|
2020-04-26 02:35:46 +08:00
|
|
|
|
private readonly ConstrainedIconContainer iconContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly SpriteText headerText;
|
2021-10-03 23:30:22 +08:00
|
|
|
|
private readonly CircularContainer selectionIndicator;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly Container text;
|
|
|
|
|
|
2021-10-03 23:30:22 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
|
|
2021-08-16 18:47:27 +08:00
|
|
|
|
// always consider as part of flow, even when not visible (for the sake of the initial animation).
|
|
|
|
|
public override bool IsPresent => true;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private SettingsSection section;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public SettingsSection Section
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => section;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
section = value;
|
|
|
|
|
headerText.Text = value.Header;
|
2020-04-26 02:35:46 +08:00
|
|
|
|
iconContainer.Icon = value.CreateIcon();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool selected;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool Selected
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => selected;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
selected = value;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2021-10-03 23:30:22 +08:00
|
|
|
|
if (IsLoaded)
|
|
|
|
|
updateState();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SidebarButton()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-10-03 23:30:22 +08:00
|
|
|
|
Height = 46;
|
2019-11-06 14:09:08 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
text = new Container
|
|
|
|
|
{
|
|
|
|
|
Width = Sidebar.DEFAULT_WIDTH,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Colour = OsuColour.Gray(0.6f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
headerText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Position = new Vector2(Sidebar.DEFAULT_WIDTH + 10, 0),
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
2020-04-26 02:35:46 +08:00
|
|
|
|
iconContainer = new ConstrainedIconContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(20),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-10-03 23:30:22 +08:00
|
|
|
|
selectionIndicator = new CircularContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
2021-10-03 23:30:22 +08:00
|
|
|
|
Width = 3,
|
|
|
|
|
Height = 18,
|
|
|
|
|
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
|
|
|
|
|
}
|
2018-08-01 15:45:48 +08:00
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-10-03 23:30:22 +08:00
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
BackgroundColour = colourProvider.Background5;
|
|
|
|
|
selectionIndicator.Colour = colourProvider.Highlight1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-03 23:30:22 +08:00
|
|
|
|
updateState();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => updateState();
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
|
|
|
|
if (Selected)
|
|
|
|
|
{
|
|
|
|
|
text.FadeColour(colourProvider.Content1, fade_duration, Easing.OutQuint);
|
|
|
|
|
selectionIndicator.FadeIn(fade_duration, Easing.OutQuint);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text.FadeColour(IsHovered ? colourProvider.Light1 : colourProvider.Light3, fade_duration, Easing.OutQuint);
|
|
|
|
|
selectionIndicator.FadeOut(fade_duration, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|