Skip to content

Commit

Permalink
Merge pull request #8 from metindikbas/v2.1-improvements
Browse files Browse the repository at this point in the history
V2.1 improvements
  • Loading branch information
metindikbas authored Sep 26, 2020
2 parents f9bbf81 + 22af25c commit d8fd3c0
Show file tree
Hide file tree
Showing 48 changed files with 319 additions and 72 deletions.
Binary file modified Assets/PushbackHelper.xd
Binary file not shown.
Binary file modified Assets/xd_output/ActivateButtonShape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/ActivateButtonShapeHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/ActivateButtonShapePressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/xd_output/CloseButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/xd_output/CloseButtonHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/xd_output/CloseButtonPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/xd_output/JetwayButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/xd_output/JetwayButtonHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/xd_output/JetwayButtonPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/LeftButtonShape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/LeftButtonShapeHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/LeftButtonShapePressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/Main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/RightButtonShape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/RightButtonShapeHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/RightButtonShapePressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/StraightButtonShape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/StraightButtonShapeHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/xd_output/StraightButtonShapePressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions PushbackHelperWpf/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="PushbackHelperWpf.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<PushbackHelperWpf.Properties.Settings>
<setting name="WindowLeft" serializeAs="String">
<value>0</value>
</setting>
<setting name="WindowTop" serializeAs="String">
<value>0</value>
</setting>
</PushbackHelperWpf.Properties.Settings>
</userSettings>
</configuration>
Binary file modified PushbackHelperWpf/Images/Xd/ActivateButtonShape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PushbackHelperWpf/Images/Xd/ActivateButtonShapeHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PushbackHelperWpf/Images/Xd/ActivateButtonShapePressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PushbackHelperWpf/Images/Xd/CloseButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PushbackHelperWpf/Images/Xd/CloseButtonHovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PushbackHelperWpf/Images/Xd/CloseButtonPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PushbackHelperWpf/Images/Xd/JetwayButton.png
Binary file modified PushbackHelperWpf/Images/Xd/LeftButtonShape.png
Binary file modified PushbackHelperWpf/Images/Xd/LeftButtonShapeHovered.png
Binary file modified PushbackHelperWpf/Images/Xd/LeftButtonShapePressed.png
Binary file modified PushbackHelperWpf/Images/Xd/Main.png
Binary file modified PushbackHelperWpf/Images/Xd/RightButtonShape.png
Binary file modified PushbackHelperWpf/Images/Xd/RightButtonShapeHovered.png
Binary file modified PushbackHelperWpf/Images/Xd/RightButtonShapePressed.png
Binary file modified PushbackHelperWpf/Images/Xd/StraightButtonShape.png
Binary file modified PushbackHelperWpf/Images/Xd/StraightButtonShapeHovered.png
Binary file modified PushbackHelperWpf/Images/Xd/StraightButtonShapePressed.png
88 changes: 82 additions & 6 deletions PushbackHelperWpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PushbackHelperWpf"
mc:Ignorable="d"
Title="Pushback Helper" Height="300" Width="350"
Title="Pushback Helper" Height="350" Width="350"
AllowsTransparency="True" Closing="Window_Closing" Topmost="True"
WindowStyle="None" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Expand All @@ -15,6 +15,72 @@
<Window.Resources>
<ImageBrush x:Key="xd_main" ImageSource="Images/Xd/Main.png" Stretch="None"/>

<Style TargetType="{x:Type Button}" x:Key="xdJetwayButtonStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Button.Background">
<Setter.Value>
<ImageBrush ImageSource="Images/Xd/JetwayButton.png" Stretch="None" />
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<ImageBrush ImageSource="Images/Xd/JetwayButtonHovered.png" Stretch="None" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<ImageBrush ImageSource="Images/Xd/JetwayButtonPressed.png" Stretch="None" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="{x:Type Button}" x:Key="xdCloseButtonStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Button.Background">
<Setter.Value>
<ImageBrush ImageSource="Images/Xd/CloseButton.png" Stretch="None" />
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<ImageBrush ImageSource="Images/Xd/CloseButtonHovered.png" Stretch="None" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<ImageBrush ImageSource="Images/Xd/CloseButtonPressed.png" Stretch="None" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="{x:Type Button}" x:Key="xdLeftButtonStyle">
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -150,19 +216,29 @@
</Window.Resources>

