Skip to content

Commit

Permalink
Merge branch 'main' into version-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom authored Mar 5, 2024
2 parents e18dc78 + 0789071 commit f8d830c
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/client/DCSInsight/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<setting name="LuaWindowLeft" serializeAs="String">
<value>-1</value>
</setting>
<setting name="ReloadAPIList" serializeAs="String">
<value>False</value>
</setting>
<setting name="AskForReloadAPIList" serializeAs="String">
<value>True</value>
</setting>
</DCSInsight.Properties.Settings>
</userSettings>
</configuration>
6 changes: 4 additions & 2 deletions src/client/DCSInsight/Communication/TCPClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ internal class TCPClientHandler : IDisposable, ICommandListener
public bool LogJSON { get; set; }
private string _currentMessage = "";
private volatile bool _responseReceived;
private bool _requestAPIList;

public TCPClientHandler(string host, string port)
public TCPClientHandler(string host, string port, bool requestAPIList)
{
_host = host;
_port = port;
_requestAPIList = requestAPIList;
ICEventHandler.AttachCommandListener(this);
}

Expand Down Expand Up @@ -75,7 +77,7 @@ private async void ClientThread()

if (!_tcpClient.Connected) break;

if (!_apiListReceived && _metaDataPollCounter < 1)
if (_requestAPIList && !_apiListReceived && _metaDataPollCounter < 1)
{
Thread.Sleep(300);
_metaDataPollCounter++;
Expand Down
5 changes: 4 additions & 1 deletion src/client/DCSInsight/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<TextBox Name="TextBoxServer" Text="127.0.0.1" Width="80"></TextBox>
<Label Content="Port" VerticalAlignment="Center" ></Label>
<TextBox Name="TextBoxPort" Text="7790" Width="40"></TextBox>
<Button Name="ButtonConnect" Content="Connect" BorderBrush="Gray" Margin="20,0,0,0" Click="ButtonConnect_OnClick"></Button>
<Button Name="ButtonConnectDisconnect" Content="Connect" BorderBrush="Gray" Margin="20,0,0,0" Click="ButtonConnectDisconnect_OnClick"></Button>
<CheckBox Name="CheckBoxTop" Content="On Top" BorderBrush="Gray" Margin="20,0,0,0" Checked="CheckBoxTop_OnChecked" Unchecked="CheckBoxTop_OnUnchecked"></CheckBox>
<TextBox Name="TextBoxSearchAPI" TextWrapping="NoWrap" IsReadOnly="False" Width="150" Margin="20,0,0,0" PreviewKeyDown="TextBoxSearchAPI_OnPreviewKeyDown" />
<Button>
Expand Down Expand Up @@ -54,6 +54,9 @@
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="{x:Static misc:Common.MouseEnter}" MouseLeave="{x:Static misc:Common.MouseLeave}" >
<TextBlock Name="TextBlockSetDCSBIOSLocation" MouseDown="TextBlockSetDCSBIOSLocation_OnMouseDown">set dcs-bios</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="{x:Static misc:Common.MouseEnter}" MouseLeave="{x:Static misc:Common.MouseLeave}" >
<TextBlock Name="TextBlockAPIReload" MouseDown="TextBlockAPIReload_OnMouseDown">API Reload Setting</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right">
<TextBlock Name="TextBlockMessage" ></TextBlock>
</StatusBarItem>
Expand Down
36 changes: 26 additions & 10 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
Top = Settings.Default.MainWindowTop.CompareTo(-1) == 0 ? Top : Settings.Default.MainWindowTop;
Left = Settings.Default.MainWindowLeft.CompareTo(-1) == 0 ? Left : Settings.Default.MainWindowLeft;

ButtonLuaWindow.Visibility = Directory.Exists(Settings.Default.DCSBiosJSONLocation) ? Visibility.Visible : Visibility.Collapsed;
ButtonLuaWindow.Visibility = Directory.Exists(Settings.Default.DCSBiosJSONLocation) ? Visibility.Visible : Visibility.Collapsed;
_formLoaded = true;
}
catch (Exception ex)
Expand All @@ -87,7 +87,7 @@ private void SetFormState()
{
try
{
ButtonConnect.IsEnabled = !string.IsNullOrEmpty(TextBoxServer.Text) && !string.IsNullOrEmpty(TextBoxPort.Text);
ButtonConnectDisconnect.IsEnabled = !string.IsNullOrEmpty(TextBoxServer.Text) && !string.IsNullOrEmpty(TextBoxPort.Text);
ButtonRangeTest.IsEnabled = _isConnected && _dcsAPIList.Count > 0;
}
catch (Exception ex)
Expand All @@ -100,12 +100,18 @@ private void Connect()
{
try
{
if (ItemsControlAPI.Items.Count > 0 && Settings.Default.AskForReloadAPIList)
{
var windowAskReloadAPIDialog = new WindowAskReloadAPIDialog();
windowAskReloadAPIDialog.ShowDialog();
}

Mouse.OverrideCursor = Cursors.Wait;
try
{
_tcpClientHandler?.Disconnect();
_isConnected = false;
_tcpClientHandler = new TCPClientHandler(TextBoxServer.Text, TextBoxPort.Text);
_tcpClientHandler = new TCPClientHandler(TextBoxServer.Text, TextBoxPort.Text, ItemsControlAPI.Items.Count == 0 || Settings.Default.ReloadAPIList);
_tcpClientHandler.Connect();
}
catch (Exception ex)
Expand All @@ -128,11 +134,8 @@ private void Disconnect()
{
_isConnected = false;
_tcpClientHandler?.Disconnect();
_dcsAPIList.Clear();
_loadedAPIUserControls.Clear();
ItemsControlAPI.ItemsSource = null;
ItemsControlAPI.Items.Clear();
SetConnectionStatus(_isConnected);
SetFormState();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -204,7 +207,7 @@ public void DataReceived(DataEventArgs args)

private void SetConnectionStatus(bool connected)
{
ButtonConnect.Content = connected ? "Disconnect" : "Connect";
ButtonConnectDisconnect.Content = connected ? "Disconnect" : "Connect";
Title = connected ? "Connected" : "Disconnected";
SetFormState();
_loadedAPIUserControls.ForEach(o => o.SetConnectionStatus(_isConnected));
Expand Down Expand Up @@ -245,7 +248,7 @@ private void HandleAPIMessage(List<DCSAPI> dcsApis)
}
}

private void ButtonConnect_OnClick(object sender, RoutedEventArgs e)
private void ButtonConnectDisconnect_OnClick(object sender, RoutedEventArgs e)
{
try
{
Expand Down Expand Up @@ -554,7 +557,7 @@ private async Task CheckForNewVersion()
{
var client = new GitHubClient(new Octokit.ProductHeaderValue("dcs-insight"));
var lastRelease = await client.Repository.Release.GetLatest("DCS-Skunkworks", "dcs-insight");
var githubVersion = new Version(lastRelease.TagName.Replace("v.", "").Replace("v",""));
var githubVersion = new Version(lastRelease.TagName.Replace("v.", "").Replace("v", ""));
if (githubVersion.CompareTo(thisVersion) > 0)
{
if (MessageBox.Show(this, $"Newer version can be downloaded ({lastRelease.TagName}).\nGo to download page?", "New Version Available", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
Expand Down Expand Up @@ -629,5 +632,18 @@ private void TextBoxSearchAPI_OnPreviewKeyDown(object sender, KeyEventArgs e)
Common.ShowErrorMessageBox(ex);
}
}

private void TextBlockAPIReload_OnMouseDown(object sender, MouseButtonEventArgs e)
{
try
{
var windowAskReloadAPIDialog = new WindowAskReloadAPIDialog();
windowAskReloadAPIDialog.ShowDialog();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}
}
}
26 changes: 25 additions & 1 deletion src/client/DCSInsight/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/client/DCSInsight/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
<Setting Name="LuaWindowLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="ReloadAPIList" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AskForReloadAPIList" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
40 changes: 40 additions & 0 deletions src/client/DCSInsight/Windows/WindowAskReloadAPIDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Window x:Class="DCSInsight.Windows.WindowAskReloadAPIDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Reload APIs from server?"
Height="200"
Width="410"
WindowStartupLocation="CenterOwner"
Loaded="Window_Loaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock FontSize="12" Margin="5,5,5,5">
<LineBreak/>
Do you want to reload all APIs from the server?
<LineBreak/>
All APIs will lose any information you may have entered.
<LineBreak/>
APIs can also be reloaded by restarting the client.
<LineBreak/>
If you restart missions frequently it is recommended to not reload APIs.
</TextBlock>
</StackPanel>
<DockPanel Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<CheckBox Name="CheckBoxDoNotAskAgain" IsChecked="False" VerticalAlignment="Bottom" Margin="10,10,10,10" HorizontalAlignment="Right" Content="Do not ask again" />
<Button Name="ButtonYes" Content="Yes" Width="40" VerticalAlignment="Bottom" Margin="10,10,0,10" HorizontalAlignment="Right" Click="ButtonYes_OnClick" />
<Button Name="ButtonNo" Content="No" Width="40" VerticalAlignment="Bottom" Margin="10,10,10,10" HorizontalAlignment="Right" Click="ButtonNo_OnClick" />
</StackPanel>
</DockPanel>
</Grid>
</Window>
65 changes: 65 additions & 0 deletions src/client/DCSInsight/Windows/WindowAskReloadAPIDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using DCSInsight.Communication;
using DCSInsight.Misc;
using System;
using System.Windows;
using System.Windows.Forms;
using DCSInsight.Properties;

namespace DCSInsight.Windows
{
/// <summary>
/// Interaction logic for WindowAskReloadAPIDialog.xaml
/// </summary>
public partial class WindowAskReloadAPIDialog
{
public DialogResult DialogResult { get; set; }

public WindowAskReloadAPIDialog()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}

private void ButtonYes_OnClick(object sender, RoutedEventArgs e)
{
try
{
Settings.Default.AskForReloadAPIList = !CheckBoxDoNotAskAgain.IsChecked == true;
Settings.Default.ReloadAPIList = true;
Settings.Default.Save();
DialogResult = DialogResult.Yes;
Close();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}

private void ButtonNo_OnClick(object sender, RoutedEventArgs e)
{
try
{
Settings.Default.AskForReloadAPIList = !CheckBoxDoNotAskAgain.IsChecked == true;
Settings.Default.ReloadAPIList = false;
Settings.Default.Save();
DialogResult = DialogResult.No;
Close();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}
}
}

0 comments on commit f8d830c

Please sign in to comment.