2019-12-17 17:16:25 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-08-08 21:54:35 +08:00
|
|
|
using osu.Framework.Utils;
|
2019-12-18 14:39:36 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2020-12-04 19:21:53 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2019-12-17 17:16:25 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-12-04 19:21:53 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2019-12-17 17:16:25 +08:00
|
|
|
{
|
2019-12-17 18:29:27 +08:00
|
|
|
public class LegacySliderBody : PlaySliderBody
|
2019-12-17 17:16:25 +08:00
|
|
|
{
|
|
|
|
protected override DrawableSliderPath CreateSliderPath() => new LegacyDrawableSliderPath();
|
|
|
|
|
|
|
|
private class LegacyDrawableSliderPath : DrawableSliderPath
|
|
|
|
{
|
2019-12-18 14:39:36 +08:00
|
|
|
private const float shadow_portion = 1 - (OsuLegacySkinTransformer.LEGACY_CIRCLE_RADIUS / OsuHitObject.OBJECT_RADIUS);
|
2019-12-18 12:37:37 +08:00
|
|
|
|
2020-09-04 18:33:23 +08:00
|
|
|
protected new float CalculatedBorderPortion
|
|
|
|
// Roughly matches osu!stable's slider border portions.
|
|
|
|
=> base.CalculatedBorderPortion * 0.77f;
|
|
|
|
|
2019-12-17 18:52:33 +08:00
|
|
|
public new Color4 AccentColour => new Color4(base.AccentColour.R, base.AccentColour.G, base.AccentColour.B, base.AccentColour.A * 0.70f);
|
2019-12-17 17:16:25 +08:00
|
|
|
|
|
|
|
protected override Color4 ColourAt(float position)
|
|
|
|
{
|
2019-12-18 12:37:37 +08:00
|
|
|
float realBorderPortion = shadow_portion + CalculatedBorderPortion;
|
|
|
|
float realGradientPortion = 1 - realBorderPortion;
|
|
|
|
|
|
|
|
if (position <= shadow_portion)
|
|
|
|
return new Color4(0f, 0f, 0f, 0.25f * position / shadow_portion);
|
|
|
|
|
|
|
|
if (position <= realBorderPortion)
|
2019-12-17 17:16:25 +08:00
|
|
|
return BorderColour;
|
|
|
|
|
2019-12-18 12:37:37 +08:00
|
|
|
position -= realBorderPortion;
|
2019-12-17 17:16:25 +08:00
|
|
|
|
2021-08-08 21:54:35 +08:00
|
|
|
// Stable interpolates slider body colour directly in sRGB space, and because
|
|
|
|
// Interpolation.ValueAt() uses linear space, we have to counteract applying it
|
|
|
|
// by calling ToSRGB() on the input colours, and ToLinear() on the resulting colour.
|
2019-12-17 17:16:25 +08:00
|
|
|
|
2021-08-08 21:54:35 +08:00
|
|
|
Color4 outerColour = AccentColour.Darken(0.1f).ToSRGB();
|
|
|
|
Color4 innerColour = lighten(AccentColour, 0.5f).ToSRGB();
|
|
|
|
|
|
|
|
return Interpolation.ValueAt(position / realGradientPortion, outerColour, innerColour, 0, 1).ToLinear();
|
2019-12-17 17:16:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Lightens a colour in a way more friendly to dark or strong colours.
|
|
|
|
/// </summary>
|
|
|
|
private static Color4 lighten(Color4 color, float amount)
|
|
|
|
{
|
|
|
|
amount *= 0.5f;
|
|
|
|
return new Color4(
|
|
|
|
Math.Min(1, color.R * (1 + 0.5f * amount) + 1 * amount),
|
|
|
|
Math.Min(1, color.G * (1 + 0.5f * amount) + 1 * amount),
|
|
|
|
Math.Min(1, color.B * (1 + 0.5f * amount) + 1 * amount),
|
|
|
|
color.A);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|