2019-12-11 11:43:16 +00: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.
|
|
|
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using System;
|
2019-12-27 10:05:17 +00:00
|
|
|
using System.Collections.Generic;
|
2019-12-22 08:45:32 +00:00
|
|
|
using osu.Game.Configuration;
|
2020-03-22 22:49:45 +00:00
|
|
|
using System.Linq;
|
2019-12-11 11:43:16 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
2019-12-20 10:30:23 +00:00
|
|
|
public abstract class ModDifficultyAdjust : Mod, IApplicableToDifficulty
|
2019-12-11 11:43:16 +00:00
|
|
|
{
|
|
|
|
public override string Name => @"Difficulty Adjust";
|
|
|
|
|
2019-12-20 10:31:16 +00:00
|
|
|
public override string Description => @"Override a beatmap's difficulty settings.";
|
2019-12-11 11:43:16 +00:00
|
|
|
|
|
|
|
public override string Acronym => "DA";
|
|
|
|
|
|
|
|
public override ModType Type => ModType.Conversion;
|
|
|
|
|
2020-01-14 13:22:00 +00:00
|
|
|
public override IconUsage? Icon => FontAwesome.Solid.Hammer;
|
2019-12-11 11:43:16 +00:00
|
|
|
|
|
|
|
public override double ScoreMultiplier => 1.0;
|
|
|
|
|
2020-01-20 16:06:36 +00:00
|
|
|
public override bool RequiresConfiguration => true;
|
|
|
|
|
2019-12-11 11:43:16 +00:00
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModHardRock) };
|
|
|
|
|
2020-02-13 05:07:37 +00:00
|
|
|
protected const int FIRST_SETTING_ORDER = 1;
|
|
|
|
|
|
|
|
protected const int LAST_SETTING_ORDER = 2;
|
|
|
|
|
2020-03-20 20:05:12 +00:00
|
|
|
[SettingSource("HP Drain", "Override a beatmap's set HP.", FIRST_SETTING_ORDER)]
|
2019-12-25 06:20:10 +00:00
|
|
|
public BindableNumber<float> DrainRate { get; } = new BindableFloat
|
2019-12-22 08:45:32 +00:00
|
|
|
{
|
|
|
|
Precision = 0.1f,
|
2020-07-13 23:15:14 +00:00
|
|
|
MinValue = 0,
|
2019-12-22 08:45:32 +00:00
|
|
|
MaxValue = 10,
|
|
|
|
Default = 5,
|
|
|
|
Value = 5,
|
|
|
|
};
|
|
|
|
|
2020-03-20 20:05:12 +00:00
|
|
|
[SettingSource("Accuracy", "Override a beatmap's set OD.", LAST_SETTING_ORDER)]
|
2019-12-25 06:20:10 +00:00
|
|
|
public BindableNumber<float> OverallDifficulty { get; } = new BindableFloat
|
2019-12-22 08:45:32 +00:00
|
|
|
{
|
|
|
|
Precision = 0.1f,
|
2020-07-13 23:15:14 +00:00
|
|
|
MinValue = 0,
|
2019-12-22 08:45:32 +00:00
|
|
|
MaxValue = 10,
|
|
|
|
Default = 5,
|
|
|
|
Value = 5,
|
|
|
|
};
|
2019-12-11 11:43:16 +00:00
|
|
|
|
2020-03-20 20:34:36 +00:00
|
|
|
public override string SettingDescription
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-03-23 02:54:21 +00:00
|
|
|
string drainRate = DrainRate.IsDefault ? string.Empty : $"HP {DrainRate.Value:N1}";
|
|
|
|
string overallDifficulty = OverallDifficulty.IsDefault ? string.Empty : $"OD {OverallDifficulty.Value:N1}";
|
2020-03-22 22:49:45 +00:00
|
|
|
|
|
|
|
return string.Join(", ", new[]
|
|
|
|
{
|
|
|
|
drainRate,
|
|
|
|
overallDifficulty
|
|
|
|
}.Where(s => !string.IsNullOrEmpty(s)));
|
2020-03-20 20:34:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-20 20:05:12 +00:00
|
|
|
|
2019-12-13 07:22:07 +00:00
|
|
|
private BeatmapDifficulty difficulty;
|
|
|
|
|
2019-12-26 05:52:08 +00:00
|
|
|
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
|
2019-12-11 11:43:16 +00:00
|
|
|
{
|
2019-12-13 07:22:07 +00:00
|
|
|
if (this.difficulty == null || this.difficulty.ID != difficulty.ID)
|
|
|
|
{
|
2019-12-25 06:20:04 +00:00
|
|
|
TransferSettings(difficulty);
|
2019-12-27 10:05:17 +00:00
|
|
|
this.difficulty = difficulty;
|
2019-12-13 07:46:58 +00:00
|
|
|
}
|
2019-12-22 08:45:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 05:52:08 +00:00
|
|
|
public void ApplyToDifficulty(BeatmapDifficulty difficulty) => ApplySettings(difficulty);
|
|
|
|
|
2019-12-25 06:20:04 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Transfer initial settings from the beatmap to settings.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="difficulty">The beatmap's initial values.</param>
|
|
|
|
protected virtual void TransferSettings(BeatmapDifficulty difficulty)
|
2019-12-22 08:45:32 +00:00
|
|
|
{
|
2019-12-27 10:05:17 +00:00
|
|
|
TransferSetting(DrainRate, difficulty.DrainRate);
|
|
|
|
TransferSetting(OverallDifficulty, difficulty.OverallDifficulty);
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly Dictionary<IBindable, bool> userChangedSettings = new Dictionary<IBindable, bool>();
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Transfer a setting from <see cref="BeatmapDifficulty"/> to a configuration bindable.
|
2020-03-19 03:42:14 +00:00
|
|
|
/// Only performs the transfer if the user is not currently overriding.
|
2019-12-27 10:05:17 +00:00
|
|
|
/// </summary>
|
|
|
|
protected void TransferSetting<T>(BindableNumber<T> bindable, T beatmapDefault)
|
|
|
|
where T : struct, IComparable<T>, IConvertible, IEquatable<T>
|
|
|
|
{
|
|
|
|
bindable.UnbindEvents();
|
|
|
|
|
|
|
|
userChangedSettings.TryAdd(bindable, false);
|
|
|
|
|
2019-12-27 14:01:52 +00:00
|
|
|
bindable.Default = beatmapDefault;
|
|
|
|
|
2019-12-27 10:05:17 +00:00
|
|
|
// users generally choose a difficulty setting and want it to stick across multiple beatmap changes.
|
|
|
|
// we only want to value transfer if the user hasn't changed the value previously.
|
|
|
|
if (!userChangedSettings[bindable])
|
2019-12-27 14:01:52 +00:00
|
|
|
bindable.Value = beatmapDefault;
|
2019-12-27 10:05:17 +00:00
|
|
|
|
|
|
|
bindable.ValueChanged += _ => userChangedSettings[bindable] = !bindable.IsDefault;
|
2019-12-22 08:45:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 06:20:04 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Apply all custom settings to the provided beatmap.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="difficulty">The beatmap to have settings applied.</param>
|
2019-12-22 08:45:32 +00:00
|
|
|
protected virtual void ApplySettings(BeatmapDifficulty difficulty)
|
|
|
|
{
|
|
|
|
difficulty.DrainRate = DrainRate.Value;
|
|
|
|
difficulty.OverallDifficulty = OverallDifficulty.Value;
|
2019-12-11 11:43:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-11 12:12:29 +00:00
|
|
|
}
|