give up on WPF -> Avalonia

This commit is contained in:
Florian Stinglmayr 2024-11-18 10:33:39 +01:00
parent f08bf38bab
commit c96060fa5d
6 changed files with 32 additions and 218 deletions

View File

@ -6,5 +6,7 @@ namespace EliteBGS {
/// </summary> /// </summary>
public partial class EliteBGSApplication : Application public partial class EliteBGSApplication : Application
{ {
public static void Main(string[] args) {
}
} }
} }

View File

@ -6,7 +6,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject>EliteBGSApplication</StartupObject> <StartupObject>EliteBGS.EliteBGSApplication</StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>Salus.ico</ApplicationIcon> <ApplicationIcon>Salus.ico</ApplicationIcon>

View File

@ -1,5 +1,5 @@
<Window x:Class="EliteBGS.LoadEntriesWindow" <Window x:Class="EliteBGS.LoadEntriesWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@ -47,8 +47,7 @@ public partial class LoadEntriesWindow : Window {
EntriesLoaded?.Invoke(entries); EntriesLoaded?.Invoke(entries);
} }
} catch (Exception exception) { } catch (Exception exception) {
MessageBox.Show(string.Format("There was an error while parsing the JSON: {0}", // TODO: MessageBox
exception.ToString()));
} }
} }
@ -57,29 +56,7 @@ public partial class LoadEntriesWindow : Window {
} }
private void LoadFile_Click(object sender, RoutedEventArgs e) { private void LoadFile_Click(object sender, RoutedEventArgs e) {
OpenFileDialog dialog = new OpenFileDialog(); // TODO: OpenFileDialog
dialog.DefaultExt = ".log";
dialog.Filter = "Log files (*.log)|*.log|All files (*.*)|*";
var location = AppConfig.DefaultJournalLocation;
if (Directory.Exists(location)) {
dialog.InitialDirectory = location;
}
bool result = dialog.ShowDialog(this) ?? false;
if (!result) {
return;
}
try {
using (FileStream stream = File.OpenRead(dialog.FileName)) {
using (StreamReader reader = new StreamReader(stream)) {
Lines.Text = reader.ReadToEnd();
}
}
} catch (Exception) {
}
} }
private void DeleteUnimportant_Click(object sender, RoutedEventArgs e) { private void DeleteUnimportant_Click(object sender, RoutedEventArgs e) {
@ -113,8 +90,7 @@ public partial class LoadEntriesWindow : Window {
; ;
Lines.Text = string.Join("\n", text).Trim(); Lines.Text = string.Join("\n", text).Trim();
} catch (Exception exception) { } catch (Exception exception) {
MessageBox.Show(string.Format("There was an error while parsing the JSON: {0}", // TODO: MessageBox
exception.ToString()));
} }
} }
} }

View File

@ -131,19 +131,6 @@
</DataTemplate> </DataTemplate>
</Window.Resources> </Window.Resources>
<!--
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands ShowSeparators="False">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,5,0">
<Hyperlink x:Name="URL" NavigateUri="https://salusinvicta.org/bgstool/" RequestNavigate="URL_RequestNavigate">Homepage</Hyperlink>
</TextBlock>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,15,0">
<Hyperlink x:Name="SRC" NavigateUri="https://codeberg.org/nola/EDBGS" RequestNavigate="URL_RequestNavigate">Source</Hyperlink>
</TextBlock>
<mah:ToggleSwitch Content="Dark Theme" x:Name="SwitchTheme" IsOn="True" Toggled="SwitchTheme_Toggled"/>
</mah:WindowCommands>
</mah:MetroWindow.RightWindowCommands>
-->
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@ -174,8 +161,6 @@
<Label Content="To (UTC):" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/> <Label Content="To (UTC):" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<DatePicker x:Name="enddate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/> <DatePicker x:Name="enddate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/> <Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/>
<Button x:Name="ResetTime" Content="Reset Time" Click="ResetTime_Click" />
<Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/>
<Button x:Name="ManuallyParse" Content="Manually Parse" Click="ManuallyParse_Click" /> <Button x:Name="ManuallyParse" Content="Manually Parse" Click="ManuallyParse_Click" />
</ToolBar> </ToolBar>
<ToolBar Grid.Row="1" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="Auto" Grid.ColumnSpan="3"> <ToolBar Grid.Row="1" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="Auto" Grid.ColumnSpan="3">
@ -313,16 +298,7 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox IsReadOnly="True" Grid.Row="1" x:Name="log" Height="Auto" Margin="5" TextWrapping="Wrap" FontFamily="Courier New" /> <TextBox IsReadOnly="True" Grid.Row="1" x:Name="log" Height="Auto" Margin="5" TextWrapping="Wrap" FontFamily="Courier New" />
<RichTextBox IsReadOnly="True" HorizontalAlignment="Left" Height="Auto" Margin="5" Width="Auto" VerticalContentAlignment="Stretch" VerticalAlignment="Top" BorderBrush="{x:Null}" SelectionBrush="{x:Null}"> <TextBox IsReadOnly="True" HorizontalAlignment="Left" Height="Auto" Margin="5" Width="Auto" VerticalContentAlignment="Stretch" VerticalAlignment="Top" Content="This tool does not recognise every option and/or configuration that E:D outputs through its JSON files.\nWithin this log you will find error messages that are of interest to the author (CMDR Hekateh). If something appears here please send it to me via Discord." />
<FlowDocument>
<Paragraph>
<Run Text="This tool does not recognise every option and/or configuration that E:D outputs through its JSON files."/>
</Paragraph>
<Paragraph>
<Run Text="Within this log you will find error messages that are of interest to the author (CMDR Hekateh). If something appears here please send it to me via Discord."/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid> </Grid>
</TabItem> </TabItem>
</TabControl> </TabControl>

