Skip to content

Commit

Permalink
Revert "Apply generic math-related changes #27965"
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed May 21, 2024
1 parent f14fa45 commit b284a15
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 42 deletions.
8 changes: 4 additions & 4 deletions osu.Game/Graphics/UserInterface/ExpandableSlider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Numerics;
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -10,15 +10,15 @@
using osu.Framework.Localisation;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using Vector2 = osuTK.Vector2;
using osuTK;

namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// An <see cref="IExpandable"/> implementation for the UI slider bar control.
/// </summary>
public partial class ExpandableSlider<T, TSlider> : CompositeDrawable, IExpandable, IHasCurrentValue<T>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
where TSlider : RoundedSliderBar<T>, new()
{
private readonly OsuSpriteText label;
Expand Down Expand Up @@ -129,7 +129,7 @@ protected override void LoadComplete()
/// An <see cref="IExpandable"/> implementation for the UI slider bar control.
/// </summary>
public partial class ExpandableSlider<T> : ExpandableSlider<T, RoundedSliderBar<T>>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
}
}
9 changes: 4 additions & 5 deletions osu.Game/Graphics/UserInterface/OsuSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Numerics;
using System.Globalization;
using osu.Framework.Allocation;
using osu.Framework.Audio;
Expand All @@ -16,7 +15,7 @@
namespace osu.Game.Graphics.UserInterface
{
public abstract partial class OsuSliderBar<T> : SliderBar<T>, IHasTooltip
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
public bool PlaySamplesOnAdjust { get; set; } = true;

Expand Down Expand Up @@ -86,11 +85,11 @@ private void playSample(T value)
private LocalisableString getTooltipText(T value)
{
if (CurrentNumber.IsInteger)
return int.CreateTruncating(value).ToString("N0");
return value.ToInt32(NumberFormatInfo.InvariantInfo).ToString("N0");

double floatValue = double.CreateTruncating(value);
double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo);

decimal decimalPrecision = normalise(decimal.CreateTruncating(CurrentNumber.Precision), max_decimal_digits);
decimal decimalPrecision = normalise(CurrentNumber.Precision.ToDecimal(NumberFormatInfo.InvariantInfo), max_decimal_digits);

// Find the number of significant digits (we could have less than 5 after normalize())
int significantDigits = FormatUtils.FindPrecision(decimalPrecision);
Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Graphics/UserInterface/RoundedSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Numerics;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
Expand All @@ -11,12 +11,11 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Overlays;
using Vector2 = osuTK.Vector2;

namespace osu.Game.Graphics.UserInterface
{
public partial class RoundedSliderBar<T> : OsuSliderBar<T>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
protected readonly Nub Nub;
protected readonly Box LeftBox;
Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Graphics/UserInterface/ShearedSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Numerics;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
Expand All @@ -12,12 +12,11 @@
using osu.Framework.Input.Events;
using osu.Game.Overlays;
using static osu.Game.Graphics.UserInterface.ShearedNub;
using Vector2 = osuTK.Vector2;

namespace osu.Game.Graphics.UserInterface
{
public partial class ShearedSliderBar<T> : OsuSliderBar<T>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
protected readonly ShearedNub Nub;
protected readonly Box LeftBox;
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Graphics/UserInterfaceV2/LabelledSliderBar.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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.Numerics;
using System;
using osu.Framework.Graphics;
using osu.Game.Overlays.Settings;

namespace osu.Game.Graphics.UserInterfaceV2
{
public partial class LabelledSliderBar<TNumber> : LabelledComponent<SettingsSlider<TNumber>, TNumber>
where TNumber : struct, INumber<TNumber>, IMinMaxValue<TNumber>
where TNumber : struct, IEquatable<TNumber>, IComparable<TNumber>, IConvertible
{
public LabelledSliderBar()
: base(true)
Expand Down
8 changes: 4 additions & 4 deletions osu.Game/Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Numerics;
using System;
using System.Globalization;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -10,12 +10,12 @@
using osu.Framework.Localisation;
using osu.Game.Overlays.Settings;
using osu.Game.Utils;
using Vector2 = osuTK.Vector2;
using osuTK;

namespace osu.Game.Graphics.UserInterfaceV2
{
public partial class SliderWithTextBoxInput<T> : CompositeDrawable, IHasCurrentValue<T>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
/// <summary>
/// A custom step value for each key press which actuates a change on this control.
Expand Down Expand Up @@ -138,7 +138,7 @@ private void updateTextBoxFromSlider(ValueChangedEvent<T> _)
{
if (updatingFromTextBox) return;

decimal decimalValue = decimal.CreateTruncating(slider.Current.Value);
decimal decimalValue = slider.Current.Value.ToDecimal(NumberFormatInfo.InvariantInfo);
textBox.Text = decimalValue.ToString($@"N{FormatUtils.FindPrecision(decimalValue)}");
}
}
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Overlays/Settings/Sections/SizeSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Numerics;
using System.Globalization;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
Expand All @@ -13,7 +12,7 @@ namespace osu.Game.Overlays.Settings.Sections
/// A slider intended to show a "size" multiplier number, where 1x is 1.0.
/// </summary>
public partial class SizeSlider<T> : RoundedSliderBar<T>
where T : struct, INumber<T>, IMinMaxValue<T>, IFormattable
where T : struct, IEquatable<T>, IComparable<T>, IConvertible, IFormattable
{
public override LocalisableString TooltipText => Current.Value.ToString(@"0.##x", NumberFormatInfo.CurrentInfo);
}
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Overlays/Settings/SettingsPercentageSlider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Numerics;
using System;
using osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
Expand All @@ -13,7 +13,7 @@ namespace osu.Game.Overlays.Settings
/// Mostly provided for convenience of use with <see cref="SettingSourceAttribute"/>.
/// </summary>
public partial class SettingsPercentageSlider<TValue> : SettingsSlider<TValue>
where TValue : struct, INumber<TValue>, IMinMaxValue<TValue>
where TValue : struct, IEquatable<TValue>, IComparable<TValue>, IConvertible
{
protected override Drawable CreateControl() => ((RoundedSliderBar<TValue>)base.CreateControl()).With(sliderBar => sliderBar.DisplayAsPercentage = true);
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Overlays/Settings/SettingsSlider.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// 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.Numerics;
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;

namespace osu.Game.Overlays.Settings
{
public partial class SettingsSlider<T> : SettingsSlider<T, RoundedSliderBar<T>>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
}

public partial class SettingsSlider<TValue, TSlider> : SettingsItem<TValue>
where TValue : struct, INumber<TValue>, IMinMaxValue<TValue>
where TValue : struct, IEquatable<TValue>, IComparable<TValue>, IConvertible
where TSlider : RoundedSliderBar<TValue>, new()
{
protected override Drawable CreateControl() => new TSlider
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Mods/DifficultyBindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public float MinValue
}
}

private float maxValue = 10; // matches default max value of `CurrentNumber`
private float maxValue;

public float MaxValue
{
Expand Down
7 changes: 0 additions & 7 deletions osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,6 @@ protected override double ComputeDrainRate()
OnIterationFail?.Invoke($"FAILED drop {testDrop}: recovery too low ({recovery} < {hpRecoveryAvailable})");
}

if (!fail && double.IsInfinity(HpMultiplierNormal))
{
OnIterationSuccess?.Invoke("Drain computation algorithm diverged to infinity. PASSING with zero drop, resetting HP multiplier to 1.");
HpMultiplierNormal = 1;
return 0;
}

if (!fail)
{
OnIterationSuccess?.Invoke($"PASSED drop {testDrop}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Numerics;
using System;
using System.Globalization;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -12,7 +12,7 @@
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays.Settings;
using osu.Game.Utils;
using Vector2 = osuTK.Vector2;
using osuTK;

namespace osu.Game.Screens.Edit.Timing
{
Expand All @@ -22,7 +22,7 @@ namespace osu.Game.Screens.Edit.Timing
/// by providing an "indeterminate state".
/// </summary>
public partial class IndeterminateSliderWithTextBoxInput<T> : CompositeDrawable, IHasCurrentValue<T?>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
/// <summary>
/// A custom step value for each key press which actuates a change on this control.
Expand Down Expand Up @@ -136,7 +136,7 @@ private void updateState()
slider.Current.Value = nonNullValue;

// use the value from the slider to ensure that any precision/min/max set on it via the initial indeterminate value have been applied correctly.
decimal decimalValue = decimal.CreateTruncating(slider.Current.Value);
decimal decimalValue = slider.Current.Value.ToDecimal(NumberFormatInfo.InvariantInfo);
textBox.Text = decimalValue.ToString($@"N{FormatUtils.FindPrecision(decimalValue)}");
textBox.PlaceholderText = string.Empty;
}
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Numerics;
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
Expand All @@ -11,7 +11,7 @@
namespace osu.Game.Screens.Play.PlayerSettings
{
public partial class PlayerSliderBar<T> : SettingsSlider<T>
where T : struct, INumber<T>, IMinMaxValue<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{
public RoundedSliderBar<T> Bar => (RoundedSliderBar<T>)Control;

Expand Down

0 comments on commit b284a15

Please sign in to comment.