173 lines
4.8 KiB
C#
173 lines
4.8 KiB
C#
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
|
|
using Brushes = System.Windows.Media.Brushes;
|
|
using Image = System.Windows.Controls.Image;
|
|
|
|
namespace Pf2eDataScrapper.WPF.ViewModels.EntityViewStructure;
|
|
|
|
internal class StructureRow(StructureField item)
|
|
{
|
|
/// <summary>
|
|
/// Отображаемая строка поля сущности.
|
|
/// </summary>
|
|
public StructureField Item { get; } = item;
|
|
|
|
/// <summary>
|
|
/// Список типов лестницы.
|
|
/// </summary>
|
|
public List<LadderType> Ladder { get; set; } = [];
|
|
|
|
/// <summary>
|
|
/// Флаг наличия кнопки.
|
|
/// </summary>
|
|
public bool HasButton => Item.FieldType == StructureFieldType.Complex;
|
|
|
|
/// <summary>
|
|
/// Флаг, указывающий, отображается ли строка.
|
|
/// </summary>
|
|
public bool Visible => Item.Visible;
|
|
|
|
/// <summary>
|
|
/// Флаг, указывающий, отображается ли строка.
|
|
/// </summary>
|
|
public Visibility ButtonVisibility => HasButton ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
/// <summary>
|
|
/// Глубина отображения поля.
|
|
/// </summary>
|
|
public int Depth => Item.Depth;
|
|
|
|
/// <summary>
|
|
/// Строковое представление названия поля.
|
|
/// </summary>
|
|
public string Name => Item.Name;
|
|
|
|
/// <summary>
|
|
/// Строковое представление типа поля.
|
|
/// </summary>
|
|
public string Type
|
|
{
|
|
get
|
|
{
|
|
string result = Item.GetTypeString();
|
|
if (result != "")
|
|
{
|
|
result = $@"({result})";
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Строковое представление значения поля.
|
|
/// </summary>
|
|
public string Value => Item.GetValueString();
|
|
}
|
|
|
|
// [ValueConversion(typeof(IEnumerable<LadderType>), typeof(Image), ParameterType = typeof(int))]
|
|
public class LadderToImageConverter : IMultiValueConverter
|
|
{
|
|
public object? Convert(
|
|
object[] value,
|
|
Type targetType,
|
|
object? parameter,
|
|
System.Globalization.CultureInfo culture
|
|
)
|
|
{
|
|
if (
|
|
value.Length != 2
|
|
|| !value[0].GetType().IsAssignableTo(typeof(IEnumerable<LadderType>))
|
|
)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
IEnumerable<LadderType> ladder = (IEnumerable<LadderType>)value[0];
|
|
|
|
if (!ladder.Any())
|
|
{
|
|
return null;
|
|
}
|
|
|
|
int n = ladder.Count();
|
|
int itemHeight = (int)value[1];
|
|
|
|
DrawingGroup result = new();
|
|
|
|
result.Children.Add(
|
|
new GeometryDrawing()
|
|
{
|
|
Geometry = new RectangleGeometry(new(0, 0, n * itemHeight, itemHeight)),
|
|
Pen = new(Brushes.Transparent, 0),
|
|
}
|
|
);
|
|
|
|
result.Children.Add(
|
|
new GeometryDrawing()
|
|
{
|
|
Geometry = GetLadderGeometryGroup(ladder, itemHeight),
|
|
Pen = new(Brushes.Black, 1),
|
|
}
|
|
);
|
|
|
|
return new DrawingImage(result);
|
|
}
|
|
|
|
private GeometryGroup GetLadderGeometryGroup(IEnumerable<LadderType> ladder, int h)
|
|
{
|
|
GeometryGroup geometryGroup = new();
|
|
float h2 = h * 0.5f;
|
|
int i = 0;
|
|
|
|
foreach (LadderType ladderType in ladder)
|
|
{
|
|
switch (ladderType)
|
|
{
|
|
case LadderType.Empty:
|
|
break;
|
|
case LadderType.Last:
|
|
geometryGroup.Children.Add(
|
|
new LineGeometry(new(i * h + h2, 0), new(i * h + h2, h2))
|
|
);
|
|
geometryGroup.Children.Add(
|
|
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 + h, h2))
|
|
);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(ladder));
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
return geometryGroup;
|
|
}
|
|
|
|
public object[] ConvertBack(
|
|
object value,
|
|
Type[] targetTypes,
|
|
object parameter,
|
|
CultureInfo culture
|
|
)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|