完善查看器
This commit is contained in:
parent
1002e9aade
commit
4b44a3ebcf
@ -1,10 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Learn.Inspector;
|
||||
using Learn.Models;
|
||||
|
||||
public partial class RawInfoPanel : Tree
|
||||
public partial class NodeInfoEditPanel : Tree
|
||||
{
|
||||
[Export]
|
||||
private ParsedInfoPanel _notifyNodeChanged;
|
||||
|
||||
private IEnumerable<TreeNode> _nodes;
|
||||
private ItemGroup _itemGroup;
|
||||
|
||||
@ -12,19 +16,15 @@ public partial class RawInfoPanel : Tree
|
||||
private readonly HashSet<TreeItem> _selectingNodes = new ();
|
||||
|
||||
#region Columns Definitions
|
||||
private const int EmptyColumn = 0;
|
||||
private const int KeyColumn = 1;
|
||||
private const int ValueColumn = 2;
|
||||
private const int KeyColumn = 0;
|
||||
private const int ValueColumn = 1;
|
||||
#endregion
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Columns = 3;
|
||||
Columns = 2;
|
||||
SetColumnTitlesVisible(true);
|
||||
|
||||
SetColumnCustomMinimumWidth(EmptyColumn, 30);
|
||||
SetColumnExpand(EmptyColumn, false);
|
||||
|
||||
SetColumnTitle(KeyColumn, "键");
|
||||
SetColumnCustomMinimumWidth(KeyColumn, 100);
|
||||
SetColumnExpand(KeyColumn, false);
|
||||
@ -59,9 +59,10 @@ public partial class RawInfoPanel : Tree
|
||||
_itemGroup.Remove(prevKey);
|
||||
}
|
||||
_itemGroup.SetValue(currentKey, value);
|
||||
_notifyNodeChanged.OnNodeChanged();
|
||||
}
|
||||
|
||||
public void SetSelectedNodes(IEnumerable<TreeNode> nodes)
|
||||
public void SetNodes(IEnumerable<TreeNode> nodes)
|
||||
{
|
||||
if (nodes == null)
|
||||
{
|
||||
@ -73,10 +74,10 @@ public partial class RawInfoPanel : Tree
|
||||
_nodes = nodes;
|
||||
_itemGroup = new ItemGroup(_nodes.Select(node => node.Info).ToList());
|
||||
}
|
||||
OnCurrentItemChanged();
|
||||
OnNodesChanged();
|
||||
}
|
||||
|
||||
private void OnCurrentItemChanged()
|
||||
private void OnNodesChanged()
|
||||
{
|
||||
Clear();
|
||||
_nodeKeys.Clear();
|
||||
@ -105,18 +106,19 @@ public partial class RawInfoPanel : Tree
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
OnCurrentItemChanged();
|
||||
OnNodesChanged();
|
||||
}
|
||||
|
||||
private void RemoveKeyValue()
|
||||
{
|
||||
if(_itemGroup == null) return;
|
||||
|
||||
|
||||
var root = GetRoot();
|
||||
foreach (var node in _selectingNodes)
|
||||
{
|
||||
_itemGroup.Remove(_nodeKeys[node]);
|
||||
root.RemoveChild(node);
|
||||
}
|
||||
_notifyNodeChanged.OnNodeChanged();
|
||||
}
|
||||
}
|
||||
1
Inspector/NodeInfoEditPanel.cs.uid
Normal file
1
Inspector/NodeInfoEditPanel.cs.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bbgo6drfpvv2a
|
||||
@ -1,8 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Learn.Models;
|
||||
|
||||
namespace Learn.Inspector;
|
||||
|
||||
public partial class ParsedInfoPanel : Tree
|
||||
{
|
||||
|
||||
private TreeNode _node;
|
||||
|
||||
#region Columns Definitions
|
||||
private const int NotesColumn = 0;
|
||||
private const int KeyColumn = 1;
|
||||
private const int ValueColumn = 2;
|
||||
#endregion
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Columns = 3;
|
||||
SetColumnTitlesVisible(true);
|
||||
|
||||
SetColumnTitle(NotesColumn, "备注");
|
||||
SetColumnCustomMinimumWidth(NotesColumn, 80);
|
||||
SetColumnExpand(NotesColumn, false);
|
||||
|
||||
SetColumnTitle(KeyColumn, "键");
|
||||
SetColumnCustomMinimumWidth(KeyColumn, 100);
|
||||
SetColumnExpand(KeyColumn, false);
|
||||
|
||||
SetColumnTitle(ValueColumn, "值");
|
||||
SetColumnExpand(ValueColumn, true);
|
||||
}
|
||||
|
||||
public void SetNode(TreeNode node)
|
||||
{
|
||||
_node = node;
|
||||
OnNodeChanged();
|
||||
}
|
||||
|
||||
public void OnNodeChanged()
|
||||
{
|
||||
Clear();
|
||||
if (_node == null) return;
|
||||
|
||||
var root = CreateItem();
|
||||
var keys = new HashSet<string>();
|
||||
var curr = _node;
|
||||
|
||||
while (curr != null)
|
||||
{
|
||||
foreach (var kv in curr.Info.Info)
|
||||
{
|
||||
if(!keys.Add(kv.Key)) continue;
|
||||
var node = CreateItem(root);
|
||||
if (curr != _node)
|
||||
{
|
||||
node.SetText(NotesColumn, "(继承)");
|
||||
}
|
||||
node.SetText(KeyColumn, kv.Key);
|
||||
node.SetText(ValueColumn, kv.Value);
|
||||
}
|
||||
curr = curr.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
uid://dehqc84newiyv
|
||||
@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Learn.Inspector;
|
||||
using Learn.Models;
|
||||
|
||||
public partial class MainTreePanel : Tree
|
||||
@ -8,7 +10,9 @@ public partial class MainTreePanel : Tree
|
||||
[Export]
|
||||
private FileDirSelector _dirSelector;
|
||||
[Export]
|
||||
private RawInfoPanel _rawInfoPanel;
|
||||
private NodeInfoEditPanel _nodeInfoEditPanel;
|
||||
[Export]
|
||||
private ParsedInfoPanel _parsedInfoPanel;
|
||||
|
||||
private bool _updateItemInfoPanel;
|
||||
private readonly HashSet<TreeNode> _selectingNodes = new ();
|
||||
@ -24,7 +28,8 @@ public partial class MainTreePanel : Tree
|
||||
if (_updateItemInfoPanel)
|
||||
{
|
||||
_updateItemInfoPanel = false;
|
||||
_rawInfoPanel.SetSelectedNodes(_selectingNodes);
|
||||
_nodeInfoEditPanel.SetNodes(_selectingNodes);
|
||||
_parsedInfoPanel.SetNode(_selectingNodes.FirstOrDefault());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Learn.Models;
|
||||
|
||||
24
tree.tscn
24
tree.tscn
@ -3,7 +3,7 @@
|
||||
[ext_resource type="Script" uid="uid://dqs5segp8tixm" path="res://Utils/FileDirSelector.cs" id="1_d2g23"]
|
||||
[ext_resource type="Script" uid="uid://bmepprx2mndih" path="res://MainTreePanel.cs" id="2_44ud8"]
|
||||
[ext_resource type="Script" uid="uid://bkx2esr711e68" path="res://Inspector/ParsedInfoPanel.cs" id="3_d2g23"]
|
||||
[ext_resource type="Script" uid="uid://dehqc84newiyv" path="res://Inspector/RawInfoPanel.cs" id="4_ind6k"]
|
||||
[ext_resource type="Script" uid="uid://bbgo6drfpvv2a" path="res://Inspector/NodeInfoEditPanel.cs" id="4_d2g23"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
@ -43,7 +43,7 @@ text = "打开文件夹"
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="MainTreePanel" type="Tree" parent="MarginContainer/VBoxContainer/HSplitContainer" node_paths=PackedStringArray("_dirSelector", "_rawInfoPanel")]
|
||||
[node name="MainTreePanel" type="Tree" parent="MarginContainer/VBoxContainer/HSplitContainer" node_paths=PackedStringArray("_dirSelector", "_nodeInfoEditPanel", "_parsedInfoPanel")]
|
||||
custom_minimum_size = Vector2(600, 0)
|
||||
layout_mode = 2
|
||||
allow_search = false
|
||||
@ -51,7 +51,8 @@ hide_root = true
|
||||
select_mode = 2
|
||||
script = ExtResource("2_44ud8")
|
||||
_dirSelector = NodePath("../../../../FileDirDialog")
|
||||
_rawInfoPanel = NodePath("../ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/Raw")
|
||||
_nodeInfoEditPanel = NodePath("../ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/NodeEditPanel")
|
||||
_parsedInfoPanel = NodePath("../ScrollContainer/VBoxContainer2/FoldableContainer2/ParsedNodePanel")
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer/HSplitContainer"]
|
||||
layout_mode = 2
|
||||
@ -64,18 +65,18 @@ size_flags_horizontal = 3
|
||||
layout_mode = 2
|
||||
title = "解析数据"
|
||||
|
||||
[node name="Parsed" type="Tree" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer2"]
|
||||
[node name="ParsedNodePanel" type="Tree" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer2"]
|
||||
custom_minimum_size = Vector2(0, 300)
|
||||
layout_mode = 2
|
||||
hide_root = true
|
||||
select_mode = 1
|
||||
script = ExtResource("3_d2g23")
|
||||
|
||||
[node name="FoldableContainer" type="FoldableContainer" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
folded = true
|
||||
title = "原始数据"
|
||||
title = "数据编辑"
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer"]
|
||||
@ -90,15 +91,16 @@ text = "添加字段"
|
||||
layout_mode = 2
|
||||
text = "移除选中"
|
||||
|
||||
[node name="Raw" type="Tree" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer"]
|
||||
[node name="NodeEditPanel" type="Tree" parent="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer" node_paths=PackedStringArray("_notifyNodeChanged")]
|
||||
custom_minimum_size = Vector2(0, 300)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
allow_search = false
|
||||
hide_root = true
|
||||
select_mode = 2
|
||||
script = ExtResource("4_ind6k")
|
||||
script = ExtResource("4_d2g23")
|
||||
_notifyNodeChanged = NodePath("../../../FoldableContainer2/ParsedNodePanel")
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/Toolbar/Button" to="MarginContainer/VBoxContainer/HSplitContainer/MainTreePanel" method="Open"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/HBoxContainer/Add" to="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/Raw" method="AddKeyValue"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/HBoxContainer/Remove" to="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/Raw" method="RemoveKeyValue"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/HBoxContainer/Add" to="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/NodeEditPanel" method="AddKeyValue"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/HBoxContainer/Remove" to="MarginContainer/VBoxContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer/VBoxContainer/NodeEditPanel" method="RemoveKeyValue"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user