mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-17 01:22:18 +00:00
@ Added OnMapSaveBegin and OnMapSaveEnd events for plugins
This commit is contained in:
parent
b7bf1299ce
commit
d913121423
7 changed files with 97 additions and 16 deletions
|
@ -697,6 +697,7 @@
|
|||
<Compile Include="General\CRC.cs" />
|
||||
<Compile Include="General\ErrorItem.cs" />
|
||||
<Compile Include="General\ErrorLogger.cs" />
|
||||
<Compile Include="General\SavePurpose.cs" />
|
||||
<Compile Include="IO\DoomColormapReader.cs" />
|
||||
<Compile Include="Map\SelectionType.cs" />
|
||||
<Compile Include="Map\MapElementCollection.cs" />
|
||||
|
|
|
@ -1109,12 +1109,14 @@ namespace CodeImp.DoomBuilder
|
|||
General.ErrorLogger.IsErrorAdded = false;
|
||||
|
||||
// Save the map
|
||||
if(map.SaveMap(map.FilePathName, MapManager.SAVE_NORMAL))
|
||||
General.Plugins.OnMapSaveBegin(SavePurpose.Normal);
|
||||
if(map.SaveMap(map.FilePathName, SavePurpose.Normal))
|
||||
{
|
||||
// Add recent file
|
||||
mainwindow.AddRecentFile(map.FilePathName);
|
||||
result = true;
|
||||
}
|
||||
General.Plugins.OnMapSaveEnd(SavePurpose.Normal);
|
||||
|
||||
// All done
|
||||
mainwindow.UpdateInterface();
|
||||
|
@ -1165,12 +1167,14 @@ namespace CodeImp.DoomBuilder
|
|||
General.ErrorLogger.IsErrorAdded = false;
|
||||
|
||||
// Save the map
|
||||
if(map.SaveMap(savefile.FileName, MapManager.SAVE_AS))
|
||||
General.Plugins.OnMapSaveBegin(SavePurpose.AsNewFile);
|
||||
if(map.SaveMap(savefile.FileName, SavePurpose.AsNewFile))
|
||||
{
|
||||
// Add recent file
|
||||
mainwindow.AddRecentFile(map.FilePathName);
|
||||
result = true;
|
||||
}
|
||||
General.Plugins.OnMapSaveEnd(SavePurpose.AsNewFile);
|
||||
|
||||
// All done
|
||||
mainwindow.UpdateInterface();
|
||||
|
@ -1222,12 +1226,14 @@ namespace CodeImp.DoomBuilder
|
|||
General.ErrorLogger.IsErrorAdded = false;
|
||||
|
||||
// Save the map
|
||||
if(map.SaveMap(savefile.FileName, MapManager.SAVE_INTO))
|
||||
General.Plugins.OnMapSaveBegin(SavePurpose.IntoFile);
|
||||
if(map.SaveMap(savefile.FileName, SavePurpose.IntoFile))
|
||||
{
|
||||
// Add recent file
|
||||
mainwindow.AddRecentFile(map.FilePathName);
|
||||
result = true;
|
||||
}
|
||||
General.Plugins.OnMapSaveEnd(SavePurpose.IntoFile);
|
||||
|
||||
// All done
|
||||
mainwindow.UpdateInterface();
|
||||
|
|
|
@ -273,7 +273,8 @@ namespace CodeImp.DoomBuilder
|
|||
// Save map to temporary file
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
tempwad = General.MakeTempFilename(General.Map.TempPath, "wad");
|
||||
if(General.Map.SaveMap(tempwad, MapManager.SAVE_TEST))
|
||||
General.Plugins.OnMapSaveBegin(SavePurpose.Testing);
|
||||
if(General.Map.SaveMap(tempwad, SavePurpose.Testing))
|
||||
{
|
||||
// No compiler errors?
|
||||
if(General.Map.Errors.Count == 0)
|
||||
|
@ -332,6 +333,7 @@ namespace CodeImp.DoomBuilder
|
|||
CleanTempFile(General.Map);
|
||||
|
||||
// Done
|
||||
General.Plugins.OnMapSaveEnd(SavePurpose.Testing);
|
||||
General.MainWindow.FocusDisplay();
|
||||
Cursor.Current = oldcursor;
|
||||
}
|
||||
|
|
|
@ -50,12 +50,6 @@ namespace CodeImp.DoomBuilder
|
|||
internal const string BUILD_MAP_HEADER = "MAP01";
|
||||
public const string CONFIG_MAP_HEADER = "~MAP";
|
||||
|
||||
// Save modes
|
||||
public const int SAVE_NORMAL = 0;
|
||||
public const int SAVE_AS = 1;
|
||||
public const int SAVE_INTO = 2;
|
||||
public const int SAVE_TEST = 3;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
@ -433,7 +427,7 @@ namespace CodeImp.DoomBuilder
|
|||
#region ================== Save
|
||||
|
||||
// Initializes for an existing map
|
||||
internal bool SaveMap(string newfilepathname, int savemode)
|
||||
internal bool SaveMap(string newfilepathname, SavePurpose purpose)
|
||||
{
|
||||
MapSet outputset;
|
||||
string nodebuildername, settingsfile;
|
||||
|
@ -468,7 +462,7 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
// Show script window if there are any errors and we are going to test the map
|
||||
// and always update the errors on the scripts window.
|
||||
if((errors.Count > 0) && (scriptwindow == null) && (savemode == SAVE_TEST)) ShowScriptEditor();
|
||||
if((errors.Count > 0) && (scriptwindow == null) && (purpose == SavePurpose.Testing)) ShowScriptEditor();
|
||||
if(scriptwindow != null) scriptwindow.Editor.ShowErrors(errors);
|
||||
|
||||
// Only write the map and rebuild nodes when the actual map has changed
|
||||
|
@ -518,7 +512,7 @@ namespace CodeImp.DoomBuilder
|
|||
outputset.Dispose();
|
||||
|
||||
// Get the corresponding nodebuilder
|
||||
nodebuildername = savemode == SAVE_TEST ? configinfo.NodebuilderTest : configinfo.NodebuilderSave;
|
||||
nodebuildername = (purpose == SavePurpose.Testing) ? configinfo.NodebuilderTest : configinfo.NodebuilderSave;
|
||||
|
||||
// Build the nodes
|
||||
oldstatus = General.MainWindow.Status;
|
||||
|
@ -554,7 +548,7 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
// Except when saving INTO another file,
|
||||
// kill the target file if it is different from source file
|
||||
if((savemode != SAVE_INTO) && (newfilepathname != filepathname))
|
||||
if((purpose != SavePurpose.IntoFile) && (newfilepathname != filepathname))
|
||||
{
|
||||
// Kill target file
|
||||
if(File.Exists(newfilepathname)) File.Delete(newfilepathname);
|
||||
|
@ -565,7 +559,7 @@ namespace CodeImp.DoomBuilder
|
|||
}
|
||||
|
||||
// On Save AS we have to copy the previous file to the new file
|
||||
if((savemode == SAVE_AS) && (filepathname != ""))
|
||||
if((purpose == SavePurpose.AsNewFile) && (filepathname != ""))
|
||||
{
|
||||
// Copy if original file still exists
|
||||
if(File.Exists(filepathname)) File.Copy(filepathname, newfilepathname, true);
|
||||
|
@ -645,7 +639,7 @@ namespace CodeImp.DoomBuilder
|
|||
data.Resume();
|
||||
|
||||
// Not saved for testing purpose?
|
||||
if(savemode != SAVE_TEST)
|
||||
if(purpose != SavePurpose.Testing)
|
||||
{
|
||||
// Saved in a different file?
|
||||
if(newfilepathname != filepathname)
|
||||
|
|
52
Source/Core/General/SavePurpose.cs
Normal file
52
Source/Core/General/SavePurpose.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
||||
* This program is released under GNU General Public License
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Namespaces
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using CodeImp.DoomBuilder.Windows;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using CodeImp.DoomBuilder.Editing;
|
||||
using CodeImp.DoomBuilder.Rendering;
|
||||
using CodeImp.DoomBuilder.Data;
|
||||
using CodeImp.DoomBuilder.Actions;
|
||||
using CodeImp.DoomBuilder.Config;
|
||||
using CodeImp.DoomBuilder.Plugins;
|
||||
using CodeImp.DoomBuilder.Compilers;
|
||||
using CodeImp.DoomBuilder.VisualModes;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder
|
||||
{
|
||||
public enum SavePurpose
|
||||
{
|
||||
Normal = 0,
|
||||
AsNewFile = 1,
|
||||
IntoFile = 2,
|
||||
Testing = 3
|
||||
}
|
||||
}
|
||||
|
|
@ -168,6 +168,20 @@ namespace CodeImp.DoomBuilder.Plugins
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before a map is saved.
|
||||
/// </summary>
|
||||
public virtual void OnMapSaveBegin(SavePurpose purpose)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after a map is saved.
|
||||
/// </summary>
|
||||
public virtual void OnMapSaveEnd(SavePurpose purpose)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before the MapSet is changed. This means that the active MapSet will be disposed and changed to a new one.
|
||||
/// </summary>
|
||||
|
|
|
@ -282,6 +282,18 @@ namespace CodeImp.DoomBuilder.Plugins
|
|||
}
|
||||
|
||||
|
||||
public void OnMapSaveBegin(SavePurpose purpose)
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnMapSaveBegin(purpose);
|
||||
}
|
||||
|
||||
|
||||
public void OnMapSaveEnd(SavePurpose purpose)
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnMapSaveEnd(purpose);
|
||||
}
|
||||
|
||||
|
||||
public void OnMapSetChangeBegin()
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnMapSetChangeBegin();
|
||||
|
|
Loading…
Reference in a new issue