From bc34dfe9323ec8a45798f35fdff557058964fbc0 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 9 Nov 2013 01:12:46 +0000 Subject: [PATCH] move controller default logic from controller config winform to client.common config object and hook it back up to the client --- BizHawk.Client.Common/config/Config.cs | 26 +++++++++++++++- .../config/ControllerConfig.cs | 30 ++----------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 7431a8dcb6..464ab7293f 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -10,9 +10,26 @@ namespace BizHawk.Client.Common { public class Config { + public static string ControlDefaultPath + { + get { return PathManager.MakeProgramRelativePath("defctrl.json"); } + } + + public void ConfigCheckAllControlDefaults() + { + if (AllTrollers.Count == 0 && AllTrollersAutoFire.Count == 0 && AllTrollersAnalog.Count == 0) + { + ControlDefaults cd = new ControlDefaults(); + cd = ConfigService.Load(ControlDefaultPath, cd); + AllTrollers = cd.AllTrollers; + AllTrollersAutoFire = cd.AllTrollersAutoFire; + AllTrollersAnalog = cd.AllTrollersAnalog; + } + } + public Config() { - /*ControllerConfig.ConfigCheckAllControlDefaults(this); TODO*/ + ConfigCheckAllControlDefaults(); } public void ResolveDefaults() @@ -651,6 +668,13 @@ namespace BizHawk.Client.Common #region Sub-classes TODO - it is about time to port these to separate files + public class ControlDefaults + { + public Dictionary> AllTrollers = new Dictionary>(); + public Dictionary> AllTrollersAutoFire = new Dictionary>(); + public Dictionary> AllTrollersAnalog = new Dictionary>(); + } + public class PathEntryCollection : IEnumerable { public List Paths { get; private set; } diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig.cs index 8c80f4c501..6caf0ace1e 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig.cs @@ -276,11 +276,6 @@ namespace BizHawk.Client.EmuHawk } - private static string ControlDefaultPath - { - get { return PathManager.MakeProgramRelativePath("defctrl.json"); } - } - private TabControl GetTabControl(System.Windows.Forms.Control.ControlCollection controls) { if (controls != null) @@ -320,7 +315,7 @@ namespace BizHawk.Client.EmuHawk // 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); + cd = ConfigService.Load(Config.ControlDefaultPath, cd); LoadPanels(cd); tabControl1.SelectTab(wasTabbedMain); @@ -355,39 +350,20 @@ namespace BizHawk.Client.EmuHawk tabControl1.ResumeLayout(); } - class ControlDefaults - { - public Dictionary> AllTrollers = new Dictionary>(); - public Dictionary> AllTrollersAutoFire = new Dictionary>(); - public Dictionary> AllTrollersAnalog = new Dictionary>(); - } - - public static void ConfigCheckAllControlDefaults(BizHawk.Client.Common.Config c) - { - if (c.AllTrollers.Count == 0 && c.AllTrollersAutoFire.Count == 0 && c.AllTrollersAnalog.Count == 0) - { - ControlDefaults cd = new ControlDefaults(); - cd = ConfigService.Load(ControlDefaultPath, cd); - c.AllTrollers = cd.AllTrollers; - c.AllTrollersAutoFire = cd.AllTrollersAutoFire; - c.AllTrollersAnalog = cd.AllTrollersAnalog; - } - } - private void buttonSaveDefaults_Click(object sender, EventArgs e) { var result = MessageBox.Show(this, "OK to overwrite defaults for current control scheme?", "Save Defaults", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { ControlDefaults cd = new ControlDefaults(); - cd = ConfigService.Load(ControlDefaultPath, cd); + cd = ConfigService.Load(Config.ControlDefaultPath, cd); cd.AllTrollers[the_definition.Name] = new Dictionary(); cd.AllTrollersAutoFire[the_definition.Name] = new Dictionary(); cd.AllTrollersAnalog[the_definition.Name] = new Dictionary(); SaveToDefaults(cd); - ConfigService.Save(ControlDefaultPath, cd); + ConfigService.Save(Config.ControlDefaultPath, cd); } } }