Skip to content

Commit

Permalink
Fixes some minor GUI bugs and adds more help text.
Browse files Browse the repository at this point in the history
  • Loading branch information
r1sc committed Jul 10, 2018
1 parent 705a186 commit 7023ace
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 52 deletions.
42 changes: 21 additions & 21 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 39 additions & 30 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ private void Change(int deviceId, int controlOrPitch, int value)
{
radioTypeButton.Checked = joystickControl.IsButton;
radioTypeAxis.Checked = !joystickControl.IsButton;
button1.Enabled = true;
btnUnmap.Enabled = true;
}
else
{
radioTypeAxis.Checked = radioTypeButton.Checked = false;
button1.Enabled = false;
btnUnmap.Enabled = false;
}
}
progessMidiData.Value = (value+1);
Expand Down Expand Up @@ -240,20 +240,28 @@ private void UpdateJoystick(JoystickControl joystickControl, int value)
}
}

private void radioTypeButton_CheckedChanged(object sender, EventArgs e)
private JoystickControl GetCurrentMapping()
{
var currentMapping = _joystickControls.SingleOrDefault(x => x.Mapping != null && (x.Mapping.DeviceId == _currentDeviceId && x.Mapping.ControlNumber == _currentControlId));
if (!radioTypeButton.Checked)
return;
var unmapped = _joystickControls.FirstOrDefault(x => x.IsButton && x.Mapping == null);

if (currentMapping == null || currentMapping.IsButton == false)
return currentMapping;
}

private void Map(bool button)
{
var currentMapping = GetCurrentMapping();
if (currentMapping == null || currentMapping.IsButton == !button)
{
if (currentMapping != null)
currentMapping.Mapping = null;

var unmapped = _joystickControls.FirstOrDefault(x => x.IsButton == button && x.Mapping == null);
if (unmapped == null)
{
MessageBox.Show("There are no unmapped buttons left. Unmap another button in order to map this control.");
string errorString = "There are no unmapped axes left. Unmap another axis in order to map this control.";
if (button)
errorString = "There are no unmapped buttons left. Unmap another button in order to map this control.";

MessageBox.Show(errorString);
}
else
{
Expand All @@ -262,35 +270,36 @@ private void radioTypeButton_CheckedChanged(object sender, EventArgs e)
ControlNumber = _currentControlId,
DeviceId = _currentDeviceId
};
btnUnmap.Enabled = true;
}
}

}

private void radioTypeButton_CheckedChanged(object sender, EventArgs e)
{
if (!radioTypeButton.Checked)
return;

Map(true);
}

private void btnUnmap_Click(object sender, EventArgs e)
{
var currentMapping = GetCurrentMapping();
if (currentMapping == null)
return;
currentMapping.Mapping = null;

radioTypeAxis.Checked = radioTypeButton.Checked = false;
btnUnmap.Enabled = false;
}

private void radioTypeAxis_CheckedChanged(object sender, EventArgs e)
{
var currentMapping = _joystickControls.SingleOrDefault(x => x.Mapping != null && (x.Mapping.DeviceId == _currentDeviceId && x.Mapping.ControlNumber == _currentControlId));
if (!radioTypeAxis.Checked)
return;
var unmapped = _joystickControls.FirstOrDefault(x => x.IsButton == false && x.Mapping == null);

if (currentMapping == null || currentMapping.IsButton)
{
if(currentMapping != null)
currentMapping.Mapping = null;
if (unmapped == null)
{
MessageBox.Show("There are no unmapped axes left. Unmap another axis in order to map this control.");
}
else
{
unmapped.Mapping = new Mapping
{
ControlNumber = _currentControlId,
DeviceId = _currentDeviceId
};
}
}

Map(false);
}
}

Expand Down
7 changes: 7 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="label1.Text" xml:space="preserve">
<value>Activate a MIDI controller to map it to a joystick function.

Simply press/twist a button or axis on your MIDI controller and choose wether it should map to a button or an axis on the virtual joystick.

vJoy MIDI Mapper must be running in order to preserve the mapping. The application will minimize to the system tray.</value>
</data>
<metadata name="notifyIcon1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion MidiFeeder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="vJoyInterfaceWrap">
<HintPath>..\..\Users\Erik\Desktop\SDK\c#\x86\vJoyInterfaceWrap.dll</HintPath>
<HintPath>C:\Program Files\vJoy\x86\vJoyInterfaceWrap.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 7023ace

Please sign in to comment.