diff --git a/BizHawk.MultiClient/config/ControllerConfig/AnalogBindPanel.cs b/BizHawk.MultiClient/config/ControllerConfig/AnalogBindPanel.cs
index 9ab2b5bc05..c23be21553 100644
--- a/BizHawk.MultiClient/config/ControllerConfig/AnalogBindPanel.cs
+++ b/BizHawk.MultiClient/config/ControllerConfig/AnalogBindPanel.cs
@@ -34,12 +34,17 @@ namespace BizHawk.MultiClient.config.ControllerConfig
ResumeLayout();
}
- public void Save()
+ ///
+ /// save to config
+ ///
+ /// if non-null, save to possibly different config object than originally initialized from
+ public void Save(Dictionary SaveConfigObject = null)
{
+ var saveto = SaveConfigObject ?? RealConfigObject;
foreach (Control c in Controls)
{
var abc = (AnalogBindControl)c;
- RealConfigObject[abc.ButtonName] = abc.Bind;
+ saveto[abc.ButtonName] = abc.Bind;
}
}
}
diff --git a/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs b/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs
index 47c605deec..917cdbda50 100644
--- a/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs
+++ b/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs
@@ -81,10 +81,15 @@ namespace BizHawk.MultiClient
}
}
- public void Save()
+ ///
+ /// save to config
+ ///
+ /// if non-null, save to possibly different config object than originally initialized from
+ public void Save(DictionarySaveConfigObject = null)
{
+ var saveto = SaveConfigObject ?? RealConfigObject;
for (int button = 0; button < buttons.Count; button++)
- RealConfigObject[buttons[button]] = Inputs[button].Text;
+ saveto[buttons[button]] = Inputs[button].Text;
}
public bool Autotab = false;
diff --git a/BizHawk.MultiClient/config/NewControllerConfig.cs b/BizHawk.MultiClient/config/NewControllerConfig.cs
index 7aaf525270..5d03278367 100644
--- a/BizHawk.MultiClient/config/NewControllerConfig.cs
+++ b/BizHawk.MultiClient/config/NewControllerConfig.cs
@@ -132,14 +132,13 @@ namespace BizHawk.MultiClient.config
private ControllerDefinition the_definition;
-
public NewControllerConfig(ControllerDefinition def)
: this()
{
the_definition = def;
ControllerType = def.Name;
SuspendLayout();
- LoadPanels();
+ LoadPanels(Global.Config);
Text = def.Name + " Configuration";
checkBoxUDLR.Checked = Global.Config.AllowUD_LR;
@@ -149,11 +148,13 @@ namespace BizHawk.MultiClient.config
ResumeLayout();
}
- private void LoadPanels()
+ private void LoadPanels(Dictionary> normal,
+ Dictionary> autofire,
+ Dictionary> analog)
{
- LoadToPanel(tabPage1, the_definition.Name, the_definition.BoolButtons, Global.Config.AllTrollers, "", CreateNormalPanel);
- LoadToPanel(tabPage2, the_definition.Name, the_definition.BoolButtons, Global.Config.AllTrollersAutoFire, "", CreateNormalPanel);
- LoadToPanel(tabPage3, the_definition.Name, the_definition.FloatControls, Global.Config.AllTrollersAnalog, new Config.AnalogBind("", 1.0f, 0.0f), CreateAnalogPanel);
+ LoadToPanel(tabPage1, the_definition.Name, the_definition.BoolButtons, normal, "", CreateNormalPanel);
+ LoadToPanel(tabPage2, the_definition.Name, the_definition.BoolButtons, autofire, "", CreateNormalPanel);
+ LoadToPanel(tabPage3, the_definition.Name, the_definition.FloatControls, analog, new Config.AnalogBind("", 1.0f, 0.0f), CreateAnalogPanel);
if (tabPage3.Controls.Count == 0)
{
@@ -161,6 +162,16 @@ namespace BizHawk.MultiClient.config
}
}
+ private void LoadPanels(ControlDefaults cd)
+ {
+ LoadPanels(cd.AllTrollers, cd.AllTrollersAutoFire, cd.AllTrollersAnalog);
+ }
+
+ private void LoadPanels(Config c)
+ {
+ LoadPanels(c.AllTrollers, c.AllTrollersAutoFire, c.AllTrollersAnalog);
+ }
+
void SetControllerPicture(string ControlName)
{
Bitmap bmp;
@@ -202,18 +213,22 @@ namespace BizHawk.MultiClient.config
SetAutoTab(cc, value);
}
- static void Save(Control c)
+ void Save()
{
- if (c is ControllerConfigPanel)
- (c as ControllerConfigPanel).Save();
- else if (c is AnalogBindPanel)
- (c as AnalogBindPanel).Save();
- else if (c.HasChildren)
- foreach (Control cc in c.Controls)
- Save(cc);
+ ActOnControlCollection(tabPage1, (c) => c.Save(Global.Config.AllTrollers[the_definition.Name]));
+ ActOnControlCollection(tabPage2, (c) => c.Save(Global.Config.AllTrollersAutoFire[the_definition.Name]));
+ ActOnControlCollection(tabPage3, (c) => c.Save(Global.Config.AllTrollersAnalog[the_definition.Name]));
}
-
+ static void ActOnControlCollection(Control c, Action proc)
+ where T : Control
+ {
+ if (c is T)
+ proc(c as T);
+ else if (c.HasChildren)
+ foreach (Control cc in c.Controls)
+ ActOnControlCollection(cc, proc);
+ }
private void checkBoxAutoTab_CheckedChanged(object sender, EventArgs e)
{
@@ -229,7 +244,7 @@ namespace BizHawk.MultiClient.config
Global.Config.AllowUD_LR = checkBoxUDLR.Checked;
Global.Config.InputConfigAutoTab = checkBoxAutoTab.Checked;
- Save(this);
+ Save();
Global.OSD.AddMessage("Controller settings saved");
DialogResult = DialogResult.OK;
@@ -270,7 +285,6 @@ namespace BizHawk.MultiClient.config
private void buttonLoadDefaults_Click(object sender, EventArgs e)
{
tabControl1.SuspendLayout();
- RestoreDefaults();
string wasTabbedMain = tabControl1.SelectedTab.Name;
TabControl tb1 = GetTabControl(tabPage1.Controls ?? null);
@@ -287,7 +301,13 @@ namespace BizHawk.MultiClient.config
tabPage1.Controls.Clear();
tabPage2.Controls.Clear();
tabPage3.Controls.Clear();
- LoadPanels();
+
+ // load panels directly from the default config.
+ // this means that the changes are NOT committed. so "Cancel" works right and you
+ // still have to hit OK at the end.
+ ControlDefaults cd = new ControlDefaults();
+ cd = ConfigService.Load(ControlDefaultPath, cd);
+ LoadPanels(cd);
tabControl1.SelectTab(wasTabbedMain);
@@ -321,43 +341,6 @@ namespace BizHawk.MultiClient.config
tabControl1.ResumeLayout();
}
- public void RestoreDefaults()
- {
- // this is not clever. i'm going to replace it with something more clever
-
- ControlDefaults cd = new ControlDefaults();
- cd = ConfigService.Load(ControlDefaultPath, cd);
- Dictionary settings;
- Dictionary asettings;
-
- if (cd.AllTrollers.TryGetValue(ControllerType, out settings))
- {
- Global.Config.AllTrollers[ControllerType] = settings;
- }
- else
- {
- Global.Config.AllTrollers[ControllerType].Clear();
- }
-
- if (cd.AllTrollersAutoFire.TryGetValue(ControllerType, out settings))
- {
- Global.Config.AllTrollersAutoFire[ControllerType] = settings;
- }
- else
- {
- Global.Config.AllTrollersAutoFire[ControllerType].Clear();
- }
-
- if (cd.AllTrollersAnalog.TryGetValue(ControllerType, out asettings))
- {
- Global.Config.AllTrollersAnalog[ControllerType] = asettings;
- }
- else
- {
- Global.Config.AllTrollersAnalog[ControllerType].Clear();
- }
- }
-
class ControlDefaults
{
public Dictionary> AllTrollers = new Dictionary>();