Skip to content

Commit

Permalink
Add Ribbon tab for Trader Config
Browse files Browse the repository at this point in the history
  • Loading branch information
rvost committed Oct 9, 2022
1 parent 282cef6 commit 0e36dd9
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections;
using System.Collections.ObjectModel;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
Expand All @@ -16,6 +17,9 @@ public partial class TraderCategoryViewModel : ObservableObject
private readonly IDialogFactory _dialogFactory;
[ObservableProperty]
private TraderCategory model;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CopyItemsCommand), nameof(MoveItemsCommand))]
private IList selectedItems;

public string Name
{
Expand All @@ -24,33 +28,40 @@ public string Name
}
public ObservableCollection<TraderItem> Items => model.TraderItems;

public IRelayCommand<object> CopyItemsCommand { get; }
public IRelayCommand<object> MoveItemsCommand { get; }
public IRelayCommand CopyItemsCommand { get; }
public IRelayCommand MoveItemsCommand { get; }

public TraderCategoryViewModel(TraderCategory model)
{
_dialogFactory = Ioc.Default.GetService<IDialogFactory>();
this.model = model;

CopyItemsCommand = new RelayCommand<object>(CopyItems);
MoveItemsCommand = new RelayCommand<object>(MoveItems);
CopyItemsCommand = new RelayCommand(CopyItems, () => CanExecuteBatchCommand());
MoveItemsCommand = new RelayCommand(MoveItems, () => CanExecuteBatchCommand());
}

public TraderCategoryViewModel() : this(new TraderCategory()) { }

private void CopyItems(object cmdParam)
protected bool CanExecuteBatchCommand() => SelectedItems is not null;
protected void CopyItems()
{
var list = (System.Collections.IList)cmdParam;
var items = list.Cast<TraderItem>();
if (SelectedItems is null)
{
return;
}
var items = SelectedItems.Cast<TraderItem>();

var dialog = _dialogFactory.CreateExportDialog();
dialog.Store = new TraderItemsExportStore(items, true);
dialog.ShowDialog();
}
private void MoveItems(object cmdParam)
protected void MoveItems()
{
var list = (System.Collections.IList)cmdParam;
var items = new List<TraderItem>(list.Cast<TraderItem>());
if (SelectedItems is null)
{
return;
}
var items = SelectedItems.Cast<TraderItem>();

var dialog = _dialogFactory.CreateExportDialog();
dialog.Store = new TraderItemsExportStore(items, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

using DayzServerTools.Application.ViewModels.Base;
using DayzServerTools.Application.Models;
Expand All @@ -13,6 +13,9 @@ namespace DayzServerTools.Application.ViewModels
{
public partial class TraderConfigViewModel : ProjectFileViewModel<TraderConfig>, IDisposable
{
[ObservableProperty]
private TraderViewModel selectedTrader;

public ObservableCollection<TraderViewModel> Traders { get; } = new();
public CurrencyCategory CurrencyCategory
{
Expand Down
27 changes: 20 additions & 7 deletions src/DayzServerTools.Application/ViewModels/TraderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public partial class TraderViewModel : ObservableObject, IDisposable
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(Name), nameof(Categories))]
private Trader model = new();
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(RemoveCategoryCommand))]
private TraderCategoryViewModel selectedCategory;

public string Name
{
Expand All @@ -32,10 +35,26 @@ public TraderViewModel(Trader trader)
);

AddCategoryCommand = new RelayCommand<string>(AddCategory);
RemoveCategoryCommand = new RelayCommand<TraderCategoryViewModel>(RemoveCategory);
RemoveCategoryCommand = new RelayCommand<TraderCategoryViewModel>(RemoveCategory, CanRemoveCategory);

Categories.CollectionChanged += CategoriesCollectionChanged;
}
protected void AddCategory(string categoryName)
=> Categories.Add(new(new TraderCategory() { CategoryName = categoryName }));
protected bool CanRemoveCategory(TraderCategoryViewModel category)
=> category is not null || SelectedCategory is not null;
protected void RemoveCategory(TraderCategoryViewModel category)
{
if (category is not null)
{
Categories.Remove(category);
}
else if (SelectedCategory is not null)
{
Categories.Remove(SelectedCategory);
SelectedCategory = null;
}
}

