From cbb7498a42d6311b94ca07f939fb72dd0c7ac532 Mon Sep 17 00:00:00 2001 From: Santeri Nogelainen Date: Sat, 16 Mar 2019 12:41:03 +0200 Subject: [PATCH] Border size to float, add min and max size, other small changes --- .../Objects/Drawables/DrawableSlider.cs | 2 +- .../Objects/Drawables/Pieces/SliderBody.cs | 20 +++++++++++++------ osu.Game/Skinning/LegacySkinDecoder.cs | 4 +++- osu.Game/Skinning/SkinConfiguration.cs | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs index 1e7155ced9..d76612e26d 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs @@ -160,7 +160,7 @@ protected override void SkinChanged(ISkinSource skin, bool allowFallback) { base.SkinChanged(skin, allowFallback); - Body.BorderSize = skin.GetValue(s => s.SliderBorderSize) ?? Body.BorderSize; + Body.BorderSize = skin.GetValue(s => s.SliderBorderSize) ?? Body.BorderSize; Body.AccentColour = skin.GetValue(s => s.CustomColours.ContainsKey("SliderTrackOverride") ? s.CustomColours["SliderTrackOverride"] : (Color4?)null) ?? Body.AccentColour; Body.BorderColour = skin.GetValue(s => s.CustomColours.ContainsKey("SliderBorder") ? s.CustomColours["SliderBorder"] : (Color4?)null) ?? Body.BorderColour; Ball.AccentColour = skin.GetValue(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : (Color4?)null) ?? Ball.AccentColour; diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs index a4b27b2ee9..9340d32bd9 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs @@ -67,7 +67,8 @@ public Color4 AccentColour /// /// Used to size the path border. /// - public int BorderSize { + public float BorderSize + { get => path.BorderSize; set { if (path.BorderSize == value) @@ -107,6 +108,9 @@ protected void SetVertices(IReadOnlyList vertices) private class SliderPath : SmoothPath { + private const float border_max_size = 10f; + private const float border_min_size = 0f; // = no border + private const float border_portion = 0.128f; private const float gradient_portion = 1 - border_portion; @@ -145,28 +149,32 @@ public Color4 AccentColour } } - private int borderSize = 100; + private float borderSize = 1f; - public int BorderSize { + public float BorderSize + { get => borderSize; set { if (borderSize == value) return; + if (value < border_min_size || value > border_max_size) + return; + borderSize = value; InvalidateTexture(); } } - private float calucatedBorderPortion => BorderSize / 100f * border_portion; + private float calculatedBorderPortion => BorderSize * border_portion; protected override Color4 ColourAt(float position) { - if (position <= calucatedBorderPortion) + if (calculatedBorderPortion != 0f && position <= calculatedBorderPortion) return BorderColour; - position -= calucatedBorderPortion; + 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); } } diff --git a/osu.Game/Skinning/LegacySkinDecoder.cs b/osu.Game/Skinning/LegacySkinDecoder.cs index 50d7191f08..1f530de4fb 100644 --- a/osu.Game/Skinning/LegacySkinDecoder.cs +++ b/osu.Game/Skinning/LegacySkinDecoder.cs @@ -2,6 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using osu.Game.Beatmaps.Formats; +using System; +using System.Globalization; namespace osu.Game.Skinning { @@ -34,7 +36,7 @@ protected override void ParseLine(SkinConfiguration skin, Section section, strin skin.CursorExpand = pair.Value != "0"; break; case @"SliderBorderSize": - if (int.TryParse(pair.Value, out int size)) + if (Single.TryParse(pair.Value, NumberStyles.Number, CultureInfo.CreateSpecificCulture("en-US"), out float size)) skin.SliderBorderSize = size; break; } diff --git a/osu.Game/Skinning/SkinConfiguration.cs b/osu.Game/Skinning/SkinConfiguration.cs index bd6393db36..043622f8ce 100644 --- a/osu.Game/Skinning/SkinConfiguration.cs +++ b/osu.Game/Skinning/SkinConfiguration.cs @@ -25,7 +25,7 @@ public class SkinConfiguration : IHasComboColours, IHasCustomColours public int HitCircleOverlap { get; set; } - public int? SliderBorderSize { get; set; } + public float? SliderBorderSize { get; set; } public bool? CursorExpand { get; set; } = true; }