<Grid x:Name="mainGrid" Background="{DynamicResource xd_main}">
<Button x:Name="btnLeft" Content="" HorizontalAlignment="Left" Margin="33,90,0,0" BorderThickness="0"
<Button x:Name="btnJetway" Content="" HorizontalAlignment="Left" BorderThickness="0"
VerticalAlignment="Top" Width="80" Height="35" Style="{DynamicResource xdJetwayButtonStyle}"
IsTabStop="False" Cursor="Hand" Click="btnJetway_Click" Margin="36,3,0,0"/>
<Button x:Name="btnClose" Content="" HorizontalAlignment="Left" Margin="280,3,0,0" BorderThickness="0"
VerticalAlignment="Top" Width="35" Height="35" Style="{DynamicResource xdCloseButtonStyle}"
IsTabStop="False" Cursor="Hand" Click="btnClose_Click"/>

<Button x:Name="btnLeft" Content="" HorizontalAlignment="Left" Margin="33,136,0,0" BorderThickness="0"
VerticalAlignment="Top" Width="53" Height="119" Style="{DynamicResource xdLeftButtonStyle}"
IsTabStop="False" Cursor="Hand" Click="btnLeft_Click"/>
<Button x:Name="btnRight" Content="" HorizontalAlignment="Left" Margin="264,90,0,0" BorderThickness="0"
<Button x:Name="btnRight" Content="" HorizontalAlignment="Left" Margin="264,136,0,0" BorderThickness="0"
VerticalAlignment="Top" Width="53" Height="119" Style="{DynamicResource ResourceKey=xdRightButtonStyle}"
IsTabStop="False" Cursor="Hand" Click="btnRight_Click"/>
<Button x:Name="btnActivate" Content="" HorizontalAlignment="Left" Margin="115,8,0,0" BorderThickness="0"
<Button x:Name="btnActivate" Content="" HorizontalAlignment="Left" Margin="115,54,0,0" BorderThickness="0"
VerticalAlignment="Top" Width="119" Height="53" Style="{DynamicResource ResourceKey=xdTopButtonStyle}"
IsTabStop="False" Cursor="Hand" Click="btnActivate_Click"/>
<Button x:Name="btnStraight" Content="" HorizontalAlignment="Left" Margin="115,239,0,0" BorderThickness="0"
<Button x:Name="btnStraight" Content="" HorizontalAlignment="Left" Margin="115,285,0,0" BorderThickness="0"
VerticalAlignment="Top" Width="119" Height="53" Style="{DynamicResource ResourceKey=xdStraightButtonStyle}"
IsTabStop="False" Cursor="Hand" Click="btnStraight_Click"/>
<Label x:Name="lblSimStatus" Content="DISCONNECTED" HorizontalAlignment="Left" Margin="140,220,0,0" VerticalAlignment="Top" FontSize="8" Height="19" Background="{x:Null}" Foreground="#FF575757" Width="70" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom"/>
<Label x:Name="lblSimStatus" Content="DISCONNECTED" HorizontalAlignment="Left" Margin="133,109,0,0" VerticalAlignment="Top" FontSize="9" Height="19" Background="{x:Null}" Foreground="#FF9C9C9C" Width="84" HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom" FontFamily="Arial"/>

<Border BorderBrush="Black" BorderThickness="0" HorizontalAlignment="Left" Height="35" Margin="121,3,0,0"
VerticalAlignment="Top" Background="Transparent" Width="154" MouseDown="Border_MouseDown"/>
</Grid>

</Window>
89 changes: 73 additions & 16 deletions PushbackHelperWpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
using Microsoft.FlightSimulator.SimConnect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace PushbackHelperWpf
Expand All @@ -36,6 +25,18 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();

var top = Properties.Settings.Default.WindowTop;
var left = Properties.Settings.Default.WindowLeft;

// Restore window location
if (top != 0 && left != 0)
{
WindowStartupLocation = WindowStartupLocation.Manual;
Top = top;
Left = left;
}

_listener = new LowLevelKeyboardListener();
_listener.OnKeyPressed += _listener_OnKeyPressed;
_listener.HookKeyboard();
Expand All @@ -47,6 +48,8 @@ public MainWindow()
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Tick += Timer_Tick;
_timer.Start();

SetConnectionText();
}

private void Timer_Tick(object sender, EventArgs e)
Expand All @@ -60,6 +63,20 @@ private void ConnectTimer_Tick(object sender, EventArgs e)
Connect();
}

private void SetConnectionText()
{
if (_simConnectionStatus)
{
lblSimStatus.Content = "CONNECTED";
lblSimStatus.Foreground = new SolidColorBrush(Colors.GreenYellow);
}
else
{
lblSimStatus.Content = "DISCONNECTED";
lblSimStatus.Foreground = new SolidColorBrush(Colors.Red);
}
}

