forked from emu-russia/breaknes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,158 @@ | ||
| ||
using SharpTools; | ||
|
||
namespace Breaknes | ||
{ | ||
public partial class FormBindingDendyController : Form | ||
{ | ||
IOConfigDevice this_device; | ||
IOProcessor io; | ||
|
||
public FormBindingDendyController(IOConfigDevice device, IOProcessor io) | ||
{ | ||
InitializeComponent(); | ||
this.io = io; | ||
this_device = device; | ||
} | ||
|
||
private void FormBindingDendyController_Load(object sender, EventArgs e) | ||
{ | ||
PopulateActuatorsList(); | ||
listView2.Clear(); | ||
} | ||
|
||
private void PopulateActuatorsList() | ||
{ | ||
listView1.Clear(); | ||
|
||
int handle = BreaksCore.IOCreateInstance(0x00000004); | ||
if (handle >= 0) | ||
{ | ||
int num_actuators = BreaksCore.IOGetNumStates(handle); | ||
|
||
for (int i = 0; i < num_actuators; i++) | ||
{ | ||
char[] actuator_name = new char[0x100]; | ||
|
||
BreaksCore.IOGetStateName(handle, i, actuator_name, actuator_name.Length); | ||
|
||
ListViewItem item = new ListViewItem(new string(actuator_name)); | ||
item.Tag = i; // Actuator ID | ||
|
||
listView1.Items.Add(item); | ||
} | ||
|
||
BreaksCore.IODisposeInstance(handle); | ||
} | ||
} | ||
|
||
// Clear all | ||
private void button1_Click(object sender, EventArgs e) | ||
{ | ||
this_device.bindings = Array.Empty<IOConfigBinding>(); | ||
} | ||
|
||
// Add binding | ||
private void button2_Click(object sender, EventArgs e) | ||
{ | ||
if (listView1.SelectedItems.Count != 0) | ||
{ | ||
var item = listView1.SelectedItems[0]; | ||
int actuator_id = (int)item.Tag; | ||
|
||
FormWaitInputEvent wait_input = new FormWaitInputEvent(actuator_id, io); | ||
wait_input.FormClosed += Wait_input_FormClosed; | ||
wait_input.ShowDialog(); | ||
} | ||
} | ||
|
||
private void AssignBinding(int actuator_id, string bindstr) | ||
{ | ||
bool found = false; | ||
|
||
for (int i = 0; i < this_device.bindings.Length; i++) | ||
{ | ||
if (this_device.bindings[i].actuator_id == actuator_id) | ||
{ | ||
this_device.bindings[i].binding = bindstr; | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found) | ||
{ | ||
List<IOConfigBinding> list = this_device.bindings.ToList(); | ||
IOConfigBinding new_binding = new(); | ||
new_binding.actuator_id = actuator_id; | ||
new_binding.binding = bindstr; | ||
list.Add(new_binding); | ||
this_device.bindings = list.ToArray(); | ||
} | ||
|
||
ShowBindings(actuator_id); | ||
} | ||
|
||
private void Wait_input_FormClosed(object? sender, FormClosedEventArgs e) | ||
{ | ||
FormWaitInputEvent wait_input = (FormWaitInputEvent)sender; | ||
if (wait_input.bindstr != null) | ||
{ | ||
AssignBinding(wait_input.saved_actuator_id, wait_input.bindstr); | ||
} | ||
} | ||
|
||
// Clear binding | ||
private void button3_Click(object sender, EventArgs e) | ||
{ | ||
if (listView1.SelectedItems.Count != 0) | ||
{ | ||
var item = listView1.SelectedItems[0]; | ||
int actuator_id = (int)item.Tag; | ||
|
||
List<IOConfigBinding> list = new(); | ||
for (int i = 0; i < this_device.bindings.Length; i++) | ||
{ | ||
if (this_device.bindings[i].actuator_id != actuator_id) | ||
{ | ||
list.Add(this_device.bindings[i]); | ||
} | ||
} | ||
this_device.bindings = list.ToArray(); | ||
|
||
ShowBindings(actuator_id); | ||
} | ||
} | ||
|
||
// Save | ||
private void button4_Click(object sender, EventArgs e) | ||
{ | ||
Close(); | ||
} | ||
|
||
private void listView1_Click(object sender, EventArgs e) | ||
{ | ||
if (listView1.SelectedItems.Count != 0) | ||
{ | ||
var item = listView1.SelectedItems[0]; | ||
ShowBindings((int)item.Tag); | ||
} | ||
else | ||
{ | ||
listView2.Clear(); | ||
} | ||
} | ||
|
||
private void ShowBindings(int actuator_id) | ||
{ | ||
listView2.Clear(); | ||
for (int i = 0; i < this_device.bindings.Length; i++) | ||
{ | ||
if (this_device.bindings[i].actuator_id == actuator_id) | ||
{ | ||
listView2.Items.Add(this_device.bindings[i].binding); | ||
} | ||
} | ||
} | ||
} | ||
} |