Always reset local user settings when a mod is deselected in ModSelectOverlay

This commit is contained in:
Dean Herbert 2021-02-09 13:44:42 +09:00
parent be379e0e3c
commit 8204d360a8
4 changed files with 21 additions and 1 deletions

View File

@ -69,6 +69,8 @@ private bool changeSelectedIndex(int newIndex)
Mod newSelection = SelectedMod ?? Mods[0];
newSelection.ResetSettingsToDefaults();
Schedule(() =>
{
if (beforeSelected != Selected)

View File

@ -197,8 +197,10 @@ private void updateButtonSelection(ModButton button, IReadOnlyList<Mod> 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;
}

View File

@ -173,5 +173,10 @@ internal virtual void CopyAdjustedSetting(IBindable target, object source)
}
public bool Equals(IMod other) => GetType() == other?.GetType();
/// <summary>
/// Reset all custom settings for this mod back to their defaults.
/// </summary>
public virtual void ResetSettingsToDefaults() => CopyFrom((Mod)Activator.CreateInstance(GetType()));
}
}

View File

@ -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);
}
}
}
}