Skip to content

Commit

Permalink
Possible to search for controls in lua window
Browse files Browse the repository at this point in the history
Main and lua window position saved
  • Loading branch information
jdahlblom committed Jan 21, 2024
1 parent 505ce6e commit 9c603a5
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 32 deletions.
15 changes: 15 additions & 0 deletions src/client/DCSInsight/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
<setting name="DCSBiosJSONLocation" serializeAs="String">
<value>%USERPROFILE%\Saved Games\DCS\Scripts\DCS-BIOS\doc\json</value>
</setting>
<setting name="MainWindowTop" serializeAs="String">
<value>-1</value>
</setting>
<setting name="MainWindowLeft" serializeAs="String">
<value>-1</value>
</setting>
<setting name="LuaWindowTop" serializeAs="String">
<value>-1</value>
</setting>
<setting name="LuaWindowLeft" serializeAs="String">
<value>-1</value>
</setting>
<setting name="MainScreenId" serializeAs="String">
<value>0</value>
</setting>
</DCSInsight.Properties.Settings>
</userSettings>
</configuration>
2 changes: 2 additions & 0 deletions src/client/DCSInsight/DCSInsight.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TCP/@EntryIndexedValue">TCP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/Abbreviations/=API/@EntryIndexedValue">API</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/Abbreviations/=DCSBIOS/@EntryIndexedValue">DCSBIOS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/Abbreviations/=JSON/@EntryIndexedValue">JSON</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Comms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=consolas/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DCSAPI/@EntryIndexedValue">True</s:Boolean>
Expand Down
12 changes: 6 additions & 6 deletions src/client/DCSInsight/Lua/LuaAssistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class LuaAssistant
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly object LockObject = new();
private static string _dcsbiosAircraftsLuaLocation;
private static string _dcsbiosAircraftLuaLocation;
private static string _dcsbiosModuleLuaFilePath;
private static readonly List<KeyValuePair<string, string>> LuaControls = new();
private static readonly List<string> LuaModuleSignatures = new();
Expand Down Expand Up @@ -45,9 +45,9 @@ internal static List<KeyValuePair<string, string>> GetLuaControls(string aircraf
internal static List<string> GetAircraftList(string dcsbiosJSONPath)
{
dcsbiosJSONPath = Environment.ExpandEnvironmentVariables(dcsbiosJSONPath);
_dcsbiosAircraftsLuaLocation = $"{dcsbiosJSONPath}\\..\\..\\lib\\modules\\aircraft_modules\\";
_dcsbiosModuleLuaFilePath = $"{dcsbiosJSONPath}\\..\\..\\lib\\modules\\Module.lua";
var directoryInfo = new DirectoryInfo(_dcsbiosAircraftsLuaLocation);
_dcsbiosAircraftLuaLocation = $@"{dcsbiosJSONPath}\..\..\lib\modules\aircraft_modules\";
_dcsbiosModuleLuaFilePath = $@"{dcsbiosJSONPath}\..\..\lib\modules\Module.lua";
var directoryInfo = new DirectoryInfo(_dcsbiosAircraftLuaLocation);
IEnumerable<FileInfo> files;
try
{
Expand All @@ -74,7 +74,7 @@ private static void ReadControlsFromLua(string aircraftId)

// input is a map from category string to a map from key string to control definition
// we read it all then flatten the grand children (the control definitions)
var lineArray = File.ReadAllLines(_dcsbiosAircraftsLuaLocation + aircraftId + ".lua");
var lineArray = File.ReadAllLines(_dcsbiosAircraftLuaLocation + aircraftId + ".lua");
try
{
var luaBuffer = "";
Expand Down Expand Up @@ -168,7 +168,7 @@ private static void ReadLuaCommandsFromFile(string aircraftId)
}
catch (Exception ex)
{
throw new Exception($"{DCSBIOS_LUA_NOT_FOUND_ERROR_MESSAGE} ==>[{_dcsbiosAircraftsLuaLocation}]<=={Environment.NewLine}{ex.Message}{Environment.NewLine}{ex.StackTrace}");
throw new Exception($"{DCSBIOS_LUA_NOT_FOUND_ERROR_MESSAGE} ==>[{_dcsbiosAircraftLuaLocation}]<=={Environment.NewLine}{ex.Message}{Environment.NewLine}{ex.StackTrace}");
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public partial class MainWindow : Window, IErrorListener, IConnectionListener, I
private TCPClientHandler _tcpClientHandler;
private bool _isConnected;
private bool _rangeTesting;
private LuaWindow _luaWindow;

public MainWindow()
{
Expand All @@ -48,6 +49,7 @@ public MainWindow()

public void Dispose()
{
_luaWindow?.Close();
ItemsControlAPI.Items.Clear();
ICEventHandler.DetachErrorListener(this);
ICEventHandler.DetachConnectionListener(this);
Expand All @@ -65,6 +67,10 @@ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
ShowVersionInfo();
SetFormState();
CheckBoxTop.IsChecked = true;

Top = Settings.Default.MainWindowTop.CompareTo(-1) == 0 ? Top : Settings.Default.MainWindowTop;
Left = Settings.Default.MainWindowLeft.CompareTo(-1) == 0 ? Left : Settings.Default.MainWindowLeft;

_formLoaded = true;
}
catch (Exception ex)
Expand Down Expand Up @@ -256,6 +262,10 @@ private void MainWindow_OnClosing(object sender, CancelEventArgs e)
{
try
{
Settings.Default.MainWindowTop = Top;
Settings.Default.MainWindowLeft = Left;
Settings.Default.Save();
_luaWindow?.Close();
_isConnected = false;
_tcpClientHandler?.Disconnect();
}
Expand Down Expand Up @@ -594,7 +604,10 @@ private void TextBlockSetDCSBIOSLocation_OnMouseDown(object sender, MouseButtonE
{
var settingsWindow = new SettingsWindow();
settingsWindow.ShowDialog();
Settings.Default.DCSBiosJSONLocation = settingsWindow.DcsBiosJSONLocation;
if (settingsWindow.DialogResult == true)
{
Settings.Default.DCSBiosJSONLocation = settingsWindow.DcsBiosJSONLocation;
}
Settings.Default.Save();
}
catch (Exception ex)
Expand All @@ -607,8 +620,9 @@ private void ButtonLuaWindow_OnClick(object sender, RoutedEventArgs e)
{
try
{
var luaWindow = new LuaWindow();
luaWindow.Show();
_luaWindow?.Close();
_luaWindow = new LuaWindow();
_luaWindow.Show();
}
catch (Exception ex)
{
Expand Down
60 changes: 60 additions & 0 deletions src/client/DCSInsight/Properties/Settings.Designer.cs

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

15 changes: 15 additions & 0 deletions src/client/DCSInsight/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@
<Setting Name="DCSBiosJSONLocation" Type="System.String" Scope="User">
<Value Profile="(Default)">%USERPROFILE%\Saved Games\DCS\Scripts\DCS-BIOS\doc\json</Value>
</Setting>
<Setting Name="MainWindowTop" Type="System.Double" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="MainWindowLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="LuaWindowTop" Type="System.Double" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="LuaWindowLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="MainScreenId" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
27 changes: 24 additions & 3 deletions src/client/DCSInsight/Windows/LuaWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@
mc:Ignorable="d"
Title="" Height="400" Width="Auto" MaxWidth="800"
Loaded="LuaWindow_OnLoaded"
WindowStartupLocation="CenterScreen"
KeyDown="LuaWindow_OnKeyDown" Icon="/Images/Magnifier_icon.png">
WindowStartupLocation="Manual"
KeyDown="LuaWindow_OnKeyDown" Icon="/Images/Magnifier_icon.png"
Closing="LuaWindow_OnClosing">
<Window.Resources>
<Popup x:Key="PopUpSearchResults" Width="500" Height="150" PlacementTarget="{Binding ElementName=text}" StaysOpen="False">
<Grid HorizontalAlignment="Stretch">
<DataGrid AutoGenerateColumns="false"
Background="White" ItemsSource="{Binding}" SelectionMode="Single" SelectionUnit="FullRow"
HorizontalAlignment="Stretch" Name="DataGridValues" VerticalAlignment="Stretch"
VerticalScrollBarVisibility="Visible" MouseDown="DataGridValues_OnMouseDown" MouseDoubleClick="DataGridValues_OnMouseDoubleClick"
SelectionChanged="DataGridValues_OnSelectionChanged" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="False">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Key}" Width="*" />
<DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Value}" Width="*" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Popup>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="26" />
Expand All @@ -24,7 +41,11 @@
<ComboBox Name="ComboBoxAircraft" Width="Auto" VerticalAlignment="Center" Margin="10,0,0,0" DockPanel.Dock="Left" />
<ComboBox Name="ComboBoxLuaControls" Width="Auto" VerticalAlignment="Center" Margin="10,0,0,0" DockPanel.Dock="Left" />
<Label Content="Search" Width="Auto" Margin="10,0,0,0" DockPanel.Dock="Left"></Label>
<TextBox Name="TextBoxSearch" Width="Auto" MinWidth="100" VerticalAlignment="Center" Margin="10,0,0,0" DockPanel.Dock="Left" TextChanged="TextBoxSearch_OnTextChanged" KeyUp="TextBoxSearch_OnKeyUp" PreviewKeyDown="TextBoxSearch_OnPreviewKeyDown"></TextBox>
<TextBox Name="TextBoxSearch" Width="Auto" MinWidth="100" VerticalAlignment="Center" Margin="10,0,0,0" DockPanel.Dock="Left" TextChanged="TextBoxSearch_OnTextChanged" KeyUp="TextBoxSearch_OnKeyUp" PreviewKeyDown="TextBoxSearch_OnPreviewKeyDown">
<TextBox.Background>
<ImageBrush ImageSource="/Images/cue_banner_search.png" AlignmentX="Left" Stretch="Uniform" />
</TextBox.Background>
</TextBox>
</DockPanel>

<ScrollViewer Grid.Row="1" Grid.Column="0">
Expand Down
Loading

0 comments on commit 9c603a5

Please sign in to comment.