private void Connect()
{
try
Expand All @@ -80,7 +97,7 @@ private void Connect()
_simClient.OnRecvSimobjectDataBytype += SimClient_OnRecvSimobjectDataBytype;
//
_simConnectionStatus = true;
lblSimStatus.Content = "CONNECTED";
SetConnectionText();
_timer.Start();
}
catch (Exception)
Expand All @@ -93,7 +110,7 @@ private void Connect()
private void SimClient_OnRecvQuit(SimConnect sender, SIMCONNECT_RECV data)
{
_simConnectionStatus = false;
lblSimStatus.Content = "DISCONNECTED";
SetConnectionText();
}

private void SimClient_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data)
Expand All @@ -103,7 +120,7 @@ private void SimClient_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data)

private void SimClient_OnRecvSimobjectDataBytype(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
{
lblSimStatus.Content = "CONNECTED";
SetConnectionText();
if (data.dwRequestID == 0)
{
HeadingDataStruct receivedData = (HeadingDataStruct)data.dwData[0];
Expand All @@ -126,7 +143,7 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b

private void SimClient_OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data)
{
lblSimStatus.Content = "ERROR!";
//lblSimStatus.Content = "ERROR!";
}

private uint GetTugHeading(TugDirection direction)
Expand Down Expand Up @@ -176,7 +193,8 @@ private enum DefinitionsEnum
private enum PushbackEventsEnum
{
KEY_PUSHBACK_SET,
KEY_TUG_HEADING
KEY_TUG_HEADING,
KEY_TOGGLE_JETWAY
}

private enum NotificationGroupsEnum
Expand Down Expand Up @@ -204,28 +222,67 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
//_listener.UnHookKeyboard();
}

private void btnClose_Click(object sender, RoutedEventArgs e)
{
try
{
// Save position
Properties.Settings.Default.WindowTop = Top;
Properties.Settings.Default.WindowLeft = Left;
Properties.Settings.Default.Save();
// Stop
_timer.Stop();
_connectTimer.Stop();
if (_simConnectionStatus) _simClient.Dispose();
_listener.UnHookKeyboard();
}
catch (Exception)
{

}

Close();
}

private void btnJetway_Click(object sender, RoutedEventArgs e)
{
if (!_simConnectionStatus) return;
_simClient.MapClientEventToSimEvent(PushbackEventsEnum.KEY_TOGGLE_JETWAY, "TOGGLE_JETWAY");
_simClient.TransmitClientEvent(0U, PushbackEventsEnum.KEY_TOGGLE_JETWAY, 1, NotificationGroupsEnum.Group0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
}

private void btnActivate_Click(object sender, RoutedEventArgs e)
{
if (!_simConnectionStatus) return;
_simClient.MapClientEventToSimEvent(PushbackEventsEnum.KEY_PUSHBACK_SET, "TOGGLE_PUSHBACK");
_simClient.TransmitClientEvent(0U, PushbackEventsEnum.KEY_PUSHBACK_SET, 1, NotificationGroupsEnum.Group0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
}

private void btnRight_Click(object sender, RoutedEventArgs e)
{
if (!_simConnectionStatus) return;
_simClient.MapClientEventToSimEvent(PushbackEventsEnum.KEY_TUG_HEADING, "KEY_TUG_HEADING");
_simClient.TransmitClientEvent(0U, PushbackEventsEnum.KEY_TUG_HEADING, GetTugHeading(TugDirection.Right), NotificationGroupsEnum.Group0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
}

private void btnLeft_Click(object sender, RoutedEventArgs e)
{
if (!_simConnectionStatus) return;
_simClient.MapClientEventToSimEvent(PushbackEventsEnum.KEY_TUG_HEADING, "KEY_TUG_HEADING");
_simClient.TransmitClientEvent(0U, PushbackEventsEnum.KEY_TUG_HEADING, GetTugHeading(TugDirection.Left), NotificationGroupsEnum.Group0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
}

private void btnStraight_Click(object sender, RoutedEventArgs e)
{
if (!_simConnectionStatus) return;
_simClient.MapClientEventToSimEvent(PushbackEventsEnum.KEY_TUG_HEADING, "KEY_TUG_HEADING");
_simClient.TransmitClientEvent(0U, PushbackEventsEnum.KEY_TUG_HEADING, GetTugHeading(TugDirection.Straight), NotificationGroupsEnum.Group0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
}

private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
DragMove();
}
}
}
Loading

0 comments on commit d8fd3c0

Please sign in to comment.