Skip to content

Commit

Permalink
FormBindingDendyController
Browse files Browse the repository at this point in the history
  • Loading branch information
ogamespec committed Aug 29, 2023
1 parent 8927ecc commit dc53b3b
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Breaknes/Breaknes/FormBindingDendyController.Designer.cs

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

144 changes: 144 additions & 0 deletions Breaknes/Breaknes/FormBindingDendyController.cs
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);
}
}
}
}
}

0 comments on commit dc53b3b

Please sign in to comment.