add a toggle all

This commit is contained in:
Florian Stinglmayr 2022-12-14 19:28:23 +01:00
parent 93a76bc429
commit ba9b108e5e
3 changed files with 36 additions and 6 deletions

View File

@ -81,7 +81,9 @@
<TextBlock Text="{Binding Faction}" FontWeight="DemiBold" Visibility="{Binding HasFaction}"/> <TextBlock Text="{Binding Faction}" FontWeight="DemiBold" Visibility="{Binding HasFaction}"/>
</StackPanel> </StackPanel>
<Separator Visibility="Hidden" Grid.Column="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" /> <Separator Visibility="Hidden" Grid.Column="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" />
<StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center"> <StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
<ToggleButton x:Name="ToggleAll" Content="Toggle All" Click="ToggleAll_Click" IsChecked="True" IsThreeState="False"/>
<Separator Margin="2,0,2,0" />
<Button x:Name="AddCombatZone" Content="Add Combat Zone" Click="AddCombatZone_Click" /> <Button x:Name="AddCombatZone" Content="Add Combat Zone" Click="AddCombatZone_Click" />
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -13,6 +13,7 @@ using EliteBGS.BGS;
using EliteBGS.Util; using EliteBGS.Util;
using System.Globalization; using System.Globalization;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Controls.Primitives;
namespace EliteBGS; namespace EliteBGS;
@ -217,13 +218,17 @@ public partial class MainWindow : Window {
journal = new PlayerJournal(Config.Global.JournalLocation); journal = new PlayerJournal(Config.Global.JournalLocation);
} }
private void AddCombatZone_Click(object sender, RoutedEventArgs e) { private Objective GetObjectiveFromControl(object sender) {
System.Windows.Controls.Control control = sender as System.Windows.Controls.Control; System.Windows.Controls.Control control = sender as System.Windows.Controls.Control;
if (control == null || control.DataContext == null) { if (control == null || control.DataContext == null) {
return; return null;
} }
Objective objective = control.DataContext as Objective; return control.DataContext as Objective;
}
private void AddCombatZone_Click(object sender, RoutedEventArgs e) {
Objective objective = GetObjectiveFromControl(sender);
if (objective == null) { if (objective == null) {
return; return;
} }
@ -395,4 +400,16 @@ public partial class MainWindow : Window {
enddate.Value = ResetTimeToZero(d.Value); enddate.Value = ResetTimeToZero(d.Value);
} }
} }
private void ToggleAll_Click(object sender, RoutedEventArgs e) {
ToggleButton button = sender as ToggleButton;
Objective objective = GetObjectiveFromControl(sender);
if (objective == null) {
return;
}
objective.UITransactions
.ForEach(x => x.IsEnabled = (button.IsChecked ?? true))
;
}
} }

View File

@ -6,11 +6,22 @@ using EDPlayerJournal.BGS;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using EDPlayerJournal; using EDPlayerJournal;
using System.ComponentModel;
namespace EliteBGS; namespace EliteBGS;
public class UITransaction { public class UITransaction : INotifyPropertyChanged {
public bool IsEnabled { get; set; } = true; private bool isenabled = true;
public event PropertyChangedEventHandler PropertyChanged;
public bool IsEnabled {
get { return isenabled; }
set {
isenabled = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsEnabled"));
}
}
public bool IsExpanded { get; set; } = true; public bool IsExpanded { get; set; } = true;