osu/osu.Game/Graphics/UserInterface/Nub.cs

153 lines
3.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 09:19:50 +00:00
using System;
2018-11-20 07:51:59 +00:00
using osuTK;
using osuTK.Graphics;
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 05:51:28 +00:00
using osu.Framework.Graphics.Effects;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Graphics.UserInterface
{
public class Nub : CircularContainer, IHasCurrentValue<bool>, IHasAccentColour
{
public const float COLLAPSED_SIZE = 20;
public const float EXPANDED_SIZE = 40;
private const float border_width = 3;
public Nub()
{
Box fill;
Size = new Vector2(COLLAPSED_SIZE, 12);
BorderColour = Color4.White;
BorderThickness = border_width;
Masking = true;
Children = new[]
{
fill = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
};
2021-02-04 05:14:27 +00:00
Current.ValueChanged += filled => fill.FadeTo(filled.NewValue ? 1 : 0, 200, Easing.OutQuint);
2018-04-13 09:19:50 +00:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.Pink;
GlowingAccentColour = colours.PinkLighter;
GlowColour = colours.PinkDarker;
EdgeEffect = new EdgeEffectParameters
{
Colour = GlowColour,
Type = EdgeEffectType.Glow,
Radius = 10,
Roundness = 8,
};
}
protected override void LoadComplete()
{
FadeEdgeEffectTo(0);
}
private bool glowing;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
public bool Glowing
{
get => glowing;
2018-04-13 09:19:50 +00:00
set
{
glowing = value;
if (value)
{
this.FadeColour(GlowingAccentColour, 500, Easing.OutQuint);
FadeEdgeEffectTo(1, 500, Easing.OutQuint);
}
else
{
FadeEdgeEffectTo(0, 500);
this.FadeColour(AccentColour, 500);
}
}
}
public bool Expanded
{
set => this.ResizeTo(new Vector2(value ? EXPANDED_SIZE : COLLAPSED_SIZE, 12), 500, Easing.OutQuint);
2018-04-13 09:19:50 +00: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 09:19:50 +00:00
private Color4 accentColour;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
public Color4 AccentColour
{
get => accentColour;
2018-04-13 09:19:50 +00:00
set
{
accentColour = value;
if (!Glowing)
Colour = value;
}
}
private Color4 glowingAccentColour;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
public Color4 GlowingAccentColour
{
get => glowingAccentColour;
2018-04-13 09:19:50 +00:00
set
{
glowingAccentColour = value;
if (Glowing)
Colour = value;
}
}
private Color4 glowColour;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
public Color4 GlowColour
{
get => glowColour;
2018-04-13 09:19:50 +00:00
set
{
glowColour = value;
var effect = EdgeEffect;
effect.Colour = value;
EdgeEffect = effect;
}
}
}
}