controller config rework: more cleanup

This commit is contained in:
goyuken 2013-07-14 02:30:57 +00:00
parent 34223780c2
commit 454e94a4bb
4 changed files with 22 additions and 98 deletions

View File

@ -172,9 +172,6 @@
<Compile Include="config\ControllerConfig\ControllerConfigPanel.Designer.cs">
<DependentUpon>ControllerConfigPanel.cs</DependentUpon>
</Compile>
<Compile Include="config\ControllerConfig\NewControllerConfigPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="config\GifAnimator.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -11,7 +11,7 @@ namespace BizHawk.MultiClient
public partial class ControllerConfigPanel : UserControl
{
iControllerConfigObject ControllerConfigObject; //Object that values will be saved to (In Config.cs)
Dictionary<string, string> RealConfigObject;
public List<string> buttons = new List<string>();
@ -76,52 +76,35 @@ namespace BizHawk.MultiClient
}
}
virtual public void Save()
public void Save()
{
for (int button = 0; button < buttons.Count; button++)
{
FieldInfo buttonF = ControllerConfigObject.GetType().GetField(buttons[button]);
buttonF.SetValue(ControllerConfigObject, Inputs[button].Text);
}
RealConfigObject[buttons[button]] = Inputs[button].Text;
}
virtual public void LoadSettings(iControllerConfigObject configobj)
public void LoadSettings(Dictionary<string, string> configobj)
{
ControllerConfigObject = configobj;
RealConfigObject = configobj;
SetButtonList();
Startup();
SetWidgetStrings();
}
virtual protected void SetButtonList()
protected void SetButtonList()
{
buttons.Clear();
MemberInfo[] members = ControllerConfigObject.GetType().GetMembers();
foreach (MemberInfo member in members)
{
if (member.MemberType.ToString() == "Field" && member.ToString().Contains("System.String"))
{
buttons.Add(member.Name);
}
}
foreach (string s in RealConfigObject.Keys)
buttons.Add(s);
}
virtual protected void SetWidgetStrings()
protected void SetWidgetStrings()
{
for (int button = 0; button < buttons.Count; button++)
{
object field = ControllerConfigObject.GetType().GetField(buttons[button]).GetValue(ControllerConfigObject);
if (field == null)
{
Inputs[button].SetBindings("");
}
else
{
Inputs[button].SetBindings(field.ToString());
}
string s;
if (!RealConfigObject.TryGetValue(buttons[button], out s))
s = "";
Inputs[button].SetBindings(s);
}
}
@ -177,9 +160,11 @@ namespace BizHawk.MultiClient
ClearAll();
}
virtual protected void restoreDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
protected void restoreDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
{
ControllerConfigObject.SetDefaults();
// this is a TODO: we have no concept of default values in our config system at the moment
// so for the moment, "defaults" = "no binds at all"
RealConfigObject.Clear();
SetWidgetStrings();
}
}

View File

@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient.config.ControllerConfig
{
class NewControllerConfigPanel : ControllerConfigPanel
{
Dictionary<string, string> RealConfigObject;
public override void Save()
{
for (int button = 0; button < buttons.Count; button++)
RealConfigObject[buttons[button]] = Inputs[button].Text;
}
public void LoadSettings(Dictionary<string, string> configobj)
{
RealConfigObject = configobj;
SetButtonList();
Startup();
SetWidgetStrings();
}
public override void LoadSettings(iControllerConfigObject configobj)
{
throw new InvalidOperationException();
}
protected override void SetButtonList()
{
buttons.Clear();
foreach (string s in RealConfigObject.Keys)
buttons.Add(s);
}
protected override void SetWidgetStrings()
{
for (int button = 0; button < buttons.Count; button++)
{
string s;
if (!RealConfigObject.TryGetValue(buttons[button], out s))
s = "";
Inputs[button].SetBindings(s);
}
}
protected override void restoreDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
{
// this is a TODO: we have no concept of default values in our config system at the moment
// so for the moment, "defaults" = "no binds at all"
RealConfigObject.Clear();
SetWidgetStrings();
}
}
}

View File

@ -6,7 +6,6 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.MultiClient.config.ControllerConfig;
namespace BizHawk.MultiClient.config
{
@ -38,10 +37,10 @@ namespace BizHawk.MultiClient.config
InitializeComponent();
}
NewControllerConfigPanel normcontrls;
NewControllerConfigPanel autofirecontrls;
ControllerConfigPanel normcontrls;
ControllerConfigPanel autofirecontrls;
static void DoLoadSettings(NewControllerConfigPanel cp, ControllerDefinition def, Dictionary<string, Dictionary<string, string>> settingsblock)
static void DoLoadSettings(ControllerConfigPanel cp, ControllerDefinition def, Dictionary<string, Dictionary<string, string>> settingsblock)
{
cp.Spacing = 24;
cp.InputSize = 100;
@ -68,12 +67,12 @@ namespace BizHawk.MultiClient.config
: this()
{
SuspendLayout();
normcontrls = new NewControllerConfigPanel();
normcontrls = new ControllerConfigPanel();
normcontrls.Dock = DockStyle.Fill;
tabPage1.Controls.Add(normcontrls);
DoLoadSettings(normcontrls, def, Global.Config.AllTrollers);
autofirecontrls = new NewControllerConfigPanel();
autofirecontrls = new ControllerConfigPanel();
autofirecontrls.Dock = DockStyle.Fill;
tabPage2.Controls.Add(autofirecontrls);
DoLoadSettings(autofirecontrls, def, Global.Config.AllTrollersAutoFire);