private void CategoriesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Expand All @@ -58,12 +77,6 @@ private void CategoriesCollectionChanged(object sender, NotifyCollectionChangedE
}
}

public void AddCategory(string categoryName)
=> Categories.Add(new(new TraderCategory() { CategoryName = categoryName }));

public void RemoveCategory(TraderCategoryViewModel category)
=> Categories.Remove(category);

public void Dispose()
{
Categories.CollectionChanged -= CategoriesCollectionChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public partial class WorkspaceViewModel : TabbedViewModel
[NotifyCanExecuteChangedFor(nameof(LoadUserDefinitionsCommand))]
private UserDefinitions userDefinitions = null;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(ActiveFileIsUserDefinitions), nameof(ActiveFileIsItemTypes))]
[NotifyPropertyChangedFor(nameof(ActiveFileIsUserDefinitions), nameof(ActiveFileIsItemTypes),
nameof(ActiveFileIsTraderConfig))]
private IProjectFileTab activeFile;
private object activePane;

Expand All @@ -53,6 +54,7 @@ public object ActivePane
}
public bool ActiveFileIsUserDefinitions => ActiveFile is UserDefinitionsViewModel;
public bool ActiveFileIsItemTypes => ActiveFile is ItemTypesViewModel;
public bool ActiveFileIsTraderConfig => ActiveFile is TraderConfigViewModel;
public ErrorsPaneViewModel ErrorsPaneViewModel => _errorsPaneViewModel;
[ObservableProperty]
private ObservableCollection<UserDefinableFlag> usages = new();
Expand Down
17 changes: 6 additions & 11 deletions src/DayzServerTools.Windows/Controls/TraderCategoryControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
CommandParameter="{Binding}"/>
</ContextMenu>
</UserControl.ContextMenu>
<Expander>
<Expander IsExpanded="{Binding Mode=OneWayToSource, Path=IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem, Mode=FindAncestor}}">
<Expander.Header>
<TextBox Text="{Binding Name}" d:Text="Category Name"
FontSize="18" FontWeight="SemiBold"
Expand All @@ -22,21 +22,16 @@
BorderThickness="0 0 0 2"
Background="Transparent"/>
</Expander.Header>
<DataGrid ItemsSource="{Binding Path=Items}" AutoGenerateColumns="False">
<local:BindableMultiSelectDataGrid ItemsSource="{Binding Path=Items}" AutoGenerateColumns="False"
SelectedItems="{Binding SelectedItems, Mode=OneWayToSource}">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy items to..."
Icon="{StaticResource CopyIcon}"
Command="{Binding CopyItemsCommand}"
CommandParameter="{Binding PlacementTarget.SelectedItems,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ContextMenu}}}"/>
Command="{Binding CopyItemsCommand}"/>
<MenuItem Header="Move items..."
Icon="{StaticResource ExportIcon}"
Command="{Binding MoveItemsCommand}"
CommandParameter="{Binding PlacementTarget.SelectedItems,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ContextMenu}}}"/>
Command="{Binding MoveItemsCommand}"/>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
Expand Down Expand Up @@ -69,6 +64,6 @@
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</local:BindableMultiSelectDataGrid>
</Expander>
</UserControl>
82 changes: 82 additions & 0 deletions src/DayzServerTools.Windows/Resources/IconsDictionary.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,38 @@
</Rectangle>
</Viewbox>

