new controller config: split into tabs by player number. this is done by examining the names in the controller definition for "P#" strings, so if it doesn't work for a particular definition, that's why...

This commit is contained in:
goyuken 2013-07-14 03:27:54 +00:00
parent 5cf95ae5f1
commit a4ea33aa6e
2 changed files with 122 additions and 15 deletions

View File

@ -11,18 +11,22 @@ namespace BizHawk.MultiClient
public partial class ControllerConfigPanel : UserControl
{
// the dictionary that results are saved to
Dictionary<string, string> RealConfigObject;
// if nonnull, the list of keys to use. used to have the config panel operate on a smaller list than the whole dictionary;
// for instance, to show only a single player
List<string> RealConfigButtons;
public List<string> buttons = new List<string>();
public int InputMarginLeft = 0;
public int LabelPadding = 10;
public int LabelPadding = 5;
public int MarginTop = 0;
public int Spacing = 30;
public int InputSize = 200;
public int ColumnWidth = 220;
public int LabelWidth = 100;
public int Spacing = 24;
public int InputSize = 100;
public int ColumnWidth = 170;
public int LabelWidth = 60;
protected List<InputWidget> Inputs = new List<InputWidget>();
protected List<Label> Labels = new List<Label>();
@ -82,9 +86,10 @@ namespace BizHawk.MultiClient
RealConfigObject[buttons[button]] = Inputs[button].Text;
}
public void LoadSettings(Dictionary<string, string> configobj)
public void LoadSettings(Dictionary<string, string> configobj, List<string> configbuttons = null)
{
RealConfigObject = configobj;
RealConfigButtons = configbuttons;
SetButtonList();
Startup();
SetWidgetStrings();
@ -93,7 +98,8 @@ namespace BizHawk.MultiClient
protected void SetButtonList()
{
buttons.Clear();
foreach (string s in RealConfigObject.Keys)
IEnumerable<string> bl = RealConfigButtons ?? (IEnumerable<string>)RealConfigObject.Keys;
foreach (string s in bl)
buttons.Add(s);
}

View File

@ -32,14 +32,90 @@ namespace BizHawk.MultiClient.config
//ControllerImages.Add(, Properties.Resources);
}
const int MAXPLAYERS = 8;
private NewControllerConfig()
{
InitializeComponent();
}
ControllerConfigPanel normcontrls;
ControllerConfigPanel autofirecontrls;
static void LoadToPanel(Control dest, ControllerDefinition def, Dictionary<string, Dictionary<string, string>> settingsblock)
{
Dictionary<string, string> settings;
if (!settingsblock.TryGetValue(def.Name, out settings))
{
settings = new Dictionary<string, string>();
settingsblock[def.Name] = settings;
}
// check to make sure that the settings object has all of the appropriate boolbuttons
foreach (string button in def.BoolButtons)
{
if (!settings.Keys.Contains(button))
settings[button] = "";
}
if (settings.Keys.Count == 0)
return;
// split the list of all settings into buckets by player number
List<string>[] buckets = new List<string>[MAXPLAYERS + 1];
for (int i = 0; i < buckets.Length; i++)
buckets[i] = new List<string>();
foreach (string button in settings.Keys)
{
int i;
for (i = 1; i <= MAXPLAYERS; i++)
{
if (button.StartsWith("P" + i))
break;
}
if (i > MAXPLAYERS) // couldn't find
i = 0;
buckets[i].Add(button);
}
if (buckets[0].Count == settings.Keys.Count)
{
// everything went into bucket 0, so make no tabs at all
var cp = new ControllerConfigPanel();
cp.Dock = DockStyle.Fill;
dest.Controls.Add(cp);
cp.LoadSettings(settings);
}
else
{
// create multiple player tabs
var tt = new TabControl();
tt.Dock = DockStyle.Fill;
dest.Controls.Add(tt);
int pageidx = 0;
for (int i = 1; i <= MAXPLAYERS; i++)
{
if (buckets[i].Count > 0)
{
tt.TabPages.Add("Player " + i);
var cp = new ControllerConfigPanel();
cp.Dock = DockStyle.Fill;
tt.TabPages[pageidx].Controls.Add(cp);
cp.LoadSettings(settings, buckets[i]);
pageidx++;
}
}
if (buckets[0].Count > 0)
{
tt.TabPages.Add("Console");
var cp = new ControllerConfigPanel();
cp.Dock = DockStyle.Fill;
tt.TabPages[pageidx].Controls.Add(cp);
cp.LoadSettings(settings, buckets[0]);
pageidx++;
}
}
}
/*
static void DoLoadSettings(ControllerConfigPanel cp, ControllerDefinition def, Dictionary<string, Dictionary<string, string>> settingsblock)
{
cp.Spacing = 24;
@ -62,20 +138,25 @@ namespace BizHawk.MultiClient.config
}
cp.LoadSettings(settings);
}
*/
public NewControllerConfig(ControllerDefinition def)
: this()
{
SuspendLayout();
normcontrls = new ControllerConfigPanel();
/*
var normcontrls = new ControllerConfigPanel();
normcontrls.Dock = DockStyle.Fill;
tabPage1.Controls.Add(normcontrls);
DoLoadSettings(normcontrls, def, Global.Config.AllTrollers);
autofirecontrls = new ControllerConfigPanel();
var autofirecontrls = new ControllerConfigPanel();
autofirecontrls.Dock = DockStyle.Fill;
tabPage2.Controls.Add(autofirecontrls);
DoLoadSettings(autofirecontrls, def, Global.Config.AllTrollersAutoFire);
*/
LoadToPanel(tabPage1, def, Global.Config.AllTrollers);
LoadToPanel(tabPage2, def, Global.Config.AllTrollersAutoFire);
label1.Text = "Currently Configuring: " + def.Name;
checkBoxUDLR.Checked = Global.Config.AllowUD_LR;
@ -96,10 +177,31 @@ namespace BizHawk.MultiClient.config
tableLayoutPanel1.ColumnStyles[1].Width = bmp.Width;
}
// lazy methods, but they're not called often and actually
// tracking all of the ControllerConfigPanels wouldn't be simpler
static void SetAutoTab(Control c, bool value)
{
if (c is ControllerConfigPanel)
(c as ControllerConfigPanel).SetAutoTab(value);
else if (c.HasChildren)
foreach (Control cc in c.Controls)
SetAutoTab(cc, value);
}
static void Save(Control c)
{
if (c is ControllerConfigPanel)
(c as ControllerConfigPanel).Save();
else if (c.HasChildren)
foreach (Control cc in c.Controls)
Save(cc);
}
private void checkBoxAutoTab_CheckedChanged(object sender, EventArgs e)
{
normcontrls.SetAutoTab(checkBoxAutoTab.Checked);
autofirecontrls.SetAutoTab(checkBoxAutoTab.Checked);
SetAutoTab(this, checkBoxAutoTab.Checked);
}
private void checkBoxUDLR_CheckedChanged(object sender, EventArgs e)
@ -111,8 +213,7 @@ namespace BizHawk.MultiClient.config
Global.Config.AllowUD_LR = checkBoxUDLR.Checked;
Global.Config.InputConfigAutoTab = checkBoxAutoTab.Checked;
normcontrls.Save();
autofirecontrls.Save();
Save(this);
Global.OSD.AddMessage("Controller settings saved");
DialogResult = DialogResult.OK;