diff --git a/YMTEditor/MainWindow.xaml b/YMTEditor/MainWindow.xaml index 117e2e7..06e9850 100644 --- a/YMTEditor/MainWindow.xaml +++ b/YMTEditor/MainWindow.xaml @@ -11,8 +11,14 @@ + + + + + - + + diff --git a/YMTEditor/MainWindow.xaml.cs b/YMTEditor/MainWindow.xaml.cs index 9dc7546..2568dc9 100644 --- a/YMTEditor/MainWindow.xaml.cs +++ b/YMTEditor/MainWindow.xaml.cs @@ -22,7 +22,8 @@ public partial class MainWindow : Window public static ObservableCollection Components; public static ObservableCollection Props; - private RpfFileEntry rpf; + + public RpfFileEntry entry; public MainWindow() { @@ -54,6 +55,7 @@ private void OpenXML_Click(object sender, RoutedEventArgs e) if (result == true) { Components.Clear(); //so if we import another file when something is imported it will clear + Props.Clear(); string filename = xmlFile.FileName; XMLHandler.LoadXML(filename); _componentsMenu.IsEnabled = true; @@ -66,7 +68,7 @@ private void OpenXML_Click(object sender, RoutedEventArgs e) private void SaveXML_Click(object sender, RoutedEventArgs e) { - OpenFileDialog xmlFile = new OpenFileDialog + SaveFileDialog xmlFile = new SaveFileDialog { DefaultExt = ".ymt.xml", Filter = "Codewalker YMT XML (*.ymt.xml)|*.ymt.xml" @@ -85,7 +87,7 @@ private void OpenYMT_Click(object sender, RoutedEventArgs e) OpenFileDialog ymtFile = new OpenFileDialog { DefaultExt = ".ymt", - Filter = "YMT (*.ymt)|*.ymt" + Filter = "Peds YMT (*.ymt)|*.ymt" }; bool? result = ymtFile.ShowDialog(); if (result == true) @@ -96,16 +98,39 @@ private void OpenYMT_Click(object sender, RoutedEventArgs e) Components.Clear(); //so if we import another file when something is imported it will clear Props.Clear(); - //todo: loading from YMT file + PedFile ymt = new PedFile(); + RpfFile.LoadResourceFile(ymt, ymtBytes, 2); + string xml = MetaXml.GetXml(ymt.Meta); + + XMLHandler.LoadXML(xml); + _componentsMenu.IsEnabled = true; + _componentsMenu.ToolTip = "Check/Uncheck components"; + _propsMenu.IsEnabled = true; + _propsMenu.ToolTip = "Check/Uncheck props"; + SetLogMessage("Loaded YMT from path: " + filename); + } + } + private void SaveYMT_Click(object sender, RoutedEventArgs e) + { + SaveFileDialog xmlFile = new SaveFileDialog + { + DefaultExt = ".ymt.xml", + Filter = "Peds YMT (*.ymt)|*.ymt" + }; + bool? result = xmlFile.ShowDialog(); + if (result == true) + { + string filename = xmlFile.FileName; + System.Xml.XmlDocument newXml = XMLHandler.SaveYMT(filename); + PedFile ymt = new PedFile(); + Meta meta = XmlMeta.GetMeta(newXml); + byte[] newYmtBytes = ResourceBuilder.Build(meta, 2); + + File.WriteAllBytes(filename, newYmtBytes); - //XMLHandler.LoadXML(filename); - //_componentsMenu.IsEnabled = true; - //_componentsMenu.ToolTip = "Check/Uncheck components"; - //_propsMenu.IsEnabled = true; - //_propsMenu.ToolTip = "Check/Uncheck props"; - SetLogMessage("Loaded YMT from path: " + filename); + SetLogMessage("Saved YMT to path: " + filename); } } @@ -175,7 +200,6 @@ private void Button_Click_AddProp(object sender, RoutedEventArgs e) MessageBox.Show("Can't add more textures, limit is 26! (a-z)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } - PropDrawable prop = Props.Where(p => p.propId == enumNumber).First().propList.Where(p => p.propIndex == index).First(); // get prop int drawableToAddTexture = Props.Where(p => p.propId == enumNumber).First().propList.IndexOf(prop); //get index of our clicked prop in collection diff --git a/YMTEditor/XMLHandler.cs b/YMTEditor/XMLHandler.cs index becafc2..1fb0752 100644 --- a/YMTEditor/XMLHandler.cs +++ b/YMTEditor/XMLHandler.cs @@ -18,7 +18,18 @@ class XMLHandler public static void LoadXML(string filePath) { - XDocument xmlFile = XDocument.Load(filePath); + XDocument xmlFile; + if (filePath.EndsWith(".xml")) + { + //loading *.ymt.xml + xmlFile = XDocument.Load(filePath); + } + else + { + //loading *.ymt + xmlFile = XDocument.Parse(filePath); + } + string usedPath = filePath; CPedVariationInfo = xmlFile.Element("CPedVariationInfo").FirstAttribute.Value.ToString(); @@ -347,6 +358,19 @@ public static void SaveXML(string filePath) MessageBox.Show("Saved to: " + filePath, "Saved", MessageBoxButton.OK, MessageBoxImage.Information); } + public static System.Xml.XmlDocument SaveYMT(string filePath) + { + XElement xmlFile = XML_Schema(filePath); + xmlFile.Save(filePath); + + //create XmlDocument from XElement (codewalker.core requires XmlDocument) + var xmldoc = new System.Xml.XmlDocument(); + xmldoc.Load(xmlFile.CreateReader()); + + MessageBox.Show("Saved to: " + filePath, "Saved", MessageBoxButton.OK, MessageBoxImage.Information); + return xmldoc; + } + public static String Number2String(int number, bool isCaps) { Char c = (Char)((isCaps ? 65 : 97) + (number));