2015-07-10 21:07:24 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms.Config
|
|
|
|
|
{
|
|
|
|
|
public partial class frmInputConfig : BaseConfigForm
|
|
|
|
|
{
|
|
|
|
|
public frmInputConfig()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2017-02-25 15:15:44 -05:00
|
|
|
|
tlpControllers.Enabled = !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording();
|
|
|
|
|
|
2016-07-16 16:25:57 -04:00
|
|
|
|
InteropEmu.UpdateInputDevices();
|
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
Entity = ConfigManager.Config.InputInfo;
|
|
|
|
|
|
2017-02-25 14:20:30 -05:00
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
|
ConfigManager.Config.InputInfo.Controllers[i].ControllerType = InteropEmu.GetControllerType(i);
|
2016-07-09 15:58:49 -04:00
|
|
|
|
}
|
2017-02-25 14:20:30 -05:00
|
|
|
|
ConfigManager.Config.InputInfo.ExpansionPortDevice = InteropEmu.GetExpansionDevice();
|
|
|
|
|
ConfigManager.Config.InputInfo.ConsoleType = InteropEmu.GetConsoleType();
|
|
|
|
|
ConfigManager.Config.InputInfo.UseFourScore = InteropEmu.HasFourScore();
|
2016-07-09 15:58:49 -04:00
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
|
AddBinding("ExpansionPortDevice", cboExpansionPort);
|
|
|
|
|
AddBinding("ConsoleType", cboConsoleType);
|
|
|
|
|
AddBinding("UseFourScore", chkFourScore);
|
2016-07-09 15:58:49 -04:00
|
|
|
|
AddBinding("AutoConfigureInput", chkAutoConfigureInput);
|
2016-07-19 16:30:18 -04:00
|
|
|
|
|
|
|
|
|
AddBinding("DisplayInputPort1", chkDisplayPort1);
|
|
|
|
|
AddBinding("DisplayInputPort2", chkDisplayPort2);
|
|
|
|
|
AddBinding("DisplayInputPort3", chkDisplayPort3);
|
|
|
|
|
AddBinding("DisplayInputPort4", chkDisplayPort4);
|
|
|
|
|
AddBinding("DisplayInputPosition", cboDisplayInputPosition);
|
|
|
|
|
AddBinding("DisplayInputHorizontally", chkDisplayInputHorizontally);
|
2017-05-02 23:16:26 -04:00
|
|
|
|
|
|
|
|
|
UpdateConflictWarning();
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
2017-02-25 14:20:30 -05:00
|
|
|
|
|
|
|
|
|
protected override void OnFormClosed(FormClosedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnFormClosed(e);
|
|
|
|
|
InputInfo.ApplyConfig();
|
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
|
|
protected override void AfterUpdateUI()
|
|
|
|
|
{
|
|
|
|
|
base.AfterUpdateUI();
|
|
|
|
|
|
|
|
|
|
this.UpdateInterface();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAvailableControllerTypes()
|
|
|
|
|
{
|
|
|
|
|
bool isNes = ((InputInfo)Entity).ConsoleType == ConsoleType.Nes;
|
|
|
|
|
bool p3and4visible = (isNes && chkFourScore.Checked) || (!isNes && ((InputInfo)Entity).ExpansionPortDevice == InteropEmu.ExpansionPortDevice.FourPlayerAdapter);
|
|
|
|
|
|
|
|
|
|
List<InteropEmu.ControllerType> controllerTypes = new List<InteropEmu.ControllerType>(new InteropEmu.ControllerType[] { InteropEmu.ControllerType.StandardController });
|
2017-02-25 10:56:38 -05:00
|
|
|
|
SetAvailableControllerTypes(cboPlayer3, controllerTypes.ToArray(), false);
|
|
|
|
|
SetAvailableControllerTypes(cboPlayer4, controllerTypes.ToArray(), false);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
|
|
if(isNes && !chkFourScore.Checked) {
|
|
|
|
|
controllerTypes.Add(InteropEmu.ControllerType.Zapper);
|
2016-02-14 12:58:35 -05:00
|
|
|
|
controllerTypes.Add(InteropEmu.ControllerType.ArkanoidController);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
2017-02-25 10:56:38 -05:00
|
|
|
|
|
|
|
|
|
bool isOriginalFamicom = !isNes && !ConfigManager.Config.EmulationInfo.UseNes101Hvc101Behavior;
|
|
|
|
|
|
|
|
|
|
SetAvailableControllerTypes(cboPlayer1, controllerTypes.ToArray(), isOriginalFamicom);
|
|
|
|
|
SetAvailableControllerTypes(cboPlayer2, controllerTypes.ToArray(), isOriginalFamicom);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-25 10:56:38 -05:00
|
|
|
|
private void SetAvailableControllerTypes(ComboBox comboBox, InteropEmu.ControllerType[] controllerTypes, bool forceController)
|
2016-02-05 23:14:27 -05:00
|
|
|
|
{
|
|
|
|
|
object currentSelection = comboBox.SelectedItem;
|
|
|
|
|
comboBox.Items.Clear();
|
2017-02-25 10:56:38 -05:00
|
|
|
|
if(!forceController) {
|
|
|
|
|
comboBox.Items.Add(ResourceHelper.GetEnumText(InteropEmu.ControllerType.None));
|
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
foreach(InteropEmu.ControllerType type in controllerTypes) {
|
2016-02-19 13:05:04 -05:00
|
|
|
|
comboBox.Items.Add(ResourceHelper.GetEnumText(type));
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comboBox.SelectedItem = currentSelection;
|
|
|
|
|
if(comboBox.SelectedIndex < 0) {
|
|
|
|
|
comboBox.SelectedIndex = 0;
|
|
|
|
|
}
|
2015-07-10 21:07:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateConfig()
|
|
|
|
|
{
|
2016-02-05 23:14:27 -05:00
|
|
|
|
InputInfo inputInfo = (InputInfo)Entity;
|
|
|
|
|
|
2016-05-22 19:29:51 -04:00
|
|
|
|
inputInfo.Controllers[0].ControllerType = cboPlayer1.GetEnumValue<InteropEmu.ControllerType>();
|
|
|
|
|
inputInfo.Controllers[1].ControllerType = cboPlayer2.GetEnumValue<InteropEmu.ControllerType>();
|
|
|
|
|
inputInfo.Controllers[2].ControllerType = cboPlayer3.GetEnumValue<InteropEmu.ControllerType>();
|
|
|
|
|
inputInfo.Controllers[3].ControllerType = cboPlayer4.GetEnumValue<InteropEmu.ControllerType>();
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateInterface()
|
|
|
|
|
{
|
|
|
|
|
if(!this.Updating) {
|
|
|
|
|
bool isNes = ((InputInfo)Entity).ConsoleType == ConsoleType.Nes;
|
|
|
|
|
cboExpansionPort.Visible = !isNes;
|
|
|
|
|
lblExpansionPort.Visible = !isNes;
|
2017-08-12 11:54:05 -04:00
|
|
|
|
btnSetupExp.Visible = !isNes;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
chkFourScore.Visible = isNes;
|
|
|
|
|
|
|
|
|
|
UpdatePlayer3And4Visibility();
|
|
|
|
|
UpdateAvailableControllerTypes();
|
2016-05-22 19:29:51 -04:00
|
|
|
|
|
|
|
|
|
cboPlayer1.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[0].ControllerType);
|
|
|
|
|
cboPlayer2.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[1].ControllerType);
|
|
|
|
|
cboPlayer3.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[2].ControllerType);
|
|
|
|
|
cboPlayer4.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[3].ControllerType);
|
2016-07-09 15:58:49 -04:00
|
|
|
|
|
|
|
|
|
if(ConfigManager.Config.PreferenceInfo.DisableGameDatabase) {
|
|
|
|
|
//This option requires the game DB to be active
|
|
|
|
|
chkAutoConfigureInput.Enabled = false;
|
|
|
|
|
chkAutoConfigureInput.Checked = false;
|
|
|
|
|
}
|
2017-05-02 23:16:26 -04:00
|
|
|
|
|
|
|
|
|
UpdateConflictWarning();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool FourScoreAttached
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
bool isNes = ((InputInfo)Entity).ConsoleType == ConsoleType.Nes;
|
|
|
|
|
return (isNes && chkFourScore.Checked) || (!isNes && ((InputInfo)Entity).ExpansionPortDevice == InteropEmu.ExpansionPortDevice.FourPlayerAdapter);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePlayer3And4Visibility()
|
|
|
|
|
{
|
2017-05-02 23:16:26 -04:00
|
|
|
|
bool visible = this.FourScoreAttached;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
|
|
lblPlayer3.Visible = visible;
|
|
|
|
|
lblPlayer4.Visible = visible;
|
|
|
|
|
cboPlayer3.Visible = visible;
|
|
|
|
|
cboPlayer4.Visible = visible;
|
|
|
|
|
btnSetupP3.Visible = visible;
|
|
|
|
|
btnSetupP4.Visible = visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cboNesType_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-02-25 14:20:30 -05:00
|
|
|
|
if(!this.Updating) {
|
|
|
|
|
UpdateObject();
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void chkFourScore_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-02-25 14:20:30 -05:00
|
|
|
|
if(!this.Updating) {
|
|
|
|
|
UpdateObject();
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cboExpansionPort_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-02-25 14:20:30 -05:00
|
|
|
|
if(!this.Updating) {
|
|
|
|
|
UpdateObject();
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
}
|
2017-07-30 19:22:01 -04:00
|
|
|
|
|
|
|
|
|
btnSetupExp.Enabled = cboExpansionPort.SelectedItem.Equals(ResourceHelper.GetEnumText(InteropEmu.ExpansionPortDevice.Zapper));
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cboPlayerController_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-07-30 19:22:01 -04:00
|
|
|
|
object selectedItem = ((ComboBox)sender).SelectedItem;
|
|
|
|
|
|
|
|
|
|
bool enableButton = selectedItem.Equals(ResourceHelper.GetEnumText(InteropEmu.ControllerType.StandardController)) ||
|
|
|
|
|
selectedItem.Equals(ResourceHelper.GetEnumText(InteropEmu.ControllerType.Zapper));
|
2016-02-05 23:14:27 -05:00
|
|
|
|
if(sender == cboPlayer1) {
|
|
|
|
|
btnSetupP1.Enabled = enableButton;
|
|
|
|
|
} else if(sender == cboPlayer2) {
|
|
|
|
|
btnSetupP2.Enabled = enableButton;
|
|
|
|
|
} else if(sender == cboPlayer3) {
|
|
|
|
|
btnSetupP3.Enabled = enableButton;
|
|
|
|
|
} else if(sender == cboPlayer4) {
|
|
|
|
|
btnSetupP4.Enabled = enableButton;
|
|
|
|
|
}
|
2017-05-02 23:16:26 -04:00
|
|
|
|
UpdateConflictWarning();
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnSetup_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
2017-07-30 19:22:01 -04:00
|
|
|
|
object selectedItem = null;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
if(sender == btnSetupP1) {
|
2017-07-30 19:22:01 -04:00
|
|
|
|
selectedItem = cboPlayer1.SelectedItem;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
index = 0;
|
|
|
|
|
} else if(sender == btnSetupP2) {
|
2017-07-30 19:22:01 -04:00
|
|
|
|
selectedItem = cboPlayer2.SelectedItem;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
index = 1;
|
|
|
|
|
} else if(sender == btnSetupP3) {
|
2017-07-30 19:22:01 -04:00
|
|
|
|
selectedItem = cboPlayer3.SelectedItem;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
index = 2;
|
|
|
|
|
} else if(sender == btnSetupP4) {
|
2017-07-30 19:22:01 -04:00
|
|
|
|
selectedItem = cboPlayer4.SelectedItem;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
index = 3;
|
2017-07-30 19:22:01 -04:00
|
|
|
|
} else if(sender == btnSetupExp) {
|
|
|
|
|
selectedItem = cboExpansionPort.SelectedItem;
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Form frm = null;
|
|
|
|
|
if(selectedItem.Equals(ResourceHelper.GetEnumText(InteropEmu.ControllerType.StandardController))) {
|
2017-08-12 11:54:05 -04:00
|
|
|
|
frm = new frmControllerConfig(ConfigManager.Config.InputInfo.Controllers[index], index, cboConsoleType.GetEnumValue<ConsoleType>());
|
2017-07-30 19:22:01 -04:00
|
|
|
|
} else if(selectedItem.Equals(ResourceHelper.GetEnumText(InteropEmu.ControllerType.Zapper))) {
|
|
|
|
|
frm = new frmZapperConfig(ConfigManager.Config.InputInfo.Zapper);
|
|
|
|
|
} else if(selectedItem.Equals(ResourceHelper.GetEnumText(InteropEmu.ExpansionPortDevice.Zapper))) {
|
|
|
|
|
frm = new frmZapperConfig(ConfigManager.Config.InputInfo.Zapper);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 19:22:01 -04:00
|
|
|
|
if(frm != null) {
|
2017-05-02 23:16:26 -04:00
|
|
|
|
Button btn = (Button)sender;
|
|
|
|
|
Point point = btn.PointToScreen(new Point(0, btn.Height));
|
|
|
|
|
Rectangle screen = Screen.FromControl(btn).Bounds;
|
|
|
|
|
|
|
|
|
|
if(frm.Height + point.Y > screen.Bottom) {
|
|
|
|
|
//Show on top instead
|
|
|
|
|
point.Y -= btn.Height + frm.Height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(frm.Width + point.X > screen.Right) {
|
|
|
|
|
//Show on left instead
|
|
|
|
|
point.X -= frm.Width - btn.Width;
|
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2017-05-02 23:16:26 -04:00
|
|
|
|
frm.StartPosition = FormStartPosition.Manual;
|
|
|
|
|
frm.Top = point.Y;
|
|
|
|
|
frm.Left = point.X;
|
|
|
|
|
if(frm.ShowDialog(this) == DialogResult.OK) {
|
|
|
|
|
UpdateConflictWarning();
|
|
|
|
|
}
|
2017-07-30 19:22:01 -04:00
|
|
|
|
frm.Dispose();
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
2017-05-02 23:16:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateConflictWarning()
|
|
|
|
|
{
|
|
|
|
|
bool needWarning = false;
|
|
|
|
|
bool[] portConflicts = new bool[4];
|
|
|
|
|
Dictionary<uint, int> mappedKeys = new Dictionary<uint, int>();
|
|
|
|
|
Action<int, uint> countMapping = (int port, uint keyCode) => {
|
|
|
|
|
if(keyCode > 0) {
|
|
|
|
|
if(mappedKeys.ContainsKey(keyCode)) {
|
|
|
|
|
needWarning = true;
|
|
|
|
|
portConflicts[port] = true;
|
|
|
|
|
portConflicts[mappedKeys[keyCode]] = true;
|
|
|
|
|
} else {
|
|
|
|
|
mappedKeys.Add(keyCode, port);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2017-05-02 23:16:26 -04:00
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
|
if(i < 2 || this.FourScoreAttached && ((i == 2 && btnSetupP3.Enabled) || (i == 3 && btnSetupP4.Enabled))) {
|
|
|
|
|
foreach(KeyMappings mappings in ConfigManager.Config.InputInfo.Controllers[i].Keys) {
|
|
|
|
|
countMapping(i, mappings.A);
|
|
|
|
|
countMapping(i, mappings.B);
|
|
|
|
|
countMapping(i, mappings.Select);
|
|
|
|
|
countMapping(i, mappings.Start);
|
|
|
|
|
countMapping(i, mappings.TurboA);
|
|
|
|
|
countMapping(i, mappings.TurboB);
|
|
|
|
|
countMapping(i, mappings.TurboSelect);
|
|
|
|
|
countMapping(i, mappings.TurboStart);
|
|
|
|
|
countMapping(i, mappings.Up);
|
|
|
|
|
countMapping(i, mappings.Down);
|
|
|
|
|
countMapping(i, mappings.Left);
|
|
|
|
|
countMapping(i, mappings.Right);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
2015-07-10 21:07:24 -04:00
|
|
|
|
|
2017-05-02 23:16:26 -04:00
|
|
|
|
pnlConflictWarning.Visible = needWarning;
|
|
|
|
|
btnSetupP1.Image = portConflicts[0] ? Properties.Resources.Warning : null;
|
|
|
|
|
btnSetupP2.Image = portConflicts[1] ? Properties.Resources.Warning : null;
|
|
|
|
|
btnSetupP3.Image = portConflicts[2] ? Properties.Resources.Warning : null;
|
|
|
|
|
btnSetupP4.Image = portConflicts[3] ? Properties.Resources.Warning : null;
|
|
|
|
|
|
|
|
|
|
this.Height = needWarning ? 360 : 310;
|
2015-07-10 21:07:24 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|