2023-01-26 12:53:17 +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.
|
|
|
|
|
2023-02-03 10:58:10 +00:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2023-01-26 12:53:17 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-02-03 10:58:10 +00:00
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2023-10-18 04:37:38 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2023-02-03 10:58:10 +00:00
|
|
|
using osu.Game.Overlays;
|
2023-01-26 12:53:17 +00:00
|
|
|
using osuTK;
|
2023-02-03 10:58:10 +00:00
|
|
|
using osuTK.Graphics;
|
2023-01-26 12:53:17 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
2023-02-03 10:58:10 +00:00
|
|
|
public partial class ShearedNub : Container, IHasCurrentValue<bool>, IHasAccentColour
|
2023-01-26 12:53:17 +00:00
|
|
|
{
|
2023-10-18 04:37:38 +00:00
|
|
|
public Action? OnDoubleClicked { get; init; }
|
|
|
|
|
2023-02-03 10:58:10 +00:00
|
|
|
protected const float BORDER_WIDTH = 3;
|
|
|
|
|
2023-01-26 13:39:11 +00:00
|
|
|
public const int HEIGHT = 30;
|
|
|
|
public const float EXPANDED_SIZE = 50;
|
|
|
|
|
2023-01-26 12:53:17 +00:00
|
|
|
public static readonly Vector2 SHEAR = new Vector2(0.15f, 0);
|
|
|
|
|
2023-02-03 10:58:10 +00:00
|
|
|
private readonly Box fill;
|
|
|
|
private readonly Container main;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Implements the shape for the nub, allowing for any type of container to be used.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
2023-01-26 13:39:11 +00:00
|
|
|
public ShearedNub()
|
|
|
|
{
|
|
|
|
Size = new Vector2(EXPANDED_SIZE, HEIGHT);
|
2023-02-03 10:58:10 +00:00
|
|
|
InternalChild = main = new Container
|
2023-01-26 12:53:17 +00:00
|
|
|
{
|
|
|
|
Shear = SHEAR,
|
|
|
|
BorderColour = Colour4.White,
|
|
|
|
BorderThickness = BORDER_WIDTH,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2023-02-03 10:58:10 +00:00
|
|
|
Child = fill = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true,
|
|
|
|
}
|
2023-01-26 12:53:17 +00:00
|
|
|
};
|
2023-02-03 10:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(OverlayColourProvider? colourProvider, OsuColour colours)
|
|
|
|
{
|
|
|
|
AccentColour = colourProvider?.Highlight1 ?? colours.Pink;
|
2023-02-08 04:59:09 +00:00
|
|
|
GlowingAccentColour = colourProvider?.Highlight1.Lighten(0.4f) ?? colours.PinkLighter;
|
2023-02-03 10:58:10 +00:00
|
|
|
GlowColour = colourProvider?.Highlight1 ?? colours.PinkLighter;
|
|
|
|
|
|
|
|
main.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Colour = GlowColour.Opacity(0),
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
Radius = 8,
|
|
|
|
Roundness = 4,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(onCurrentValueChanged, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool glowing;
|
|
|
|
|
|
|
|
public bool Glowing
|
|
|
|
{
|
|
|
|
get => glowing;
|
|
|
|
set
|
|
|
|
{
|
2023-02-08 04:59:09 +00:00
|
|
|
if (glowing == value)
|
|
|
|
return;
|
|
|
|
|
2023-02-03 10:58:10 +00:00
|
|
|
glowing = value;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
2023-02-08 04:59:09 +00:00
|
|
|
main.FadeColour(GlowingAccentColour.Lighten(0.1f), 40, Easing.OutQuint)
|
2023-02-03 10:58:10 +00:00
|
|
|
.Then()
|
|
|
|
.FadeColour(GlowingAccentColour, 800, Easing.OutQuint);
|
|
|
|
|
|
|
|
main.FadeEdgeEffectTo(Color4.White.Opacity(0.1f), 40, Easing.OutQuint)
|
|
|
|
.Then()
|
|
|
|
.FadeEdgeEffectTo(GlowColour.Opacity(0.1f), 800, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
main.FadeEdgeEffectTo(GlowColour.Opacity(0), 800, Easing.OutQuint);
|
|
|
|
main.FadeColour(AccentColour, 800, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly Bindable<bool> current = new Bindable<bool>();
|
|
|
|
|
|
|
|
public Bindable<bool> Current
|
|
|
|
{
|
|
|
|
get => current;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
ArgumentNullException.ThrowIfNull(value);
|
|
|
|
|
|
|
|
current.UnbindBindings();
|
|
|
|
current.BindTo(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
|
|
|
get => accentColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accentColour = value;
|
|
|
|
if (!Glowing)
|
|
|
|
main.Colour = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 glowingAccentColour;
|
|
|
|
|
|
|
|
public Color4 GlowingAccentColour
|
|
|
|
{
|
|
|
|
get => glowingAccentColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
glowingAccentColour = value;
|
|
|
|
if (Glowing)
|
|
|
|
main.Colour = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 glowColour;
|
|
|
|
|
|
|
|
public Color4 GlowColour
|
|
|
|
{
|
|
|
|
get => glowColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
glowColour = value;
|
|
|
|
|
|
|
|
var effect = main.EdgeEffect;
|
|
|
|
effect.Colour = Glowing ? value : value.Opacity(0);
|
|
|
|
main.EdgeEffect = effect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onCurrentValueChanged(ValueChangedEvent<bool> filled)
|
|
|
|
{
|
|
|
|
const double duration = 200;
|
|
|
|
|
|
|
|
fill.FadeTo(filled.NewValue ? 1 : 0, duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
if (filled.NewValue)
|
|
|
|
{
|
|
|
|
main.ResizeWidthTo(1, duration, Easing.OutElasticHalf);
|
|
|
|
main.TransformTo(nameof(BorderThickness), 8.5f, duration, Easing.OutElasticHalf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
main.ResizeWidthTo(0.75f, duration, Easing.OutQuint);
|
|
|
|
main.TransformTo(nameof(BorderThickness), BORDER_WIDTH, duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
2023-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
|
|
|
protected override bool OnDoubleClick(DoubleClickEvent e)
|
|
|
|
{
|
|
|
|
OnDoubleClicked?.Invoke();
|
|
|
|
return true;
|
|
|
|
}
|
2023-01-26 12:53:17 +00:00
|
|
|
}
|
|
|
|
}
|