/trunk/WingMan/WingManForm.cs |
@@ -24,7 +24,7 @@ |
{ |
public partial class WingManForm : Form |
{ |
private const int tabControlDetachPixelOffset = 20; |
private const int TabControlDetachPixelOffset = 20; |
|
public WingManForm() |
{ |
@@ -45,6 +45,7 @@ |
Task.Run(() => AutoCompletion.Load(Address.Name, Address.AutoCompleteCustomSource)); |
Task.Run(() => AutoCompletion.Load(Port.Name, Address.AutoCompleteCustomSource)); |
Task.Run(() => AutoCompletion.Load(Nick.Name, Nick.AutoCompleteCustomSource)); |
Task.Run(() => AutoCompletion.Load(LocalNameTextBox.Name, LocalNameTextBox.AutoCompleteCustomSource)); |
|
MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); |
MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed; |
@@ -65,6 +66,7 @@ |
DataSource = LocalKeyBindings.Bindings |
}; |
LocalCheckedListBoxBindingSource.ListChanged += LocalCheckedListBoxBindingSourceOnListChanged; |
|
LocalBindingsCheckedListBox.DisplayMember = "DisplayName"; |
LocalBindingsCheckedListBox.ValueMember = "Keys"; |
LocalBindingsCheckedListBox.DataSource = LocalCheckedListBoxBindingSource; |
@@ -78,10 +80,13 @@ |
{ |
DataSource = KeyBindingsExchange.ExchangeBindings |
}; |
RemoteBindingsComboBoxSource.ListChanged += RemoteBindingsComboBoxSourceOnListChanged; |
|
RemoteBindingsComboBox.DisplayMember = "Nick"; |
RemoteBindingsComboBox.ValueMember = "KeyBindings"; |
RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource; |
|
|
// Start lobby message synchronizer. |
LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler, |
FormCancellationTokenSource.Token); |
@@ -113,7 +118,7 @@ |
|
private List<string> MouseKeyCombo { get; set; } |
|
private LocalKeyBindings LocalKeyBindings { get; } |
public LocalKeyBindings LocalKeyBindings { get; set; } |
|
private RemoteKeyBindings RemoteKeyBindings { get; } |
|
@@ -133,19 +138,24 @@ |
|
public KeySimulator KeySimulator { get; set; } |
|
private static Point tabControlClickStartPosition { get; set; } |
private static Point TabControlClickStartPosition { get; set; } |
private static TabControl DetachedTabControl { get; set; } |
private static Form DetachedForm { get; set; } |
|
private void RemoteBindingsComboBoxSourceOnListChanged(object sender, ListChangedEventArgs e) |
{ |
UpdateRemoteBindingsListBox(); |
} |
|
public void OnDiscoveryPortMapFailed(object sender, DiscoveryFailedEventArgs args) |
{ |
switch (args.Type) |
{ |
case DiscoveryType.UPnP: |
case DiscoveryType.Upnp: |
ActivityTextBox.AppendText( |
$"{Strings.Failed_to_create_UPnP_port_mapping}{Environment.NewLine}"); |
break; |
case DiscoveryType.PMP: |
case DiscoveryType.Pmp: |
ActivityTextBox.AppendText( |
$"{Strings.Failed_to_create_PMP_port_mapping}{Environment.NewLine}"); |
break; |
@@ -281,47 +291,36 @@ |
{ |
KeyBindingsExchange.ExchangeBindings.Add(e.Bindings); |
RemoteBindingsComboBoxSource.ResetBindings(false); |
UpdateRemoteItems(); |
return; |
} |
|
// If the bindings for the nick have not changed then do not update. |
if (exchangeBindings.KeyBindings.SequenceEqual(e.Bindings.KeyBindings)) |
if (e.Bindings.KeyBindings.Count == exchangeBindings.KeyBindings.Count && |
e.Bindings.KeyBindings.All(exchangeBindings.KeyBindings.Contains)) |
{ |
RemoteBindingsComboBoxSource.ResetBindings(false); |
UpdateRemoteItems(); |
return; |
} |
|
// Update the bindings. |
exchangeBindings.KeyBindings = e.Bindings.KeyBindings; |
exchangeBindings.KeyBindings.RemoveAll(binding => !e.Bindings.KeyBindings.Contains(binding)); |
exchangeBindings.KeyBindings.AddRange( |
e.Bindings.KeyBindings.Where(binding => !exchangeBindings.KeyBindings.Contains(binding))); |
RemoteBindingsComboBoxSource.ResetBindings(false); |
UpdateRemoteItems(); |
} |
|
private void UpdateRemoteItems() |
private void UpdateRemoteBindingsListBox() |
{ |
var exchangeBindings = (List<KeyBinding>) RemoteBindingsComboBox.SelectedValue; |
if (exchangeBindings == null) |
var keyBindingExchange = (KeyBindingExchange) RemoteBindingsComboBox.SelectedItem; |
if (keyBindingExchange == null) |
return; |
|
var replaceMouseBindings = new ObservableCollection<RemoteKeyBinding>(); |
foreach (var remoteBinding in RemoteKeyBindings.Bindings) |
{ |
if (!exchangeBindings.Any(binding => |
string.Equals(binding.Name, remoteBinding.Name, StringComparison.Ordinal))) |
continue; |
RemoteBindingsListBox.Items.Clear(); |
var bindings = KeyBindingsExchange.ExchangeBindings |
.Where(binding => binding.Nick == keyBindingExchange.Nick) |
.SelectMany(binding => binding.KeyBindings.Select(keyBinding => keyBinding)) |
.Select(binding => (object) binding).ToArray(); |
|
replaceMouseBindings.Add(remoteBinding); |
} |
|
RemoteKeyBindings.Bindings.Clear(); |
foreach (var binding in replaceMouseBindings) RemoteKeyBindings.Bindings.Add(binding); |
|
RemoteBindingsListBox.Items.Clear(); |
RemoteBindingsListBox.DisplayMember = "Name"; |
RemoteBindingsListBox.ValueMember = "Name"; |
var bindings = exchangeBindings.Select(binding => (object) binding.Name).ToArray(); |
if (bindings.Length == 0) |
return; |
|
@@ -330,9 +329,9 @@ |
|
private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e) |
{ |
notifyIcon1.BalloonTipTitle = Strings.Lobby_message; |
notifyIcon1.BalloonTipText = $"{e.Nick} : {e.Message}{Environment.NewLine}"; |
notifyIcon1.ShowBalloonTip(1000); |
WingManNotifyIcon.BalloonTipTitle = Strings.Lobby_message; |
WingManNotifyIcon.BalloonTipText = $"{e.Nick} : {e.Message}{Environment.NewLine}"; |
WingManNotifyIcon.ShowBalloonTip(1000); |
|
LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}"); |
} |
@@ -352,7 +351,16 @@ |
// Stop the MQTT server if it is running. |
if (MqttCommunication.Running) |
{ |
// Remote UPnP and Pmp mappings. |
await Task.Delay(0, FormCancellationTokenSource.Token).ContinueWith(async _ => |
{ |
await Discovery.DeleteMapping(DiscoveryType.Upnp, MqttCommunication.Port); |
await Discovery.DeleteMapping(DiscoveryType.Pmp, MqttCommunication.Port); |
}, |
FormCancellationTokenSource.Token, TaskContinuationOptions.LongRunning, FormTaskScheduler); |
|
await MqttCommunication.Stop(); |
|
HostButton.BackColor = Color.Empty; |
|
// Enable controls. |
@@ -370,10 +378,14 @@ |
StoreConnectionAutocomplete(); |
|
// Try to reserve port: try UPnP followed by PMP. |
if (!await Discovery.CreateMapping(DiscoveryType.UPnP, port) && |
!await Discovery.CreateMapping(DiscoveryType.PMP, port)) |
ActivityTextBox.AppendText( |
$"{Strings.Failed_creating_automatic_port_mapping_please_make_sure_the_port_is_routed_properly}{Environment.NewLine}"); |
await Task.Delay(0, FormCancellationTokenSource.Token).ContinueWith(async _ => |
{ |
if (!await Discovery.CreateMapping(DiscoveryType.Upnp, port) && |
!await Discovery.CreateMapping(DiscoveryType.Pmp, port)) |
ActivityTextBox.AppendText( |
$"{Strings.Failed_creating_automatic_port_mapping_please_make_sure_the_port_is_routed_properly}{Environment.NewLine}"); |
}, |
FormCancellationTokenSource.Token, TaskContinuationOptions.LongRunning, FormTaskScheduler); |
|
// Start the MQTT server. |
if (!await MqttCommunication |
@@ -468,7 +480,7 @@ |
return false; |
} |
|
password = AES.ExpandKey(Password.Text); |
password = Aes.ExpandKey(Password.Text); |
|
Address.BackColor = Color.Empty; |
Port.BackColor = Color.Empty; |
@@ -531,7 +543,7 @@ |
LobbySayTextBox.Text = string.Empty; |
} |
|
private void LocalAddBindingButtonClick(object sender, EventArgs e) |
private async void LocalAddBindingButtonClick(object sender, EventArgs e) |
{ |
if (string.IsNullOrEmpty(LocalNameTextBox.Text)) |
{ |
@@ -551,6 +563,10 @@ |
LocalNameTextBox.BackColor = Color.Empty; |
LocalBindingsCheckedListBox.BackColor = Color.Empty; |
|
LocalNameTextBox.AutoCompleteCustomSource.Add(LocalNameTextBox.Text); |
|
await AutoCompletion.Save(LocalNameTextBox.Name, LocalNameTextBox.AutoCompleteCustomSource); |
|
ShowOverlayPanel(); |
|
MouseKeyCombo = new List<string>(); |
@@ -607,11 +623,11 @@ |
|
private async void LocalBindingsRemoveButtonClick(object sender, EventArgs e) |
{ |
var helmBinding = (KeyBinding) LocalBindingsCheckedListBox.SelectedItem; |
if (helmBinding == null) |
var localBinding = (KeyBinding) LocalBindingsCheckedListBox.SelectedItem; |
if (localBinding == null) |
return; |
|
LocalKeyBindings.Bindings.Remove(helmBinding); |
LocalKeyBindings.Bindings.Remove(localBinding); |
LocalCheckedListBoxBindingSource.ResetBindings(false); |
|
await SaveLocalMouseKeyBindings(); |
@@ -630,7 +646,7 @@ |
|
private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) |
{ |
UpdateRemoteItems(); |
UpdateRemoteBindingsListBox(); |
} |
|
private async void WingManFormOnLoad(object sender, EventArgs e) |
@@ -762,7 +778,7 @@ |
{ |
if (e.Button != MouseButtons.Left) return; |
|
tabControlClickStartPosition = e.Location; |
TabControlClickStartPosition = e.Location; |
} |
|
private void WingManTabControlMouseMove(object sender, MouseEventArgs e) |
@@ -769,19 +785,19 @@ |
{ |
if (e.Button == MouseButtons.Left) |
{ |
var mouseOffsetX = tabControlClickStartPosition.X - e.X; |
var mouseOffsetY = tabControlClickStartPosition.Y - e.Y; |
var mouseOffsetX = TabControlClickStartPosition.X - e.X; |
var mouseOffsetY = TabControlClickStartPosition.Y - e.Y; |
|
if (mouseOffsetX <= tabControlDetachPixelOffset && mouseOffsetY <= tabControlDetachPixelOffset) |
if (mouseOffsetX <= TabControlDetachPixelOffset && mouseOffsetY <= TabControlDetachPixelOffset) |
return; |
|
tabControl1.DoDragDrop(tabControl1.SelectedTab, DragDropEffects.Move); |
tabControlClickStartPosition = new Point(); |
TabControlClickStartPosition = new Point(); |
|
return; |
} |
|
tabControlClickStartPosition = new Point(); |
TabControlClickStartPosition = new Point(); |
} |
|
private void WingManTabControlGiveFeedback(object sender, GiveFeedbackEventArgs e) |
@@ -814,7 +830,10 @@ |
Location = MousePosition, |
MaximizeBox = false, |
SizeGripStyle = SizeGripStyle.Hide, |
FormBorderStyle = FormBorderStyle.FixedSingle |
FormBorderStyle = FormBorderStyle.FixedSingle, |
Name = Name, |
Text = Text, |
Icon = Icon |
}; |
|
DetachedTabControl = new TabControl |