1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Use Interpolation.Lerp instead of transforms

Better handles cases where the combo may be changing faster than the
transition length.
This commit is contained in:
Dean Herbert 2021-10-15 14:25:50 +09:00
parent 538d980072
commit 6a80a417bd

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
@ -19,15 +20,18 @@ namespace osu.Game.Rulesets.Osu.Mods
public class OsuModNoScope : Mod, IUpdatableByPlayfield, IApplicableToScoreProcessor public class OsuModNoScope : Mod, IUpdatableByPlayfield, IApplicableToScoreProcessor
{ {
public const float CURSOR_ALPHA_TRANSITION_DURATION = 100; public const float CURSOR_ALPHA_TRANSITION_DURATION = 100;
public override string Name => "No Scope"; public override string Name => "No Scope";
public override string Acronym => "NS"; public override string Acronym => "NS";
public override ModType Type => ModType.Fun; public override ModType Type => ModType.Fun;
public override IconUsage? Icon => FontAwesome.Solid.EyeSlash; public override IconUsage? Icon => FontAwesome.Solid.EyeSlash;
public override string Description => "Where's the cursor?"; public override string Description => "Where's the cursor?";
public override double ScoreMultiplier => 1; public override double ScoreMultiplier => 1;
private readonly BindableFloat cursorAlpha = new BindableFloat();
private BindableNumber<int> currentCombo; private BindableNumber<int> currentCombo;
private float targetAlpha;
[SettingSource( [SettingSource(
"Hidden at combo", "Hidden at combo",
"The combo count at which the cursor becomes completely hidden", "The combo count at which the cursor becomes completely hidden",
@ -43,22 +47,25 @@ namespace osu.Game.Rulesets.Osu.Mods
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
/// <summary>
/// Slightly higher than the cutoff for <see cref="Drawable.IsPresent"/>.
/// </summary>
private const float min_alpha = 0.0002f;
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
{ {
if (HiddenComboCount.Value != 0) if (HiddenComboCount.Value == 0) return;
currentCombo = scoreProcessor.Combo.GetBoundCopy();
currentCombo.BindValueChanged(combo =>
{ {
currentCombo = scoreProcessor.Combo.GetBoundCopy(); targetAlpha = Math.Max(min_alpha, 1 - (float)combo.NewValue / HiddenComboCount.Value);
currentCombo.BindValueChanged(combo => }, true);
{
float targetCursorAlpha = (float)Math.Max(1e-3, 1 - (float)combo.NewValue / HiddenComboCount.Value);
scoreProcessor.TransformBindableTo(cursorAlpha, targetCursorAlpha, CURSOR_ALPHA_TRANSITION_DURATION, Easing.OutQuint);
}, true);
}
} }
public virtual void Update(Playfield playfield) public virtual void Update(Playfield playfield)
{ {
playfield.Cursor.Alpha = cursorAlpha.Value; playfield.Cursor.Alpha = (float)Interpolation.Lerp(playfield.Cursor.Alpha, targetAlpha, Math.Clamp(playfield.Time.Elapsed / CURSOR_ALPHA_TRANSITION_DURATION, 0, 1));
} }
} }