mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-15 11:25:21 +08:00
Animations XML conversion
This commit is contained in:
+109
-23
@@ -1,4 +1,5 @@
|
||||
using CodeWalker.GameFiles;
|
||||
using FastColoredTextBoxNS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -29,6 +30,8 @@ namespace CodeWalker.Forms
|
||||
}
|
||||
public string FilePath { get; set; }
|
||||
|
||||
private bool LoadingXml = false;
|
||||
private bool DelayHighlight = false;
|
||||
|
||||
|
||||
public YcdForm()
|
||||
@@ -43,30 +46,7 @@ namespace CodeWalker.Forms
|
||||
|
||||
private void ExportOnim_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MainListView.SelectedItems[0].Tag is Animation anim)
|
||||
{
|
||||
var saveFileDialog = new SaveFileDialog();
|
||||
|
||||
string newfn = $"{Path.GetFileNameWithoutExtension(Ycd.Name)}_{MainListView.SelectedItems[0].Text}.onim";
|
||||
|
||||
saveFileDialog.FileName = newfn;
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string path = saveFileDialog.FileName;
|
||||
|
||||
try
|
||||
{
|
||||
using (var file = File.OpenWrite(path))
|
||||
{
|
||||
Ycd.SaveOpenFormatsAnimation(anim, file);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error saving file " + path + ":\n" + ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFormTitle()
|
||||
@@ -74,6 +54,49 @@ namespace CodeWalker.Forms
|
||||
Text = fileName + " - Clip Dictionary Inspector - CodeWalker by dexyfex";
|
||||
}
|
||||
|
||||
private void UpdateXmlTextBox(string xml)
|
||||
{
|
||||
LoadingXml = true;
|
||||
XmlTextBox.Text = "";
|
||||
XmlTextBox.Language = Language.XML;
|
||||
DelayHighlight = false;
|
||||
|
||||
if (string.IsNullOrEmpty(xml))
|
||||
{
|
||||
LoadingXml = false;
|
||||
return;
|
||||
}
|
||||
//if (xml.Length > (1048576 * 5))
|
||||
//{
|
||||
// XmlTextBox.Language = Language.Custom;
|
||||
// XmlTextBox.Text = "[XML size > 10MB - Not shown due to performance limitations - Please use an external viewer for this file.]";
|
||||
// return;
|
||||
//}
|
||||
//else
|
||||
if (xml.Length > (1024 * 512))
|
||||
{
|
||||
XmlTextBox.Language = Language.Custom;
|
||||
DelayHighlight = true;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// XmlTextBox.Language = Language.XML;
|
||||
//}
|
||||
|
||||
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
|
||||
|
||||
XmlTextBox.Text = xml;
|
||||
//XmlTextBox.IsChanged = false;
|
||||
XmlTextBox.ClearUndo();
|
||||
|
||||
Cursor = Cursors.Default;
|
||||
LoadingXml = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void LoadYcd(YcdFile ycd)
|
||||
{
|
||||
@@ -120,8 +143,60 @@ namespace CodeWalker.Forms
|
||||
|
||||
}
|
||||
|
||||
public void LoadXml()
|
||||
{
|
||||
if (Ycd != null)
|
||||
{
|
||||
var xml = YcdXml.GetXml(Ycd);
|
||||
UpdateXmlTextBox(xml);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void HTMLSyntaxHighlight(Range range)
|
||||
{
|
||||
try
|
||||
{
|
||||
Style BlueStyle = new TextStyle(Brushes.Blue, null, FontStyle.Regular);
|
||||
Style RedStyle = new TextStyle(Brushes.Red, null, FontStyle.Regular);
|
||||
Style MaroonStyle = new TextStyle(Brushes.Maroon, null, FontStyle.Regular);
|
||||
|
||||
//clear style of changed range
|
||||
range.ClearStyle(BlueStyle, MaroonStyle, RedStyle);
|
||||
//tag brackets highlighting
|
||||
range.SetStyle(BlueStyle, @"<|/>|</|>");
|
||||
//tag name
|
||||
range.SetStyle(MaroonStyle, @"<(?<range>[!\w]+)");
|
||||
//end of tag
|
||||
range.SetStyle(MaroonStyle, @"</(?<range>\w+)>");
|
||||
//attributes
|
||||
range.SetStyle(RedStyle, @"(?<range>\S+?)='[^']*'|(?<range>\S+)=""[^""]*""|(?<range>\S+)=\S+");
|
||||
//attribute values
|
||||
range.SetStyle(BlueStyle, @"\S+?=(?<range>'[^']*')|\S+=(?<range>""[^""]*"")|\S+=(?<range>\S+)");
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
private void XmlTextBox_VisibleRangeChangedDelayed(object sender, EventArgs e)
|
||||
{
|
||||
//this approach is much faster to load, but no outlining is available
|
||||
|
||||
//highlight only visible area of text
|
||||
if (DelayHighlight)
|
||||
{
|
||||
HTMLSyntaxHighlight(XmlTextBox.VisibleRange);
|
||||
}
|
||||
}
|
||||
|
||||
private void XmlTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (!LoadingXml)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void MainListView_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (MainListView.SelectedItems.Count == 1)
|
||||
@@ -143,5 +218,16 @@ namespace CodeWalker.Forms
|
||||
//MainPropertyGrid.SelectedObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void MainTabControl_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (MainTabControl.SelectedTab == XmlTabPage)
|
||||
{
|
||||
if (string.IsNullOrEmpty(XmlTextBox.Text))
|
||||
{
|
||||
LoadXml();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user