<Viewbox x:Key="CopyVecIcon" x:Shared="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
<Rectangle Width="16 " Height="16">
<Rectangle.Resources>
<SolidColorBrush x:Key="canvas" Opacity="0" />
<SolidColorBrush x:Key="light-defaultgrey-10" Color="#212121" Opacity="0.1" />
<SolidColorBrush x:Key="light-defaultgrey" Color="#212121" Opacity="1" />
<System:Double x:Key="cls-1">0.75</System:Double>
</Rectangle.Resources>
<Rectangle.Fill>
<DrawingBrush Stretch="None">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup x:Name="canvas">
<GeometryDrawing Brush="{DynamicResource canvas}" Geometry="F1M16,16H0V0H16Z" />
</DrawingGroup>
<DrawingGroup x:Name="level_1">
<DrawingGroup Opacity="{DynamicResource cls-1}">
<GeometryDrawing Brush="{DynamicResource light-defaultgrey-10}" Geometry="F1M14.5,1.5v10H10v-7L9.5,4h-3V1.5Z" />
<GeometryDrawing Brush="{DynamicResource light-defaultgrey}" Geometry="F1M6.5,1h8l.5.5v10l-.5.5H10V11h4V2H7V4H6V1.5Z" />
</DrawingGroup>
<GeometryDrawing Brush="{DynamicResource light-defaultgrey-10}" Geometry="F1M9.5,4.5v10h-8V4.5Z" />
<GeometryDrawing Brush="{DynamicResource light-defaultgrey}" Geometry="F1M1,4.5v10l.5.5h8l.5-.5V4.5L9.5,4h-8ZM2,5H9v9H2Z" />
</DrawingGroup>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>

<Viewbox x:Key="OpenVecIcon" x:Shared="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
Expand Down Expand Up @@ -244,6 +276,31 @@
</Rectangle>
</Viewbox>

<Viewbox x:Key="ExportVecIcon" x:Shared="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
<Rectangle Width="16 " Height="16">
<Rectangle.Resources>
<SolidColorBrush x:Key="canvas" Opacity="0" />
<SolidColorBrush x:Key="light-defaultgrey" Color="#212121" Opacity="1" />
</Rectangle.Resources>
<Rectangle.Fill>
<DrawingBrush Stretch="None">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup x:Name="canvas">
<GeometryDrawing Brush="{DynamicResource canvas}" Geometry="F1M16,16H0V0H16Z" />
</DrawingGroup>
<DrawingGroup x:Name="level_1">
<GeometryDrawing Brush="{DynamicResource light-defaultgrey}" Geometry="F1M4.646,1.646l.708.708L2.707,5H9.5a4.5,4.5,0,0,1,0,9V13a3.5,3.5,0,0,0,0-7H2.707L5.354,8.646l-.708.708-3.5-3.5V5.146Z" />
</DrawingGroup>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>

<Viewbox x:Key="ExportTraderVecIcon" x:Shared="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
Expand Down Expand Up @@ -424,6 +481,31 @@
</Rectangle>
</Viewbox>

<Viewbox x:Key="RemoveVecIcon" x:Shared="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
<Rectangle Width="16 " Height="16">
<Rectangle.Resources>
<SolidColorBrush x:Key="canvas" Opacity="0" />
<SolidColorBrush x:Key="light-red" Color="#c50b17" Opacity="1" />
</Rectangle.Resources>
<Rectangle.Fill>
<DrawingBrush Stretch="None">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup x:Name="canvas">
<GeometryDrawing Brush="{DynamicResource canvas}" Geometry="F1M16,16H0V0H16Z" />
</DrawingGroup>
<DrawingGroup x:Name="level_1">
<GeometryDrawing Brush="{DynamicResource light-red}" Geometry="F1M14,9H2V7H14Z" />
</DrawingGroup>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>

