-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerOptions.cs
More file actions
101 lines (94 loc) · 4.4 KB
/
ControllerOptions.cs
File metadata and controls
101 lines (94 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using SlimDX.DirectInput;
namespace XOutput
{
public partial class ControllerOptions : Form
{
ControllerDevice dev;
public ControllerOptions(ControllerDevice device)
{
InitializeComponent();
dev = device;
int ind = 0;
//dev.keyboard.Acquire();
//KeyboardState kState = dev.keyboard.GetCurrentState();
//dev.keyboard.Unacquire();
foreach (MultiLevelComboBox m in this.Controls.OfType<MultiLevelComboBox>()) {
//Tag structure: [Type, Number, Index]
m.Items[0] = getBindingText(ind); //Change combobox text according to saved binding
m.addOption("Disabled", tag: new byte[] { 255, 0, (byte)ind });
ToolStripMenuItem axes = m.addMenu("Axes");
ToolStripMenuItem buttons = m.addMenu("Buttons");
//ToolStripMenuItem keys = m.addMenu("Keys");
ToolStripMenuItem dpads = m.addMenu("D-Pads");
ToolStripMenuItem iaxes = m.addMenu("Inverted Axes", axes);
ToolStripMenuItem haxes = m.addMenu("Half Axes", axes);
ToolStripMenuItem ihaxes = m.addMenu("Inverted Half Axes", axes);
for (int i = 1; i <= dev.joystick.Capabilities.ButtonCount; i++)
{
m.addOption("Button " + i.ToString(), buttons,
new byte[] { 0, (byte)(i - 1), (byte)ind });
}
/*for (int i = 0; i < kState.AllKeys.Count; i++)
{
m.addOption(kState.AllKeys[i].ToString(), keys,
new byte[] { 0, (byte)(i), (byte)ind });
}*/
for (int i = 1; i <= dev.joystick.Capabilities.PovCount; i++)
{
m.addOption("D-Pad " + i.ToString() + " Up", dpads,
new byte[] { 32, (byte)(i - 1), (byte)ind });
m.addOption("D-Pad " + i.ToString() + " Down", dpads,
new byte[] { 33, (byte)(i - 1), (byte)ind });
m.addOption("D-Pad " + i.ToString() + " Left", dpads,
new byte[] { 34, (byte)(i - 1), (byte)ind });
m.addOption("D-Pad " + i.ToString() + " Right", dpads,
new byte[] { 35, (byte)(i - 1), (byte)ind });
}
for (int i = 1; i <= dev.joystick.Capabilities.AxesCount; i++)
{
m.addOption("Axis " + i.ToString(), axes,
new byte[] { 16, (byte)(i - 1), (byte)ind });
m.addOption("IAxis " + i.ToString(), iaxes,
new byte[] { 17, (byte)(i - 1), (byte)ind });
m.addOption("HAxis" + i.ToString(), haxes,
new byte[] { 18, (byte)(i - 1), (byte)ind });
m.addOption("IHAxis" + i.ToString(), ihaxes,
new byte[] { 19, (byte)(i - 1), (byte)ind });
}
m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged);
ind++;
}
}
private string getBindingText(int i)
{
if (dev.mapping[i * 2] == 255) {
return "Disabled";
}
byte subType = (byte)(dev.mapping[i * 2] & 0x0F);
byte type = (byte)((dev.mapping[i * 2] & 0xF0) >> 4);
byte num = (byte)(dev.mapping[(i * 2) + 1] + 1);
string[] typeString = new string[] { "Button {0}", "{1}Axis {0}", "D-Pad {0} {2}" };
string[] axesString = new string[] { "", "I", "H", "IH" };
string[] dpadString = new string[] { "Up", "Down", "Left", "Right" };
return string.Format(typeString[type], num, axesString[subType], dpadString[subType]);
}
private void SelectionChanged(object sender, EventArgs e) {
ToolStripMenuItem i = (ToolStripMenuItem)sender;
byte[] b = (byte[])i.Tag;
if (b[0] == 254) {
//start thread
return;
}
dev.mapping[b[2] * 2] = b[0];
dev.mapping[(b[2] * 2) + 1] = b[1];
dev.Save();
}
private void onClose(object sender, EventArgs e) {
dev.Save();
}
}
}