diff --git a/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs new file mode 100644 index 0000000000..bbe543e73e --- /dev/null +++ b/osu.Game.Rulesets.Catch.Tests/Mods/TestSceneCatchModNoScope.cs @@ -0,0 +1,110 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using NUnit.Framework; +using osu.Framework.Utils; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Timing; +using osu.Game.Rulesets.Catch.Mods; +using osu.Game.Rulesets.Catch.Objects; +using osu.Game.Rulesets.Catch.UI; +using osu.Game.Rulesets.Objects; +using osu.Game.Tests.Visual; + +namespace osu.Game.Rulesets.Catch.Tests.Mods +{ + public class TestSceneCatchModNoScope : ModTestScene + { + protected override Ruleset CreatePlayerRuleset() => new CatchRuleset(); + + [Test] + public void TestVisibleDuringBreak() + { + CreateModTest(new ModTestData + { + Mod = new CatchModNoScope + { + HiddenComboCount = { Value = 0 }, + }, + Autoplay = true, + PassCondition = () => true, + Beatmap = new Beatmap + { + HitObjects = new List + { + new Fruit + { + X = CatchPlayfield.CENTER_X, + StartTime = 1000, + }, + new Fruit + { + X = CatchPlayfield.CENTER_X, + StartTime = 5000, + } + }, + Breaks = new List + { + new BreakPeriod(2000, 4000), + } + } + }); + + AddUntilStep("wait for catcher to hide", () => catcherAlphaAlmostEquals(0)); + AddUntilStep("wait for start of break", isBreak); + AddUntilStep("wait for catcher to show", () => catcherAlphaAlmostEquals(1)); + AddUntilStep("wait for end of break", () => !isBreak()); + AddUntilStep("wait for catcher to hide", () => catcherAlphaAlmostEquals(0)); + } + + [Test] + public void TestVisibleAfterComboBreak() + { + CreateModTest(new ModTestData + { + Mod = new CatchModNoScope + { + HiddenComboCount = { Value = 2 }, + }, + Autoplay = true, + PassCondition = () => true, + Beatmap = new Beatmap + { + HitObjects = new List + { + new Fruit + { + X = 0, + StartTime = 1000, + }, + new Fruit + { + X = CatchPlayfield.CENTER_X, + StartTime = 3000, + }, + new Fruit + { + X = CatchPlayfield.WIDTH, + StartTime = 5000, + }, + } + } + }); + + AddAssert("catcher must start visible", () => catcherAlphaAlmostEquals(1)); + AddUntilStep("wait for combo", () => Player.ScoreProcessor.Combo.Value >= 2); + AddAssert("catcher must dim after combo", () => !catcherAlphaAlmostEquals(1)); + AddStep("break combo", () => Player.ScoreProcessor.Combo.Value = 0); + AddUntilStep("wait for catcher to show", () => catcherAlphaAlmostEquals(1)); + } + + private bool isBreak() => Player.IsBreakTime.Value; + + private bool catcherAlphaAlmostEquals(float alpha) + { + var playfield = (CatchPlayfield)Player.DrawableRuleset.Playfield; + return Precision.AlmostEquals(playfield.CatcherArea.Alpha, alpha); + } + } +} diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 9fee6b2bc1..c256172177 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -133,6 +133,7 @@ namespace osu.Game.Rulesets.Catch new MultiMod(new ModWindUp(), new ModWindDown()), new CatchModFloatingFruits(), new CatchModMuted(), + new CatchModNoScope(), }; default: diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs b/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs new file mode 100644 index 0000000000..a24a6227fe --- /dev/null +++ b/osu.Game.Rulesets.Catch/Mods/CatchModNoScope.cs @@ -0,0 +1,40 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Bindables; +using osu.Game.Rulesets.Mods; +using osu.Framework.Utils; +using osu.Game.Configuration; +using osu.Game.Overlays.Settings; +using osu.Game.Rulesets.Catch.UI; +using osu.Game.Rulesets.UI; + +namespace osu.Game.Rulesets.Catch.Mods +{ + public class CatchModNoScope : ModNoScope, IUpdatableByPlayfield + { + public override string Description => "Where's the catcher?"; + + [SettingSource( + "Hidden at combo", + "The combo count at which the catcher becomes completely hidden", + SettingControlType = typeof(SettingsSlider) + )] + public override BindableInt HiddenComboCount { get; } = new BindableInt + { + Default = 10, + Value = 10, + MinValue = 0, + MaxValue = 50, + }; + + public void Update(Playfield playfield) + { + var catchPlayfield = (CatchPlayfield)playfield; + bool shouldAlwaysShowCatcher = IsBreakTime.Value; + float targetAlpha = shouldAlwaysShowCatcher ? 1 : ComboBasedAlpha; + catchPlayfield.CatcherArea.Alpha = (float)Interpolation.Lerp(catchPlayfield.CatcherArea.Alpha, targetAlpha, Math.Clamp(catchPlayfield.Time.Elapsed / TRANSITION_DURATION, 0, 1)); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs index 501c0a55bd..8e377ea632 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModNoScope.cs @@ -4,52 +4,29 @@ using System; using System.Linq; using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Localisation; using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.UI; -using osu.Game.Rulesets.Scoring; -using osu.Game.Scoring; -using osu.Game.Screens.Play; using osu.Game.Utils; namespace osu.Game.Rulesets.Osu.Mods { - public class OsuModNoScope : Mod, IUpdatableByPlayfield, IApplicableToScoreProcessor, IApplicableToPlayer, IApplicableToBeatmap + public class OsuModNoScope : ModNoScope, IUpdatableByPlayfield, IApplicableToBeatmap { - /// - /// Slightly higher than the cutoff for . - /// - private const float min_alpha = 0.0002f; - - private const float transition_duration = 100; - - public override string Name => "No Scope"; - public override string Acronym => "NS"; - public override ModType Type => ModType.Fun; - public override IconUsage? Icon => FontAwesome.Solid.EyeSlash; public override string Description => "Where's the cursor?"; - public override double ScoreMultiplier => 1; - private BindableNumber currentCombo; - private IBindable isBreakTime; private PeriodTracker spinnerPeriods; - private float comboBasedAlpha; - [SettingSource( "Hidden at combo", "The combo count at which the cursor becomes completely hidden", SettingControlType = typeof(SettingsSlider) )] - public BindableInt HiddenComboCount { get; } = new BindableInt + public override BindableInt HiddenComboCount { get; } = new BindableInt { Default = 10, Value = 10, @@ -57,39 +34,16 @@ namespace osu.Game.Rulesets.Osu.Mods MaxValue = 50, }; - public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; - - public void ApplyToPlayer(Player player) - { - isBreakTime = player.IsBreakTime.GetBoundCopy(); - } - public void ApplyToBeatmap(IBeatmap beatmap) { - spinnerPeriods = new PeriodTracker(beatmap.HitObjects.OfType().Select(b => new Period(b.StartTime - transition_duration, b.EndTime))); + spinnerPeriods = new PeriodTracker(beatmap.HitObjects.OfType().Select(b => new Period(b.StartTime - TRANSITION_DURATION, b.EndTime))); } - public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) + public void Update(Playfield playfield) { - if (HiddenComboCount.Value == 0) return; - - currentCombo = scoreProcessor.Combo.GetBoundCopy(); - currentCombo.BindValueChanged(combo => - { - comboBasedAlpha = Math.Max(min_alpha, 1 - (float)combo.NewValue / HiddenComboCount.Value); - }, true); + bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.IsInAny(playfield.Clock.CurrentTime); + float targetAlpha = shouldAlwaysShowCursor ? 1 : ComboBasedAlpha; + playfield.Cursor.Alpha = (float)Interpolation.Lerp(playfield.Cursor.Alpha, targetAlpha, Math.Clamp(playfield.Time.Elapsed / TRANSITION_DURATION, 0, 1)); } - - public virtual void Update(Playfield playfield) - { - bool shouldAlwaysShowCursor = isBreakTime.Value || spinnerPeriods.IsInAny(playfield.Clock.CurrentTime); - float targetAlpha = shouldAlwaysShowCursor ? 1 : comboBasedAlpha; - playfield.Cursor.Alpha = (float)Interpolation.Lerp(playfield.Cursor.Alpha, targetAlpha, Math.Clamp(playfield.Time.Elapsed / transition_duration, 0, 1)); - } - } - - public class HiddenComboSlider : OsuSliderBar - { - public override LocalisableString TooltipText => Current.Value == 0 ? "always hidden" : base.TooltipText; } } diff --git a/osu.Game/Rulesets/Mods/ModNoScope.cs b/osu.Game/Rulesets/Mods/ModNoScope.cs new file mode 100644 index 0000000000..7a935eb38f --- /dev/null +++ b/osu.Game/Rulesets/Mods/ModNoScope.cs @@ -0,0 +1,62 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Localisation; +using osu.Game.Graphics.UserInterface; +using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring; +using osu.Game.Screens.Play; + +namespace osu.Game.Rulesets.Mods +{ + public abstract class ModNoScope : Mod, IApplicableToScoreProcessor, IApplicableToPlayer + { + public override string Name => "No Scope"; + public override string Acronym => "NS"; + public override ModType Type => ModType.Fun; + public override IconUsage? Icon => FontAwesome.Solid.EyeSlash; + public override double ScoreMultiplier => 1; + + /// + /// Slightly higher than the cutoff for . + /// + protected const float MIN_ALPHA = 0.0002f; + + protected const float TRANSITION_DURATION = 100; + + protected BindableNumber CurrentCombo; + + protected IBindable IsBreakTime; + + protected float ComboBasedAlpha; + + public abstract BindableInt HiddenComboCount { get; } + + public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; + + public void ApplyToPlayer(Player player) + { + IsBreakTime = player.IsBreakTime.GetBoundCopy(); + } + + public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) + { + if (HiddenComboCount.Value == 0) return; + + CurrentCombo = scoreProcessor.Combo.GetBoundCopy(); + CurrentCombo.BindValueChanged(combo => + { + ComboBasedAlpha = Math.Max(MIN_ALPHA, 1 - (float)combo.NewValue / HiddenComboCount.Value); + }, true); + } + } + + public class HiddenComboSlider : OsuSliderBar + { + public override LocalisableString TooltipText => Current.Value == 0 ? "always hidden" : base.TooltipText; + } +}