add checkboxes to enable/disable objectives

This commit is contained in:
Florian Stinglmayr 2022-01-09 11:13:01 +01:00
parent 7f6311b888
commit ae7495632e
6 changed files with 59 additions and 22 deletions

View File

@ -197,6 +197,10 @@ namespace EliteBGS.BGS {
continue; continue;
} }
if (!objective.IsEnabled) {
continue;
}
log.AppendFormat("**Date:** {0}\n", FormatDate()); log.AppendFormat("**Date:** {0}\n", FormatDate());
log.AppendFormat("**Location:** {0}\n", objective.ToShortString()); log.AppendFormat("**Location:** {0}\n", objective.ToShortString());
log.AppendFormat("**Faction:** {0}\n", objective.Faction); log.AppendFormat("**Faction:** {0}\n", objective.Faction);

View File

@ -32,5 +32,7 @@ namespace EliteBGS.BGS {
public virtual int CompareTo(LogEntry other) { public virtual int CompareTo(LogEntry other) {
throw new NotImplementedException("not implemented"); throw new NotImplementedException("not implemented");
} }
public string Name => this.ToString();
} }
} }

View File

@ -196,6 +196,10 @@ namespace EliteBGS.BGS {
continue; continue;
} }
if (!objective.IsEnabled) {
continue;
}
log.AppendFormat(":globe_with_meridians: `Location:` {0}\n", objective.ToShortString()); log.AppendFormat(":globe_with_meridians: `Location:` {0}\n", objective.ToShortString());
log.Append(":clipboard: `Conducted:`\n"); log.Append(":clipboard: `Conducted:`\n");
log.Append("```\n"); log.Append("```\n");

View File

@ -11,11 +11,26 @@ namespace EliteBGS.BGS {
private List<LogEntry> entries = new List<LogEntry>(); private List<LogEntry> entries = new List<LogEntry>();
[JsonIgnore]
public bool IsEnabled { get; set; }
[JsonIgnore]
public List<LogEntry> Children {
get => entries;
}
[JsonIgnore]
public string Name => this.ToString();
[JsonIgnore]
public bool IsExpanded { get; set; }
[JsonIgnore] [JsonIgnore]
public List<LogEntry> LogEntries { public List<LogEntry> LogEntries {
get => entries; get => entries;
set => entries = value; set => entries = value;
} }
public void Clear() { public void Clear() {
if (entries == null) { if (entries == null) {
return; return;
@ -23,6 +38,8 @@ namespace EliteBGS.BGS {
entries.RemoveAll(x => !x.ManuallyAdded); entries.RemoveAll(x => !x.ManuallyAdded);
} }
public bool ManuallyAdded { get; set; }
public int Matches(LogEntry e) { public int Matches(LogEntry e) {
int match_count = 0; int match_count = 0;

View File

@ -48,7 +48,26 @@
<Label Content="To:" Height="26.2857142857143" VerticalAlignment="Top"/> <Label Content="To:" Height="26.2857142857143" VerticalAlignment="Top"/>
<DatePicker x:Name="enddate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/> <DatePicker x:Name="enddate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</ToolBar> </ToolBar>
<TreeView x:Name="entries" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="2" KeyUp="entries_KeyUp"/> <TreeView x:Name="entries" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="2" KeyUp="entries_KeyUp">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type BGS:Objective}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<CheckBox Focusable="False" IsChecked="{Binding IsEnabled}" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Name}" Margin="5,0" />
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
</Grid> </Grid>
</TabItem> </TabItem>
<TabItem Header="Discord Report"> <TabItem Header="Discord Report">

View File

@ -107,22 +107,10 @@ namespace EliteBGS {
return; return;
} }
foreach (var obj in report.Objectives) { foreach (Objective obj in report.Objectives) {
var item_objective = new TreeViewItem { entries.Items.Add(obj);
Header = obj.ToString(), obj.IsExpanded = obj.ManuallyAdded;
Tag = obj obj.IsEnabled = obj.ManuallyAdded;
};
foreach (var log in obj.LogEntries) {
var log_objective = new TreeViewItem {
Header = log.ToString(),
Tag = log
};
item_objective.Items.Add(log_objective);
}
item_objective.IsExpanded = true;
entries.Items.Add(item_objective);
} }
} }
@ -144,7 +132,8 @@ namespace EliteBGS {
Objective objective = new Objective { Objective objective = new Objective {
System = system.Text, System = system.Text,
Faction = faction.Text, Faction = faction.Text,
Station = station.Text Station = station.Text,
ManuallyAdded = true,
}; };
if (!objective.IsValid) { if (!objective.IsValid) {
@ -179,16 +168,18 @@ namespace EliteBGS {
return; return;
} }
TreeViewItem item = entries.SelectedItem as TreeViewItem; object obj = entries.SelectedItem;
var obj = item.Tag;
bool removed = false; bool removed = false;
if (obj.GetType() == typeof(Objective)) { if (obj.GetType() == typeof(Objective)) {
removed = report.Objectives.Remove(obj as Objective); removed = report.Objectives.Remove(obj as Objective);
} else if (obj.GetType() == typeof(LogEntry) || } else if (obj.GetType() == typeof(LogEntry) ||
obj.GetType().IsSubclassOf(typeof(LogEntry))) { obj.GetType().IsSubclassOf(typeof(LogEntry))) {
var parent = (item.Parent as TreeViewItem).Tag as Objective; foreach (Objective parent in report.Objectives) {
removed = parent.LogEntries.Remove(obj as LogEntry); if (parent.LogEntries.Remove(obj as LogEntry)) {
removed = true;
}
}
} }
if (removed) { if (removed) {