View File

@ -11,6 +11,7 @@ using System.Globalization;
using System.Diagnostics; using System.Diagnostics;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Input; using Avalonia.Input;
@ -57,98 +58,22 @@ public partial class MainWindow : Window {
LogType.SelectedIndex = 0; LogType.SelectedIndex = 0;
} }
this.NoInfluenceSupport.IsOn = Config.Global.IgnoreInfluenceSupport; this.NoInfluenceSupport.IsChecked = Config.Global.IgnoreInfluenceSupport;
this.NoMarketBuy.IsOn = Config.Global.IgnoreMarketBuy; this.NoMarketBuy.IsChecked = Config.Global.IgnoreMarketBuy;
this.NoFleetCarrier.IsOn = Config.Global.IgnoreFleetCarrier; this.NoFleetCarrier.IsChecked = Config.Global.IgnoreFleetCarrier;
// Apply theme
try {
AddCustomThemes();
string[] colours = ThemeManager.Current.Themes
.Select(x => x.ColorScheme)
.DistinctBy(x => x)
.OrderBy(x => x)
.ToArray()
;
foreach (var colour in colours) {
Colour.Items.Add(colour);
if (!string.IsNullOrEmpty(Config.Global.Colour) &&
string.Compare(colour, Config.Global.Colour, true) == 0) {
Colour.SelectedIndex = Colour.Items.Count - 1;
}
}
if (Colour.SelectedIndex < 0) {
Colour.SelectedIndex = 0;
}
SwitchTheme.IsOn = (string.Compare(Config.Global.Theme, "dark", true) == 0);
ThemeManager.Current.ChangeTheme(this, Config.Global.FullTheme);
} catch (Exception) {
// Theme is invalid, revert back to our standard dark theme
Config.Global.Colour = "Amber";
Config.Global.Theme = "Dark";
}
InitialiseTime();
journal = new PlayerJournal(Config.Global.JournalLocation); journal = new PlayerJournal(Config.Global.JournalLocation);
// Set both to now
InitialiseTime();
journallocation.Text = Config.Global.JournalLocation; journallocation.Text = Config.Global.JournalLocation;
} }
private void AddCustomThemes() {
Dictionary<string, Color> colorThemes = new() {
//{ "HouseSalus", Color.FromRgb(0xBC, 0x94, 0x39) },
{ "HouseSalus", Color.FromRgb(0xED, 0xDA, 0x70) },
{ "NovaNavy", Color.FromRgb(0xA1, 0xA4, 0xDB) },
// Official Red of the Polish Flag
{ "PolskaGurom", Color.FromRgb(0xD4, 0x21, 0x3D) },
// Official Blue in the Armenian Flag
{ "ArmeniaBlue", Color.FromRgb(0x00, 0x33, 0xA0) },
};
foreach (var colourtheme in colorThemes) {
var brush = new SolidColorBrush(colourtheme.Value);
// Add light theme
ThemeManager.Current.AddTheme(new Theme(
"Light." + colourtheme.Key,
"Light." + colourtheme.Key,
"Light",
colourtheme.Key,
colourtheme.Value,
brush,
true,
false)
);
// Add dark theme
ThemeManager.Current.AddTheme(new Theme(
"Dark." + colourtheme.Key,
"Dark." + colourtheme.Key,
"Dark",
colourtheme.Key,
colourtheme.Value,
brush,
true,
false)
);
}
}
private void InitialiseTime() { private void InitialiseTime() {
DateTime today = DateTime.Today; DateTime today = DateTime.Today;
DateTime tomorrow = today.AddDays(1); DateTime tomorrow = today.AddDays(1);
// HOCHKULTUR startdate.SelectedDate = today;
startdate.Culture = enddate.Culture = CultureInfo.GetCultureInfo("de-AT"); enddate.SelectedDate = tomorrow;
startdate.SelectedDateTime = today;
enddate.SelectedDateTime = tomorrow;
} }
private void TreeView_CheckBox_Updated(object sender, RoutedEventArgs args) { private void TreeView_CheckBox_Updated(object sender, RoutedEventArgs args) {
@ -163,7 +88,7 @@ public partial class MainWindow : Window {
builder.Append(message); builder.Append(message);
builder.Append("\n"); builder.Append("\n");
log.AppendText(builder.ToString()); log.Text = log.Text + builder.ToString();
} }
private void Log(string message) { private void Log(string message) {
@ -209,7 +134,9 @@ public partial class MainWindow : Window {
} }
private void HandleEntries(List<Entry> entries) { private void HandleEntries(List<Entry> entries) {
HandleEntries(entries, startdate.SelectedDateTime ?? DateTime.Now, enddate.SelectedDateTime ?? DateTime.Now); HandleEntries(entries,
startdate.SelectedDate?.Date ?? DateTime.Now,
enddate.SelectedDate?.Date ?? DateTime.Now);
} }
private void Loadentries_EntriesLoaded(List<Entry> lines) { private void Loadentries_EntriesLoaded(List<Entry> lines) {
@ -220,8 +147,8 @@ public partial class MainWindow : Window {
try { try {
TransactionParser parser = new TransactionParser(); TransactionParser parser = new TransactionParser();
DateTime start = startdate.SelectedDateTime ?? DateTime.Now; DateTime start = startdate.SelectedDate?.Date ?? DateTime.Now;
DateTime end = enddate.SelectedDateTime ?? DateTime.Now; DateTime end = enddate.SelectedDate?.Date ?? DateTime.Now;
journal.Open(); // Load all files journal.Open(); // Load all files
// Log files only get rotated if you restart the game client. This means that there might // Log files only get rotated if you restart the game client. This means that there might
@ -314,15 +241,11 @@ public partial class MainWindow : Window {
} }
private void browsejournallocation_Click(object sender, RoutedEventArgs e) { private void browsejournallocation_Click(object sender, RoutedEventArgs e) {
var dialog = new VistaFolderBrowserDialog(); // TODO: dialog
if ((bool)!dialog.ShowDialog()) { //Config.Global.JournalLocation = dialog.SelectedPath;
return; //journallocation.Text = Config.Global.JournalLocation;
} //journal = new PlayerJournal(Config.Global.JournalLocation);
Config.Global.JournalLocation = dialog.SelectedPath;
journallocation.Text = Config.Global.JournalLocation;
journal = new PlayerJournal(Config.Global.JournalLocation);
} }
private Objective GetObjectiveFromControl(object sender) { private Objective GetObjectiveFromControl(object sender) {
@ -354,7 +277,6 @@ public partial class MainWindow : Window {
} }
private void RefreshView() { private void RefreshView() {
entries.Items.Refresh();
GenerateLog(); GenerateLog();
} }
@ -391,7 +313,7 @@ public partial class MainWindow : Window {
try { try {
Config.SaveGlobal(); Config.SaveGlobal();
} catch (Exception error) { } catch (Exception error) {
MessageBox.Show("There was an error saving your settings: " + error.Message); //TODO: MessageBox
} }
} }
@ -492,28 +414,6 @@ public partial class MainWindow : Window {
} }
} }
private DateTime ResetTimeToZero(DateTime d) {
DateTime obj = d;
obj = obj.AddHours(d.Hour * -1);
obj = obj.AddMinutes(d.Minute * -1);
obj = obj.AddSeconds(d.Second * -1);
return obj;
}
private void ResetTime_Click(object sender, RoutedEventArgs e) {
DateTime? d = startdate.SelectedDateTime;
if (d != null) {
startdate.SelectedDateTime = ResetTimeToZero(d.Value);
}
d = enddate.SelectedDateTime;
if (d != null) {
enddate.SelectedDateTime = ResetTimeToZero(d.Value);
}
}
private void ToggleAll_Click(object sender, RoutedEventArgs e) { private void ToggleAll_Click(object sender, RoutedEventArgs e) {
ToggleButton button = sender as ToggleButton; ToggleButton button = sender as ToggleButton;
Objective objective = GetObjectiveFromControl(sender); Objective objective = GetObjectiveFromControl(sender);
@ -526,49 +426,16 @@ public partial class MainWindow : Window {
; ;
} }
private void UpdateTheme() {
ThemeManager.Current.ChangeTheme(this, Config.Global.FullTheme);
}
private void SwitchTheme_Toggled(object sender, RoutedEventArgs e) {
ToggleSwitch toggle = sender as ToggleSwitch;
if (toggle.IsOn) {
Config.Global.Theme = "Dark";
} else {
Config.Global.Theme = "Light";
}
UpdateTheme();
}
private void Colour_SelectionChanged(object sender, SelectionChangedEventArgs e) {
if (Colour.SelectedItem == null) {
return;
}
Config.Global.Colour = Colour.SelectedItem.ToString();
UpdateTheme();
}
/*
private void URL_RequestNavigate(object sender, RequestNavigateEventArgs e) {
ProcessStartInfo info = new ProcessStartInfo();
info.UseShellExecute = true;
info.FileName = e.Uri.AbsoluteUri;
Process.Start(info);
e.Handled = true;
}
*/
private void NoInfluenceSupport_Toggled(object sender, RoutedEventArgs e) { private void NoInfluenceSupport_Toggled(object sender, RoutedEventArgs e) {
Config.Global.IgnoreInfluenceSupport = this.NoInfluenceSupport.IsOn; Config.Global.IgnoreInfluenceSupport = (bool)this.NoInfluenceSupport.IsChecked;
} }
private void NoMarketBuy_Toggled(object sender, RoutedEventArgs e) { private void NoMarketBuy_Toggled(object sender, RoutedEventArgs e) {
Config.Global.IgnoreMarketBuy = this.NoMarketBuy.IsOn; Config.Global.IgnoreMarketBuy = (bool)this.NoMarketBuy.IsChecked;
} }
private void NoFleetCarrier_Toggled(object sender, RoutedEventArgs e) { private void NoFleetCarrier_Toggled(object sender, RoutedEventArgs e) {
Config.Global.IgnoreFleetCarrier = this.NoFleetCarrier.IsOn; Config.Global.IgnoreFleetCarrier = (bool)this.NoFleetCarrier.IsChecked;
} }
private void OpenInExplorer_Click(object sender, RoutedEventArgs e) { private void OpenInExplorer_Click(object sender, RoutedEventArgs e) {
@ -592,7 +459,6 @@ public partial class MainWindow : Window {
Name = "Discord Server Name", Name = "Discord Server Name",
Webhook = "..." Webhook = "..."
}); });
Webhooks.Items.Refresh();
RefreshPostMenu(); RefreshPostMenu();
} }
@ -608,17 +474,16 @@ public partial class MainWindow : Window {
foreach (var item in selection) { foreach (var item in selection) {
Config.Global.Webhooks.Remove(item); Config.Global.Webhooks.Remove(item);
} }
Webhooks.Items.Refresh();
RefreshPostMenu(); RefreshPostMenu();
} }
private void Webhooks_KeyUp(object sender, KeyEventArgs e) { private void Webhooks_KeyUp(object sender, KeyEventArgs e) {
DataGridCell cell = e.OriginalSource as DataGridCell; DataGridCell cell = e.Source as DataGridCell;
/* We also get keypresses from DataGridCells that are currently /* We also get keypresses from DataGridCells that are currently
* editing their content. Filter those out. We don't want to delete * editing their content. Filter those out. We don't want to delete
* the row when the user presses DEL while editing the cells content * the row when the user presses DEL while editing the cells content
*/ */
if (cell == null || cell.IsEditing) { if (cell == null) {
return; return;
} }
if (e.Key == Key.Delete) { if (e.Key == Key.Delete) {
@ -667,12 +532,7 @@ public partial class MainWindow : Window {
try { try {
chunks = discord.SplitLog(DiscordLog.Text); chunks = discord.SplitLog(DiscordLog.Text);
} catch (Exception) { } catch (Exception) {
MessageBox.Show( //TODO: Messagebox
"The log could not be split into discord appropriate length.\n" +
"This happens with the bigger logs formats if you do lots of things in one system.\n" +
"Try posting the log in the OneLine format.",
"Sorry!", MessageBoxButton.OK, MessageBoxImage.Error
);
return; return;
} }