2017-09-29 20:23:37 +08:00
|
|
|
|
using CodeWalker.GameFiles;
|
2019-11-14 15:58:20 +08:00
|
|
|
|
using FastColoredTextBoxNS;
|
2017-09-29 20:23:37 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
2019-10-31 12:01:20 +08:00
|
|
|
|
using System.IO;
|
2017-09-29 20:23:37 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace CodeWalker.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class YcdForm : Form
|
|
|
|
|
{
|
|
|
|
|
|
2017-10-04 11:35:39 +08:00
|
|
|
|
YcdFile Ycd;
|
|
|
|
|
|
2017-09-29 20:23:37 +08:00
|
|
|
|
private string fileName;
|
|
|
|
|
public string FileName
|
|
|
|
|
{
|
|
|
|
|
get { return fileName; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
fileName = value;
|
|
|
|
|
UpdateFormTitle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
|
2019-11-14 15:58:20 +08:00
|
|
|
|
private bool LoadingXml = false;
|
|
|
|
|
private bool DelayHighlight = false;
|
2017-09-29 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public YcdForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-10-31 12:01:20 +08:00
|
|
|
|
|
|
|
|
|
MainListView.ContextMenu = new ContextMenu(new[]
|
|
|
|
|
{
|
|
|
|
|
new MenuItem("Export to openFormats (.onim)...", this.ExportOnim_Click)
|
|
|
|
|
});
|
2017-09-29 20:23:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 12:01:20 +08:00
|
|
|
|
private void ExportOnim_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2017-09-29 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
private void UpdateFormTitle()
|
|
|
|
|
{
|
|
|
|
|
Text = fileName + " - Clip Dictionary Inspector - CodeWalker by dexyfex";
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-14 15:58:20 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-29 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
public void LoadYcd(YcdFile ycd)
|
|
|
|
|
{
|
2017-10-04 11:35:39 +08:00
|
|
|
|
Ycd = ycd;
|
|
|
|
|
|
2017-09-29 20:23:37 +08:00
|
|
|
|
fileName = ycd?.Name;
|
|
|
|
|
if (string.IsNullOrEmpty(fileName))
|
|
|
|
|
{
|
|
|
|
|
fileName = ycd?.RpfFileEntry?.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateFormTitle();
|
|
|
|
|
|
2017-10-04 11:35:39 +08:00
|
|
|
|
//MainPropertyGrid.SelectedObject = ycd;
|
|
|
|
|
|
|
|
|
|
MainListView.Items.Clear();
|
|
|
|
|
|
|
|
|
|
if (ycd?.ClipMapEntries != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var cme in ycd.ClipMapEntries)
|
|
|
|
|
{
|
|
|
|
|
if (cme != null)
|
|
|
|
|
{
|
|
|
|
|
var lvi = MainListView.Items.Add(cme.Clip?.ShortName ?? cme.Hash.ToString());
|
|
|
|
|
lvi.Tag = cme.Clip;
|
|
|
|
|
lvi.Group = MainListView.Groups["Clips"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ycd?.AnimMapEntries != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ame in ycd.AnimMapEntries)
|
|
|
|
|
{
|
|
|
|
|
if (ame != null)
|
|
|
|
|
{
|
|
|
|
|
var lvi = MainListView.Items.Add(ame.Hash.ToString());
|
|
|
|
|
lvi.Tag = ame.Animation;
|
|
|
|
|
lvi.Group = MainListView.Groups["Anims"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 20:23:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-14 15:58:20 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 20:23:37 +08:00
|
|
|
|
|
2019-11-14 15:58:20 +08:00
|
|
|
|
private void XmlTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!LoadingXml)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-04 11:35:39 +08:00
|
|
|
|
|
|
|
|
|
private void MainListView_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MainListView.SelectedItems.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
MainPropertyGrid.SelectedObject = MainListView.SelectedItems[0].Tag;
|
2019-10-31 12:01:20 +08:00
|
|
|
|
|
|
|
|
|
if (MainPropertyGrid.SelectedObject is Animation)
|
|
|
|
|
{
|
|
|
|
|
MainListView.ContextMenu.MenuItems[0].Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MainListView.ContextMenu.MenuItems[0].Enabled = false;
|
|
|
|
|
}
|
2017-10-04 11:35:39 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-31 12:01:20 +08:00
|
|
|
|
MainListView.ContextMenu.MenuItems[0].Enabled = false;
|
2017-10-04 11:35:39 +08:00
|
|
|
|
//MainPropertyGrid.SelectedObject = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-14 15:58:20 +08:00
|
|
|
|
|
|
|
|
|
private void MainTabControl_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MainTabControl.SelectedTab == XmlTabPage)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(XmlTextBox.Text))
|
|
|
|
|
{
|
|
|
|
|
LoadXml();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 20:23:37 +08:00
|
|
|
|
}
|
2019-10-31 12:01:20 +08:00
|
|
|
|
}
|