From 6e004329f45ac620a4392aa791622f299f39657c Mon Sep 17 00:00:00 2001 From: dexy Date: Thu, 31 Oct 2019 15:01:20 +1100 Subject: [PATCH] Merged changes to YcdForm - export .onim (experimental) --- Forms/YcdForm.cs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/Forms/YcdForm.cs b/Forms/YcdForm.cs index 31ed2f8..2b7690a 100644 --- a/Forms/YcdForm.cs +++ b/Forms/YcdForm.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -33,9 +34,40 @@ namespace CodeWalker.Forms public YcdForm() { InitializeComponent(); + + MainListView.ContextMenu = new ContextMenu(new[] + { + new MenuItem("Export to openFormats (.onim)...", this.ExportOnim_Click) + }); } + 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() { @@ -95,11 +127,21 @@ namespace CodeWalker.Forms if (MainListView.SelectedItems.Count == 1) { MainPropertyGrid.SelectedObject = MainListView.SelectedItems[0].Tag; + + if (MainPropertyGrid.SelectedObject is Animation) + { + MainListView.ContextMenu.MenuItems[0].Enabled = true; + } + else + { + MainListView.ContextMenu.MenuItems[0].Enabled = false; + } } else { + MainListView.ContextMenu.MenuItems[0].Enabled = false; //MainPropertyGrid.SelectedObject = null; } } } -} +} \ No newline at end of file