Skip to content

Commit

Permalink
Improve status label with visual green indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
astenlund committed Sep 29, 2020
1 parent db6a3e8 commit 6d34aba
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 19 deletions.
23 changes: 13 additions & 10 deletions MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Net;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using fs2ff.FlightSim;
using fs2ff.ForeFlight;
using fs2ff.Models;
Expand Down Expand Up @@ -81,6 +80,8 @@ public bool BroadcastEnabled

public string? ConnectButtonText { get; private set; }

public bool ConnectedLabelVisible { get; private set; }

public bool DataAttitudeEnabled
{
get => _dataAttitudeEnabled;
Expand Down Expand Up @@ -125,8 +126,12 @@ public bool DataTrafficEnabled

public ICommand DismissSettingsPaneCommand { get; }

public bool ErrorLabelVisible { get; private set; }

public ICommand GotoNewReleaseCommand { get; }

public bool IndicatorVisible { get; private set; }

public IPAddress? IpAddress
{
get => _ipAddress;
Expand All @@ -142,11 +147,9 @@ public bool DataTrafficEnabled
}
}

public bool SettingsPaneVisible { get; set; }

public Brush? StateLabelColor { get; set; }
public bool NotLabelVisible { get; private set; }

public string? StateLabelText { get; set; }
public bool SettingsPaneVisible { get; set; }

public ActionCommand ToggleConnectCommand { get; }

Expand Down Expand Up @@ -269,12 +272,12 @@ private void UpdateForeFlightConnection()

private void UpdateVisualState()
{
(ConnectButtonText, StateLabelColor, StateLabelText) = CurrentFlightSimState switch
(IndicatorVisible, NotLabelVisible, ErrorLabelVisible, ConnectedLabelVisible, ConnectButtonText) = CurrentFlightSimState switch
{
FlightSimState.Connected => ("Disconnect", Brushes.Goldenrod, "CONNECTED"),
FlightSimState.Disconnected => ("Connect", Brushes.DarkGray, "NOT CONNECTED"),
FlightSimState.ErrorOccurred => ("Connect", Brushes.OrangeRed, "UNABLE TO CONNECT"),
_ => ("Connect", Brushes.DarkGray, "")
FlightSimState.Connected => (true, false, false, true, "Disconnect"),
FlightSimState.Disconnected => (false, true, false, true, "Connect"),
FlightSimState.ErrorOccurred => (false, false, true, false, "Connect"),
_ => (false, true, false, true, "Connect")
};
}
}
Expand Down
59 changes: 50 additions & 9 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
mc:Ignorable="d"
Title="{Binding WindowTitle}"
Icon="img\icon.ico"
Width="525" Height="350"
MinWidth="500" MinHeight="300"
Width="520" Height="350"
MinWidth="520" MinHeight="300"
Closing="Window_Closing"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Window.Resources>
Expand Down Expand Up @@ -113,11 +113,16 @@
</StackPanel>
</ui:SplitView.Pane>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
Visibility="{Binding BroadcastHintVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
HorizontalAlignment="Center"
Expand All @@ -135,7 +140,9 @@
</StackPanel>
</Label>
<Button
Grid.Row="0"
Grid.Column="0"
Grid.RowSpan="2"
Name="ConnectButton"
Content="{Binding ConnectButtonText, FallbackValue='Connect'}"
Command="{Binding ToggleConnectCommand}"
Expand All @@ -144,24 +151,58 @@
VerticalAlignment="Center"
Width="144"
Height="60" />
<Ellipse
Grid.Row="1"
Grid.Column="0"
Fill="LawnGreen"
Stroke="ForestGreen"
StrokeThickness="1"
Width="10" Height="10"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Visibility="{Binding IndicatorVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="25,0,0,0" />
<Label
Grid.Row="1"
Grid.Column="0"
Content="NOT"
Foreground="DarkGray"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Visibility="{Binding NotLabelVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="15,0,0,0" />
<Label
Grid.Row="1"
Grid.Column="0"
Content="{Binding StateLabelText, FallbackValue='NOT CONNECTED'}"
Content="CONNECTED"
Foreground="DarkGray"
VerticalAlignment="Center"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Foreground="{Binding StateLabelColor, FallbackValue='DarkGray'}"
Margin="15,0,15,10" />
Visibility="{Binding ConnectedLabelVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="43,0,0,0" />
<Label
Grid.Row="1"
Grid.Column="0"
Visibility="{Binding UpdateMsgVisible, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
VerticalAlignment="Bottom"
Content="UNABLE TO CONNECT TO FLIGHT SIMULATOR"
Foreground="OrangeRed"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Visibility="{Binding ErrorLabelVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="15,0,0,0" />
<Label
Grid.Row="1"
Grid.Column="0"
Visibility="{Binding UpdateMsgVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
VerticalAlignment="Center"
HorizontalAlignment="Right"
FontStyle="Italic"
Margin="15,0,15,10">
Margin="15,0,15,0">
<Hyperlink Command="{Binding GotoNewReleaseCommand}">Update available</Hyperlink>
</Label>
<ToggleButton
Grid.Row="0"
Grid.Column="1"
Grid.RowSpan="2"
IsChecked="{Binding SettingsPaneVisible, Mode=TwoWay}"
VerticalAlignment="Stretch"
Width="47">
Expand Down

0 comments on commit 6d34aba

Please sign in to comment.