Skip to content

Commit

Permalink
Move DefaultSliderBody to own class and make SliderBody more abst…
Browse files Browse the repository at this point in the history
…ract
  • Loading branch information
peppy committed Oct 25, 2024
1 parent df9a78e commit e802731
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
4 changes: 0 additions & 4 deletions osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ protected override void UpdateHitStateTransforms(ArmedState state)

public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => SliderBody?.ReceivePositionalInputAt(screenSpacePos) ?? base.ReceivePositionalInputAt(screenSpacePos);

private partial class DefaultSliderBody : PlaySliderBody
{
}

#region FOR EDITOR USE ONLY, DO NOT USE FOR ANY OTHER PURPOSE

internal void SuppressHitAnimations()
Expand Down
35 changes: 35 additions & 0 deletions osu.Game.Rulesets.Osu/Skinning/Default/DefaultSliderBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Rulesets.Osu.Objects;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Osu.Skinning.Default
{
public partial class DefaultSliderBody : SliderBody
{
protected override DrawableSliderPath CreateSliderPath() => new DefaultDrawableSliderPath();

private partial class DefaultDrawableSliderPath : DrawableSliderPath
{
private const float opacity_at_centre = 0.3f;
private const float opacity_at_edge = 0.8f;

protected override Color4 ColourAt(float position)
{
const float actual_to_visual_radius = OsuHitObject.OBJECT_RADIUS / OsuHitObject.VISUAL_OBJECT_RADIUS;

position = 1 - (1 - position) * actual_to_visual_radius;

if (position < 0.0)
return Color4.Transparent;

if (CalculatedBorderPortion != 0f && position <= CalculatedBorderPortion)
return BorderColour;

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);
}
}
}
}
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Skinning/Default/ManualSliderBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
/// <summary>
/// A <see cref="SliderBody"/> with the ability to set the drawn vertices manually.
/// </summary>
public partial class ManualSliderBody : SliderBody
public partial class ManualSliderBody : DefaultSliderBody
{
public ManualSliderBody()
{
Expand Down
25 changes: 1 addition & 24 deletions osu.Game.Rulesets.Osu/Skinning/SliderBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Skinning.Default;
using osuTK;
using osuTK.Graphics;
Expand Down Expand Up @@ -111,28 +110,6 @@ public virtual void RecyclePath()
/// <param name="vertices">The vertices</param>
protected void SetVertices(IReadOnlyList<Vector2> vertices) => path.Vertices = vertices;

protected virtual DrawableSliderPath CreateSliderPath() => new DefaultDrawableSliderPath();

private partial class DefaultDrawableSliderPath : DrawableSliderPath
{
private const float opacity_at_centre = 0.3f;
private const float opacity_at_edge = 0.8f;

protected override Color4 ColourAt(float position)
{
const float actual_to_visual_radius = OsuHitObject.OBJECT_RADIUS / OsuHitObject.VISUAL_OBJECT_RADIUS;

position = 1 - (1 - position) * actual_to_visual_radius;

if (position < 0.0)
return Color4.Transparent;

if (CalculatedBorderPortion != 0f && position <= CalculatedBorderPortion)
return BorderColour;

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);
}
}
protected abstract DrawableSliderPath CreateSliderPath();
}
}

0 comments on commit e802731

Please sign in to comment.