1
0
mirror of synced 2024-12-02 02:57:23 +01:00

Improve byaml editor more

This commit is contained in:
KillzXGaming 2019-04-20 15:22:10 -04:00
parent 41fa2673c9
commit c661b10d12
11 changed files with 295 additions and 60 deletions

Binary file not shown.

Binary file not shown.

View File

@ -41,22 +41,37 @@
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.importFromXmlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.listViewCustom1 = new Switch_Toolbox.Library.Forms.ListViewCustom();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.stButton1 = new Switch_Toolbox.Library.Forms.STButton();
this.stButton2 = new Switch_Toolbox.Library.Forms.STButton();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.stContextMenuStrip1 = new Switch_Toolbox.Library.Forms.STContextMenuStrip(this.components);
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.renameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contentContainer.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.stPanel1.SuspendLayout();
this.stContextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// contentContainer
//
this.contentContainer.Controls.Add(this.stPanel1);
this.contentContainer.Controls.Add(this.stButton2);
this.contentContainer.Controls.Add(this.stButton1);
this.contentContainer.Controls.Add(this.stPanel1);
this.contentContainer.Controls.SetChildIndex(this.stPanel1, 0);
this.contentContainer.Paint += new System.Windows.Forms.PaintEventHandler(this.contentContainer_Paint);
this.contentContainer.Controls.SetChildIndex(this.stButton1, 0);
this.contentContainer.Controls.SetChildIndex(this.stButton2, 0);
this.contentContainer.Controls.SetChildIndex(this.stPanel1, 0);
//
// treeView1
//
@ -65,9 +80,10 @@
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(543, 336);
this.treeView1.Size = new System.Drawing.Size(179, 334);
this.treeView1.TabIndex = 0;
this.treeView1.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.BeforeExpand);
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// contextMenuStrip1
//
@ -153,23 +169,45 @@
this.importFromXmlToolStripMenuItem.Text = "Import from xml";
this.importFromXmlToolStripMenuItem.Click += new System.EventHandler(this.importFromXmlToolStripMenuItem_Click);
//
// stPanel1
// listViewCustom1
//
this.stPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stPanel1.Controls.Add(this.treeView1);
this.stPanel1.Location = new System.Drawing.Point(0, 25);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(543, 336);
this.stPanel1.TabIndex = 11;
this.listViewCustom1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.listViewCustom1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listViewCustom1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listViewCustom1.FullRowSelect = true;
this.listViewCustom1.Location = new System.Drawing.Point(0, 0);
this.listViewCustom1.Name = "listViewCustom1";
this.listViewCustom1.OwnerDraw = true;
this.listViewCustom1.Size = new System.Drawing.Size(354, 334);
this.listViewCustom1.TabIndex = 0;
this.listViewCustom1.UseCompatibleStateImageBehavior = false;
this.listViewCustom1.View = System.Windows.Forms.View.Details;
this.listViewCustom1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listViewCustom1_MouseClick);
//
// columnHeader1
//
this.columnHeader1.Text = "Name";
this.columnHeader1.Width = 114;
//
// columnHeader2
//
this.columnHeader2.Text = "Type";
this.columnHeader2.Width = 93;
//
// columnHeader3
//
this.columnHeader3.Text = "Data";
this.columnHeader3.Width = 136;
//
// stButton1
//
this.stButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.stButton1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.stButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.stButton1.Location = new System.Drawing.Point(465, 367);
this.stButton1.Location = new System.Drawing.Point(462, 367);
this.stButton1.Name = "stButton1";
this.stButton1.Size = new System.Drawing.Size(75, 23);
this.stButton1.TabIndex = 12;
@ -181,13 +219,71 @@
this.stButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.stButton2.DialogResult = System.Windows.Forms.DialogResult.OK;
this.stButton2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.stButton2.Location = new System.Drawing.Point(369, 367);
this.stButton2.Location = new System.Drawing.Point(366, 367);
this.stButton2.Name = "stButton2";
this.stButton2.Size = new System.Drawing.Size(75, 23);
this.stButton2.TabIndex = 13;
this.stButton2.Text = "Save";
this.stButton2.UseVisualStyleBackColor = false;
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.treeView1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.listViewCustom1);
this.splitContainer1.Size = new System.Drawing.Size(537, 334);
this.splitContainer1.SplitterDistance = 179;
this.splitContainer1.TabIndex = 14;
//
// stPanel1
//
this.stPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stPanel1.Controls.Add(this.splitContainer1);
this.stPanel1.Location = new System.Drawing.Point(3, 27);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(537, 334);
this.stPanel1.TabIndex = 15;
//
// stContextMenuStrip1
//
this.stContextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.editToolStripMenuItem,
this.renameToolStripMenuItem,
this.deleteToolStripMenuItem});
this.stContextMenuStrip1.Name = "stContextMenuStrip1";
this.stContextMenuStrip1.Size = new System.Drawing.Size(181, 92);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.editToolStripMenuItem.Text = "Edit";
this.editToolStripMenuItem.Click += new System.EventHandler(this.editValueNodeMenuItem_Click);
//
// renameToolStripMenuItem
//
this.renameToolStripMenuItem.Name = "renameToolStripMenuItem";
this.renameToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.renameToolStripMenuItem.Text = "Rename";
this.renameToolStripMenuItem.Click += new System.EventHandler(this.renameToolStripMenuItem_Click);
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.deleteToolStripMenuItem.Text = "Delete";
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click);
//
// ByamlEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -199,7 +295,12 @@
this.Controls.SetChildIndex(this.contentContainer, 0);
this.contentContainer.ResumeLayout(false);
this.contextMenuStrip1.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.stPanel1.ResumeLayout(false);
this.stContextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -218,8 +319,17 @@
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem importFromXmlToolStripMenuItem;
private Switch_Toolbox.Library.Forms.STPanel stPanel1;
private Switch_Toolbox.Library.Forms.STButton stButton2;
private Switch_Toolbox.Library.Forms.STButton stButton1;
private Switch_Toolbox.Library.Forms.ListViewCustom listViewCustom1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.SplitContainer splitContainer1;
private Switch_Toolbox.Library.Forms.STPanel stPanel1;
private Switch_Toolbox.Library.Forms.STContextMenuStrip stContextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem renameToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;
}
}

