2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-07-25 09:22:56 +00:00
|
|
|
using System;
|
2016-12-06 09:54:32 +00:00
|
|
|
using System.Collections.Generic;
|
2019-12-17 08:53:48 +00:00
|
|
|
using osu.Framework.Graphics;
|
2016-12-06 09:54:32 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-02-16 10:30:31 +00:00
|
|
|
using osu.Framework.Graphics.Lines;
|
2022-11-09 04:23:53 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-11-09 04:23:53 +00:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning
|
2016-12-06 09:54:32 +00:00
|
|
|
{
|
2018-10-25 06:49:45 +00:00
|
|
|
public abstract partial class SliderBody : CompositeDrawable
|
2016-12-06 09:54:32 +00:00
|
|
|
{
|
2019-12-17 08:53:48 +00:00
|
|
|
private DrawableSliderPath path;
|
2019-07-16 09:19:13 +00:00
|
|
|
|
2018-10-25 06:49:45 +00:00
|
|
|
protected Path Path => path;
|
|
|
|
|
2019-07-29 10:12:41 +00:00
|
|
|
public virtual float PathRadius
|
2016-12-06 09:54:32 +00:00
|
|
|
{
|
2019-03-07 08:39:19 +00:00
|
|
|
get => path.PathRadius;
|
|
|
|
set => path.PathRadius = value;
|
2017-03-23 06:37:16 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-02-23 11:27:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Offset in absolute coordinates from the start of the curve.
|
|
|
|
/// </summary>
|
2018-10-25 06:49:45 +00:00
|
|
|
public virtual Vector2 PathOffset => path.PositionInBoundingBox(path.Vertices[0]);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2023-01-10 20:16:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Offset in absolute coordinates from the end of the curve.
|
|
|
|
/// </summary>
|
|
|
|
public virtual Vector2 PathEndOffset => path.PositionInBoundingBox(path.Vertices[^1]);
|
|
|
|
|
2017-03-23 06:37:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Used to colour the path.
|
|
|
|
/// </summary>
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
2018-10-05 06:45:45 +00:00
|
|
|
get => path.AccentColour;
|
2016-12-06 09:54:32 +00:00
|
|
|
set
|
|
|
|
{
|
2018-10-05 06:45:45 +00:00
|
|
|
if (path.AccentColour == value)
|
2017-03-23 06:37:16 +00:00
|
|
|
return;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-10-05 06:45:45 +00:00
|
|
|
path.AccentColour = value;
|
2016-12-06 09:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-02-20 11:51:28 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Used to colour the path border.
|
|
|
|
/// </summary>
|
|
|
|
public new Color4 BorderColour
|
|
|
|
{
|
2018-10-05 06:45:45 +00:00
|
|
|
get => path.BorderColour;
|
2018-02-20 11:51:28 +00:00
|
|
|
set
|
|
|
|
{
|
2018-10-05 06:45:45 +00:00
|
|
|
if (path.BorderColour == value)
|
2018-02-20 11:51:28 +00:00
|
|
|
return;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-10-05 06:45:45 +00:00
|
|
|
path.BorderColour = value;
|
2018-02-20 11:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-03-14 19:57:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Used to size the path border.
|
|
|
|
/// </summary>
|
2019-03-16 10:41:03 +00:00
|
|
|
public float BorderSize
|
|
|
|
{
|
2019-03-14 19:57:39 +00:00
|
|
|
get => path.BorderSize;
|
2019-05-12 13:53:12 +00:00
|
|
|
set
|
|
|
|
{
|
2019-03-14 19:57:39 +00:00
|
|
|
if (path.BorderSize == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
path.BorderSize = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 06:49:45 +00:00
|
|
|
protected SliderBody()
|
2016-12-06 09:54:32 +00:00
|
|
|
{
|
2019-07-25 09:22:56 +00:00
|
|
|
RecyclePath();
|
2016-12-06 09:54:32 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-07-16 09:19:13 +00:00
|
|
|
/// <summary>
|
2019-12-17 08:53:48 +00:00
|
|
|
/// Initialises a new <see cref="DrawableSliderPath"/>, releasing all resources retained by the old one.
|
2019-07-16 09:19:13 +00:00
|
|
|
/// </summary>
|
2019-07-25 09:22:56 +00:00
|
|
|
public virtual void RecyclePath()
|
2019-07-16 09:19:13 +00:00
|
|
|
{
|
2019-12-17 08:53:48 +00:00
|
|
|
InternalChild = path = CreateSliderPath().With(p =>
|
2019-07-16 09:19:13 +00:00
|
|
|
{
|
2019-12-17 08:53:48 +00:00
|
|
|
p.Position = path?.Position ?? Vector2.Zero;
|
|
|
|
p.PathRadius = path?.PathRadius ?? 10;
|
|
|
|
p.AccentColour = path?.AccentColour ?? Color4.White;
|
|
|
|
p.BorderColour = path?.BorderColour ?? Color4.White;
|
|
|
|
p.BorderSize = path?.BorderSize ?? 1;
|
|
|
|
p.Vertices = path?.Vertices ?? Array.Empty<Vector2>();
|
|
|
|
});
|
2019-07-16 09:19:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => path.ReceivePositionalInputAt(screenSpacePos);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-10-25 06:49:45 +00: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 07:32:43 +00:00
|
|
|
protected void SetVertices(IReadOnlyList<Vector2> vertices) => path.Vertices = vertices;
|
2018-10-05 06:45:45 +00:00
|
|
|
|
2019-12-17 08:53:48 +00:00
|
|
|
protected virtual DrawableSliderPath CreateSliderPath() => new DefaultDrawableSliderPath();
|
2018-10-05 06:45:45 +00:00
|
|
|
|
2019-12-17 10:29:27 +00:00
|
|
|
private partial class DefaultDrawableSliderPath : DrawableSliderPath
|
2019-12-17 08:53:48 +00:00
|
|
|
{
|
2018-10-05 06:45:45 +00:00
|
|
|
private const float opacity_at_centre = 0.3f;
|
|
|
|
private const float opacity_at_edge = 0.8f;
|
|
|
|
|
|
|
|
protected override Color4 ColourAt(float position)
|
|
|
|
{
|
2019-12-17 08:53:48 +00:00
|
|
|
if (CalculatedBorderPortion != 0f && position <= CalculatedBorderPortion)
|
2018-10-05 06:45:45 +00:00
|
|
|
return BorderColour;
|
|
|
|
|
2019-12-17 08:53:48 +00:00
|
|
|
position -= CalculatedBorderPortion;
|
|
|
|
return new Color4(AccentColour.R, AccentColour.G, AccentColour.B, (opacity_at_edge - (opacity_at_edge - opacity_at_centre) * position / GRADIENT_PORTION) * AccentColour.A);
|
2018-10-05 06:45:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-06 09:54:32 +00:00
|
|
|
}
|
2017-12-01 15:26:02 +00:00
|
|
|
}
|