From b49be9883e3d8aeb9b04aeab73fb922a5c4689f1 Mon Sep 17 00:00:00 2001 From: Ilya Kozhemyakin Date: Tue, 20 May 2025 01:23:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pf2eDataScrapper/Program.cs | 2 + .../WPF/Components/EntityViewControl.xaml | 57 ++++++++++++++----- .../WPF/Components/EntityViewControl.xaml.cs | 4 +- .../EntityViewStructure/StructureRow.cs | 45 +++++++-------- .../WPF/ViewModels/EntityViewViewModel.cs | 9 +-- 5 files changed, 68 insertions(+), 49 deletions(-) diff --git a/Pf2eDataScrapper/Program.cs b/Pf2eDataScrapper/Program.cs index 6fc7b65..71d8b6c 100644 --- a/Pf2eDataScrapper/Program.cs +++ b/Pf2eDataScrapper/Program.cs @@ -30,6 +30,8 @@ internal static class Program ImportApplication app = ActivatorUtilities.CreateInstance( serviceProvider ); + + Application.Run(app); } private static IServiceCollection RegisterServices() diff --git a/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml b/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml index cfc9f51..e525e0c 100644 --- a/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml +++ b/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml @@ -40,27 +40,56 @@ - + - + - - - - - - - - - + + + + - + + - - + + diff --git a/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml.cs b/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml.cs index 8080899..842ef58 100644 --- a/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml.cs +++ b/Pf2eDataScrapper/WPF/Components/EntityViewControl.xaml.cs @@ -24,7 +24,7 @@ namespace Pf2eDataScrapper.WPF.Components; internal partial class EntityViewControl : System.Windows.Controls.UserControl { - public EntityViewViewModel ViewModel + public EntityViewViewModel? ViewModel { get => _viewModel; set @@ -33,7 +33,7 @@ internal partial class EntityViewControl : System.Windows.Controls.UserControl DataContext = ViewModel; } } - private EntityViewViewModel _viewModel; + private EntityViewViewModel? _viewModel; #region "Поля элемента управления" diff --git a/Pf2eDataScrapper/WPF/ViewModels/EntityViewStructure/StructureRow.cs b/Pf2eDataScrapper/WPF/ViewModels/EntityViewStructure/StructureRow.cs index 28991e7..4d0a76c 100644 --- a/Pf2eDataScrapper/WPF/ViewModels/EntityViewStructure/StructureRow.cs +++ b/Pf2eDataScrapper/WPF/ViewModels/EntityViewStructure/StructureRow.cs @@ -1,13 +1,10 @@ -using System.CodeDom; -using System.Globalization; -using System.Security.Cryptography; +using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Media; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header; -using Brush = System.Windows.Media.Brush; using Brushes = System.Windows.Media.Brushes; -using Color = System.Windows.Media.Color; +using Image = System.Windows.Controls.Image; namespace Pf2eDataScrapper.WPF.ViewModels.EntityViewStructure; @@ -33,6 +30,11 @@ internal class StructureRow(StructureField item) /// public bool Visible => Item.Visible; + /// + /// Флаг, указывающий, отображается ли строка. + /// + public Visibility ButtonVisibility => HasButton ? Visibility.Visible : Visibility.Collapsed; + /// /// Глубина отображения поля. /// @@ -68,9 +70,6 @@ internal class StructureRow(StructureField item) // [ValueConversion(typeof(IEnumerable), typeof(Image), ParameterType = typeof(int))] public class LadderToImageConverter : IMultiValueConverter { - #region IValueConverter Members - - public object? Convert( object[] value, Type targetType, @@ -78,7 +77,10 @@ public class LadderToImageConverter : IMultiValueConverter System.Globalization.CultureInfo culture ) { - if (value.Length != 2) + if ( + value.Length != 2 + || !value[0].GetType().IsAssignableTo(typeof(IEnumerable)) + ) { return null; } @@ -91,19 +93,14 @@ public class LadderToImageConverter : IMultiValueConverter } int n = ladder.Count(); - if (!int.TryParse((string)value[1], out int itemHeight)) - { - return null; - } + int itemHeight = (int)value[1]; DrawingGroup result = new(); - // Rectangle - result.Children.Add( new GeometryDrawing() { - Geometry = new RectangleGeometry(new(0, 0, n * 100, 100)), + Geometry = new RectangleGeometry(new(0, 0, n * itemHeight, itemHeight)), Pen = new(Brushes.Transparent, 0), } ); @@ -116,16 +113,13 @@ public class LadderToImageConverter : IMultiValueConverter } ); - return result; + return new DrawingImage(result); } private GeometryGroup GetLadderGeometryGroup(IEnumerable ladder, int h) { - float h2 = h * 0.5f; GeometryGroup geometryGroup = new(); - - //geometryGroup.Children.Add(new RectangleGeometry(new(0, 0, ladder.Count() * 100, 100))); - + float h2 = h * 0.5f; int i = 0; foreach (LadderType ladderType in ladder) @@ -139,20 +133,23 @@ public class LadderToImageConverter : IMultiValueConverter new LineGeometry(new(i * h + h2, 0), new(i * h + h2, h2)) ); geometryGroup.Children.Add( - new LineGeometry(new(i * h + h2, 50), new(i * h + h, h2)) + new LineGeometry(new(i * h + h2, h2), new(i * h + h, h2)) ); break; + case LadderType.Through: geometryGroup.Children.Add( new LineGeometry(new(i * h + h2, 0), new(i * h + h2, h)) ); + if (i == ladder.Count() - 1) { geometryGroup.Children.Add( - new LineGeometry(new(i * h + h2, h2), new(i * h + h2, h2)) + new LineGeometry(new(i * h + h2, h2), new(i * h + h, h2)) ); } break; + default: throw new ArgumentOutOfRangeException(nameof(ladder)); } @@ -172,6 +169,4 @@ public class LadderToImageConverter : IMultiValueConverter { throw new NotSupportedException(); } - - #endregion } diff --git a/Pf2eDataScrapper/WPF/ViewModels/EntityViewViewModel.cs b/Pf2eDataScrapper/WPF/ViewModels/EntityViewViewModel.cs index a89abd2..36171af 100644 --- a/Pf2eDataScrapper/WPF/ViewModels/EntityViewViewModel.cs +++ b/Pf2eDataScrapper/WPF/ViewModels/EntityViewViewModel.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Data; -using Pf2eDataScrapper.Forms.Controls.EntityTreeViewer; +using System.Collections.ObjectModel; using Pf2eDataScrapper.Helpers; using Pf2eDataScrapper.WPF.Stores; using Pf2eDataScrapper.WPF.ViewModels.EntityViewStructure;