View File

@ -140,33 +140,88 @@ namespace FirstPlugin
}
}
void parseDictNode(IDictionary<string, dynamic> node, TreeNodeCollection addto)
void parseDictNode(IDictionary<string, dynamic> node)
{
foreach (string k in node.Keys)
{
TreeNode current = addto.Add(k);
if (node[k] is IDictionary<string, dynamic>)
if ((node[k] is Dictionary<string, dynamic>) ||
(node[k] is List<dynamic>) ||
(node[k] is List<ByamlPathPoint>))
{
current.Text += " : <Dictionary>";
current.Tag = node[k];
current.Nodes.Add("✯✯dummy✯✯"); //a text that can't be in a byml
continue;
}
else if (node[k] is IList<dynamic>)
string ValueText = (node[k] == null ? "<NULL>" : node[k].ToString());
string NameText = k;
Type ValueType = node[k].GetType();
string TypeString = ValueType.ToString().Replace("System.", "");
ListViewItem item = new ListViewItem(NameText);
item.SubItems.Add(TypeString);
item.SubItems.Add(ValueText);
if (node[k] != null) item.Tag = new EditableNode(node, k);
listViewCustom1.Items.Add(item);
}
}
void parseArrayNode(IList<dynamic> list)
{
foreach (dynamic k in list)
{
if ((k is Dictionary<string, dynamic>) ||
(k is List<dynamic>) ||
(k is List<ByamlPathPoint>))
{
current.Text += " : <Array>";
current.Tag = ((IList<dynamic>)node[k]);
current.Nodes.Add("✯✯dummy✯✯");
continue;
}
else if (node[k] is IList<ByamlPathPoint>)
string ValueText = (k == null ? "<NULL>" : k.ToString());
Type ValueType = k.GetType();
ListViewItem item = new ListViewItem(ValueText);
item.SubItems.Add(ValueType.ToString());
item.SubItems.Add(ValueText);
listViewCustom1.Items.Add(item);
}
}
void parseDictNode(IDictionary<string, dynamic> node, TreeNodeCollection addto)
{
int dictionaryIndex = 0;
int arrayIndex = 0;
int pathPointIndex = 0;
foreach (string k in node.Keys)
{
if (node[k] is IDictionary<string, dynamic> ||
node[k] is IList<dynamic> ||
node[k] is IList<ByamlPathPoint>)
{
current.Text += " : <PathPointArray>";
current.Tag = ((IList<ByamlPathPoint>)node[k]);
parsePathPointArray(node[k], current.Nodes);
}
else
{
current.Text = current.Text + " : " + (node[k] == null ? "<NULL>" : node[k].ToString());
if (node[k] != null) current.Tag = new EditableNode(node, k);
TreeNode current = addto.Add(k);
if (node[k] is IDictionary<string, dynamic>)
{
current.Text += $" : <Dictionary> {dictionaryIndex++}";
current.Tag = node[k];
current.Nodes.Add("✯✯dummy✯✯"); //a text that can't be in a byml
}
else if (node[k] is IList<dynamic>)
{
current.Text += $" : <Array> {arrayIndex++}";
current.Tag = ((IList<dynamic>)node[k]);
current.Nodes.Add("✯✯dummy✯✯");
}
else if (node[k] is IList<ByamlPathPoint>)
{
current.Text += $" : <PathPointArray> {pathPointIndex++}";
current.Tag = ((IList<ByamlPathPoint>)node[k]);
parsePathPointArray(node[k], current.Nodes);
}
}
}
}
@ -184,32 +239,38 @@ namespace FirstPlugin
void parseArrayNode(IList<dynamic> list, TreeNodeCollection addto)
{
int dictionaryIndex = 0;
int arrayIndex = 0;
int pathPointIndex = 0;
int index = 0;
foreach (dynamic k in list)
{
if (k is IDictionary<string, dynamic>)
if (k is IDictionary<string, dynamic> ||
k is IList<dynamic> ||
k is IList<ByamlPathPoint>)
{
TreeNode current = addto.Add("<Dictionary>");
current.Tag = ((IDictionary<string, dynamic>)k);
current.Nodes.Add("✯✯dummy✯✯");
}
else if (k is IList<dynamic>)
{
TreeNode current = addto.Add("<Array>");
current.Tag = ((IList<dynamic>)k);
current.Nodes.Add("✯✯dummy✯✯");
}
else if (k is IList<ByamlPathPoint>)
{
TreeNode current = addto.Add("<PathPointArray>");
current.Tag = ((IList<ByamlPathPoint>)k);
parsePathPointArray(k, current.Nodes);
}
else
{
var n = addto.Add(k == null ? "<NULL>" : k.ToString());
if (k != null) n.Tag = new EditableNode(list, index);
if (k is IDictionary<string, dynamic>)
{
TreeNode current = addto.Add($"<Dictionary> {dictionaryIndex++}");
current.Tag = ((IDictionary<string, dynamic>)k);
current.Nodes.Add("✯✯dummy✯✯");
}
else if (k is IList<dynamic>)
{
TreeNode current = addto.Add($"<Array> {arrayIndex++}");
current.Tag = ((IList<dynamic>)k);
current.Nodes.Add("✯✯dummy✯✯");
}
else if (k is IList<ByamlPathPoint>)
{
TreeNode current = addto.Add($"<PathPointArray> {pathPointIndex++}");
current.Tag = ((IList<ByamlPathPoint>)k);
parsePathPointArray(k, current.Nodes);
}
}
index++;
}
}
@ -233,7 +294,7 @@ namespace FirstPlugin
private void ContextMenuOpening(object sender, CancelEventArgs e)
{
CopyNode.Enabled = treeView1.SelectedNode != null;
editValueNodeMenuItem.Enabled = treeView1.SelectedNode != null && treeView1.SelectedNode.Tag is EditableNode;
editValueNodeMenuItem.Enabled = listViewCustom1.SelectedItems.Count > 0 && listViewCustom1.SelectedItems[0].Tag is EditableNode;
}
private void CopyNode_Click(object sender, EventArgs e)
@ -316,7 +377,10 @@ namespace FirstPlugin
private void editValueNodeMenuItem_Click(object sender, EventArgs e)
{
var node = treeView1.SelectedNode.Tag as EditableNode;
if (listViewCustom1.SelectedItems.Count <= 0)
return;
var node = listViewCustom1.SelectedItems[0].Tag as EditableNode;
if (node == null) return;
if (node.Get() is ByamlPathPoint)
@ -331,7 +395,34 @@ namespace FirstPlugin
if (value.Trim() == "") return;
node.Set(ByamlTypeHelper.ConvertValue(node.type, value));
}
treeView1.SelectedNode.Text = node.GetTreeViewString();
ResetValues();
}
private void ResetValues()
{
if (treeView1.SelectedNode == null)
return;
listViewCustom1.Items.Clear();
var targetNodeCollection = treeView1.SelectedNode.Nodes;
dynamic target = treeView1.SelectedNode.Tag;
if (target is IDictionary<string, dynamic>)
{
parseDictNode((IDictionary<string, dynamic>)target);
}
else if (target is IList<dynamic>)
{
parseArrayNode((IList<dynamic>)target);
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
ResetValues();
}
private void addNodeToolStripMenuItem_Click(object sender, EventArgs e)
@ -375,6 +466,23 @@ namespace FirstPlugin
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listViewCustom1.SelectedItems.Count <= 0)
return;
dynamic target = listViewCustom1.SelectedItems[0].Tag;
int index = listViewCustom1.Items.IndexOf(listViewCustom1.SelectedItems[0]);
listViewCustom1.Items.RemoveAt(index);
}
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void deleteNodeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (treeView1.SelectedNode == null)
@ -423,5 +531,19 @@ namespace FirstPlugin
byml = XmlConverter.ToByml(t.ReadToEnd()).RootNode;
ParseBymlFirstNode();
}
private void contentContainer_Paint(object sender, PaintEventArgs e)
{
}
private void listViewCustom1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point pt = listViewCustom1.PointToScreen(e.Location);
stContextMenuStrip1.Show(pt);
}
}
}
}

View File

@ -120,4 +120,7 @@
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>172, 17</value>
</metadata>
</root>

View File

@ -155,7 +155,7 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs
}
catch (Exception ex)
{
Switch_Toolbox.Library.Forms.STErrorDialog.Show($"Invalid path points! Group {groupID} Path {pathID}", "Path Creator",
Switch_Toolbox.Library.Forms.STErrorDialog.Show($"Invalid path points at Group {groupID} Path {pathID}! Invalid connection to group {pathPoint.PathID} point {pathPoint.PtID}", "Path Creator",
$"Group {groupID} \n" +
$"Path {pathID} \n" +
$"Group ID {pathPoint.PathID} \n" +