Simplify settings update logic

This commit is contained in:
Dean Herbert 2019-12-11 13:19:02 +09:00
parent 138b83c9ea
commit a37af311d0
1 changed files with 23 additions and 24 deletions

View File

@ -331,32 +331,10 @@ private void load(OsuColour colours, IBindable<RulesetInfo> ruleset, AudioManage
Ruleset.BindTo(ruleset);
if (mods != null) SelectedMods.BindTo(mods);
SelectedMods.ValueChanged += updateModSettings;
Ruleset.ValueChanged += _ => ModSettingsContent.Clear();
sampleOn = audio.Samples.Get(@"UI/check-on");
sampleOff = audio.Samples.Get(@"UI/check-off");
}
private void updateModSettings(ValueChangedEvent<IReadOnlyList<Mod>> selectedMods)
{
foreach (var added in selectedMods.NewValue.Except(selectedMods.OldValue))
{
var controls = added.CreateSettingsControls().ToList();
if (controls.Count > 0)
ModSettingsContent.Add(new ModControlSection(added) { Children = controls });
}
foreach (var removed in selectedMods.OldValue.Except(selectedMods.NewValue))
ModSettingsContent.RemoveAll(section => section.Mod == removed);
bool hasSettings = ModSettingsContent.Children.Count > 0;
CustomiseButton.Enabled.Value = hasSettings;
if (!hasSettings)
ModSettingsContainer.Hide();
}
public void DeselectAll()
{
foreach (var section in ModSectionsContainer.Children)
@ -450,12 +428,14 @@ private void rulesetChanged(ValueChangedEvent<RulesetInfo> e)
refreshSelectedMods();
}
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> e)
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
{
foreach (var section in ModSectionsContainer.Children)
section.SelectTypes(e.NewValue.Select(m => m.GetType()).ToList());
section.SelectTypes(mods.NewValue.Select(m => m.GetType()).ToList());
updateMods();
updateModSettings(mods);
}
private void updateMods()
@ -480,6 +460,25 @@ private void updateMods()
UnrankedLabel.FadeTo(ranked ? 0 : 1, 200);
}
private void updateModSettings(ValueChangedEvent<IReadOnlyList<Mod>> selectedMods)
{
foreach (var added in selectedMods.NewValue.Except(selectedMods.OldValue))
{
var controls = added.CreateSettingsControls().ToList();
if (controls.Count > 0)
ModSettingsContent.Add(new ModControlSection(added) { Children = controls });
}
foreach (var removed in selectedMods.OldValue.Except(selectedMods.NewValue))
ModSettingsContent.RemoveAll(section => section.Mod == removed);
bool hasSettings = ModSettingsContent.Children.Count > 0;
CustomiseButton.Enabled.Value = hasSettings;
if (!hasSettings)
ModSettingsContainer.Hide();
}
private void modButtonPressed(Mod selectedMod)
{
if (selectedMod != null)