2021-07-28 18:21:08 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-07-30 14:49:11 +08:00
|
|
|
using System;
|
2021-07-28 18:21:08 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
using osu.Framework.Bindables;
|
2021-07-30 14:49:11 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-07-28 18:21:08 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-07-30 14:49:11 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2021-07-28 18:21:08 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2021-07-30 14:49:11 +08:00
|
|
|
using osu.Game.Scoring;
|
2021-07-28 18:21:08 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
|
|
|
public abstract class ModMuted : Mod
|
|
|
|
{
|
|
|
|
public override string Name => "Muted";
|
|
|
|
public override string Acronym => "MU";
|
|
|
|
public override IconUsage? Icon => FontAwesome.Solid.VolumeMute;
|
2021-07-29 14:41:47 +08:00
|
|
|
public override string Description => "Can you still feel the rhythm without music?";
|
2021-07-28 18:21:08 +08:00
|
|
|
public override ModType Type => ModType.Fun;
|
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:49:11 +08:00
|
|
|
public abstract class ModMuted<TObject> : ModMuted, IApplicableToDrawableRuleset<TObject>, IApplicableToTrack, IApplicableToScoreProcessor
|
2021-07-28 18:21:08 +08:00
|
|
|
where TObject : HitObject
|
|
|
|
{
|
2021-07-30 14:49:11 +08:00
|
|
|
private readonly BindableNumber<double> trackVolumeAdjust = new BindableDouble(0.5);
|
|
|
|
private readonly BindableNumber<double> metronomeVolumeAdjust = new BindableDouble(0.5);
|
|
|
|
|
|
|
|
private BindableNumber<int> currentCombo;
|
|
|
|
|
|
|
|
private AudioContainer metronomeContainer;
|
2021-07-28 18:21:08 +08:00
|
|
|
|
|
|
|
[SettingSource("Enable metronome", "Add a metronome to help you keep track of the rhythm.")]
|
|
|
|
public BindableBool EnableMetronome { get; } = new BindableBool
|
|
|
|
{
|
|
|
|
Default = true,
|
|
|
|
Value = true
|
|
|
|
};
|
|
|
|
|
2021-07-30 14:49:11 +08:00
|
|
|
[SettingSource("Muted at combo", "The combo count at which point the music is completely muted.")]
|
|
|
|
public BindableInt MuteComboCount { get; } = new BindableInt
|
|
|
|
{
|
|
|
|
Default = 100,
|
|
|
|
Value = 100,
|
|
|
|
MinValue = 0,
|
|
|
|
MaxValue = 500,
|
|
|
|
};
|
|
|
|
|
2021-07-30 15:10:10 +08:00
|
|
|
[SettingSource("Start muted", "Increase volume as combo builds.")]
|
|
|
|
public BindableBool InverseMuting { get; } = new BindableBool
|
|
|
|
{
|
|
|
|
Default = false,
|
|
|
|
Value = false
|
|
|
|
};
|
|
|
|
|
2021-07-28 18:21:08 +08:00
|
|
|
public void ApplyToTrack(ITrack track)
|
|
|
|
{
|
2021-07-30 14:49:11 +08:00
|
|
|
track.AddAdjustment(AdjustableProperty.Volume, trackVolumeAdjust);
|
2021-07-28 18:21:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ApplyToDrawableRuleset(DrawableRuleset<TObject> drawableRuleset)
|
|
|
|
{
|
2021-07-30 14:49:11 +08:00
|
|
|
if (!EnableMetronome.Value) return;
|
|
|
|
|
|
|
|
drawableRuleset.Overlays.Add(metronomeContainer = new AudioContainer
|
|
|
|
{
|
|
|
|
Child = new Metronome(drawableRuleset.Beatmap.HitObjects.First().StartTime)
|
|
|
|
});
|
|
|
|
|
|
|
|
metronomeContainer.AddAdjustment(AdjustableProperty.Volume, metronomeVolumeAdjust);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
|
|
|
{
|
|
|
|
currentCombo = scoreProcessor.Combo.GetBoundCopy();
|
|
|
|
currentCombo.BindValueChanged(combo =>
|
|
|
|
{
|
|
|
|
double dimFactor = Math.Min(1, (double)combo.NewValue / MuteComboCount.Value);
|
|
|
|
|
|
|
|
metronomeVolumeAdjust.Value = dimFactor;
|
|
|
|
trackVolumeAdjust.Value = 1 - dimFactor;
|
2021-07-30 15:10:10 +08:00
|
|
|
if (InverseMuting.Value)
|
|
|
|
dimFactor = 1 - dimFactor;
|
2021-07-30 14:49:11 +08:00
|
|
|
}, true);
|
2021-07-28 18:21:08 +08:00
|
|
|
}
|
2021-07-30 14:49:11 +08:00
|
|
|
|
|
|
|
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
2021-07-28 18:21:08 +08:00
|
|
|
}
|
|
|
|
}
|