Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5296687d14 | ||
|
|
fda74b661a | ||
|
|
e856f91f9e | ||
|
|
6ec4e43f9d | ||
|
|
c6548349b9 | ||
|
|
732988bd18 |
@@ -3,7 +3,7 @@
|
|||||||
"isRoot": true,
|
"isRoot": true,
|
||||||
"tools": {
|
"tools": {
|
||||||
"csharpier": {
|
"csharpier": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"commands": [
|
"commands": [
|
||||||
"csharpier"
|
"csharpier"
|
||||||
],
|
],
|
||||||
|
|||||||
+23
-7
@@ -1,5 +1,5 @@
|
|||||||
# Удалите строку ниже, если вы хотите наследовать параметры .editorconfig из каталогов, расположенных выше в иерархии
|
root = true
|
||||||
root = true
|
# Удалите строку ниже, если вы хотите наследовать параметры .editorconfig из каталогов, расположенных выше в иерархии
|
||||||
|
|
||||||
# Файлы C#
|
# Файлы C#
|
||||||
[*.cs]
|
[*.cs]
|
||||||
@@ -34,8 +34,8 @@ dotnet_search_reference_assemblies = true
|
|||||||
|
|
||||||
# Упорядочение Using
|
# Упорядочение Using
|
||||||
dotnet_separate_import_directive_groups = false
|
dotnet_separate_import_directive_groups = false
|
||||||
dotnet_sort_system_directives_first = false
|
dotnet_sort_system_directives_first = true
|
||||||
file_header_template = unset
|
file_header_template =
|
||||||
|
|
||||||
# Предпочтения для this. и Me.
|
# Предпочтения для this. и Me.
|
||||||
dotnet_style_qualification_for_event = false
|
dotnet_style_qualification_for_event = false
|
||||||
@@ -121,7 +121,7 @@ csharp_style_conditional_delegate_call = true
|
|||||||
# Предпочтения модификатора
|
# Предпочтения модификатора
|
||||||
csharp_prefer_static_anonymous_function = true
|
csharp_prefer_static_anonymous_function = true
|
||||||
csharp_prefer_static_local_function = true
|
csharp_prefer_static_local_function = true
|
||||||
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
|
csharp_preferred_modifier_order = public, private, protected, readonly, file, static, extern, internal, virtual, abstract, override, sealed, new, unsafe, required, volatile, async:suggestion
|
||||||
csharp_style_prefer_readonly_struct = true
|
csharp_style_prefer_readonly_struct = true
|
||||||
csharp_style_prefer_readonly_struct_member = true
|
csharp_style_prefer_readonly_struct_member = true
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ csharp_indent_labels = one_less_than_current
|
|||||||
csharp_indent_switch_labels = true
|
csharp_indent_switch_labels = true
|
||||||
|
|
||||||
# Предпочтения для интервалов
|
# Предпочтения для интервалов
|
||||||
csharp_space_after_cast = true
|
csharp_space_after_cast = false
|
||||||
csharp_space_after_colon_in_inheritance_clause = true
|
csharp_space_after_colon_in_inheritance_clause = true
|
||||||
csharp_space_after_comma = true
|
csharp_space_after_comma = true
|
||||||
csharp_space_after_dot = false
|
csharp_space_after_dot = false
|
||||||
@@ -249,6 +249,22 @@ dotnet_naming_style.begins_with_i.required_suffix =
|
|||||||
dotnet_naming_style.begins_with_i.word_separator =
|
dotnet_naming_style.begins_with_i.word_separator =
|
||||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||||
|
|
||||||
|
# ReSharper properties
|
||||||
|
resharper_accessor_owner_body = accessors_with_expression_body
|
||||||
|
resharper_blank_lines_after_multiline_statements = 1
|
||||||
|
resharper_csharp_blank_lines_around_single_line_field = 1
|
||||||
|
resharper_csharp_wrap_after_invocation_lpar = true
|
||||||
|
resharper_csharp_wrap_arguments_style = chop_if_long
|
||||||
|
resharper_csharp_wrap_before_invocation_rpar = true
|
||||||
|
resharper_instance_members_qualify_declared_in =
|
||||||
|
resharper_local_function_body = expression_body
|
||||||
|
resharper_parentheses_redundancy_style = remove
|
||||||
|
resharper_place_expr_accessor_on_single_line = true
|
||||||
|
resharper_place_expr_method_on_single_line = true
|
||||||
|
resharper_place_expr_property_on_single_line = true
|
||||||
|
resharper_trailing_comma_in_multiline_lists = true
|
||||||
|
resharper_use_heuristics_for_body_style = true
|
||||||
|
|
||||||
[*.{cs,vb}]
|
[*.{cs,vb}]
|
||||||
dotnet_style_coalesce_expression = true:suggestion
|
dotnet_style_coalesce_expression = true:suggestion
|
||||||
dotnet_style_null_propagation = true:suggestion
|
dotnet_style_null_propagation = true:suggestion
|
||||||
@@ -270,4 +286,4 @@ dotnet_code_quality_unused_parameters = all:suggestion
|
|||||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||||
tab_width = 4
|
tab_width = 4
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
dotnet_diagnostic.CA1822.severity = none
|
dotnet_diagnostic.ca1822.severity = none
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ EndProject
|
|||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{754FC069-D67B-A9D7-50A1-8D1CA196D8F1}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{754FC069-D67B-A9D7-50A1-8D1CA196D8F1}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.editorconfig = .editorconfig
|
.editorconfig = .editorconfig
|
||||||
|
.config\dotnet-tools.json = .config\dotnet-tools.json
|
||||||
README.md = README.md
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
namespace Pf2eViewer.EntityTreeViewer;
|
namespace Pf2eViewer.EntityTreeViewer;
|
||||||
|
|
||||||
partial class EntityTreeViewerControl
|
sealed partial class EntityTreeViewerControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обязательная переменная конструктора.
|
/// Обязательная переменная конструктора.
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
namespace Pf2eViewer.EntityTreeViewer;
|
using System.Collections.Generic;
|
||||||
|
using Pf2eViewer.EntityTreeViewer;
|
||||||
|
namespace Pf2eViewer.EntityTreeViewer;
|
||||||
|
|
||||||
public sealed partial class EntityTreeViewerControl : UserControl
|
public sealed partial class EntityTreeViewerControl : UserControl
|
||||||
|
public partial class EntityTreeViewerControl : UserControl
|
||||||
{
|
{
|
||||||
private int _itemHeight = 20;
|
private int _itemHeight = 20;
|
||||||
|
|
||||||
private EntityView? _entityView = null;
|
private EntityView? _entityView;
|
||||||
|
|
||||||
private int _depthSize = 20;
|
private int _depthSize = 20;
|
||||||
|
|
||||||
@@ -44,39 +47,15 @@ public sealed partial class EntityTreeViewerControl : UserControl
|
|||||||
|
|
||||||
private List<EntityTreeViewerRow> _viewerRows = [];
|
private List<EntityTreeViewerRow> _viewerRows = [];
|
||||||
|
|
||||||
public DarkModeCS? DarkMode;
|
|
||||||
|
|
||||||
public EntityTreeViewerControl()
|
public EntityTreeViewerControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DoubleBuffered = true;
|
DoubleBuffered = true;
|
||||||
|
|
||||||
ContentPanel.AutoScroll = false;
|
ContentPanel.AutoScroll = false;
|
||||||
ContentPanel.VerticalScroll.Enabled = true;
|
ContentPanel.HorizontalScroll.Maximum = 0;
|
||||||
ContentPanel.VerticalScroll.Visible = true;
|
ContentPanel.HorizontalScroll.Visible = false;
|
||||||
|
ContentPanel.AutoScroll = true;
|
||||||
ContentPanel.MouseWheel += ContentPanel_MouseWheel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int _visibleRows;
|
|
||||||
|
|
||||||
public int ScrollPosition
|
|
||||||
{
|
|
||||||
get => ContentPanel.VerticalScroll.Value / ItemHeight;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
VScrollProperties scrollBar = ContentPanel.VerticalScroll;
|
|
||||||
int oldValue = scrollBar.Value / ItemHeight;
|
|
||||||
int visibleItems = scrollBar.LargeChange / ItemHeight;
|
|
||||||
|
|
||||||
int scrollValue = Math.Min(Math.Max(value, 0), _visibleRows - visibleItems);
|
|
||||||
|
|
||||||
if (oldValue != scrollValue)
|
|
||||||
{
|
|
||||||
ContentPanel.VerticalScroll.Value = scrollValue * ItemHeight;
|
|
||||||
UpdateScroll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateData()
|
public void UpdateData()
|
||||||
@@ -110,8 +89,8 @@ public sealed partial class EntityTreeViewerControl : UserControl
|
|||||||
_viewerRows = _rows.SelectMany(r => r.GetTextRows(this)).ToList();
|
_viewerRows = _rows.SelectMany(r => r.GetTextRows(this)).ToList();
|
||||||
|
|
||||||
ContentPanel.Controls.Clear();
|
ContentPanel.Controls.Clear();
|
||||||
|
ContentPanel.Controls.AddRange(_viewerRows.ToArray<Control>());
|
||||||
ContentPanel.Controls.AddRange(_viewerRows.ToArray());
|
ContentPanel.Controls.AddRange(ViewerRows.ToArray());
|
||||||
|
|
||||||
UpdateView();
|
UpdateView();
|
||||||
}
|
}
|
||||||
@@ -131,53 +110,67 @@ public sealed partial class EntityTreeViewerControl : UserControl
|
|||||||
foreach (EntityTreeViewerRow row in rows)
|
foreach (EntityTreeViewerRow row in rows)
|
||||||
{
|
{
|
||||||
row.ViewIndex = viewRow++;
|
row.ViewIndex = viewRow++;
|
||||||
int nameWidth = row.GetNameWidth() + row.Item.Depth * DepthSize;
|
int nameWidth = row.NameWidth + row.Item.Depth * DepthSize;
|
||||||
maxNameWidth = Math.Max(maxNameWidth, nameWidth);
|
maxNameWidth = Math.Max(maxNameWidth, nameWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
NameWidth = maxNameWidth;
|
NameWidth = maxNameWidth;
|
||||||
|
|
||||||
|
BuildLadder(rows);
|
||||||
|
|
||||||
foreach (EntityTreeViewerRow row in rows)
|
foreach (EntityTreeViewerRow row in rows)
|
||||||
{
|
{
|
||||||
row.Refresh();
|
row.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateScroll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateScroll()
|
private void BuildLadder(List<EntityTreeViewerRow> rows)
|
||||||
{
|
List<LadderType> lastLadder = [];
|
||||||
List<EntityTreeViewerRow> rows = _viewerRows.Where(r => r.Item.Visible).ToList();
|
|
||||||
_visibleRows = rows.Count;
|
|
||||||
|
|
||||||
ContentPanel.VerticalScroll.Enabled = true;
|
|
||||||
ContentPanel.VerticalScroll.Visible = true;
|
ContentPanel.VerticalScroll.Visible = true;
|
||||||
|
|
||||||
ContentPanel.VerticalScroll.SmallChange = ItemHeight;
|
for (int i = rows.Count - 1; i >= 0; i--)
|
||||||
ContentPanel.VerticalScroll.LargeChange = ContentPanel.Height;
|
{
|
||||||
ContentPanel.VerticalScroll.Minimum = 0;
|
EntityTreeViewerRow row = rows[i];
|
||||||
ContentPanel.VerticalScroll.Maximum = _visibleRows * ItemHeight;
|
List<LadderType> ladder;
|
||||||
|
|
||||||
// ContentPanel.VerticalScroll.Value = VerticalScrollBar.Value * ItemHeight;
|
if (row.Depth == 0)
|
||||||
/*
|
{
|
||||||
ContentPanel.Top = -VerticalScrollBar.Value * ItemHeight;
|
ladder = [];
|
||||||
ContentPanel.Invalidate();
|
}
|
||||||
*/
|
else if (row.Depth < lastLadder.Count)
|
||||||
|
{
|
||||||
|
ladder =
|
||||||
|
[
|
||||||
|
.. lastLadder[..(row.Depth - 1)],
|
||||||
|
lastLadder[row.Depth - 1] == LadderType.Empty
|
||||||
|
? LadderType.Last
|
||||||
|
: LadderType.Through,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else if (row.Depth == lastLadder.Count)
|
||||||
|
{
|
||||||
|
ladder = lastLadder;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ladder =
|
||||||
|
[
|
||||||
|
.. lastLadder,
|
||||||
|
.. Enumerable.Repeat(LadderType.Empty, row.Depth - lastLadder.Count - 1),
|
||||||
|
LadderType.Last,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
row.Ladder = ladder;
|
||||||
|
|
||||||
|
lastLadder = ladder
|
||||||
|
.Select(l => (l == LadderType.Last) ? LadderType.Through : l)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|
||||||
private void VerticalScrollBar_Scroll(object sender, ScrollEventArgs e)
|
|
||||||
{
|
|
||||||
UpdateScroll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ContentPanel_MouseWheel(object? sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
Focus();
|
|
||||||
// ScrollPosition -= e.Delta / 120;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ContentPanel_Resize(object sender, EventArgs e)
|
private void ContentPanel_Resize(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdateView();
|
UpdateView();
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
namespace Pf2eViewer.EntityTreeViewer;
|
namespace Pf2eViewer.EntityTreeViewer;
|
||||||
|
|
||||||
partial class EntityTreeViewerRow
|
sealed partial class EntityTreeViewerRow
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обязательная переменная конструктора.
|
/// Обязательная переменная конструктора.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using FontAwesome.Sharp;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
|
using FontAwesome.Sharp;
|
||||||
|
|
||||||
namespace Pf2eViewer.EntityTreeViewer;
|
namespace Pf2eViewer.EntityTreeViewer;
|
||||||
|
|
||||||
internal partial class EntityTreeViewerRow : UserControl
|
internal sealed partial class EntityTreeViewerRow : UserControl
|
||||||
{
|
{
|
||||||
public readonly EntityTreeViewerControl ParentControl;
|
public readonly EntityTreeViewerControl ParentControl;
|
||||||
|
|
||||||
@@ -11,12 +11,66 @@ internal partial class EntityTreeViewerRow : UserControl
|
|||||||
|
|
||||||
public int ViewIndex = 0;
|
public int ViewIndex = 0;
|
||||||
|
|
||||||
|
public Bitmap IconCache
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_iconCache == null)
|
||||||
|
{
|
||||||
|
UpdateCache();
|
||||||
|
}
|
||||||
|
return _iconCache!;
|
||||||
|
}
|
||||||
|
set => _iconCache = value;
|
||||||
|
}
|
||||||
|
private Bitmap? _iconCache;
|
||||||
|
|
||||||
|
public List<LadderType> Ladder
|
||||||
|
{
|
||||||
|
get => _ladder;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_ladder = value;
|
||||||
|
_iconCache = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private List<LadderType> _ladder = [];
|
||||||
|
|
||||||
|
public override Font Font
|
||||||
|
{
|
||||||
|
get => ParentControl.Font;
|
||||||
|
set => ParentControl.Font = value;
|
||||||
|
}
|
||||||
|
public override Color ForeColor
|
||||||
|
{
|
||||||
|
get => ParentControl.ForeColor;
|
||||||
|
set => ParentControl.ForeColor = value;
|
||||||
|
}
|
||||||
|
public override Color BackColor
|
||||||
|
{
|
||||||
|
get => ParentControl.BackColor;
|
||||||
|
set => ParentControl.BackColor = value;
|
||||||
|
}
|
||||||
|
public int ItemHeight
|
||||||
|
{
|
||||||
|
get => ParentControl.ItemHeight;
|
||||||
|
set => ParentControl.ItemHeight = value;
|
||||||
|
}
|
||||||
|
public int DepthSize
|
||||||
|
{
|
||||||
|
get => ParentControl.ItemHeight;
|
||||||
|
set => ParentControl.ItemHeight = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value functions
|
||||||
|
|
||||||
|
public bool HasButton => Item.FieldType == StructureFieldType.Complex;
|
||||||
public int Depth => Item.Depth;
|
public int Depth => Item.Depth;
|
||||||
|
public int NameWidth => TextRenderer.MeasureText(NameLabel.Text, Font).Width + DepthSize;
|
||||||
|
|
||||||
public EntityTreeViewerRow(EntityTreeViewerControl parent, StructureField item)
|
public EntityTreeViewerRow(EntityTreeViewerControl parent, StructureField item)
|
||||||
{
|
{
|
||||||
ParentControl = parent;
|
ParentControl = parent;
|
||||||
Font = ParentControl.Font;
|
|
||||||
|
|
||||||
Item = item;
|
Item = item;
|
||||||
|
|
||||||
@@ -27,52 +81,25 @@ internal partial class EntityTreeViewerRow : UserControl
|
|||||||
|
|
||||||
private void ApplyItem()
|
private void ApplyItem()
|
||||||
{
|
{
|
||||||
TypeLabel.Font = new Font(Font.FontFamily, Font.Size - 2, FontStyle.Italic);
|
TypeLabel.Font = new(Font.FontFamily, Font.Size - 2, FontStyle.Italic);
|
||||||
|
|
||||||
NameLabel.Text = Item.Name;
|
NameLabel.Text = Item.Name;
|
||||||
TypeLabel.Text = Item.GetTypeString();
|
TypeLabel.Text = Item.GetTypeString();
|
||||||
if (TypeLabel.Text != "")
|
if (TypeLabel.Text != "")
|
||||||
{
|
{
|
||||||
TypeLabel.Text = $"({TypeLabel.Text})";
|
TypeLabel.Text = $@"({TypeLabel.Text})";
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueLabel.Text = Item.GetValueString();
|
ValueLabel.Text = Item.GetValueString();
|
||||||
|
TypeLabel.ForeColor = ValueLabel.ForeColor = GetValueColor();
|
||||||
|
|
||||||
switch (Item)
|
if (Item.FieldType == StructureFieldType.Complex)
|
||||||
{
|
{
|
||||||
case StructureFieldPrimitive primitive:
|
ValueLabel.Font = new(Font, FontStyle.Italic);
|
||||||
switch (Type.GetTypeCode(primitive.Type))
|
|
||||||
{
|
|
||||||
case TypeCode.Boolean:
|
|
||||||
ValuePanel.ForeColor = Color.Red;
|
|
||||||
break;
|
|
||||||
case TypeCode.Int32:
|
|
||||||
ValuePanel.ForeColor = Color.Blue;
|
|
||||||
break;
|
|
||||||
case TypeCode.String:
|
|
||||||
ValuePanel.ForeColor = Color.OrangeRed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueLabel.ForeColor = ValuePanel.ForeColor;
|
|
||||||
TypeLabel.ForeColor = ValuePanel.ForeColor;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case StructureFieldComplex complex:
|
|
||||||
ValueLabel.Font = new(Font, FontStyle.Italic);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case StructureFieldNull @null:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case StructureFieldReference reference:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int GetNameWidth()
|
UpdateCache();
|
||||||
{
|
Refresh();
|
||||||
Size textSize = TextRenderer.MeasureText(NameLabel.Text, Font);
|
|
||||||
return textSize.Width + ParentControl.DepthSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void Refresh()
|
public new void Refresh()
|
||||||
@@ -85,10 +112,14 @@ internal partial class EntityTreeViewerRow : UserControl
|
|||||||
Height = ParentControl.ItemHeight;
|
Height = ParentControl.ItemHeight;
|
||||||
|
|
||||||
// Name Panel
|
// Name Panel
|
||||||
NamePanel.Left = Depth * ParentControl.DepthSize;
|
NamePanel.Left = 0;
|
||||||
NamePanel.Width = ParentControl.NameWidth - NamePanel.Left;
|
NamePanel.Width = ParentControl.NameWidth - NamePanel.Left;
|
||||||
|
|
||||||
IconPictureBox.Width = ParentControl.ItemHeight;
|
IconPictureBox.Width = IconCache.Width;
|
||||||
|
IconPictureBox.Image = IconCache;
|
||||||
|
|
||||||
|
NameLabel.Left = IconPictureBox.Width;
|
||||||
|
NameLabel.Width = NamePanel.Width - NameLabel.Left;
|
||||||
|
|
||||||
// Value Panel
|
// Value Panel
|
||||||
ValuePanel.Left = NamePanel.Left + NamePanel.Width;
|
ValuePanel.Left = NamePanel.Left + NamePanel.Width;
|
||||||
@@ -96,63 +127,133 @@ internal partial class EntityTreeViewerRow : UserControl
|
|||||||
|
|
||||||
Size typeSize = TextRenderer.MeasureText(TypeLabel.Text, TypeLabel.Font);
|
Size typeSize = TextRenderer.MeasureText(TypeLabel.Text, TypeLabel.Font);
|
||||||
TypeLabel.Width = typeSize.Width + 3;
|
TypeLabel.Width = typeSize.Width + 3;
|
||||||
|
}
|
||||||
|
|
||||||
TypeLabel.ForeColor = ValueLabel.ForeColor = GetValueColor();
|
private Color BlendColor(Color color, double rate = 0.5)
|
||||||
|
{
|
||||||
|
return BlendColor(ForeColor, color, rate);
|
||||||
|
}
|
||||||
|
|
||||||
if (Item.GetType() == typeof(StructureFieldComplex))
|
private Color BlendColor(Color color1, Color color2, double rate)
|
||||||
{
|
{
|
||||||
StructureFieldComplex complex = (StructureFieldComplex)Item;
|
return Color.FromArgb(
|
||||||
|
Mix(color1.A, color2.A),
|
||||||
|
Mix(color1.R, color2.R),
|
||||||
|
Mix(color1.G, color2.G),
|
||||||
|
Mix(color1.B, color2.B)
|
||||||
|
);
|
||||||
|
|
||||||
IconPictureBox.Image = complex.Collapsed
|
int Mix(int a, int b) => Convert.ToInt32(Math.Round(a * rate + b * (1 - rate)));
|
||||||
? IconChar.PlusSquare.ToBitmap(IconFont.Auto, ParentControl.DepthSize, ForeColor)
|
|
||||||
: IconChar.MinusSquare.ToBitmap(IconFont.Auto, ParentControl.DepthSize, ForeColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color GetValueColor()
|
public Color GetValueColor()
|
||||||
{
|
{
|
||||||
Func<Color, Color> blend = (Color color) => _colorBlend([ForeColor, color]);
|
return Item switch
|
||||||
|
|
||||||
switch (Item)
|
|
||||||
{
|
{
|
||||||
case StructureFieldPrimitive primitive:
|
StructureFieldPrimitive primitive => Type.GetTypeCode(primitive.Type) switch
|
||||||
return Type.GetTypeCode(primitive.Type) switch
|
{
|
||||||
{
|
TypeCode.Boolean => BlendColor(Color.DarkGoldenrod),
|
||||||
TypeCode.Boolean => blend(Color.DarkGoldenrod),
|
TypeCode.Int32 => BlendColor(Color.Blue),
|
||||||
TypeCode.Int32 => blend(Color.Blue),
|
TypeCode.Double => BlendColor(Color.Aqua),
|
||||||
TypeCode.Double => blend(Color.Aqua),
|
TypeCode.String => BlendColor(Color.Green),
|
||||||
TypeCode.String => blend(Color.Green),
|
_ => ForeColor,
|
||||||
};
|
},
|
||||||
|
StructureFieldEnum => BlendColor(Color.Red),
|
||||||
case StructureFieldEnum @enum:
|
_ => ForeColor,
|
||||||
return blend(Color.Red);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return ForeColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color _colorBlend(List<Color> clrArr)
|
// Events
|
||||||
{
|
|
||||||
int r = 0;
|
|
||||||
int g = 0;
|
|
||||||
int b = 0;
|
|
||||||
foreach (Color color in clrArr)
|
|
||||||
{
|
|
||||||
r += color.R;
|
|
||||||
g += color.G;
|
|
||||||
b += color.B;
|
|
||||||
}
|
|
||||||
return Color.FromArgb(r / clrArr.Count, g / clrArr.Count, b / clrArr.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void IconPictureBox_Click(object sender, EventArgs e)
|
private void IconPictureBox_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (Item.GetType() == typeof(StructureFieldComplex))
|
if (Item.GetType() != typeof(StructureFieldComplex))
|
||||||
{
|
{
|
||||||
StructureFieldComplex complex = (StructureFieldComplex)Item;
|
return;
|
||||||
|
|
||||||
complex.Collapsed = !complex.Collapsed;
|
|
||||||
ParentControl.UpdateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StructureFieldComplex complex = (StructureFieldComplex)Item;
|
||||||
|
|
||||||
|
complex.Collapsed = !complex.Collapsed;
|
||||||
|
ParentControl.UpdateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap? GetIconImage()
|
||||||
|
{
|
||||||
|
if (Item.GetType() != typeof(StructureFieldComplex))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
StructureFieldComplex complex = (StructureFieldComplex)Item;
|
||||||
|
|
||||||
|
int size = Convert.ToInt32(Math.Round(DepthSize * 0.6));
|
||||||
|
|
||||||
|
return complex.Collapsed
|
||||||
|
? IconChar.PlusSquare.ToBitmap(IconFont.Auto, size, ForeColor)
|
||||||
|
: IconChar.MinusSquare.ToBitmap(IconFont.Auto, size, ForeColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateCache()
|
||||||
|
{
|
||||||
|
int n = Depth;
|
||||||
|
int h = ItemHeight;
|
||||||
|
int w = DepthSize;
|
||||||
|
|
||||||
|
_iconCache = new(w * (n + 1), h);
|
||||||
|
|
||||||
|
if (_ladder.Count < Depth)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics g = Graphics.FromImage(_iconCache);
|
||||||
|
|
||||||
|
Pen pen = new(Color.FromArgb(127, ForeColor.R, ForeColor.G, ForeColor.B), 1);
|
||||||
|
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
|
||||||
|
|
||||||
|
float cy = 0.5f * h;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
float cx = (i + 1.5f) * w;
|
||||||
|
|
||||||
|
switch (_ladder[i])
|
||||||
|
{
|
||||||
|
case LadderType.Last:
|
||||||
|
g.DrawLine(pen, cx, 0, cx, cy);
|
||||||
|
break;
|
||||||
|
case LadderType.Through:
|
||||||
|
g.DrawLine(pen, cx, 0, cx, h);
|
||||||
|
break;
|
||||||
|
case LadderType.Empty:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == n - 1)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, cx, cy, (i + 2) * w, cy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap? icon = GetIconImage();
|
||||||
|
|
||||||
|
if (icon is not null)
|
||||||
|
{
|
||||||
|
float cx = (n + 0.5f) * w;
|
||||||
|
|
||||||
|
g.FillRectangle(
|
||||||
|
new SolidBrush(BackColor),
|
||||||
|
cx - 0.5f * icon.Width - 1,
|
||||||
|
cy - 0.5f * icon.Height - 1,
|
||||||
|
icon.Width + 2,
|
||||||
|
icon.Height + 2
|
||||||
|
);
|
||||||
|
|
||||||
|
g.DrawImage(icon, new PointF(cx - 0.5f * icon.Width, cy - 0.5f * icon.Height));
|
||||||
|
}
|
||||||
|
|
||||||
|
g.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,13 @@ internal enum StructureFieldType
|
|||||||
Reference,
|
Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal enum LadderType
|
||||||
|
{
|
||||||
|
Empty,
|
||||||
|
Last,
|
||||||
|
Through,
|
||||||
|
}
|
||||||
|
|
||||||
internal abstract class StructureField(StructureBuilder builder, string name, int depth)
|
internal abstract class StructureField(StructureBuilder builder, string name, int depth)
|
||||||
{
|
{
|
||||||
public readonly string Name = name;
|
public readonly string Name = name;
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ public partial class MainViewForm : Form
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
_ = new DarkModeCS(this) { ColorMode = DarkModeCS.DisplayMode.SystemDefault };
|
|
||||||
|
|
||||||
using StreamReader reader = new("Resources/json-viewer.html");
|
using StreamReader reader = new("Resources/json-viewer.html");
|
||||||
JsonViewerHtml = reader.ReadToEnd();
|
JsonViewerHtml = reader.ReadToEnd();
|
||||||
|
|
||||||
|
|||||||
@@ -5,19 +5,13 @@ namespace Pf2eViewer;
|
|||||||
|
|
||||||
public partial class TestForm : Form
|
public partial class TestForm : Form
|
||||||
{
|
{
|
||||||
public readonly DarkModeCS DarkMode;
|
public Pf2eDbContext Context = new();
|
||||||
|
|
||||||
public readonly Pf2eDbContext Context = new();
|
|
||||||
|
|
||||||
public int Count = 0;
|
public int Count = 0;
|
||||||
|
|
||||||
public TestForm()
|
public TestForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
DarkMode = new DarkModeCS(this) { ColorMode = DarkModeCS.DisplayMode.SystemDefault };
|
|
||||||
|
|
||||||
entityTreeViewerControl1.DarkMode = DarkMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RandomEntity()
|
public void RandomEntity()
|
||||||
|
|||||||
Reference in New Issue
Block a user