/trunk/WingMan/WingManForm.Designer.cs |
@@ -17,22 +17,22 @@ |
{ |
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WingManForm)); |
this.groupBox1 = new System.Windows.Forms.GroupBox(); |
this.WingBindingsComboBox = new System.Windows.Forms.ComboBox(); |
this.RemoteBindingsComboBox = new System.Windows.Forms.ComboBox(); |
this.button2 = new System.Windows.Forms.Button(); |
this.button1 = new System.Windows.Forms.Button(); |
this.label1 = new System.Windows.Forms.Label(); |
this.WingBindingsBindToBox = new System.Windows.Forms.TextBox(); |
this.WingBindingsListBox = new System.Windows.Forms.ListBox(); |
this.RemoteBindingsBindToBox = new System.Windows.Forms.TextBox(); |
this.RemoteBindingsListBox = new System.Windows.Forms.ListBox(); |
this.groupBox2 = new System.Windows.Forms.GroupBox(); |
this.button5 = new System.Windows.Forms.Button(); |
this.LobbySayTextBox = new System.Windows.Forms.TextBox(); |
this.LobbyTextBox = new System.Windows.Forms.TextBox(); |
this.groupBox3 = new System.Windows.Forms.GroupBox(); |
this.HelmBindingsListBox = new System.Windows.Forms.ListBox(); |
this.LocalBindingsListBox = new System.Windows.Forms.ListBox(); |
this.button3 = new System.Windows.Forms.Button(); |
this.HelmAddButton = new System.Windows.Forms.Button(); |
this.label2 = new System.Windows.Forms.Label(); |
this.HelmNameTextBox = new System.Windows.Forms.TextBox(); |
this.LocalNameTextBox = new System.Windows.Forms.TextBox(); |
this.groupBox4 = new System.Windows.Forms.GroupBox(); |
this.label6 = new System.Windows.Forms.Label(); |
this.Password = new System.Windows.Forms.TextBox(); |
@@ -73,27 +73,27 @@ |
// |
// groupBox1 |
// |
this.groupBox1.Controls.Add(this.WingBindingsComboBox); |
this.groupBox1.Controls.Add(this.RemoteBindingsComboBox); |
this.groupBox1.Controls.Add(this.button2); |
this.groupBox1.Controls.Add(this.button1); |
this.groupBox1.Controls.Add(this.label1); |
this.groupBox1.Controls.Add(this.WingBindingsBindToBox); |
this.groupBox1.Controls.Add(this.WingBindingsListBox); |
this.groupBox1.Controls.Add(this.RemoteBindingsBindToBox); |
this.groupBox1.Controls.Add(this.RemoteBindingsListBox); |
this.groupBox1.Location = new System.Drawing.Point(8, 10); |
this.groupBox1.Name = "groupBox1"; |
this.groupBox1.Size = new System.Drawing.Size(248, 296); |
this.groupBox1.TabIndex = 0; |
this.groupBox1.TabStop = false; |
this.groupBox1.Text = "Wing (Them)"; |
this.groupBox1.Text = "Remote (Them)"; |
// |
// WingBindingsComboBox |
// RemoteBindingsComboBox |
// |
this.WingBindingsComboBox.FormattingEnabled = true; |
this.WingBindingsComboBox.Location = new System.Drawing.Point(8, 24); |
this.WingBindingsComboBox.Name = "WingBindingsComboBox"; |
this.WingBindingsComboBox.Size = new System.Drawing.Size(232, 21); |
this.WingBindingsComboBox.TabIndex = 5; |
this.WingBindingsComboBox.SelectionChangeCommitted += new System.EventHandler(this.WingBindingsComboBoxSelectionChangeCompleted); |
this.RemoteBindingsComboBox.FormattingEnabled = true; |
this.RemoteBindingsComboBox.Location = new System.Drawing.Point(8, 24); |
this.RemoteBindingsComboBox.Name = "RemoteBindingsComboBox"; |
this.RemoteBindingsComboBox.Size = new System.Drawing.Size(232, 21); |
this.RemoteBindingsComboBox.TabIndex = 5; |
this.RemoteBindingsComboBox.SelectionChangeCommitted += new System.EventHandler(this.RemoteBindingsComboBoxSelectionChangeCompleted); |
// |
// button2 |
// |
@@ -114,7 +114,7 @@ |
this.button1.TabIndex = 3; |
this.button1.Text = "Bind"; |
this.button1.UseVisualStyleBackColor = true; |
this.button1.Click += new System.EventHandler(this.WingBindingsBindButtonClicked); |
this.button1.Click += new System.EventHandler(this.RemoteBindingsBindButtonClicked); |
// |
// label1 |
// |
@@ -125,23 +125,23 @@ |
this.label1.TabIndex = 2; |
this.label1.Text = "Bound To"; |
// |
// WingBindingsBindToBox |
// RemoteBindingsBindToBox |
// |
this.WingBindingsBindToBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.WingBindingsBindToBox.Location = new System.Drawing.Point(72, 232); |
this.WingBindingsBindToBox.Name = "WingBindingsBindToBox"; |
this.WingBindingsBindToBox.ReadOnly = true; |
this.WingBindingsBindToBox.Size = new System.Drawing.Size(168, 20); |
this.WingBindingsBindToBox.TabIndex = 1; |
this.RemoteBindingsBindToBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.RemoteBindingsBindToBox.Location = new System.Drawing.Point(72, 232); |
this.RemoteBindingsBindToBox.Name = "RemoteBindingsBindToBox"; |
this.RemoteBindingsBindToBox.ReadOnly = true; |
this.RemoteBindingsBindToBox.Size = new System.Drawing.Size(168, 20); |
this.RemoteBindingsBindToBox.TabIndex = 1; |
// |
// WingBindingsListBox |
// RemoteBindingsListBox |
// |
this.WingBindingsListBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.WingBindingsListBox.FormattingEnabled = true; |
this.WingBindingsListBox.Location = new System.Drawing.Point(8, 56); |
this.WingBindingsListBox.Name = "WingBindingsListBox"; |
this.WingBindingsListBox.Size = new System.Drawing.Size(232, 158); |
this.WingBindingsListBox.TabIndex = 0; |
this.RemoteBindingsListBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.RemoteBindingsListBox.FormattingEnabled = true; |
this.RemoteBindingsListBox.Location = new System.Drawing.Point(8, 56); |
this.RemoteBindingsListBox.Name = "RemoteBindingsListBox"; |
this.RemoteBindingsListBox.Size = new System.Drawing.Size(232, 158); |
this.RemoteBindingsListBox.TabIndex = 0; |
// |
// groupBox2 |
// |
@@ -187,26 +187,26 @@ |
// |
// groupBox3 |
// |
this.groupBox3.Controls.Add(this.HelmBindingsListBox); |
this.groupBox3.Controls.Add(this.LocalBindingsListBox); |
this.groupBox3.Controls.Add(this.button3); |
this.groupBox3.Controls.Add(this.HelmAddButton); |
this.groupBox3.Controls.Add(this.label2); |
this.groupBox3.Controls.Add(this.HelmNameTextBox); |
this.groupBox3.Controls.Add(this.LocalNameTextBox); |
this.groupBox3.Location = new System.Drawing.Point(272, 8); |
this.groupBox3.Name = "groupBox3"; |
this.groupBox3.Size = new System.Drawing.Size(248, 296); |
this.groupBox3.TabIndex = 2; |
this.groupBox3.TabStop = false; |
this.groupBox3.Text = "Helm (You)"; |
this.groupBox3.Text = "Local (You)"; |
// |
// HelmBindingsListBox |
// LocalBindingsListBox |
// |
this.HelmBindingsListBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.HelmBindingsListBox.FormattingEnabled = true; |
this.HelmBindingsListBox.Location = new System.Drawing.Point(8, 16); |
this.HelmBindingsListBox.Name = "HelmBindingsListBox"; |
this.HelmBindingsListBox.Size = new System.Drawing.Size(232, 197); |
this.HelmBindingsListBox.TabIndex = 7; |
this.LocalBindingsListBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.LocalBindingsListBox.FormattingEnabled = true; |
this.LocalBindingsListBox.Location = new System.Drawing.Point(8, 16); |
this.LocalBindingsListBox.Name = "LocalBindingsListBox"; |
this.LocalBindingsListBox.Size = new System.Drawing.Size(232, 197); |
this.LocalBindingsListBox.TabIndex = 7; |
// |
// button3 |
// |
@@ -239,14 +239,14 @@ |
this.label2.TabIndex = 4; |
this.label2.Text = "Name"; |
// |
// HelmNameTextBox |
// LocalNameTextBox |
// |
this.HelmNameTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.HelmNameTextBox.Location = new System.Drawing.Point(72, 232); |
this.HelmNameTextBox.Name = "HelmNameTextBox"; |
this.HelmNameTextBox.Size = new System.Drawing.Size(172, 20); |
this.HelmNameTextBox.TabIndex = 3; |
this.HelmNameTextBox.Click += new System.EventHandler(this.HelmNameTextBoxClick); |
this.LocalNameTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; |
this.LocalNameTextBox.Location = new System.Drawing.Point(72, 232); |
this.LocalNameTextBox.Name = "LocalNameTextBox"; |
this.LocalNameTextBox.Size = new System.Drawing.Size(172, 20); |
this.LocalNameTextBox.TabIndex = 3; |
this.LocalNameTextBox.Click += new System.EventHandler(this.HelmNameTextBoxClick); |
// |
// groupBox4 |
// |
@@ -504,6 +504,7 @@ |
this.Name = "WingManForm"; |
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; |
this.Text = "WingMan © 2018 Wizardry and Steamworks"; |
this.Load += new System.EventHandler(this.WingManFormOnLoad); |
this.groupBox1.ResumeLayout(false); |
this.groupBox1.PerformLayout(); |
this.groupBox2.ResumeLayout(false); |
@@ -534,13 +535,13 @@ |
private System.Windows.Forms.GroupBox groupBox1; |
private System.Windows.Forms.GroupBox groupBox2; |
private System.Windows.Forms.GroupBox groupBox3; |
private System.Windows.Forms.ListBox WingBindingsListBox; |
private System.Windows.Forms.ListBox RemoteBindingsListBox; |
private System.Windows.Forms.Label label1; |
private System.Windows.Forms.TextBox WingBindingsBindToBox; |
private System.Windows.Forms.TextBox RemoteBindingsBindToBox; |
private System.Windows.Forms.TextBox LobbySayTextBox; |
public System.Windows.Forms.TextBox LobbyTextBox; |
private System.Windows.Forms.Label label2; |
private System.Windows.Forms.TextBox HelmNameTextBox; |
private System.Windows.Forms.TextBox LocalNameTextBox; |
private System.Windows.Forms.Button button2; |
private System.Windows.Forms.Button button1; |
private System.Windows.Forms.Button button3; |
@@ -555,7 +556,7 @@ |
private System.Windows.Forms.TextBox Address; |
private System.Windows.Forms.StatusStrip statusStrip; |
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel; |
private System.Windows.Forms.ComboBox WingBindingsComboBox; |
private System.Windows.Forms.ComboBox RemoteBindingsComboBox; |
private System.Windows.Forms.Label label5; |
private System.Windows.Forms.TextBox Nick; |
private System.Windows.Forms.TabControl tabControl1; |
@@ -566,7 +567,7 @@ |
private System.Windows.Forms.TabPage tabPage3; |
private System.Windows.Forms.PictureBox pictureBox1; |
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; |
private System.Windows.Forms.ListBox HelmBindingsListBox; |
private System.Windows.Forms.ListBox LocalBindingsListBox; |
private System.Windows.Forms.Panel OverlayPanel; |
private System.Windows.Forms.Label OverlayPanelLabel; |
private System.Windows.Forms.Label label6; |
/trunk/WingMan/WingManForm.cs |
@@ -1,6 +1,7 @@ |
using System; |
using System.Collections.Generic; |
using System.Drawing; |
using System.IO; |
using System.Linq; |
using System.Net; |
using System.Threading; |
@@ -7,6 +8,8 @@ |
using System.Threading.Tasks; |
using System.Windows.Forms; |
using Gma.System.MouseKeyHook; |
using MQTTnet.Extensions.ManagedClient; |
using MQTTnet.Server; |
using WingMan.Communication; |
using WingMan.Lobby; |
using WingMan.MouseKey; |
@@ -24,19 +27,27 @@ |
FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); |
FormCancellationTokenSource = new CancellationTokenSource(); |
|
MQTTCommunication = new MQTTCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); |
MQTTCommunication.OnClientAuthenticationFailed += OnMQTTClientAuthenticationFailed; |
MQTTCommunication.OnServerAuthenticationFailed += OnMQTTServerAuthenticationFailed; |
MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); |
MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed; |
MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed; |
MqttCommunication.OnClientDisconnected += OnMqttClientDisconnected; |
MqttCommunication.OnClientConnected += OnMqttClientConnected; |
MqttCommunication.OnServerAuthenticationFailed += OnMqttServerAuthenticationFailed; |
MqttCommunication.OnServerStopped += OnMqttServerStopped; |
MqttCommunication.OnServerStarted += OnMqttServerStarted; |
MqttCommunication.OnServerClientConnected += OnMqttServerClientConnected; |
MqttCommunication.OnServerClientDisconnected += OnMqttServerClientDisconnected; |
|
MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); |
LocalMouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); |
RemoteMouseKeyBindings = new RemoteMouseKeyBindings(new List<RemoteMouseKeyBinding>()); |
|
HelmListBoxBindingSource = new BindingSource |
LocalListBoxBindingSource = new BindingSource |
{ |
DataSource = MouseKeyBindings.Bindings |
DataSource = LocalMouseKeyBindings.Bindings |
}; |
HelmBindingsListBox.DisplayMember = "DisplayName"; |
HelmBindingsListBox.ValueMember = "Keys"; |
HelmBindingsListBox.DataSource = HelmListBoxBindingSource; |
LocalBindingsListBox.DisplayMember = "DisplayName"; |
LocalBindingsListBox.ValueMember = "Keys"; |
LocalBindingsListBox.DataSource = LocalListBoxBindingSource; |
|
MouseKeyBindingsExchange = new MouseKeyBindingsExchange |
{ |
@@ -43,23 +54,25 @@ |
ExchangeBindings = new List<MouseKeyBindingExchange>() |
}; |
|
WingBindingsComboBoxSource = new BindingSource |
RemoteBindingsComboBoxSource = new BindingSource |
{ |
DataSource = MouseKeyBindingsExchange.ExchangeBindings |
}; |
WingBindingsComboBox.DisplayMember = "Nick"; |
WingBindingsComboBox.ValueMember = "MouseKeyBindings"; |
WingBindingsComboBox.DataSource = WingBindingsComboBoxSource; |
RemoteBindingsComboBox.DisplayMember = "Nick"; |
RemoteBindingsComboBox.ValueMember = "MouseKeyBindings"; |
RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource; |
|
// Start lobby message synchronizer. |
LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MQTTCommunication, FormTaskScheduler, |
LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler, |
FormCancellationTokenSource.Token); |
LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived; |
|
// Start mouse key bindings synchronizer. |
MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(MouseKeyBindings, MQTTCommunication, |
MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(LocalMouseKeyBindings, MqttCommunication, |
FormTaskScheduler, FormCancellationTokenSource.Token); |
MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; |
|
// Start key binding simulator. |
} |
|
private static CancellationTokenSource FormCancellationTokenSource { get; set; } |
@@ -70,27 +83,94 @@ |
|
private List<string> MouseKeyCombo { get; set; } |
|
private MouseKeyBindings MouseKeyBindings { get; } |
private MouseKeyBindings LocalMouseKeyBindings { get; } |
|
private BindingSource HelmListBoxBindingSource { get; } |
private RemoteMouseKeyBindings RemoteMouseKeyBindings { get; } |
|
private BindingSource WingBindingsComboBoxSource { get; } |
private BindingSource LocalListBoxBindingSource { get; } |
|
private BindingSource RemoteBindingsComboBoxSource { get; } |
|
private MouseKeyBindingsExchange MouseKeyBindingsExchange { get; } |
|
public MQTTCommunication MQTTCommunication { get; set; } |
public MqttCommunication MqttCommunication { get; set; } |
|
public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; } |
|
public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; } |
|
private void OnMQTTServerAuthenticationFailed(object sender, EventArgs e) |
private async Task SaveLocalMouseKeyBindings() |
{ |
try |
{ |
using (var memoryStream = new MemoryStream()) |
{ |
MouseKeyBindings.XmlSerializer.Serialize(memoryStream, LocalMouseKeyBindings); |
|
memoryStream.Position = 0L; |
|
using (var fileStream = new FileStream("LocalMouseKeyBindings.xml", FileMode.Create)) |
{ |
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false); |
} |
} |
} |
catch (Exception) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_saving_local_bindings}{Environment.NewLine}"); |
} |
} |
|
private void OnMqttServerClientDisconnected(object sender, MqttClientDisconnectedEventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Client_disconnected}{Environment.NewLine}"); |
} |
|
private void OnMqttServerClientConnected(object sender, MqttClientConnectedEventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Client_connected}{Environment.NewLine}"); |
} |
|
private void OnMqttServerStarted(object sender, EventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Server_started}{Environment.NewLine}"); |
} |
|
private void OnMqttServerStopped(object sender, EventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Server_stopped}{Environment.NewLine}"); |
} |
|
private void OnMqttClientConnected(object sender, MQTTnet.Client.MqttClientConnectedEventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Client_connected}{Environment.NewLine}"); |
} |
|
private void OnMqttClientDisconnected(object sender, MQTTnet.Client.MqttClientDisconnectedEventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Client_disconnected}{Environment.NewLine}"); |
} |
|
private void OnMqttClientConnectionFailed(object sender, MqttManagedProcessFailedEventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Client_connection_failed}{Environment.NewLine}"); |
} |
|
private void OnMqttServerAuthenticationFailed(object sender, EventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_to_authenticate_client}{Environment.NewLine}"); |
} |
|
private void OnMQTTClientAuthenticationFailed(object sender, EventArgs e) |
private void OnMqttClientAuthenticationFailed(object sender, EventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Server_authentication_failed}{Environment.NewLine}"); |
@@ -125,8 +205,8 @@ |
if (exchangeBindings == null) |
{ |
MouseKeyBindingsExchange.ExchangeBindings.Add(e.Bindings); |
WingBindingsComboBoxSource.ResetBindings(false); |
UpdateWingListBoxItems(); |
RemoteBindingsComboBoxSource.ResetBindings(false); |
UpdateRemoteListBoxItems(); |
return; |
} |
|
@@ -133,39 +213,36 @@ |
// If the bindings for the nick have not changed then do not update. |
if (exchangeBindings.MouseKeyBindings.SequenceEqual(e.Bindings.MouseKeyBindings)) |
{ |
WingBindingsComboBoxSource.ResetBindings(false); |
UpdateWingListBoxItems(); |
RemoteBindingsComboBoxSource.ResetBindings(false); |
UpdateRemoteListBoxItems(); |
return; |
} |
|
// Update the bindings. |
exchangeBindings.MouseKeyBindings = e.Bindings.MouseKeyBindings; |
WingBindingsComboBoxSource.ResetBindings(false); |
UpdateWingListBoxItems(); |
RemoteBindingsComboBoxSource.ResetBindings(false); |
UpdateRemoteListBoxItems(); |
} |
|
private void UpdateWingListBoxItems() |
private void UpdateRemoteListBoxItems() |
{ |
var exchangeBinding = (List<MouseKeyBinding>) WingBindingsComboBox.SelectedValue; |
var exchangeBinding = (List<MouseKeyBinding>) RemoteBindingsComboBox.SelectedValue; |
if (exchangeBinding == null) |
return; |
|
WingBindingsListBox.Items.Clear(); |
WingBindingsListBox.DisplayMember = "Name"; |
WingBindingsListBox.ValueMember = "Name"; |
RemoteBindingsListBox.Items.Clear(); |
RemoteBindingsListBox.DisplayMember = "Name"; |
RemoteBindingsListBox.ValueMember = "Name"; |
var i = exchangeBinding.Select(binding => (object) binding.Name).ToArray(); |
if (i.Length == 0) |
return; |
|
WingBindingsListBox.Items.AddRange(i); |
RemoteBindingsListBox.Items.AddRange(i); |
} |
|
private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e) |
{ |
LobbyTextBox.Invoke((MethodInvoker) delegate |
{ |
LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}"); |
}); |
LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}"); |
} |
|
private void AddressTextBoxClick(object sender, EventArgs e) |
@@ -181,10 +258,9 @@ |
private async void HostButtonClickAsync(object sender, EventArgs e) |
{ |
// Stop the MQTT server if it is running. |
if (MQTTCommunication.Running) |
if (MqttCommunication.Running) |
{ |
await MQTTCommunication.Stop().ConfigureAwait(false); |
toolStripStatusLabel.Text = Strings.Server_stopped; |
await MqttCommunication.Stop().ConfigureAwait(false); |
HostButton.BackColor = Color.Empty; |
|
// Enable controls. |
@@ -200,9 +276,14 @@ |
return; |
|
// Start the MQTT server. |
await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick, password) |
.ConfigureAwait(false); |
toolStripStatusLabel.Text = Strings.Server_started; |
if (!await MqttCommunication.Start(MqttCommunicationType.Server, ipAddress, port, nick, password) |
.ConfigureAwait(false)) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_starting_server}{Environment.NewLine}"); |
return; |
} |
|
HostButton.BackColor = Color.Aquamarine; |
|
// Disable controls |
@@ -271,9 +352,9 @@ |
|
private async void ConnectButtonClickAsync(object sender, EventArgs e) |
{ |
if (MQTTCommunication.Running) |
if (MqttCommunication.Running) |
{ |
await MQTTCommunication.Stop().ConfigureAwait(false); |
await MqttCommunication.Stop().ConfigureAwait(false); |
ConnectButton.Text = Strings.Connect; |
ConnectButton.BackColor = Color.Empty; |
|
@@ -287,10 +368,14 @@ |
if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
return; |
|
await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick, password) |
.ConfigureAwait(false); |
if (!await MqttCommunication.Start(MqttCommunicationType.Client, ipAddress, port, nick, password) |
.ConfigureAwait(false)) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_starting_client}{Environment.NewLine}"); |
return; |
} |
|
toolStripStatusLabel.Text = Strings.Client_started; |
ConnectButton.Text = Strings.Disconnect; |
ConnectButton.BackColor = Color.Aquamarine; |
|
@@ -312,9 +397,9 @@ |
|
private void HelmAddButtonClick(object sender, EventArgs e) |
{ |
if (string.IsNullOrEmpty(HelmNameTextBox.Text)) |
if (string.IsNullOrEmpty(LocalNameTextBox.Text)) |
{ |
HelmNameTextBox.BackColor = Color.LightPink; |
LocalNameTextBox.BackColor = Color.LightPink; |
return; |
} |
|
@@ -323,10 +408,10 @@ |
MouseKeyCombo = new List<string>(); |
|
MouseKeyApplicationHook = Hook.AppEvents(); |
MouseKeyApplicationHook.MouseDown += MouseKeyHookOnMouseDown; |
MouseKeyApplicationHook.KeyUp += MouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown += MouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp; |
MouseKeyApplicationHook.MouseDown += LocalMouseKeyHookOnMouseDown; |
MouseKeyApplicationHook.KeyUp += LocalMouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown += LocalMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.MouseUp += LocalMouseKeyHookOnMouseUp; |
} |
|
private void ShowOverlayPanel() |
@@ -336,21 +421,23 @@ |
OverlayPanel.Invalidate(); |
} |
|
private void MouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
private async void LocalMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
{ |
MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); |
LocalMouseKeyBindings.Bindings.Add(new MouseKeyBinding(LocalNameTextBox.Text, MouseKeyCombo)); |
|
HelmListBoxBindingSource.ResetBindings(false); |
LocalListBoxBindingSource.ResetBindings(false); |
|
MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
|
MouseKeyApplicationHook.Dispose(); |
|
HelmNameTextBox.Text = string.Empty; |
LocalNameTextBox.Text = string.Empty; |
HideOverlayPanel(); |
|
await SaveLocalMouseKeyBindings().ConfigureAwait(false); |
} |
|
private void HideOverlayPanel() |
@@ -360,30 +447,32 @@ |
OverlayPanel.Invalidate(); |
} |
|
private void MouseKeyHookOnMouseUp(object sender, MouseEventArgs e) |
private async void LocalMouseKeyHookOnMouseUp(object sender, MouseEventArgs e) |
{ |
MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); |
LocalMouseKeyBindings.Bindings.Add(new MouseKeyBinding(LocalNameTextBox.Text, MouseKeyCombo)); |
|
HelmListBoxBindingSource.ResetBindings(false); |
LocalListBoxBindingSource.ResetBindings(false); |
|
MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
|
MouseKeyApplicationHook.Dispose(); |
|
HelmNameTextBox.Text = string.Empty; |
LocalNameTextBox.Text = string.Empty; |
HideOverlayPanel(); |
|
await SaveLocalMouseKeyBindings().ConfigureAwait(false); |
} |
|
|
private void MouseKeyHookOnMouseDown(object sender, MouseEventArgs e) |
private void LocalMouseKeyHookOnMouseDown(object sender, MouseEventArgs e) |
{ |
MouseKeyCombo.Add(e.Button.ToDisplayName()); |
} |
|
private void MouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
private void LocalMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
{ |
e.SuppressKeyPress = true; |
|
@@ -392,17 +481,19 @@ |
|
private void HelmNameTextBoxClick(object sender, EventArgs e) |
{ |
HelmNameTextBox.BackColor = Color.Empty; |
LocalNameTextBox.BackColor = Color.Empty; |
} |
|
private void HelmRemoveButtonClick(object sender, EventArgs e) |
private async void HelmRemoveButtonClick(object sender, EventArgs e) |
{ |
var helmBinding = (MouseKeyBinding) HelmBindingsListBox.SelectedItem; |
var helmBinding = (MouseKeyBinding) LocalBindingsListBox.SelectedItem; |
if (helmBinding == null) |
return; |
|
MouseKeyBindings.Bindings.Remove(helmBinding); |
HelmListBoxBindingSource.ResetBindings(false); |
LocalMouseKeyBindings.Bindings.Remove(helmBinding); |
LocalListBoxBindingSource.ResetBindings(false); |
|
await SaveLocalMouseKeyBindings().ConfigureAwait(false); |
} |
|
private async void LobbySayButtonClick(object sender, EventArgs e) |
@@ -412,13 +503,153 @@ |
LobbySayTextBox.Text = string.Empty; |
} |
|
private void WingBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) |
private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) |
{ |
UpdateWingListBoxItems(); |
UpdateRemoteListBoxItems(); |
} |
|
private void WingBindingsBindButtonClicked(object sender, EventArgs e) |
private async void WingManFormOnLoad(object sender, EventArgs e) |
{ |
await LoadLocalMouseKeyBindings(); |
await LoadRemoteMouseKeyBindings(); |
} |
|
private async Task LoadLocalMouseKeyBindings() |
{ |
try |
{ |
using (var fileStream = new FileStream("LocalMouseKeyBindings.xml", FileMode.Open)) |
{ |
using (var memoryStream = new MemoryStream()) |
{ |
await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false); |
|
memoryStream.Position = 0L; |
|
var loadedBindings = |
(MouseKeyBindings) MouseKeyBindings.XmlSerializer.Deserialize(memoryStream); |
|
foreach (var binding in loadedBindings.Bindings) LocalMouseKeyBindings.Bindings.Add(binding); |
|
LocalListBoxBindingSource.ResetBindings(false); |
} |
} |
} |
catch (Exception) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_loading_local_bindings}{Environment.NewLine}"); |
} |
} |
|
private void RemoteBindingsBindButtonClicked(object sender, EventArgs e) |
{ |
ShowOverlayPanel(); |
|
MouseKeyCombo = new List<string>(); |
|
MouseKeyApplicationHook = Hook.AppEvents(); |
MouseKeyApplicationHook.MouseDown += RemoteMouseKeyHookOnMouseDown; |
MouseKeyApplicationHook.KeyUp += RemoteMouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown += RemoteMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.MouseUp += RemoteMouseKeyHookOnMouseUp; |
} |
|
private void RemoteMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
{ |
e.SuppressKeyPress = true; |
|
MouseKeyCombo.Add(e.KeyCode.ToDisplayName()); |
} |
|
private void RemoteMouseKeyHookOnMouseDown(object sender, MouseEventArgs e) |
{ |
MouseKeyCombo.Add(e.Button.ToDisplayName()); |
} |
|
private async void RemoteMouseKeyHookOnMouseUp(object sender, MouseEventArgs e) |
{ |
RemoteMouseKeyBindings.Bindings.Add(new RemoteMouseKeyBinding(RemoteBindingsComboBox.Text, |
(string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); |
|
MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp; |
|
MouseKeyApplicationHook.Dispose(); |
|
RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo); |
HideOverlayPanel(); |
|
await SaveRemoteMouseKeyBindings().ConfigureAwait(false); |
} |
|
private async void RemoteMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
{ |
RemoteMouseKeyBindings.Bindings.Add(new RemoteMouseKeyBinding(RemoteBindingsComboBox.Text, |
(string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); |
|
MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp; |
MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown; |
MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp; |
|
MouseKeyApplicationHook.Dispose(); |
|
RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo); |
HideOverlayPanel(); |
|
await SaveRemoteMouseKeyBindings().ConfigureAwait(false); |
} |
|
private async Task SaveRemoteMouseKeyBindings() |
{ |
try |
{ |
using (var memoryStream = new MemoryStream()) |
{ |
RemoteMouseKeyBindings.XmlSerializer.Serialize(memoryStream, RemoteMouseKeyBindings); |
|
memoryStream.Position = 0L; |
|
using (var fileStream = new FileStream("RemoteMouseKeyBindings.xml", FileMode.Create)) |
{ |
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false); |
} |
} |
} |
catch (Exception) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_saving_remote_bindings}{Environment.NewLine}"); |
} |
} |
|
private async Task LoadRemoteMouseKeyBindings() |
{ |
try |
{ |
using (var fileStream = new FileStream("RemoteMouseKeyBindings.xml", FileMode.Open)) |
{ |
using (var memoryStream = new MemoryStream()) |
{ |
await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false); |
|
memoryStream.Position = 0L; |
|
var loadedBindings = |
(RemoteMouseKeyBindings) RemoteMouseKeyBindings.XmlSerializer.Deserialize(memoryStream); |
|
foreach (var binding in loadedBindings.Bindings) RemoteMouseKeyBindings.Bindings.Add(binding); |
} |
} |
} |
catch (Exception) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}"); |
} |
} |
} |
} |