-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Import items to types.xml from list of class names; * Import items to trader config from list of class names
- Loading branch information
Showing
12 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/DayzServerTools.Application/Models/IClassnameImportDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using DayzServerTools.Application.Stores; | ||
|
||
namespace DayzServerTools.Application.Models; | ||
|
||
public interface IClassnameImportDialog | ||
{ | ||
IClassnameImportStore Store { get; set; } | ||
bool? ShowDialog(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/DayzServerTools.Application/Stores/ItemTypesClassnameImportStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using DayzServerTools.Application.Extensions; | ||
using DayzServerTools.Application.ViewModels; | ||
using DayzServerTools.Library.Trader; | ||
using DayzServerTools.Library.Xml; | ||
|
||
namespace DayzServerTools.Application.Stores; | ||
|
||
public interface IClassnameImportStore | ||
{ | ||
void Accept(IEnumerable<string> classnames); | ||
} | ||
|
||
public class ItemTypesClassnameImportStore : IClassnameImportStore | ||
{ | ||
private readonly ItemTypesViewModel _viewModel; | ||
|
||
public ItemTypesClassnameImportStore(ItemTypesViewModel viewModel) | ||
{ | ||
_viewModel = viewModel; | ||
} | ||
|
||
public void Accept(IEnumerable<string> classnames) | ||
{ | ||
var itemTypes = classnames.Select(name => new ItemType() { Name = name }); | ||
_viewModel.CopyItemTypes(itemTypes); | ||
} | ||
} | ||
|
||
public class TraderCategoryClassnameImportStore : IClassnameImportStore | ||
{ | ||
private readonly TraderCategoryViewModel _viewModel; | ||
|
||
public TraderCategoryClassnameImportStore(TraderCategoryViewModel viewModel) | ||
{ | ||
_viewModel = viewModel; | ||
} | ||
|
||
public void Accept(IEnumerable<string> classnames) | ||
{ | ||
var traderItems = classnames.Select(name => new TraderItem() { Name = name }); | ||
var viewModels = traderItems.Select(item => new TraderItemViewModel(item)); | ||
|
||
_viewModel.Items.AddRange(viewModels); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/DayzServerTools.Application/ViewModels/ClassnamesImportViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Text.RegularExpressions; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
|
||
using DayzServerTools.Application.Stores; | ||
|
||
namespace DayzServerTools.Application.ViewModels; | ||
|
||
public partial class ClassnamesImportViewModel : ObservableObject | ||
{ | ||
private readonly IClassnameImportStore _importStore; | ||
[ObservableProperty] | ||
private string rawInput = ""; | ||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(ImportCommand))] | ||
private IEnumerable<string> classnames = new List<string>(); | ||
|
||
public IRelayCommand<IEnumerable<string>> ImportCommand { get; } | ||
public IRelayCommand ParseCommand { get; } | ||
public event EventHandler CloseRequested; | ||
|
||
public ClassnamesImportViewModel(IClassnameImportStore importStore) | ||
{ | ||
_importStore = importStore; | ||
|
||
ImportCommand = new RelayCommand<IEnumerable<string>>(Import, CanImport); | ||
ParseCommand = new RelayCommand(Parse); | ||
} | ||
|
||
protected bool CanImport(IEnumerable<string> classnames) | ||
=> classnames?.Any() ?? false; | ||
protected void Import(IEnumerable<string> classnames) | ||
{ | ||
_importStore.Accept(classnames); | ||
CloseRequested?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
protected void Parse() | ||
{ | ||
if (!string.IsNullOrWhiteSpace(rawInput)) | ||
{ | ||
var regex = new Regex(@"\w+"); | ||
Classnames = regex.Matches(RawInput).Select(m => m.Value).ToList(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/DayzServerTools.Windows/Models/WindowsClassnameImportDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using DayzServerTools.Application.Models; | ||
using DayzServerTools.Application.Stores; | ||
using DayzServerTools.Application.ViewModels; | ||
using DayzServerTools.Windows.Views; | ||
|
||
namespace DayzServerTools.Windows.Models; | ||
|
||
internal class WindowsClassnameImportDialog : IClassnameImportDialog | ||
{ | ||
public IClassnameImportStore Store { get; set; } | ||
|
||
public bool? ShowDialog() | ||
{ | ||
var vm = new ClassnamesImportViewModel(Store); | ||
var window = new ClassnamesImportView(vm); | ||
return window.ShowDialog(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/DayzServerTools.Windows/Views/ClassnamesImportView.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Window x:Class="DayzServerTools.Windows.Views.ClassnamesImportView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:DayzServerTools.Windows.Views" | ||
mc:Ignorable="d" | ||
Title="Import items from class names" | ||
WindowStartupLocation="CenterScreen" | ||
WindowStyle="ToolWindow" | ||
Height="450" Width="400"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="2*"/> | ||
<RowDefinition Height="auto"/> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="auto"/> | ||
</Grid.RowDefinitions> | ||
<GroupBox Grid.Row="0" Header="Paste class names:"> | ||
<TextBox Text="{Binding RawInput}" TextWrapping="Wrap" | ||
VerticalScrollBarVisibility="Auto" | ||
AcceptsReturn="True"/> | ||
</GroupBox> | ||
<Button Grid.Row="1" Content="Parse" Command="{Binding ParseCommand}"/> | ||
<GroupBox Grid.Row="2" Header="Items to be imported:"> | ||
<ListView ItemsSource="{Binding Classnames}"/> | ||
</GroupBox> | ||
<Button Grid.Row="3" Content="Import" Command="{Binding ImportCommand}" | ||
CommandParameter="{Binding Classnames}"/> | ||
</Grid> | ||
</Window> |
39 changes: 39 additions & 0 deletions
39
src/DayzServerTools.Windows/Views/ClassnamesImportView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using DayzServerTools.Application.ViewModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
|
||
namespace DayzServerTools.Windows.Views | ||
{ | ||
/// <summary> | ||
/// Interaction logic for ClassnamesImportView.xaml | ||
/// </summary> | ||
public partial class ClassnamesImportView : Window | ||
{ | ||
private readonly ClassnamesImportViewModel _model; | ||
public ClassnamesImportView(ClassnamesImportViewModel model) | ||
{ | ||
InitializeComponent(); | ||
_model = model; | ||
DataContext = _model; | ||
_model.CloseRequested += OnCloseRequested; | ||
} | ||
|
||
private void OnCloseRequested(object sender, EventArgs e) | ||
{ | ||
DialogResult = true; | ||
_model.CloseRequested -= OnCloseRequested; | ||
Close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters