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
|
|
|
|
2019-07-25 17:22:56 +08:00
|
|
|
using System;
|
2018-04-13 17:19:50 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Lines;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|
|
|
{
|
2018-10-25 14:49:45 +08:00
|
|
|
public abstract class SliderBody : CompositeDrawable
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-05-12 22:08:42 +08:00
|
|
|
public const float DEFAULT_BORDER_SIZE = 1;
|
|
|
|
|
2019-07-16 17:19:13 +08:00
|
|
|
private SliderPath path;
|
|
|
|
|
2018-10-25 14:49:45 +08:00
|
|
|
protected Path Path => path;
|
|
|
|
|
2019-07-29 18:12:41 +08:00
|
|
|
public virtual float PathRadius
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-03-07 16:39:19 +08:00
|
|
|
get => path.PathRadius;
|
|
|
|
set => path.PathRadius = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Offset in absolute coordinates from the start of the curve.
|
|
|
|
/// </summary>
|
2018-10-25 14:49:45 +08:00
|
|
|
public virtual Vector2 PathOffset => path.PositionInBoundingBox(path.Vertices[0]);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to colour the path.
|
|
|
|
/// </summary>
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
2018-10-05 14:45:45 +08:00
|
|
|
get => path.AccentColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
set
|
|
|
|
{
|
2018-10-05 14:45:45 +08:00
|
|
|
if (path.AccentColour == value)
|
2018-04-13 17:19:50 +08:00
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2018-10-05 14:45:45 +08:00
|
|
|
path.AccentColour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to colour the path border.
|
|
|
|
/// </summary>
|
|
|
|
public new Color4 BorderColour
|
|
|
|
{
|
2018-10-05 14:45:45 +08:00
|
|
|
get => path.BorderColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
set
|
|
|
|
{
|
2018-10-05 14:45:45 +08:00
|
|
|
if (path.BorderColour == value)
|
2018-04-13 17:19:50 +08:00
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2018-10-05 14:45:45 +08:00
|
|
|
path.BorderColour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:57:39 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Used to size the path border.
|
|
|
|
/// </summary>
|
2019-03-16 18:41:03 +08:00
|
|
|
public float BorderSize
|
|
|
|
{
|
2019-03-15 03:57:39 +08:00
|
|
|
get => path.BorderSize;
|
2019-05-12 21:53:12 +08:00
|
|
|
set
|
|
|
|
{
|
2019-03-15 03:57:39 +08:00
|
|
|
if (path.BorderSize == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
path.BorderSize = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 14:49:45 +08:00
|
|
|
protected SliderBody()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-07-25 17:22:56 +08:00
|
|
|
RecyclePath();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 17:19:13 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Initialises a new <see cref="SliderPath"/>, releasing all resources retained by the old one.
|
|
|
|
/// </summary>
|
2019-07-25 17:22:56 +08:00
|
|
|
public virtual void RecyclePath()
|
2019-07-16 17:19:13 +08:00
|
|
|
{
|
|
|
|
InternalChild = path = new SliderPath
|
|
|
|
{
|
2019-07-25 17:22:56 +08:00
|
|
|
Position = path?.Position ?? Vector2.Zero,
|
|
|
|
PathRadius = path?.PathRadius ?? 10,
|
|
|
|
AccentColour = path?.AccentColour ?? Color4.White,
|
|
|
|
BorderColour = path?.BorderColour ?? Color4.White,
|
|
|
|
BorderSize = path?.BorderSize ?? DEFAULT_BORDER_SIZE,
|
|
|
|
Vertices = path?.Vertices ?? Array.Empty<Vector2>()
|
2019-07-16 17:19:13 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => path.ReceivePositionalInputAt(screenSpacePos);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-25 14:49:45 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the vertices of the path which should be drawn by this <see cref="SliderBody"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="vertices">The vertices</param>
|
2019-06-06 15:32:43 +08:00
|
|
|
protected void SetVertices(IReadOnlyList<Vector2> vertices) => path.Vertices = vertices;
|
2018-10-05 14:45:45 +08:00
|
|
|
|
|
|
|
private class SliderPath : SmoothPath
|
|
|
|
{
|
2019-03-16 18:47:37 +08:00
|
|
|
private const float border_max_size = 8f;
|
|
|
|
private const float border_min_size = 0f;
|
2019-03-16 18:41:03 +08:00
|
|
|
|
2018-10-05 14:45:45 +08:00
|
|
|
private const float border_portion = 0.128f;
|
|
|
|
private const float gradient_portion = 1 - border_portion;
|
|
|
|
|
|
|
|
private const float opacity_at_centre = 0.3f;
|
|
|
|
private const float opacity_at_edge = 0.8f;
|
|
|
|
|
|
|
|
private Color4 borderColour = Color4.White;
|
|
|
|
|
|
|
|
public Color4 BorderColour
|
|
|
|
{
|
|
|
|
get => borderColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (borderColour == value)
|
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2018-10-05 14:45:45 +08:00
|
|
|
borderColour = value;
|
|
|
|
|
|
|
|
InvalidateTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 accentColour = Color4.White;
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
|
|
|
get => accentColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (accentColour == value)
|
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2018-10-05 14:45:45 +08:00
|
|
|
accentColour = value;
|
|
|
|
|
|
|
|
InvalidateTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-12 22:08:42 +08:00
|
|
|
private float borderSize = DEFAULT_BORDER_SIZE;
|
2019-03-15 03:57:39 +08:00
|
|
|
|
2019-03-16 18:41:03 +08:00
|
|
|
public float BorderSize
|
|
|
|
{
|
2019-03-15 03:57:39 +08:00
|
|
|
get => borderSize;
|
2019-05-12 21:53:12 +08:00
|
|
|
set
|
|
|
|
{
|
2019-03-15 03:57:39 +08:00
|
|
|
if (borderSize == value)
|
|
|
|
return;
|
|
|
|
|
2019-03-16 18:41:03 +08:00
|
|
|
if (value < border_min_size || value > border_max_size)
|
|
|
|
return;
|
|
|
|
|
2019-03-15 03:57:39 +08:00
|
|
|
borderSize = value;
|
|
|
|
|
|
|
|
InvalidateTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 18:41:03 +08:00
|
|
|
private float calculatedBorderPortion => BorderSize * border_portion;
|
2019-03-15 03:57:39 +08:00
|
|
|
|
2018-10-05 14:45:45 +08:00
|
|
|
protected override Color4 ColourAt(float position)
|
|
|
|
{
|
2019-03-16 18:41:03 +08:00
|
|
|
if (calculatedBorderPortion != 0f && position <= calculatedBorderPortion)
|
2018-10-05 14:45:45 +08:00
|
|
|
return BorderColour;
|
|
|
|
|
2019-03-16 18:41:03 +08:00
|
|
|
position -= calculatedBorderPortion;
|
2018-10-05 14:45:45 +08:00
|
|
|
return new Color4(AccentColour.R, AccentColour.G, AccentColour.B, (opacity_at_edge - (opacity_at_edge - opacity_at_centre) * position / gradient_portion) * AccentColour.A);
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|