2013-07-14 01:48:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2013-07-24 02:14:25 +00:00
|
|
|
|
using BizHawk.MultiClient.config.ControllerConfig;
|
2013-07-14 01:48:05 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient.config
|
|
|
|
|
{
|
|
|
|
|
public partial class NewControllerConfig : Form
|
|
|
|
|
{
|
2013-07-17 01:05:36 +00:00
|
|
|
|
static readonly Dictionary<string, Bitmap> ControllerImages = new Dictionary<string, Bitmap>();
|
2013-07-14 02:21:41 +00:00
|
|
|
|
static NewControllerConfig()
|
|
|
|
|
{
|
|
|
|
|
ControllerImages.Add("NES Controller", Properties.Resources.NES_Controller);
|
|
|
|
|
ControllerImages.Add("Atari 7800 ProLine Joystick Controller", Properties.Resources.A78Joystick);
|
|
|
|
|
ControllerImages.Add("SNES Controller", Properties.Resources.SNES_Controller);
|
|
|
|
|
ControllerImages.Add("Commodore 64 Controller", Properties.Resources.C64Joystick);
|
|
|
|
|
ControllerImages.Add("GBA Controller", Properties.Resources.GBA_Controller);
|
|
|
|
|
ControllerImages.Add("Dual Gameboy Controller", Properties.Resources.GBController);
|
|
|
|
|
ControllerImages.Add("Nintento 64 Controller", Properties.Resources.N64);
|
|
|
|
|
ControllerImages.Add("Saturn Controller", Properties.Resources.SaturnController);
|
|
|
|
|
//ControllerImages.Add("PSP Controller", Properties.Resources);
|
|
|
|
|
ControllerImages.Add("PC Engine Controller", Properties.Resources.PCEngineController);
|
|
|
|
|
ControllerImages.Add("Atari 2600 Basic Controller", Properties.Resources.atari_controller);
|
|
|
|
|
ControllerImages.Add("Genesis 3-Button Controller", Properties.Resources.GENController);
|
|
|
|
|
ControllerImages.Add("Gameboy Controller", Properties.Resources.GBController);
|
|
|
|
|
ControllerImages.Add("SMS Controller", Properties.Resources.SMSController);
|
|
|
|
|
ControllerImages.Add("TI83 Controller", Properties.Resources.TI83_Controller);
|
|
|
|
|
//ControllerImages.Add(, Properties.Resources);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-14 03:27:54 +00:00
|
|
|
|
const int MAXPLAYERS = 8;
|
2013-07-17 01:20:21 +00:00
|
|
|
|
string ControllerType;
|
2013-07-14 03:27:54 +00:00
|
|
|
|
|
2013-07-14 01:48:05 +00:00
|
|
|
|
private NewControllerConfig()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 01:38:52 +00:00
|
|
|
|
delegate Control PanelCreator<T>(Dictionary<string, T> settings, List<string> buttons, Size size);
|
|
|
|
|
|
|
|
|
|
Control CreateNormalPanel(Dictionary<string, string> settings, List<string> buttons, Size size)
|
|
|
|
|
{
|
|
|
|
|
var cp = new ControllerConfigPanel {Dock = DockStyle.Fill};
|
|
|
|
|
cp.LoadSettings(settings, buttons, size.Width, size.Height);
|
|
|
|
|
return cp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Control CreateAnalogPanel(Dictionary<string, Config.AnalogBind> settings, List<string> buttons, Size size)
|
2013-07-14 03:27:54 +00:00
|
|
|
|
{
|
2013-07-25 00:28:11 +00:00
|
|
|
|
var acp = new AnalogBindPanel(settings, buttons) { Dock = DockStyle.Fill };
|
2013-07-24 01:38:52 +00:00
|
|
|
|
return acp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void LoadToPanel<T>(Control dest, string ControllerName, IEnumerable<string> ControllerButtons, Dictionary<string, Dictionary<string, T>> settingsblock, T defaultvalue, PanelCreator<T> createpanel)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, T> settings;
|
|
|
|
|
if (!settingsblock.TryGetValue(ControllerName, out settings))
|
2013-07-14 03:27:54 +00:00
|
|
|
|
{
|
2013-07-24 01:38:52 +00:00
|
|
|
|
settings = new Dictionary<string, T>();
|
|
|
|
|
settingsblock[ControllerName] = settings;
|
2013-07-14 03:27:54 +00:00
|
|
|
|
}
|
|
|
|
|
// check to make sure that the settings object has all of the appropriate boolbuttons
|
2013-07-24 01:38:52 +00:00
|
|
|
|
foreach (string button in ControllerButtons)
|
2013-07-14 03:27:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (!settings.Keys.Contains(button))
|
2013-07-24 01:38:52 +00:00
|
|
|
|
settings[button] = defaultvalue;
|
2013-07-14 03:27:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings.Keys.Count == 0)
|
|
|
|
|
return;
|
2013-07-14 01:48:05 +00:00
|
|
|
|
|
2013-07-14 03:27:54 +00:00
|
|
|
|
// 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
|
2013-07-24 01:38:52 +00:00
|
|
|
|
dest.Controls.Add(createpanel(settings, null, dest.Size));
|
2013-07-14 03:27:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// create multiple player tabs
|
2013-07-17 01:05:36 +00:00
|
|
|
|
var tt = new TabControl {Dock = DockStyle.Fill};
|
2013-07-14 03:27:54 +00:00
|
|
|
|
dest.Controls.Add(tt);
|
|
|
|
|
int pageidx = 0;
|
|
|
|
|
for (int i = 1; i <= MAXPLAYERS; i++)
|
|
|
|
|
{
|
|
|
|
|
if (buckets[i].Count > 0)
|
|
|
|
|
{
|
|
|
|
|
tt.TabPages.Add("Player " + i);
|
2013-07-24 01:38:52 +00:00
|
|
|
|
tt.TabPages[pageidx].Controls.Add(createpanel(settings, buckets[i], tt.Size));
|
2013-07-14 03:27:54 +00:00
|
|
|
|
pageidx++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (buckets[0].Count > 0)
|
|
|
|
|
{
|
|
|
|
|
tt.TabPages.Add("Console");
|
2013-07-24 01:38:52 +00:00
|
|
|
|
tt.TabPages[pageidx].Controls.Add(createpanel(settings, buckets[0], tt.Size));
|
2013-07-14 03:27:54 +00:00
|
|
|
|
pageidx++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 17:59:40 +00:00
|
|
|
|
private ControllerDefinition the_definition;
|
|
|
|
|
|
|
|
|
|
|
2013-07-14 01:48:05 +00:00
|
|
|
|
public NewControllerConfig(ControllerDefinition def)
|
|
|
|
|
: this()
|
|
|
|
|
{
|
2013-07-27 17:59:40 +00:00
|
|
|
|
the_definition = def;
|
2013-07-17 01:20:21 +00:00
|
|
|
|
ControllerType = def.Name;
|
2013-07-14 01:48:05 +00:00
|
|
|
|
SuspendLayout();
|
2013-07-27 17:59:40 +00:00
|
|
|
|
LoadPanels();
|
2013-07-14 01:48:05 +00:00
|
|
|
|
|
2013-07-14 20:38:23 +00:00
|
|
|
|
Text = def.Name + " Configuration";
|
2013-07-14 01:48:05 +00:00
|
|
|
|
checkBoxUDLR.Checked = Global.Config.AllowUD_LR;
|
|
|
|
|
checkBoxAutoTab.Checked = Global.Config.InputConfigAutoTab;
|
2013-07-14 02:21:41 +00:00
|
|
|
|
|
|
|
|
|
SetControllerPicture(def.Name);
|
2013-07-14 01:48:05 +00:00
|
|
|
|
ResumeLayout();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 17:59:40 +00:00
|
|
|
|
private void LoadPanels()
|
|
|
|
|
{
|
|
|
|
|
LoadToPanel(tabPage1, the_definition.Name, the_definition.BoolButtons, Global.Config.AllTrollers, "", CreateNormalPanel);
|
|
|
|
|
LoadToPanel(tabPage2, the_definition.Name, the_definition.BoolButtons, Global.Config.AllTrollersAutoFire, "", CreateNormalPanel);
|
|
|
|
|
LoadToPanel(tabPage3, the_definition.Name, the_definition.FloatControls, Global.Config.AllTrollersAnalog, new Config.AnalogBind("", 1.0f), CreateAnalogPanel);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-14 02:21:41 +00:00
|
|
|
|
void SetControllerPicture(string ControlName)
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp;
|
|
|
|
|
if (!ControllerImages.TryGetValue(ControlName, out bmp))
|
|
|
|
|
bmp = Properties.Resources.Help;
|
|
|
|
|
|
|
|
|
|
pictureBox1.Image = bmp;
|
|
|
|
|
pictureBox1.Size = bmp.Size;
|
|
|
|
|
tableLayoutPanel1.ColumnStyles[1].Width = bmp.Width;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-14 03:27:54 +00:00
|
|
|
|
// 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);
|
2013-07-24 02:14:25 +00:00
|
|
|
|
else if (c is AnalogBindPanel)
|
|
|
|
|
;// TODO
|
2013-07-14 03:27:54 +00:00
|
|
|
|
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();
|
2013-07-24 02:14:25 +00:00
|
|
|
|
else if (c is AnalogBindPanel)
|
|
|
|
|
(c as AnalogBindPanel).Save();
|
2013-07-14 03:27:54 +00:00
|
|
|
|
else if (c.HasChildren)
|
|
|
|
|
foreach (Control cc in c.Controls)
|
|
|
|
|
Save(cc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-14 01:48:05 +00:00
|
|
|
|
private void checkBoxAutoTab_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-07-14 03:27:54 +00:00
|
|
|
|
SetAutoTab(this, checkBoxAutoTab.Checked);
|
2013-07-14 01:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBoxUDLR_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonOK_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Global.Config.AllowUD_LR = checkBoxUDLR.Checked;
|
|
|
|
|
Global.Config.InputConfigAutoTab = checkBoxAutoTab.Checked;
|
|
|
|
|
|
2013-07-14 03:27:54 +00:00
|
|
|
|
Save(this);
|
2013-07-14 01:48:05 +00:00
|
|
|
|
|
|
|
|
|
Global.OSD.AddMessage("Controller settings saved");
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Global.OSD.AddMessage("Controller config aborted");
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2013-07-14 20:38:23 +00:00
|
|
|
|
|
|
|
|
|
private void NewControllerConfig_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-17 01:20:21 +00:00
|
|
|
|
|
|
|
|
|
private static string ControlDefaultPath
|
|
|
|
|
{
|
|
|
|
|
get { return PathManager.MakeProgramRelativePath("defctrl.json"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonLoadDefaults_Click(object sender, EventArgs e)
|
2013-07-27 18:22:15 +00:00
|
|
|
|
{
|
|
|
|
|
RestoreDefaults();
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RestoreDefaults()
|
2013-07-17 01:20:21 +00:00
|
|
|
|
{
|
|
|
|
|
// this is not clever. i'm going to replace it with something more clever
|
|
|
|
|
|
2013-07-27 17:59:40 +00:00
|
|
|
|
ControlDefaults cd = new ControlDefaults();
|
|
|
|
|
cd = ConfigService.Load(ControlDefaultPath, cd);
|
|
|
|
|
Dictionary<string, string> settings;
|
|
|
|
|
Dictionary<string, Config.AnalogBind> asettings;
|
2013-07-27 18:22:15 +00:00
|
|
|
|
|
2013-07-27 17:59:40 +00:00
|
|
|
|
if (cd.AllTrollers.TryGetValue(ControllerType, out settings))
|
2013-07-17 01:20:21 +00:00
|
|
|
|
{
|
2013-07-27 17:59:40 +00:00
|
|
|
|
Global.Config.AllTrollers[ControllerType] = settings;
|
2013-07-17 01:20:21 +00:00
|
|
|
|
}
|
2013-07-27 17:59:40 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Global.Config.AllTrollers[ControllerType].Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cd.AllTrollersAutoFire.TryGetValue(ControllerType, out settings))
|
|
|
|
|
{
|
|
|
|
|
Global.Config.AllTrollersAutoFire[ControllerType] = settings;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Global.Config.AllTrollersAutoFire[ControllerType].Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cd.AllTrollersAnalog.TryGetValue(ControllerType, out asettings))
|
|
|
|
|
{
|
|
|
|
|
Global.Config.AllTrollersAnalog[ControllerType] = asettings;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Global.Config.AllTrollersAnalog[ControllerType].Clear();
|
|
|
|
|
}
|
2013-07-17 01:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>>();
|
2013-07-24 00:08:50 +00:00
|
|
|
|
public Dictionary<string, Dictionary<string, Config.AnalogBind>> AllTrollersAnalog = new Dictionary<string, Dictionary<string, Config.AnalogBind>>();
|
2013-07-17 01:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ConfigCheckAllControlDefaults(Config c)
|
|
|
|
|
{
|
2013-07-24 00:08:50 +00:00
|
|
|
|
if (c.AllTrollers.Count == 0 && c.AllTrollersAutoFire.Count == 0 && c.AllTrollersAnalog.Count == 0)
|
2013-07-17 01:20:21 +00:00
|
|
|
|
{
|
|
|
|
|
ControlDefaults cd = new ControlDefaults();
|
|
|
|
|
cd = ConfigService.Load(ControlDefaultPath, cd);
|
|
|
|
|
c.AllTrollers = cd.AllTrollers;
|
|
|
|
|
c.AllTrollersAutoFire = cd.AllTrollersAutoFire;
|
2013-07-24 00:08:50 +00:00
|
|
|
|
c.AllTrollersAnalog = cd.AllTrollersAnalog;
|
2013-07-17 01:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-14 01:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|