Skip to content

Commit

Permalink
Add import functionality to RandomPresets
Browse files Browse the repository at this point in the history
  • Loading branch information
rvost committed Oct 20, 2022
1 parent d51e6f5 commit 3c3a24a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System.Collections.ObjectModel;

using CommunityToolkit.Mvvm.ComponentModel;

using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using DayzServerTools.Application.Services;
using DayzServerTools.Application.Stores;
using DayzServerTools.Library.Xml;

namespace DayzServerTools.Application.ViewModels;

public class RandomPresetViewModel: ObservableObject
{
private RandomPreset _model;
private readonly IDialogFactory _dialogFactory;

public RandomPreset Model => _model;
public string Name
Expand All @@ -23,8 +27,20 @@ public double Chance
}
public ObservableCollection<SpawnableItem> Items => _model.Items;

public RelayCommand ImportClassnamesCommand { get; }

public RandomPresetViewModel(RandomPreset model)
{
_model=model;
}
_dialogFactory = Ioc.Default.GetRequiredService<IDialogFactory>();

ImportClassnamesCommand = new RelayCommand(ImportClassnames);
}

protected void ImportClassnames()
{
var dialog = _dialogFactory.CreateClassnameImportDialog();
dialog.Store = new PresetImportStore(Items);
dialog.ShowDialog();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;

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

using DayzServerTools.Application.Extensions;
Expand All @@ -13,6 +13,9 @@ namespace DayzServerTools.Application.ViewModels;

public partial class RandomPresetsViewModel : ProjectFileViewModel<RandomPresets>, IDisposable
{
[ObservableProperty]
private RandomPresetViewModel selectedPreset;

public ObservableCollection<RandomPresetViewModel> CargoPresets { get; } = new();
public ObservableCollection<RandomPresetViewModel> AttachmentsPresets { get; } = new();

Expand Down
11 changes: 9 additions & 2 deletions src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
x:Name="root"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<local:BindableMultiSelectDataGrid ItemsSource="{Binding ItemsSource, ElementName=root}"
<local:BindableMultiSelectDataGrid ItemsSource="{Binding ElementName=root, Path=ItemsSource}"
SelectedItem="{Binding ElementName=root, Path=SelectedItem}"
EnableRowVirtualization="False"
EnableColumnVirtualization="False"
VirtualizingPanel.ScrollUnit="Pixel"
Expand All @@ -21,7 +22,13 @@
<DataTemplate>
<StackPanel>
<TextBlock HorizontalAlignment="Center" Margin="0 2">Items:</TextBlock>
<DataGrid ItemsSource="{Binding Items}"/>
<DataGrid ItemsSource="{Binding Items}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Chance" Binding="{Binding Chance}"/>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ public ObservableCollection<RandomPresetViewModel> ItemsSource
get { return (ObservableCollection<RandomPresetViewModel>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public object SelectedItem
{
get { return GetValue(SelectedItemProperty); }
set { SetValue(SelectedItemProperty, value); }
}

public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(ObservableCollection<RandomPresetViewModel>), typeof(RandomPresetsGrid), new PropertyMetadata(default));
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.Register("SelectedItem", typeof(object), typeof(RandomPresetsGrid), new PropertyMetadata(default));

public RandomPresetsGrid()
{
Expand Down
4 changes: 4 additions & 0 deletions src/DayzServerTools.Windows/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
<fluent:Button Header="Add" Icon="{StaticResource AddAttachmentsRandomPresetVecIcon}"
Command="{Binding ActiveFile.NewAttachmentsPresetCommand}"/>
</fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Import">
<fluent:Button Header="Classnames" Icon="{StaticResource ImportVecIcon}"
Command="{Binding ActiveFile.SelectedPreset.ImportClassnamesCommand}"/>
</fluent:RibbonGroupBox>
</fluent:RibbonTabItem>
<!-- Item Types Tools Group -->
<!-- Item Types General -->
Expand Down
6 changes: 4 additions & 2 deletions src/DayzServerTools.Windows/Views/RandomPresetsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
Cargo
</TextBlock>
<controls:RandomPresetsGrid Grid.Row="1" Grid.Column="0"
ItemsSource="{Binding CargoPresets}"/>
ItemsSource="{Binding CargoPresets}"
SelectedItem="{Binding SelectedPreset, Mode=OneWayToSource}"/>
<!-- Attachments -->
<TextBlock Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Center"
FontSize="18" Margin="5 10">
Attachments
</TextBlock>
<controls:RandomPresetsGrid Grid.Row="1" Grid.Column="1"
ItemsSource="{Binding AttachmentsPresets}"/>
ItemsSource="{Binding AttachmentsPresets}"
SelectedItem="{Binding SelectedPreset, Mode=OneWayToSource}"/>
<GridSplitter Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Left" VerticalAlignment="Stretch"
ShowsPreview="true" ResizeDirection="Columns" BorderThickness="3" BorderBrush="LightGray"/>
</Grid>
Expand Down

0 comments on commit 3c3a24a

Please sign in to comment.