Merged changes to YcdForm - export .onim (experimental)

This commit is contained in:
dexy 2019-10-31 15:01:20 +11:00
parent 7adc4b6eea
commit 6e004329f4

View File

@ -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,9 +127,19 @@ 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;
}
}