From dc53b3baa6614a2354b2f31738fc854a6a7b498c Mon Sep 17 00:00:00 2001 From: org Date: Tue, 29 Aug 2023 12:40:27 +0300 Subject: [PATCH] FormBindingDendyController --- .../FormBindingDendyController.Designer.cs | 6 + .../Breaknes/FormBindingDendyController.cs | 144 ++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/Breaknes/Breaknes/FormBindingDendyController.Designer.cs b/Breaknes/Breaknes/FormBindingDendyController.Designer.cs index 49183c3..4897fa4 100644 --- a/Breaknes/Breaknes/FormBindingDendyController.Designer.cs +++ b/Breaknes/Breaknes/FormBindingDendyController.Designer.cs @@ -93,6 +93,7 @@ private void InitializeComponent() listView1.TabIndex = 0; listView1.UseCompatibleStateImageBehavior = false; listView1.View = View.List; + listView1.Click += listView1_Click; // // splitContainer1 // @@ -174,6 +175,7 @@ private void InitializeComponent() button4.TabIndex = 3; button4.Text = "Save"; button4.UseVisualStyleBackColor = true; + button4.Click += button4_Click; // // button3 // @@ -183,6 +185,7 @@ private void InitializeComponent() button3.TabIndex = 2; button3.Text = "Clear Binding"; button3.UseVisualStyleBackColor = true; + button3.Click += button3_Click; // // button2 // @@ -192,6 +195,7 @@ private void InitializeComponent() button2.TabIndex = 1; button2.Text = "Add Binding"; button2.UseVisualStyleBackColor = true; + button2.Click += button2_Click; // // button1 // @@ -201,6 +205,7 @@ private void InitializeComponent() button1.TabIndex = 0; button1.Text = "Clear all"; button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; // // FormBindingDendyController // @@ -210,6 +215,7 @@ private void InitializeComponent() Controls.Add(splitContainer1); Name = "FormBindingDendyController"; Text = "Dendy Controller Binding"; + Load += FormBindingDendyController_Load; tabControl1.ResumeLayout(false); tabPage1.ResumeLayout(false); splitContainer1.Panel1.ResumeLayout(false); diff --git a/Breaknes/Breaknes/FormBindingDendyController.cs b/Breaknes/Breaknes/FormBindingDendyController.cs index 7ba3203..da32255 100644 --- a/Breaknes/Breaknes/FormBindingDendyController.cs +++ b/Breaknes/Breaknes/FormBindingDendyController.cs @@ -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(); + } + + // 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 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 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); + } + } } } }