2021-07-09 11:03:30 +02:00
|
|
|
|
using System;
|
2022-01-22 09:19:16 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
2021-07-09 11:03:30 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Ookii.Dialogs.Wpf;
|
2021-08-25 16:36:57 +02:00
|
|
|
|
using EDJournal;
|
2021-11-10 21:24:39 +01:00
|
|
|
|
using EliteBGS.BGS;
|
|
|
|
|
using EliteBGS.Util;
|
2021-08-25 16:36:57 +02:00
|
|
|
|
|
2021-11-10 21:24:39 +01:00
|
|
|
|
namespace EliteBGS {
|
2021-07-09 11:03:30 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window {
|
|
|
|
|
private PlayerJournal journal = null;
|
|
|
|
|
private Report report = new Report();
|
|
|
|
|
private Config config = new Config();
|
2021-07-29 21:07:53 +02:00
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
public Config Config => config;
|
|
|
|
|
|
|
|
|
|
public Report Report => report;
|
|
|
|
|
|
2022-04-06 16:15:03 +02:00
|
|
|
|
private LoadEntriesWindow loadentries = null;
|
2022-01-23 15:52:19 +01:00
|
|
|
|
|
2022-02-11 13:01:42 +01:00
|
|
|
|
private static readonly List<DiscordLogGenerator> logtypes = new List<DiscordLogGenerator>() {
|
2022-01-22 09:19:16 +01:00
|
|
|
|
new NonaDiscordLog(),
|
|
|
|
|
new GenericDiscordLog(),
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
public MainWindow() {
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
config.LoadGlobal();
|
|
|
|
|
} catch (Exception) {
|
|
|
|
|
/* ignored */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report.OnLog += Report_OnLog;
|
|
|
|
|
|
2022-02-11 13:01:42 +01:00
|
|
|
|
foreach (DiscordLogGenerator type in logtypes) {
|
2022-01-22 09:19:16 +01:00
|
|
|
|
LogType.Items.Add(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string lastused = config.Global.LastUsedDiscordTemplate;
|
|
|
|
|
int lastindex = logtypes.FindIndex(x => x.ToString() == lastused);
|
|
|
|
|
if (lastindex > -1) {
|
|
|
|
|
LogType.SelectedIndex = lastindex;
|
|
|
|
|
} else {
|
|
|
|
|
LogType.SelectedIndex = 0;
|
|
|
|
|
}
|
2022-01-06 16:24:20 +01:00
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
journal = new PlayerJournal(config.Global.JournalLocation);
|
|
|
|
|
|
|
|
|
|
// Set both to now
|
|
|
|
|
startdate.SelectedDate = DateTime.Now;
|
|
|
|
|
enddate.SelectedDate = DateTime.Now;
|
|
|
|
|
journallocation.Text = Config.Global.JournalLocation;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
config.LoadObjectives(Report);
|
|
|
|
|
RefreshObjectives();
|
2021-07-09 14:40:27 +02:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log(e.Message);
|
|
|
|
|
}
|
2021-07-13 17:46:06 +02:00
|
|
|
|
}
|
2021-07-09 14:40:27 +02:00
|
|
|
|
|
2022-01-23 15:52:19 +01:00
|
|
|
|
private void Loadentries_EntriesLoaded(List<Entry> lines) {
|
|
|
|
|
try {
|
|
|
|
|
report.Scan(lines);
|
|
|
|
|
RefreshObjectives();
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
Log("Something went terribly wrong while parsing the E:D player journal.");
|
|
|
|
|
Log("Please send this to CMDR Hekateh:");
|
|
|
|
|
Log(exception.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
private void Report_OnLog(string message) {
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append(DateTime.Now.ToString());
|
|
|
|
|
builder.Append(": ");
|
|
|
|
|
builder.Append(message);
|
|
|
|
|
builder.Append("\n");
|
|
|
|
|
|
|
|
|
|
log.AppendText(builder.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 14:40:27 +02:00
|
|
|
|
private void Log(string message) {
|
|
|
|
|
Report_OnLog(message);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
private void RefreshObjectives() {
|
|
|
|
|
entries.Items.Clear();
|
|
|
|
|
|
|
|
|
|
if (report.Objectives == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:13:01 +01:00
|
|
|
|
foreach (Objective obj in report.Objectives) {
|
|
|
|
|
entries.Items.Add(obj);
|
2022-04-06 16:02:51 +02:00
|
|
|
|
obj.IsExpanded = obj.ManuallyAdded || obj.IsExpanded;
|
|
|
|
|
obj.IsEnabled = obj.ManuallyAdded || obj.IsEnabled;
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ParseJournal_Click(object sender, RoutedEventArgs e) {
|
2022-01-06 16:40:55 +01:00
|
|
|
|
try {
|
|
|
|
|
journal.Open(); // Load all files
|
|
|
|
|
var start = startdate.SelectedDate ?? DateTime.Now;
|
2022-01-13 12:02:33 +01:00
|
|
|
|
var end = enddate.SelectedDate ?? DateTime.Now;
|
2022-01-06 16:40:55 +01:00
|
|
|
|
report.Scan(journal, start, end);
|
|
|
|
|
RefreshObjectives();
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
Log("Something went terribly wrong while parsing the E:D player journal.");
|
|
|
|
|
Log("Please send this to CMDR Hekateh:");
|
|
|
|
|
Log(exception.ToString());
|
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 11:24:46 +02:00
|
|
|
|
private void AddObjective() {
|
2021-07-09 11:03:30 +02:00
|
|
|
|
Objective objective = new Objective {
|
|
|
|
|
System = system.Text,
|
|
|
|
|
Faction = faction.Text,
|
2022-01-09 11:13:01 +01:00
|
|
|
|
Station = station.Text,
|
|
|
|
|
ManuallyAdded = true,
|
2021-07-09 11:03:30 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!objective.IsValid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (report.AddObjective(objective)) {
|
|
|
|
|
RefreshObjectives();
|
|
|
|
|
config.SaveObjectives(Report);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 11:24:46 +02:00
|
|
|
|
private void AddFilter_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
AddObjective();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 11:03:30 +02:00
|
|
|
|
private void GenerateDiscord_Click(object sender, RoutedEventArgs e) {
|
2022-01-06 16:40:55 +01:00
|
|
|
|
try {
|
2022-02-11 13:01:42 +01:00
|
|
|
|
DiscordLogGenerator discord = LogType.SelectedItem as DiscordLogGenerator;
|
2022-01-06 16:40:55 +01:00
|
|
|
|
string report = discord.GenerateDiscordLog(Report);
|
2021-07-09 11:03:30 +02:00
|
|
|
|
|
2022-01-06 16:40:55 +01:00
|
|
|
|
DiscordLog.Text = report;
|
2022-01-06 16:42:39 +01:00
|
|
|
|
} catch (Exception exception) {
|
2022-01-06 16:40:55 +01:00
|
|
|
|
Log("Something went terribly wrong while generating the Discord log.");
|
|
|
|
|
Log("Please send this to CMDR Hekateh:");
|
2022-01-06 16:42:39 +01:00
|
|
|
|
Log(exception.ToString());
|
2022-01-06 16:40:55 +01:00
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveCurrentObjective() {
|
|
|
|
|
if (entries.SelectedItem == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:13:01 +01:00
|
|
|
|
object obj = entries.SelectedItem;
|
2021-07-09 11:03:30 +02:00
|
|
|
|
bool removed = false;
|
|
|
|
|
|
|
|
|
|
if (obj.GetType() == typeof(Objective)) {
|
|
|
|
|
removed = report.Objectives.Remove(obj as Objective);
|
|
|
|
|
} else if (obj.GetType() == typeof(LogEntry) ||
|
|
|
|
|
obj.GetType().IsSubclassOf(typeof(LogEntry))) {
|
2022-01-09 11:13:01 +01:00
|
|
|
|
foreach (Objective parent in report.Objectives) {
|
|
|
|
|
if (parent.LogEntries.Remove(obj as LogEntry)) {
|
|
|
|
|
removed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (removed) {
|
|
|
|
|
RefreshObjectives();
|
|
|
|
|
config.SaveObjectives(Report);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void entries_KeyUp(object sender, KeyEventArgs e) {
|
|
|
|
|
if (e.Key == Key.Delete) {
|
|
|
|
|
RemoveCurrentObjective();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void browsejournallocation_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
var dialog = new VistaFolderBrowserDialog();
|
|
|
|
|
|
|
|
|
|
if ((bool)!dialog.ShowDialog()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Config.Global.JournalLocation = dialog.SelectedPath;
|
|
|
|
|
journallocation.Text = Config.Global.JournalLocation;
|
|
|
|
|
journal = new PlayerJournal(config.Global.JournalLocation);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 11:24:46 +02:00
|
|
|
|
private void Filter_KeyDown(object sender, KeyEventArgs e) {
|
|
|
|
|
if (e.Key == Key.Enter) {
|
|
|
|
|
AddObjective();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-29 21:07:53 +02:00
|
|
|
|
|
2022-07-24 13:27:53 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the currently selected objective, even if a log entry in said objective
|
|
|
|
|
/// is selected instead. If nothing is selected, returns null.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private Objective GetSelectedObjective() {
|
|
|
|
|
var obj = entries.SelectedItem;
|
|
|
|
|
|
|
|
|
|
if (obj == null) {
|
|
|
|
|
return null;
|
2021-09-28 14:14:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-24 13:27:53 +02:00
|
|
|
|
if (obj.GetType() == typeof(Objective)) {
|
|
|
|
|
return obj as Objective;
|
|
|
|
|
}
|
2021-09-28 14:14:16 +02:00
|
|
|
|
|
2022-07-24 13:27:53 +02:00
|
|
|
|
// Some form of entry perhaps?
|
|
|
|
|
if (obj.GetType().IsSubclassOf(typeof(LogEntry))) {
|
|
|
|
|
LogEntry entry = obj as LogEntry;
|
|
|
|
|
Objective objective = entries.Items
|
|
|
|
|
.OfType<Objective>()
|
|
|
|
|
.First(x => x.LogEntries.Contains(entry))
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
return objective;
|
2021-09-28 14:14:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-24 13:27:53 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddCombatZone_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
Objective objective = GetSelectedObjective();
|
|
|
|
|
|
|
|
|
|
if (objective == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-28 14:14:16 +02:00
|
|
|
|
|
|
|
|
|
CombatZoneDialog dialog = new CombatZoneDialog() { Owner = this };
|
|
|
|
|
|
|
|
|
|
if (!(dialog.ShowDialog() ?? false)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 08:03:51 +01:00
|
|
|
|
CombatZone zone = new CombatZone {
|
|
|
|
|
ManuallyAdded = true,
|
|
|
|
|
Faction = objective.Faction,
|
|
|
|
|
System = objective.System,
|
|
|
|
|
Station = objective.Station,
|
2021-09-28 14:14:16 +02:00
|
|
|
|
|
2022-01-10 08:03:51 +01:00
|
|
|
|
Grade = dialog.Grade,
|
|
|
|
|
Type = dialog.Type,
|
|
|
|
|
Amount = dialog.Amount
|
|
|
|
|
};
|
2021-09-28 14:14:16 +02:00
|
|
|
|
|
|
|
|
|
objective.LogEntries.Add(zone);
|
|
|
|
|
RefreshObjectives();
|
|
|
|
|
}
|
2022-01-12 17:29:58 +01:00
|
|
|
|
|
|
|
|
|
private void AdjustProfit_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
if (entries.SelectedItem == null || entries.SelectedItem.GetType() != typeof(SellCargo)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SellCargo sell = entries.SelectedItem as SellCargo;
|
|
|
|
|
AdjustProfitWindow adjust = new AdjustProfitWindow() { Owner = this };
|
|
|
|
|
|
|
|
|
|
adjust.Profit.Text = sell.Profit.ToString();
|
|
|
|
|
|
|
|
|
|
if (!(adjust.ShowDialog() ?? false)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(adjust.Profit.Text, out int newprofit)) {
|
|
|
|
|
sell.Profit = newprofit;
|
|
|
|
|
RefreshObjectives();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-22 09:19:16 +01:00
|
|
|
|
|
|
|
|
|
private void LogType_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
|
|
|
|
if (LogType.SelectedItem == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string template = LogType.SelectedItem.ToString();
|
|
|
|
|
config.Global.LastUsedDiscordTemplate = template;
|
|
|
|
|
}
|
2022-01-23 15:52:19 +01:00
|
|
|
|
|
|
|
|
|
private void ManuallyParse_Click(object sender, RoutedEventArgs e) {
|
2022-04-06 16:15:03 +02:00
|
|
|
|
if (loadentries != null) {
|
|
|
|
|
loadentries.Show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadentries = new LoadEntriesWindow();
|
|
|
|
|
loadentries.Closed += Loadentries_Closed;
|
|
|
|
|
loadentries.EntriesLoaded += Loadentries_EntriesLoaded;
|
2022-01-23 15:52:19 +01:00
|
|
|
|
loadentries.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-06 16:15:03 +02:00
|
|
|
|
private void Loadentries_Closed(object sender, EventArgs e) {
|
|
|
|
|
loadentries = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-23 15:52:19 +01:00
|
|
|
|
private void window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
2022-04-06 16:15:03 +02:00
|
|
|
|
loadentries?.Close();
|
|
|
|
|
loadentries = null;
|
2022-01-23 15:52:19 +01:00
|
|
|
|
}
|
2021-07-09 11:03:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|