From 8204d360a8d84f5ac3fe2eec40155999c23a5ba2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 9 Feb 2021 13:44:42 +0900 Subject: [PATCH] Always reset local user settings when a mod is deselected in ModSelectOverlay --- osu.Game/Overlays/Mods/ModButton.cs | 2 ++ osu.Game/Overlays/Mods/ModSection.cs | 4 +++- osu.Game/Rulesets/Mods/Mod.cs | 5 +++++ osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs | 11 +++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Mods/ModButton.cs b/osu.Game/Overlays/Mods/ModButton.cs index 8e0d1f5bbd..06f2fea43f 100644 --- a/osu.Game/Overlays/Mods/ModButton.cs +++ b/osu.Game/Overlays/Mods/ModButton.cs @@ -69,6 +69,8 @@ private bool changeSelectedIndex(int newIndex) Mod newSelection = SelectedMod ?? Mods[0]; + newSelection.ResetSettingsToDefaults(); + Schedule(() => { if (beforeSelected != Selected) diff --git a/osu.Game/Overlays/Mods/ModSection.cs b/osu.Game/Overlays/Mods/ModSection.cs index ecbcba7ad3..08bd3f8622 100644 --- a/osu.Game/Overlays/Mods/ModSection.cs +++ b/osu.Game/Overlays/Mods/ModSection.cs @@ -197,8 +197,10 @@ private void updateButtonSelection(ModButton button, IReadOnlyList newSelec continue; var buttonMod = button.Mods[index]; - buttonMod.CopyFrom(mod); button.SelectAt(index); + + // the selection above will reset settings to defaults, but as this is an external change we want to copy the new settings across. + buttonMod.CopyFrom(mod); return; } diff --git a/osu.Game/Rulesets/Mods/Mod.cs b/osu.Game/Rulesets/Mods/Mod.cs index dec72d94e5..2a11c92223 100644 --- a/osu.Game/Rulesets/Mods/Mod.cs +++ b/osu.Game/Rulesets/Mods/Mod.cs @@ -173,5 +173,10 @@ internal virtual void CopyAdjustedSetting(IBindable target, object source) } public bool Equals(IMod other) => GetType() == other?.GetType(); + + /// + /// Reset all custom settings for this mod back to their defaults. + /// + public virtual void ResetSettingsToDefaults() => CopyFrom((Mod)Activator.CreateInstance(GetType())); } } diff --git a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs index a531e885db..dbc35569e7 100644 --- a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs +++ b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs @@ -141,5 +141,16 @@ protected virtual void ApplySettings(BeatmapDifficulty difficulty) ApplySetting(DrainRate, dr => difficulty.DrainRate = dr); ApplySetting(OverallDifficulty, od => difficulty.OverallDifficulty = od); } + + public override void ResetSettingsToDefaults() + { + base.ResetSettingsToDefaults(); + + if (difficulty != null) + { + // base implementation potentially overwrite modified defaults that came from a beatmap selection. + TransferSettings(difficulty); + } + } } }