Some byaml improvements
Add XML format to byaml text editor. Disable reference nodes in text editor for now till i find a better method to handle them.
This commit is contained in:
parent
07b0259805
commit
9e0f3e0516
@ -180,7 +180,7 @@ namespace FirstPlugin
|
|||||||
if (node == null) {
|
if (node == null) {
|
||||||
return new YamlScalarNode("null");
|
return new YamlScalarNode("null");
|
||||||
}
|
}
|
||||||
else if (NodePaths.ContainsKey(node))
|
else if (IsReferenceNode(node))
|
||||||
{
|
{
|
||||||
if (NodePaths[node].Tag == null)
|
if (NodePaths[node].Tag == null)
|
||||||
NodePaths[node].Tag = $"!ref{refNodeId++}";
|
NodePaths[node].Tag = $"!ref{refNodeId++}";
|
||||||
@ -189,7 +189,7 @@ namespace FirstPlugin
|
|||||||
else if ((node is IList<dynamic>))
|
else if ((node is IList<dynamic>))
|
||||||
{
|
{
|
||||||
var yamlNode = new YamlSequenceNode();
|
var yamlNode = new YamlSequenceNode();
|
||||||
NodePaths.Add(node, yamlNode);
|
// NodePaths.Add(node, yamlNode);
|
||||||
|
|
||||||
if (!HasEnumerables((IList<dynamic>)node) &&
|
if (!HasEnumerables((IList<dynamic>)node) &&
|
||||||
((IList<dynamic>)node).Count < 6)
|
((IList<dynamic>)node).Count < 6)
|
||||||
@ -203,7 +203,7 @@ namespace FirstPlugin
|
|||||||
else if (node is IDictionary<string, dynamic>)
|
else if (node is IDictionary<string, dynamic>)
|
||||||
{
|
{
|
||||||
var yamlNode = new YamlMappingNode();
|
var yamlNode = new YamlMappingNode();
|
||||||
NodePaths.Add(node, yamlNode);
|
// NodePaths.Add(node, yamlNode);
|
||||||
|
|
||||||
if (!HasEnumerables((IDictionary<string, dynamic>)node) &&
|
if (!HasEnumerables((IDictionary<string, dynamic>)node) &&
|
||||||
((IDictionary<string, dynamic>)node).Count < 6)
|
((IDictionary<string, dynamic>)node).Count < 6)
|
||||||
@ -227,6 +227,11 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsReferenceNode(dynamic node)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool HasEnumerables(IDictionary<string, dynamic> node)
|
private static bool HasEnumerables(IDictionary<string, dynamic> node)
|
||||||
{
|
{
|
||||||
foreach (var item in node.Values)
|
foreach (var item in node.Values)
|
||||||
|
@ -633,7 +633,6 @@ namespace LayoutBXLYT
|
|||||||
|
|
||||||
//Huge thanks to layout studio for the window pane rendering code
|
//Huge thanks to layout studio for the window pane rendering code
|
||||||
//https://github.com/Treeki/LayoutStudio/blob/master/layoutgl/widget.cpp
|
//https://github.com/Treeki/LayoutStudio/blob/master/layoutgl/widget.cpp
|
||||||
//Note i still need to fix UV coordinates being flips and transformed!
|
|
||||||
public static void DrawWindowPane(BasePane pane, LayoutViewer.Camera2D camera, bool gameWindow, byte effectiveAlpha, Dictionary<string, STGenericTexture> Textures, bool isSelected)
|
public static void DrawWindowPane(BasePane pane, LayoutViewer.Camera2D camera, bool gameWindow, byte effectiveAlpha, Dictionary<string, STGenericTexture> Textures, bool isSelected)
|
||||||
{
|
{
|
||||||
if (!Runtime.LayoutEditor.DisplayWindowPane)
|
if (!Runtime.LayoutEditor.DisplayWindowPane)
|
||||||
|
@ -43,12 +43,20 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
bool useMuunt = true;
|
bool useMuunt = true;
|
||||||
|
|
||||||
|
bool IsXML => xmlToolstrip.Checked;
|
||||||
|
|
||||||
private TextEditor textEditor;
|
private TextEditor textEditor;
|
||||||
|
private STToolStipMenuItem xmlToolstrip;
|
||||||
|
private STToolStipMenuItem yamlToolstrip;
|
||||||
|
|
||||||
public ByamlEditor()
|
public ByamlEditor()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Reload();
|
Reload();
|
||||||
|
|
||||||
|
xmlToolstrip = new STToolStipMenuItem("XML", null, OnFormatChanged);
|
||||||
|
yamlToolstrip = new STToolStipMenuItem("YAML", null, OnFormatChanged);
|
||||||
|
yamlToolstrip.Checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
|
public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
|
||||||
@ -104,9 +112,29 @@ namespace FirstPlugin
|
|||||||
textEditor.ClearContextMenus();
|
textEditor.ClearContextMenus();
|
||||||
textEditor.AddContextMenu("Decompile", TextEditorToYaml);
|
textEditor.AddContextMenu("Decompile", TextEditorToYaml);
|
||||||
textEditor.AddContextMenu("Compile", TextEditorFromYaml);
|
textEditor.AddContextMenu("Compile", TextEditorFromYaml);
|
||||||
|
|
||||||
|
var formatMenu = new STToolStripItem("Change Formatting");
|
||||||
|
formatMenu.DropDownItems.Add(xmlToolstrip);
|
||||||
|
formatMenu.DropDownItems.Add(yamlToolstrip);
|
||||||
|
|
||||||
|
textEditor.AddContextMenu(formatMenu, TextEditorFromYaml);
|
||||||
|
|
||||||
stPanel4.Controls.Add(textEditor);
|
stPanel4.Controls.Add(textEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnFormatChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
yamlToolstrip.Checked = false;
|
||||||
|
xmlToolstrip.Checked = false;
|
||||||
|
|
||||||
|
var menu = sender as STToolStipMenuItem;
|
||||||
|
menu.Checked = true;
|
||||||
|
|
||||||
|
if (textEditor.GetText() != string.Empty) {
|
||||||
|
UpdateTextEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ParseBymlFirstNode()
|
void ParseBymlFirstNode()
|
||||||
{
|
{
|
||||||
TreeNode root = new TreeNode(FileName);
|
TreeNode root = new TreeNode(FileName);
|
||||||
@ -719,16 +747,25 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextEditorToYaml(object sender, EventArgs e)
|
private void TextEditorToYaml(object sender, EventArgs e) {
|
||||||
{
|
UpdateTextEditor();
|
||||||
var format = (IConvertableTextFormat)FileFormat;
|
}
|
||||||
textEditor.FillEditor(((IConvertableTextFormat)FileFormat).ConvertToString());
|
|
||||||
|
|
||||||
if (format.TextFileType == TextFileType.Xml)
|
private void UpdateTextEditor() {
|
||||||
|
textEditor.IsXML = false;
|
||||||
|
textEditor.IsYAML = false;
|
||||||
|
|
||||||
|
if (IsXML)
|
||||||
|
{
|
||||||
|
textEditor.FillEditor(XmlByamlConverter.ToXML(FileFormat.BymlData));
|
||||||
textEditor.IsXML = true;
|
textEditor.IsXML = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
textEditor.FillEditor(YamlByamlConverter.ToYaml(FileFormat.BymlData));
|
||||||
textEditor.IsYAML = true;
|
textEditor.IsYAML = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void TextEditorFromYaml(object sender, EventArgs e)
|
private void TextEditorFromYaml(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -739,7 +776,10 @@ namespace FirstPlugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (FileFormat != null) {
|
if (FileFormat != null) {
|
||||||
FileFormat.ConvertFromString(textEditor.GetText());
|
if (IsXML)
|
||||||
|
FileFormat.BymlData = XmlByamlConverter.FromXML(textEditor.GetText());
|
||||||
|
else
|
||||||
|
FileFormat.BymlData = YamlByamlConverter.FromYaml(textEditor.GetText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -196,6 +196,15 @@ namespace Toolbox.Library.Forms
|
|||||||
private Color BACK_COLOR = Color.FromArgb(30, 30, 30);
|
private Color BACK_COLOR = Color.FromArgb(30, 30, 30);
|
||||||
private Color FORE_COLOR = Color.White;
|
private Color FORE_COLOR = Color.White;
|
||||||
|
|
||||||
|
public void AddContextMenu(STToolStripItem menu, EventHandler handler)
|
||||||
|
{
|
||||||
|
foreach (ToolStripItem item in stContextMenuStrip1.Items)
|
||||||
|
if (item.Text == menu.Text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
stContextMenuStrip1.Items.Add(menu);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddContextMenu(string text, EventHandler handler)
|
public void AddContextMenu(string text, EventHandler handler)
|
||||||
{
|
{
|
||||||
foreach (ToolStripItem item in stContextMenuStrip1.Items)
|
foreach (ToolStripItem item in stContextMenuStrip1.Items)
|
||||||
|
Loading…
Reference in New Issue
Block a user