controller config rework: more cleanup
This commit is contained in:
parent
34223780c2
commit
454e94a4bb
|
@ -172,9 +172,6 @@
|
||||||
<Compile Include="config\ControllerConfig\ControllerConfigPanel.Designer.cs">
|
<Compile Include="config\ControllerConfig\ControllerConfigPanel.Designer.cs">
|
||||||
<DependentUpon>ControllerConfigPanel.cs</DependentUpon>
|
<DependentUpon>ControllerConfigPanel.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="config\ControllerConfig\NewControllerConfigPanel.cs">
|
|
||||||
<SubType>UserControl</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="config\GifAnimator.cs">
|
<Compile Include="config\GifAnimator.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
public partial class ControllerConfigPanel : UserControl
|
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>();
|
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++)
|
for (int button = 0; button < buttons.Count; button++)
|
||||||
{
|
RealConfigObject[buttons[button]] = Inputs[button].Text;
|
||||||
FieldInfo buttonF = ControllerConfigObject.GetType().GetField(buttons[button]);
|
|
||||||
buttonF.SetValue(ControllerConfigObject, Inputs[button].Text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual public void LoadSettings(iControllerConfigObject configobj)
|
public void LoadSettings(Dictionary<string, string> configobj)
|
||||||
{
|
{
|
||||||
ControllerConfigObject = configobj;
|
RealConfigObject = configobj;
|
||||||
|
|
||||||
SetButtonList();
|
SetButtonList();
|
||||||
Startup();
|
Startup();
|
||||||
SetWidgetStrings();
|
SetWidgetStrings();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual protected void SetButtonList()
|
protected void SetButtonList()
|
||||||
{
|
{
|
||||||
buttons.Clear();
|
buttons.Clear();
|
||||||
MemberInfo[] members = ControllerConfigObject.GetType().GetMembers();
|
foreach (string s in RealConfigObject.Keys)
|
||||||
|
buttons.Add(s);
|
||||||
foreach (MemberInfo member in members)
|
|
||||||
{
|
|
||||||
if (member.MemberType.ToString() == "Field" && member.ToString().Contains("System.String"))
|
|
||||||
{
|
|
||||||
buttons.Add(member.Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual protected void SetWidgetStrings()
|
protected void SetWidgetStrings()
|
||||||
{
|
{
|
||||||
for (int button = 0; button < buttons.Count; button++)
|
for (int button = 0; button < buttons.Count; button++)
|
||||||
{
|
{
|
||||||
object field = ControllerConfigObject.GetType().GetField(buttons[button]).GetValue(ControllerConfigObject);
|
string s;
|
||||||
|
if (!RealConfigObject.TryGetValue(buttons[button], out s))
|
||||||
if (field == null)
|
s = "";
|
||||||
{
|
Inputs[button].SetBindings(s);
|
||||||
Inputs[button].SetBindings("");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Inputs[button].SetBindings(field.ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,9 +160,11 @@ namespace BizHawk.MultiClient
|
||||||
ClearAll();
|
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();
|
SetWidgetStrings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,6 @@ using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using BizHawk.MultiClient.config.ControllerConfig;
|
|
||||||
|
|
||||||
namespace BizHawk.MultiClient.config
|
namespace BizHawk.MultiClient.config
|
||||||
{
|
{
|
||||||
|
@ -38,10 +37,10 @@ namespace BizHawk.MultiClient.config
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
NewControllerConfigPanel normcontrls;
|
ControllerConfigPanel normcontrls;
|
||||||
NewControllerConfigPanel autofirecontrls;
|
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.Spacing = 24;
|
||||||
cp.InputSize = 100;
|
cp.InputSize = 100;
|
||||||
|
@ -68,12 +67,12 @@ namespace BizHawk.MultiClient.config
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
normcontrls = new NewControllerConfigPanel();
|
normcontrls = new ControllerConfigPanel();
|
||||||
normcontrls.Dock = DockStyle.Fill;
|
normcontrls.Dock = DockStyle.Fill;
|
||||||
tabPage1.Controls.Add(normcontrls);
|
tabPage1.Controls.Add(normcontrls);
|
||||||
DoLoadSettings(normcontrls, def, Global.Config.AllTrollers);
|
DoLoadSettings(normcontrls, def, Global.Config.AllTrollers);
|
||||||
|
|
||||||
autofirecontrls = new NewControllerConfigPanel();
|
autofirecontrls = new ControllerConfigPanel();
|
||||||
autofirecontrls.Dock = DockStyle.Fill;
|
autofirecontrls.Dock = DockStyle.Fill;
|
||||||
tabPage2.Controls.Add(autofirecontrls);
|
tabPage2.Controls.Add(autofirecontrls);
|
||||||
DoLoadSettings(autofirecontrls, def, Global.Config.AllTrollersAutoFire);
|
DoLoadSettings(autofirecontrls, def, Global.Config.AllTrollersAutoFire);
|
||||||
|
|
Loading…
Reference in New Issue