1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Merge pull request #14100 from frenzibyte/fix-muted-dim-factor

Fix "muted" mod metronome not playing when expected
This commit is contained in:
Dan Balasescu 2021-08-04 12:33:38 +09:00 committed by GitHub
commit 374d279e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 3 deletions

View File

@ -0,0 +1,52 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
namespace osu.Game.Rulesets.Osu.Tests.Mods
{
public class TestSceneOsuModMuted : OsuModTestScene
{
/// <summary>
/// Ensures that a final volume combo of 0 (i.e. "always muted" mode) constantly plays metronome and completely mutes track.
/// </summary>
[Test]
public void TestZeroFinalCombo() => CreateModTest(new ModTestData
{
Mod = new OsuModMuted
{
MuteComboCount = { Value = 0 },
},
PassCondition = () => Beatmap.Value.Track.AggregateVolume.Value == 0.0 &&
Player.ChildrenOfType<Metronome>().SingleOrDefault()?.AggregateVolume.Value == 1.0,
});
/// <summary>
/// Ensures that copying from a normal mod with 0 final combo while originally inversed does not yield incorrect results.
/// </summary>
[Test]
public void TestModCopy()
{
OsuModMuted muted = null;
AddStep("create inversed mod", () => muted = new OsuModMuted
{
MuteComboCount = { Value = 100 },
InverseMuting = { Value = true },
});
AddStep("copy from normal", () => muted.CopyFrom(new OsuModMuted
{
MuteComboCount = { Value = 0 },
InverseMuting = { Value = false },
}));
AddAssert("mute combo count = 0", () => muted.MuteComboCount.Value == 0);
AddAssert("inverse muting = false", () => muted.InverseMuting.Value == false);
}
}
}

View File

@ -1,14 +1,16 @@
// 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;
using System.Linq;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
@ -41,7 +43,7 @@ namespace osu.Game.Rulesets.Mods
Value = true
};
[SettingSource("Final volume at combo", "The combo count at which point the track reaches its final volume.")]
[SettingSource("Final volume at combo", "The combo count at which point the track reaches its final volume.", SettingControlType = typeof(SettingsSlider<int, MuteComboSlider>))]
public BindableInt MuteComboCount { get; } = new BindableInt
{
Default = 100,
@ -64,6 +66,11 @@ namespace osu.Game.Rulesets.Mods
Value = true
};
protected ModMuted()
{
InverseMuting.BindValueChanged(i => MuteComboCount.MinValue = i.NewValue ? 1 : 0, true);
}
public void ApplyToTrack(ITrack track)
{
track.AddAdjustment(AdjustableProperty.Volume, mainVolumeAdjust);
@ -89,7 +96,7 @@ namespace osu.Game.Rulesets.Mods
currentCombo = scoreProcessor.Combo.GetBoundCopy();
currentCombo.BindValueChanged(combo =>
{
double dimFactor = Math.Min(1, (double)combo.NewValue / MuteComboCount.Value);
double dimFactor = MuteComboCount.Value == 0 ? 1 : (double)combo.NewValue / MuteComboCount.Value;
if (InverseMuting.Value)
dimFactor = 1 - dimFactor;
@ -101,4 +108,9 @@ namespace osu.Game.Rulesets.Mods
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
}
public class MuteComboSlider : OsuSliderBar<int>
{
public override LocalisableString TooltipText => Current.Value == 0 ? "always muted" : base.TooltipText;
}
}