mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 12:33:12 +00:00
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
4 changed files with 63 additions and 10 deletions
|
@ -180,7 +180,7 @@ namespace FirstPlugin
|
|||
if (node == null) {
|
||||
return new YamlScalarNode("null");
|
||||
}
|
||||
else if (NodePaths.ContainsKey(node))
|
||||
else if (IsReferenceNode(node))
|
||||
{
|
||||
if (NodePaths[node].Tag == null)
|
||||
NodePaths[node].Tag = $"!ref{refNodeId++}";
|
||||
|
@ -189,7 +189,7 @@ namespace FirstPlugin
|
|||
else if ((node is IList<dynamic>))
|
||||
{
|
||||
var yamlNode = new YamlSequenceNode();
|
||||
NodePaths.Add(node, yamlNode);
|
||||
// NodePaths.Add(node, yamlNode);
|
||||
|
||||
if (!HasEnumerables((IList<dynamic>)node) &&
|
||||
((IList<dynamic>)node).Count < 6)
|
||||
|
@ -203,7 +203,7 @@ namespace FirstPlugin
|
|||
else if (node is IDictionary<string, dynamic>)
|
||||
{
|
||||
var yamlNode = new YamlMappingNode();
|
||||
NodePaths.Add(node, yamlNode);
|
||||
// NodePaths.Add(node, yamlNode);
|
||||
|
||||
if (!HasEnumerables((IDictionary<string, dynamic>)node) &&
|
||||
((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)
|
||||
{
|
||||
foreach (var item in node.Values)
|
||||
|
|
|
@ -633,7 +633,6 @@ namespace LayoutBXLYT
|
|||
|
||||
//Huge thanks to layout studio for the window pane rendering code
|
||||
//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)
|
||||
{
|
||||
if (!Runtime.LayoutEditor.DisplayWindowPane)
|
||||
|
|
|
@ -43,12 +43,20 @@ namespace FirstPlugin
|
|||
|
||||
bool useMuunt = true;
|
||||
|
||||
bool IsXML => xmlToolstrip.Checked;
|
||||
|
||||
private TextEditor textEditor;
|
||||
private STToolStipMenuItem xmlToolstrip;
|
||||
private STToolStipMenuItem yamlToolstrip;
|
||||
|
||||
public ByamlEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
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)
|
||||
|
@ -104,9 +112,29 @@ namespace FirstPlugin
|
|||
textEditor.ClearContextMenus();
|
||||
textEditor.AddContextMenu("Decompile", TextEditorToYaml);
|
||||
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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
TreeNode root = new TreeNode(FileName);
|
||||
|
@ -719,15 +747,24 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
private void TextEditorToYaml(object sender, EventArgs e)
|
||||
{
|
||||
var format = (IConvertableTextFormat)FileFormat;
|
||||
textEditor.FillEditor(((IConvertableTextFormat)FileFormat).ConvertToString());
|
||||
private void TextEditorToYaml(object sender, EventArgs e) {
|
||||
UpdateTextEditor();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
textEditor.FillEditor(YamlByamlConverter.ToYaml(FileFormat.BymlData));
|
||||
textEditor.IsYAML = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextEditorFromYaml(object sender, EventArgs e)
|
||||
|
@ -739,7 +776,10 @@ namespace FirstPlugin
|
|||
try
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -196,6 +196,15 @@ namespace Toolbox.Library.Forms
|
|||
private Color BACK_COLOR = Color.FromArgb(30, 30, 30);
|
||||
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)
|
||||
{
|
||||
foreach (ToolStripItem item in stContextMenuStrip1.Items)
|
||||
|
|
Loading…
Reference in a new issue