<Viewbox x:Key="ValidateVecIcon" x:Shared="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib">
Expand Down
44 changes: 42 additions & 2 deletions src/DayzServerTools.Windows/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
WindowState="Maximized"
d:Height="800" d:Width="1200">
<Window.Resources>
<Style TargetType="fluent:Button">
<Setter Property="IsEnabled" Value="True"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Command}"
Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ScaleButton" TargetType="Button">
<Setter Property="Height" Value="32"/>
<Setter Property="Width" Value="32"/>
Expand Down Expand Up @@ -119,6 +128,11 @@
BorderBrush="Orange"
x:Name="ItemTypesToolsGroup"
Visibility="{Binding ActiveFileIsItemTypes, Converter={StaticResource AvalonBoolToVisibilityConverter}, Mode=OneWay}" />
<fluent:RibbonContextualTabGroup Header="Trader"
Background="Gold"
BorderBrush="Gold"
x:Name="TraderConfigToolsGroup"
Visibility="{Binding ActiveFileIsTraderConfig, Converter={StaticResource AvalonBoolToVisibilityConverter}, Mode=OneWay}" />
</fluent:Ribbon.ContextualGroups>
<fluent:RibbonTabItem Header="Workspace">
<fluent:RibbonGroupBox Header="Limits Definitions" MinWidth="100"
Expand Down Expand Up @@ -204,6 +218,7 @@
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
<!-- Item Types Tools Group -->
<!-- Item Types General -->
<fluent:RibbonTabItem Header="General" Group="{Binding ElementName=ItemTypesToolsGroup}"
Visibility="{Binding ActiveFileIsItemTypes, Converter={StaticResource AvalonBoolToVisibilityConverter}, Mode=OneWay}">
<fluent:RibbonGroupBox Header="Edit">
Expand All @@ -224,8 +239,8 @@
Command="{Binding ActiveFile.ValidateCommand}"/>
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>

<fluent:RibbonTabItem Header="Batch Edit" Group="{Binding ElementName=ItemTypesToolsGroup}"
<!-- Item Types Batch Edit -->
<fluent:RibbonTabItem Header="Batch Edit" Group="{Binding ElementName=ItemTypesToolsGroup}"
Visibility="{Binding ActiveFileIsItemTypes, Converter={StaticResource AvalonBoolToVisibilityConverter}, Mode=OneWay}">
<fluent:RibbonGroupBox Header="Quantity">
<Button Content="×½" Style="{StaticResource ScaleButton}"
Expand Down Expand Up @@ -324,6 +339,31 @@
CommandParameter="{Binding ElementName=newTagComboBox, Path=SelectedItem}"/>
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
<!-- Trader Tools Tools Group -->
<fluent:RibbonTabItem Header="Trader Tools" Group="{Binding ElementName=TraderConfigToolsGroup}"
Visibility="{Binding ActiveFileIsTraderConfig, Converter={StaticResource AvalonBoolToVisibilityConverter}, Mode=OneWay}">
<fluent:RibbonGroupBox Header="Category">
<RibbonTextBox x:Name="newTraderCategoryTextBox" Label="New:"
Background="LightGray"
Padding="2" Margin="4"
Command="{Binding ActiveFile.SelectedTrader.AddCategoryCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
<fluent:Button Header="Add" Icon="{StaticResource AddVecIcon}"
Command="{Binding ActiveFile.SelectedTrader.AddCategoryCommand}"
CommandParameter="{Binding ElementName=newTraderCategoryTextBox, Path=Text}"/>
<fluent:Button Header="Remove" Icon="{StaticResource RemoveVecIcon}"
Command="{Binding ActiveFile.SelectedTrader.RemoveCategoryCommand}"
CommandParameter="{x:Null}"/>
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Items">
<fluent:Button Header="Copy to..."
Icon="{StaticResource CopyVecIcon}"
Command="{Binding ActiveFile.SelectedTrader.SelectedCategory.CopyItemsCommand}"/>
<fluent:Button Header="Move..."
Icon="{StaticResource ExportVecIcon}"
Command="{Binding ActiveFile.SelectedTrader.SelectedCategory.MoveItemsCommand}"/>
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
</fluent:Ribbon>
<xcad:DockingManager AllowMixedOrientation="True"
DocumentsSource="{Binding Tabs}"
Expand Down
Loading

0 comments on commit 0e36dd9

Please sign in to comment.