Worms4Editor/W4Gui/Main.cs

168 lines
5.5 KiB
C#
Raw Permalink Normal View History

2023-01-11 09:22:45 +00:00
using LibW4M;
using LibW4M.Data.WeaponFactory;
2023-03-03 15:59:36 +00:00
using LibW4M.PS2;
2023-03-04 00:24:02 +00:00
using LibW4M.XBOX;
2023-01-11 09:22:45 +00:00
using LibXom;
using LibXom.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
2023-03-05 23:38:01 +00:00
using System.Security.AccessControl;
2023-01-11 09:22:45 +00:00
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2023-03-04 16:10:07 +00:00
using W4Gui.Dialogs;
2023-02-16 04:12:22 +00:00
using W4Gui.Tabs;
2023-01-11 09:22:45 +00:00
namespace W4Gui
{
public partial class Main : Form
{
2023-02-16 04:12:22 +00:00
private static int lastTabIndex = -1;
2023-01-11 09:22:45 +00:00
private const string defaultTitle = "Worms 4: Mayhem! (Save Editor)";
public Main()
{
InitializeComponent();
}
private void W4Gui_Load(object sender, EventArgs e)
{
}
2023-03-03 15:59:36 +00:00
2023-01-11 09:22:45 +00:00
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
2023-03-05 00:01:54 +00:00
#if !DEBUG
2023-03-04 16:10:07 +00:00
try
2023-01-11 09:22:45 +00:00
{
2023-03-05 00:01:54 +00:00
#endif
2023-03-04 16:10:07 +00:00
OpenFileDialog fd = new OpenFileDialog();
2023-03-05 23:38:01 +00:00
fd.Filter = "Worms 4: Mayhem Save Files|*.xom;*.psu;*.zip|Worms 4: Mayhem PC Save File|*.xom|Worms 4: Mayhem PS2 Save File|*.psu|Worms 4: Mayhem XBOX Save File|*.zip";
2023-03-04 16:10:07 +00:00
fd.Title = "Open Worms 4 Save File";
if (fd.ShowDialog() == DialogResult.OK)
2023-03-03 15:59:36 +00:00
{
2023-03-05 23:38:01 +00:00
DataManager.Load(fd.FileName, (SaveType)(fd.FilterIndex-1));
2023-03-04 00:24:02 +00:00
2023-03-04 16:10:07 +00:00
this.mainTabControl.Enabled = true;
this.saveToolStripMenuItem.Enabled = true;
this.saveAsToolStripMenuItem.Enabled = true;
2023-01-11 09:22:45 +00:00
2023-03-04 16:10:07 +00:00
this.Text = defaultTitle + " (" + DataManager.LoadedSaveType.ToString() + ") " + "[" + fd.FileName + "]";
2023-01-11 09:22:45 +00:00
2023-03-05 23:38:01 +00:00
DataManager.ParseData();
2023-03-04 16:10:07 +00:00
}
2023-03-05 00:01:54 +00:00
#if !DEBUG
2023-03-04 16:10:07 +00:00
}
catch (Exception ex)
{
2023-03-05 00:01:54 +00:00
MessageBox.Show("Failed to load save due to an error\n" + ex.Message + "\nThe file may be invalid or corrupt.", "Load failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
2023-01-11 09:22:45 +00:00
}
2023-03-05 00:01:54 +00:00
#endif
2023-01-11 09:22:45 +00:00
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
2023-03-05 00:01:54 +00:00
#if !DEBUG
2023-03-04 16:10:07 +00:00
try
2023-01-11 09:22:45 +00:00
{
2023-03-05 00:01:54 +00:00
#endif
2023-03-04 16:10:07 +00:00
mainTabControl.Enabled = false;
2023-03-05 23:38:01 +00:00
DataManager.CommitData();
DataManager.Save(DataManager.LoadedSavePath, DataManager.LoadedSaveType);
2023-03-04 16:10:07 +00:00
mainTabControl.Enabled = true;
MessageBox.Show("File saved to: " + DataManager.LoadedSavePath, "Save Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information);
2023-03-05 00:01:54 +00:00
#if !DEBUG
2023-01-12 03:50:02 +00:00
}
2023-03-04 16:10:07 +00:00
catch (Exception ex)
2023-01-12 03:50:02 +00:00
{
2023-03-07 07:49:53 +00:00
this.mainTabControl.Enabled = true;
2023-03-04 16:10:07 +00:00
MessageBox.Show("Failed to save: " + ex.Message, "Save failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
2023-01-11 09:22:45 +00:00
}
2023-03-05 00:01:54 +00:00
#endif
2023-01-11 09:22:45 +00:00
}
2023-02-16 04:12:22 +00:00
private void mainTabControl_SelectedIndexChanged(object sender, EventArgs e)
{
if (lastTabIndex >= 0)
{
foreach (Control ctrl in this.mainTabControl.TabPages[lastTabIndex].Controls)
{
try
{
TabEntry? tab = ctrl as TabEntry;
if (tab is TabEntry)
tab.SaveFromControl();
}
catch { }
}
}
if (this.mainTabControl.SelectedIndex >= 0)
{
foreach (Control ctrl in this.mainTabControl.TabPages[this.mainTabControl.SelectedIndex].Controls)
{
try
{
TabEntry? tab = ctrl as TabEntry;
if (tab is TabEntry)
tab.LoadIntoControl();
}
catch { }
}
}
lastTabIndex = this.mainTabControl.SelectedIndex;
}
2023-02-23 09:43:15 +00:00
2023-03-03 15:59:36 +00:00
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
2023-03-05 00:01:54 +00:00
#if !DEBUG
2023-03-04 16:10:07 +00:00
try
2023-03-03 15:59:36 +00:00
{
2023-03-05 00:01:54 +00:00
#endif
2023-03-04 16:10:07 +00:00
SaveFileDialog fd = new SaveFileDialog();
2023-03-05 23:56:45 +00:00
fd.Filter = "Worms 4: Mayhem PC Save File|*.xom|Worms 4: Mayhem PS2 Save File|*.psu|Worms 4: Mayhem XBOX \"NTSC\" (United States) Save File|*.zip|Worms 4: Mayhem XBOX \"PAL\" (Europe & Australia) Save File|*.zip";
2023-03-04 16:10:07 +00:00
fd.Title = "Save Worms 4 Save File";
2023-03-05 23:38:01 +00:00
fd.FilterIndex = (int)DataManager.LoadedSaveType;
2023-03-04 16:10:07 +00:00
fd.FileName = Path.GetFileName(DataManager.LoadedSavePath);
if (fd.ShowDialog() == DialogResult.OK)
{
this.mainTabControl.Enabled = false;
2023-03-03 15:59:36 +00:00
2023-03-05 23:38:01 +00:00
DataManager.CommitData();
2023-03-03 15:59:36 +00:00
2023-03-05 23:38:01 +00:00
SaveType saveType = (SaveType)(fd.FilterIndex);
DataManager.Save(fd.FileName, saveType);
2023-03-03 15:59:36 +00:00
2023-03-05 23:38:01 +00:00
this.Text = defaultTitle + " (" + DataManager.LoadedSaveType.ToString() + ") " + "[" + fd.FileName + "]";
2023-03-04 00:24:02 +00:00
2023-03-07 07:49:53 +00:00
this.mainTabControl.Enabled = true;
2023-03-04 16:10:07 +00:00
MessageBox.Show("File saved to: " + fd.FileName, "Save Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information);
2023-03-05 23:38:01 +00:00
2023-03-04 16:10:07 +00:00
}
2023-03-05 00:01:54 +00:00
#if !DEBUG
2023-03-04 16:10:07 +00:00
}
catch (Exception ex)
{
2023-03-07 07:49:53 +00:00
MessageBox.Show("Failed to save: " + ex.Message, "Save failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.mainTabControl.Enabled = true;
2023-03-03 15:59:36 +00:00
}
2023-03-05 00:01:54 +00:00
#endif
2023-03-03 15:59:36 +00:00
}
2023-03-04 16:10:07 +00:00
private void aboutProgramToolStripMenuItem_Click(object sender, EventArgs e)
{
new AboutW4Gui().ShowDialog();
}
2023-01-11 09:22:45 +00:00
}
}