From 1362e53d6b190d122a28279ecfefc3674a2497d1 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sun, 24 Jul 2022 13:27:53 +0200 Subject: [PATCH] allow adding combat zone wins even if an entry is selected --- MainWindow.xaml.cs | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index b368957..f6618a1 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -206,18 +206,42 @@ namespace EliteBGS { } } - private void AddCombatZone_Click(object sender, RoutedEventArgs e) { - if (entries.SelectedItem == null) { - return; - } - + /// + /// Gets the currently selected objective, even if a log entry in said objective + /// is selected instead. If nothing is selected, returns null. + /// + /// + private Objective GetSelectedObjective() { var obj = entries.SelectedItem; - if (obj.GetType() != typeof(Objective)) { - return; + if (obj == null) { + return null; } - Objective objective = obj as Objective; + if (obj.GetType() == typeof(Objective)) { + return obj as Objective; + } + + // Some form of entry perhaps? + if (obj.GetType().IsSubclassOf(typeof(LogEntry))) { + LogEntry entry = obj as LogEntry; + Objective objective = entries.Items + .OfType() + .First(x => x.LogEntries.Contains(entry)) + ; + + return objective; + } + + return null; + } + + private void AddCombatZone_Click(object sender, RoutedEventArgs e) { + Objective objective = GetSelectedObjective(); + + if (objective == null) { + return; + } CombatZoneDialog dialog = new CombatZoneDialog() { Owner = this };