also allow changing of profit through tree view

This commit is contained in:
Florian Stinglmayr 2022-11-26 17:09:01 +01:00
parent 697cbc2bc6
commit 10351af7f9
3 changed files with 46 additions and 22 deletions

View File

@ -82,7 +82,7 @@
<TextBlock Text="{Binding Name}" FontWeight="DemiBold" TextAlignment="Center"/> <TextBlock Text="{Binding Name}" FontWeight="DemiBold" TextAlignment="Center"/>
</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" Orientation="Horizontal" HorizontalAlignment="Right" x:Name="CombatZone"> <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" x:Name="CombatZone" Visibility="{Binding IsCombatZone}">
<Button x:Name="Low" Content="Low" Click="Low_Click"/> <Button x:Name="Low" Content="Low" Click="Low_Click"/>
<Separator Margin="2,0,2,0" VerticalAlignment="Top"/> <Separator Margin="2,0,2,0" VerticalAlignment="Top"/>
<Button Content="Med" x:Name="Med" Click="Med_Click" /> <Button Content="Med" x:Name="Med" Click="Med_Click" />
@ -93,6 +93,10 @@
<Separator Margin="2,0,2,0" VerticalAlignment="Top"/> <Separator Margin="2,0,2,0" VerticalAlignment="Top"/>
<Button Content="Ship" x:Name="Ship" Click="Ship_Click"/> <Button Content="Ship" x:Name="Ship" Click="Ship_Click"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" x:Name="SellCargo" Visibility="{Binding IsSellCargo}">
<TextBlock Text="Adjust Profit: " TextAlignment="Center" />
<TextBox x:Name="Profit" MinWidth="80" HorizontalContentAlignment="Right" Text="{Binding Profit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextChanged="Profit_TextChanged"/>
</StackPanel>
</Grid> </Grid>
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate> </HierarchicalDataTemplate.ItemTemplate>

View File

@ -315,27 +315,6 @@ public partial class MainWindow : Window {
} }
private void Transaction_Initialized(object sender, EventArgs e) { private void Transaction_Initialized(object sender, EventArgs e) {
Grid grid = sender as Grid;
if (grid == null || grid.DataContext == null) {
return;
}
UITransaction t = grid.DataContext as UITransaction;
if (t == null) {
return;
}
bool iscombatzone = (t.Transaction.GetType() == typeof(CombatZone));
var children = grid
.Children
.OfType<StackPanel>()
.Where(x => x.Name == "CombatZone")
;
foreach (var child in children ) {
child.Visibility = (iscombatzone ? Visibility.Visible : Visibility.Collapsed);
}
} }
private TransactionType GetTransaction<TransactionType>(object sender) where TransactionType : Transaction { private TransactionType GetTransaction<TransactionType>(object sender) where TransactionType : Transaction {
@ -401,4 +380,8 @@ public partial class MainWindow : Window {
transaction.Type = "Ship"; transaction.Type = "Ship";
RefreshView(); RefreshView();
} }
private void Profit_TextChanged(object sender, TextChangedEventArgs e) {
RefreshView();
}
} }

View File

@ -4,6 +4,7 @@ using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
using EDPlayerJournal.BGS; using EDPlayerJournal.BGS;
using System.Linq; using System.Linq;
using System.Windows;
namespace EliteBGS; namespace EliteBGS;
@ -12,6 +13,42 @@ public class UITransaction {
public bool IsExpanded { get; set; } = true; public bool IsExpanded { get; set; } = true;
public Visibility IsCombatZone {
get {
return (Transaction != null && Transaction.GetType() == typeof(CombatZone)) ? Visibility.Visible : Visibility.Hidden;
}
}
public Visibility IsSellCargo {
get {
return (Transaction != null && Transaction.GetType() == typeof(SellCargo)) ? Visibility.Visible : Visibility.Hidden;
}
}
/// <summary>
/// Profit from selling, used in the XAML ui for binding
/// </summary>
public string Profit {
get {
SellCargo cargo = Transaction as SellCargo;
if (cargo == null) {
return "";
}
return cargo.Profit.ToString();
}
set {
SellCargo cargo = Transaction as SellCargo;
if (cargo == null) {
return;
}
try {
long profit_as_number = Convert.ToInt64(value);
cargo.Profit = profit_as_number;
} catch (FormatException) {
}
}
}
public Transaction Transaction { get; set; } public Transaction Transaction { get; set; }
public UITransaction() { } public UITransaction() { }