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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-12-20 20:06:40 +08:00
|
|
|
|
using System;
|
2021-10-04 00:44:23 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-08-16 17:58:26 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-10-04 00:44:23 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2021-10-15 11:13:42 +08:00
|
|
|
|
public class Nub : CompositeDrawable, IHasCurrentValue<bool>, IHasAccentColour
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-04 00:44:23 +08:00
|
|
|
|
public const float HEIGHT = 15;
|
|
|
|
|
|
|
|
|
|
public const float EXPANDED_SIZE = 50;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private const float border_width = 3;
|
|
|
|
|
|
2021-10-15 10:48:19 +08:00
|
|
|
|
private const double animate_in_duration = 200;
|
2021-08-11 11:33:14 +08:00
|
|
|
|
private const double animate_out_duration = 500;
|
|
|
|
|
|
2021-10-15 11:13:42 +08:00
|
|
|
|
private readonly Box fill;
|
|
|
|
|
private readonly Container main;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Nub()
|
|
|
|
|
{
|
2021-10-15 11:13:42 +08:00
|
|
|
|
Size = new Vector2(EXPANDED_SIZE, HEIGHT);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-15 11:13:42 +08:00
|
|
|
|
InternalChildren = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-15 11:13:42 +08:00
|
|
|
|
main = new CircularContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-15 11:13:42 +08:00
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
BorderThickness = border_width,
|
|
|
|
|
Masking = true,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-10-15 11:13:42 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
fill = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true,
|
|
|
|
|
},
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-04 00:44:23 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
|
private void load([CanBeNull] OverlayColourProvider colourProvider, OsuColour colours)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-10-04 00:44:23 +08:00
|
|
|
|
AccentColour = colourProvider?.Highlight1 ?? colours.Pink;
|
|
|
|
|
GlowingAccentColour = colourProvider?.Highlight1.Lighten(0.2f) ?? colours.PinkLighter;
|
2021-10-15 11:35:19 +08:00
|
|
|
|
GlowColour = colourProvider?.Highlight1 ?? colours.PinkLighter;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-15 11:13:42 +08:00
|
|
|
|
main.EdgeEffect = new EdgeEffectParameters
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-08-16 17:58:26 +08:00
|
|
|
|
Colour = GlowColour.Opacity(0),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Type = EdgeEffectType.Glow,
|
2021-10-15 11:35:19 +08:00
|
|
|
|
Radius = 8,
|
|
|
|
|
Roundness = 5,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 11:13:42 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Current.BindValueChanged(onCurrentValueChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private bool glowing;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool Glowing
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => glowing;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
glowing = value;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
2021-10-15 11:13:42 +08:00
|
|
|
|
main.FadeColour(GlowingAccentColour, animate_in_duration, Easing.OutQuint);
|
2021-10-15 11:35:19 +08:00
|
|
|
|
main.FadeEdgeEffectTo(0.2f, animate_in_duration, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-10-15 11:35:19 +08:00
|
|
|
|
main.FadeEdgeEffectTo(0, animate_out_duration, Easing.OutQuint);
|
|
|
|
|
main.FadeColour(AccentColour, animate_out_duration, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 20:06:40 +08:00
|
|
|
|
private readonly Bindable<bool> current = new Bindable<bool>();
|
|
|
|
|
|
|
|
|
|
public Bindable<bool> Current
|
|
|
|
|
{
|
|
|
|
|
get => current;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(value));
|
|
|
|
|
|
|
|
|
|
current.UnbindBindings();
|
|
|
|
|
current.BindTo(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => accentColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
if (!Glowing)
|
2021-10-15 11:13:42 +08:00
|
|
|
|
main.Colour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 glowingAccentColour;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Color4 GlowingAccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => glowingAccentColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
glowingAccentColour = value;
|
|
|
|
|
if (Glowing)
|
2021-10-15 11:13:42 +08:00
|
|
|
|
main.Colour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 glowColour;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Color4 GlowColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => glowColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
glowColour = value;
|
|
|
|
|
|
2021-10-15 11:35:19 +08:00
|
|
|
|
var effect = main.EdgeEffect;
|
2021-08-20 11:33:19 +08:00
|
|
|
|
effect.Colour = Glowing ? value : value.Opacity(0);
|
2021-10-15 11:13:42 +08:00
|
|
|
|
main.EdgeEffect = effect;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-15 11:13:42 +08:00
|
|
|
|
|
|
|
|
|
private void onCurrentValueChanged(ValueChangedEvent<bool> filled)
|
|
|
|
|
{
|
|
|
|
|
fill.FadeTo(filled.NewValue ? 1 : 0, 200, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
if (filled.NewValue)
|
|
|
|
|
main.ResizeWidthTo(1, animate_in_duration, Easing.OutElasticHalf);
|
|
|
|
|
else
|
|
|
|
|
main.ResizeWidthTo(0.9f, animate_out_duration, Easing.OutElastic);
|
|
|
|
|
|
|
|
|
|
main.TransformTo(nameof(BorderThickness), filled.NewValue ? 8.5f : border_width, 200, Easing.OutQuint);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|