move controller default logic from controller config winform to client.common config object and hook it back up to the client

This commit is contained in:
adelikat 2013-11-09 01:12:46 +00:00
parent 52146bff6b
commit bc34dfe932
2 changed files with 28 additions and 28 deletions

View File

@ -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<string, Dictionary<string, string>> AllTrollers = new Dictionary<string, Dictionary<string, string>>();
public Dictionary<string, Dictionary<string, string>> AllTrollersAutoFire = new Dictionary<string, Dictionary<string, string>>();
public Dictionary<string, Dictionary<string, BizHawk.Client.Common.Config.AnalogBind>> AllTrollersAnalog = new Dictionary<string, Dictionary<string, BizHawk.Client.Common.Config.AnalogBind>>();
}
public class PathEntryCollection : IEnumerable<PathEntry>
{
public List<PathEntry> Paths { get; private set; }

View File

@ -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<string, Dictionary<string, string>> AllTrollers = new Dictionary<string, Dictionary<string, string>>();
public Dictionary<string, Dictionary<string, string>> AllTrollersAutoFire = new Dictionary<string, Dictionary<string, string>>();
public Dictionary<string, Dictionary<string, BizHawk.Client.Common.Config.AnalogBind>> AllTrollersAnalog = new Dictionary<string, Dictionary<string, BizHawk.Client.Common.Config.AnalogBind>>();
}
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<string, string>();
cd.AllTrollersAutoFire[the_definition.Name] = new Dictionary<string, string>();
cd.AllTrollersAnalog[the_definition.Name] = new Dictionary<string, BizHawk.Client.Common.Config.AnalogBind>();
SaveToDefaults(cd);
ConfigService.Save(ControlDefaultPath, cd);
ConfigService.Save(Config.ControlDefaultPath, cd);
}
}
}