mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
more events for plugins they can handle by overriding the methods
This commit is contained in:
parent
b1ccdbbc7f
commit
ed829d6ca8
4 changed files with 250 additions and 115 deletions
|
@ -91,37 +91,40 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
// This performs the copy. Returns false when copy was cancelled.
|
||||
private bool DoCopySelection()
|
||||
{
|
||||
// Ask the editing mode to prepare selection for copying.
|
||||
// The edit mode should mark all vertices, lines and sectors
|
||||
// that need to be copied.
|
||||
if(General.Map.Mode.OnCopyBegin())
|
||||
// Let the plugins know
|
||||
if(General.Plugins.OnPasteBegin())
|
||||
{
|
||||
// Get all marked elements
|
||||
ICollection<Vertex> verts = General.Map.Map.GetMarkedVertices(true);
|
||||
ICollection<Sidedef> sides = General.Map.Map.GetMarkedSidedefs(true);
|
||||
ICollection<Sector> sectors = General.Map.Map.GetMarkedSectors(true);
|
||||
ICollection<Linedef> lines = General.Map.Map.GetMarkedLinedefs(true);
|
||||
ICollection<Thing> things = General.Map.Map.GetMarkedThings(true);
|
||||
|
||||
// Write data to stream
|
||||
MemoryStream memstream = new MemoryStream();
|
||||
UniversalStreamWriter writer = new UniversalStreamWriter();
|
||||
writer.RememberCustomTypes = false;
|
||||
writer.Write(verts, lines, sides, sectors, things, memstream, null);
|
||||
|
||||
// Set on clipboard
|
||||
Clipboard.SetData(CLIPBOARD_DATA_FORMAT, memstream);
|
||||
|
||||
// Done
|
||||
memstream.Dispose();
|
||||
General.Map.Mode.OnCopyEnd();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
General.MessageBeep(MessageBeepType.Warning);
|
||||
return false;
|
||||
// Ask the editing mode to prepare selection for copying.
|
||||
// The edit mode should mark all vertices, lines and sectors
|
||||
// that need to be copied.
|
||||
if(General.Map.Mode.OnCopyBegin())
|
||||
{
|
||||
// Get all marked elements
|
||||
ICollection<Vertex> verts = General.Map.Map.GetMarkedVertices(true);
|
||||
ICollection<Sidedef> sides = General.Map.Map.GetMarkedSidedefs(true);
|
||||
ICollection<Sector> sectors = General.Map.Map.GetMarkedSectors(true);
|
||||
ICollection<Linedef> lines = General.Map.Map.GetMarkedLinedefs(true);
|
||||
ICollection<Thing> things = General.Map.Map.GetMarkedThings(true);
|
||||
|
||||
// Write data to stream
|
||||
MemoryStream memstream = new MemoryStream();
|
||||
UniversalStreamWriter writer = new UniversalStreamWriter();
|
||||
writer.RememberCustomTypes = false;
|
||||
writer.Write(verts, lines, sides, sectors, things, memstream, null);
|
||||
|
||||
// Set on clipboard
|
||||
Clipboard.SetData(CLIPBOARD_DATA_FORMAT, memstream);
|
||||
|
||||
// Done
|
||||
memstream.Dispose();
|
||||
General.Map.Mode.OnCopyEnd();
|
||||
General.Plugins.OnCopyEnd();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Aborted
|
||||
return false;
|
||||
}
|
||||
|
||||
// This performs the paste. Returns false when paste was cancelled.
|
||||
|
@ -130,36 +133,40 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
// Anything to paste?
|
||||
if(Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT))
|
||||
{
|
||||
// Ask the editing mode to prepare selection for pasting.
|
||||
if(General.Map.Mode.OnPasteBegin())
|
||||
// Let the plugins know
|
||||
if(General.Plugins.OnPasteBegin())
|
||||
{
|
||||
// Read from clipboard
|
||||
Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT);
|
||||
memstream.Seek(0, SeekOrigin.Begin);
|
||||
// Ask the editing mode to prepare selection for pasting.
|
||||
if(General.Map.Mode.OnPasteBegin())
|
||||
{
|
||||
// Read from clipboard
|
||||
Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT);
|
||||
memstream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Mark all current geometry
|
||||
General.Map.Map.ClearAllMarks(true);
|
||||
// Mark all current geometry
|
||||
General.Map.Map.ClearAllMarks(true);
|
||||
|
||||
// Read data stream
|
||||
UniversalStreamReader reader = new UniversalStreamReader();
|
||||
reader.Read(General.Map.Map, memstream);
|
||||
// Read data stream
|
||||
UniversalStreamReader reader = new UniversalStreamReader();
|
||||
reader.Read(General.Map.Map, memstream);
|
||||
|
||||
// The new geometry is not marked, so invert the marks to get it marked
|
||||
General.Map.Map.InvertAllMarks();
|
||||
// The new geometry is not marked, so invert the marks to get it marked
|
||||
General.Map.Map.InvertAllMarks();
|
||||
|
||||
// Done
|
||||
memstream.Dispose();
|
||||
General.Map.Mode.OnPasteEnd();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
General.MessageBeep(MessageBeepType.Warning);
|
||||
return false;
|
||||
// Done
|
||||
memstream.Dispose();
|
||||
General.Map.Mode.OnPasteEnd();
|
||||
General.Plugins.OnPasteEnd();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Aborted
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing usefull on the clipboard
|
||||
General.MessageBeep(MessageBeepType.Warning);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -218,42 +218,49 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
Cursor oldcursor = Cursor.Current;
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
// Call UndoBegin event
|
||||
if(General.Map.Mode.OnUndoBegin())
|
||||
// Let the plugins know
|
||||
if(General.Plugins.OnUndoBegin())
|
||||
{
|
||||
// Cancel volatile mode, if any
|
||||
// This returns false when mode was not volatile
|
||||
if(!General.CancelVolatileMode())
|
||||
// Call UndoBegin event
|
||||
if(General.Map.Mode.OnUndoBegin())
|
||||
{
|
||||
// Anything to undo?
|
||||
if(undos.Count > 0)
|
||||
// Cancel volatile mode, if any
|
||||
// This returns false when mode was not volatile
|
||||
if(!General.CancelVolatileMode())
|
||||
{
|
||||
// Get undo snapshot
|
||||
u = undos[0];
|
||||
undos.RemoveAt(0);
|
||||
// Anything to undo?
|
||||
if(undos.Count > 0)
|
||||
{
|
||||
// Get undo snapshot
|
||||
u = undos[0];
|
||||
undos.RemoveAt(0);
|
||||
|
||||
General.WriteLogLine("Performing undo \"" + u.description + "\", Ticket ID " + u.ticketid + "...");
|
||||
General.WriteLogLine("Performing undo \"" + u.description + "\", Ticket ID " + u.ticketid + "...");
|
||||
|
||||
// Make a snapshot for redo
|
||||
r = new UndoSnapshot(u, General.Map.Map.Clone());
|
||||
// Make a snapshot for redo
|
||||
r = new UndoSnapshot(u, General.Map.Map.Clone());
|
||||
|
||||
// Put it on the stack
|
||||
redos.Insert(0, r);
|
||||
LimitUndoRedoLevel(redos);
|
||||
// Put it on the stack
|
||||
redos.Insert(0, r);
|
||||
LimitUndoRedoLevel(redos);
|
||||
|
||||
// Reset grouping
|
||||
lastgroup = UndoGroup.None;
|
||||
// Reset grouping
|
||||
lastgroup = UndoGroup.None;
|
||||
|
||||
// Remove selection
|
||||
u.map.ClearAllMarks(false);
|
||||
u.map.ClearAllSelected();
|
||||
// Remove selection
|
||||
u.map.ClearAllMarks(false);
|
||||
u.map.ClearAllSelected();
|
||||
|
||||
// Change map set
|
||||
General.Map.ChangeMapSet(u.map);
|
||||
// Change map set
|
||||
General.Map.ChangeMapSet(u.map);
|
||||
|
||||
// Update
|
||||
General.MainWindow.RedrawDisplay();
|
||||
General.MainWindow.UpdateInterface();
|
||||
// Update
|
||||
General.MainWindow.RedrawDisplay();
|
||||
General.MainWindow.UpdateInterface();
|
||||
|
||||
// Done
|
||||
General.Plugins.OnUndoEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,41 +276,48 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
Cursor oldcursor = Cursor.Current;
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
// Call RedoBegin event
|
||||
if(General.Map.Mode.OnRedoBegin())
|
||||
// Let the plugins know
|
||||
if(General.Plugins.OnRedoBegin())
|
||||
{
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
|
||||
// Anything to redo?
|
||||
if(redos.Count > 0)
|
||||
// Call RedoBegin event
|
||||
if(General.Map.Mode.OnRedoBegin())
|
||||
{
|
||||
// Get redo snapshot
|
||||
r = redos[0];
|
||||
redos.RemoveAt(0);
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
|
||||
General.WriteLogLine("Performing redo \"" + r.description + "\", Ticket ID " + r.ticketid + "...");
|
||||
// Anything to redo?
|
||||
if(redos.Count > 0)
|
||||
{
|
||||
// Get redo snapshot
|
||||
r = redos[0];
|
||||
redos.RemoveAt(0);
|
||||
|
||||
// Make a snapshot for undo
|
||||
u = new UndoSnapshot(r, General.Map.Map.Clone());
|
||||
General.WriteLogLine("Performing redo \"" + r.description + "\", Ticket ID " + r.ticketid + "...");
|
||||
|
||||
// Put it on the stack
|
||||
undos.Insert(0, u);
|
||||
LimitUndoRedoLevel(undos);
|
||||
// Make a snapshot for undo
|
||||
u = new UndoSnapshot(r, General.Map.Map.Clone());
|
||||
|
||||
// Reset grouping
|
||||
lastgroup = UndoGroup.None;
|
||||
// Put it on the stack
|
||||
undos.Insert(0, u);
|
||||
LimitUndoRedoLevel(undos);
|
||||
|
||||
// Remove selection
|
||||
r.map.ClearAllMarks(false);
|
||||
r.map.ClearAllSelected();
|
||||
// Reset grouping
|
||||
lastgroup = UndoGroup.None;
|
||||
|
||||
// Change map set
|
||||
General.Map.ChangeMapSet(r.map);
|
||||
// Remove selection
|
||||
r.map.ClearAllMarks(false);
|
||||
r.map.ClearAllSelected();
|
||||
|
||||
// Update
|
||||
General.MainWindow.RedrawDisplay();
|
||||
General.MainWindow.UpdateInterface();
|
||||
// Change map set
|
||||
General.Map.ChangeMapSet(r.map);
|
||||
|
||||
// Update
|
||||
General.MainWindow.RedrawDisplay();
|
||||
General.MainWindow.UpdateInterface();
|
||||
|
||||
// Done
|
||||
General.Plugins.OnRedoEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,10 +136,71 @@ namespace CodeImp.DoomBuilder.Plugins
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user wants to copy selected geometry.
|
||||
/// Return false to abort the copy operation.
|
||||
/// The result parameter is false when the operation was already aborted by another plugin.
|
||||
/// </summary>
|
||||
public virtual bool OnCopyBegin(bool result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user has copied geometry.
|
||||
/// </summary>
|
||||
public virtual void OnCopyEnd()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user wants to paste geometry into the map.
|
||||
/// Return false to abort the paste operation.
|
||||
/// The result parameter is false when the operation was already aborted by another plugin.
|
||||
/// </summary>
|
||||
public virtual bool OnPasteBegin(bool result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user pastes geometry into the map. The new geometry is created and marked before this method is called.
|
||||
/// </summary>
|
||||
public virtual void OnPaste()
|
||||
public virtual void OnPasteEnd()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user wants to undo the previous action.
|
||||
/// Return false to abort the operation.
|
||||
/// The result parameter is false when the operation was already aborted by another plugin.
|
||||
/// </summary>
|
||||
public virtual bool OnUndoBegin(bool result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user has undone the previous action.
|
||||
/// </summary>
|
||||
public virtual void OnUndoEnd()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user wants to redo the previously undone action.
|
||||
/// Return false to abort the operation.
|
||||
/// The result parameter is false when the operation was already aborted by another plugin.
|
||||
/// </summary>
|
||||
public virtual bool OnRedoBegin(bool result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Doom Builder core when the user has redone the action.
|
||||
/// </summary>
|
||||
public virtual void OnRedoEnd()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -201,33 +201,86 @@ namespace CodeImp.DoomBuilder.Plugins
|
|||
|
||||
#region ================== Events
|
||||
|
||||
// This calls OnReloadResources on all plugins
|
||||
|
||||
public void ReloadResources()
|
||||
{
|
||||
foreach(Plugin p in plugins)
|
||||
p.Plug.OnReloadResources();
|
||||
foreach(Plugin p in plugins) p.Plug.OnReloadResources();
|
||||
}
|
||||
|
||||
// This calls OnModeChange on all plugins
|
||||
|
||||
public void ModeChanges(EditMode oldmode, EditMode newmode)
|
||||
{
|
||||
foreach(Plugin p in plugins)
|
||||
p.Plug.OnModeChange(oldmode, newmode);
|
||||
foreach(Plugin p in plugins) p.Plug.OnModeChange(oldmode, newmode);
|
||||
}
|
||||
|
||||
// This calls OnProgramReconfigure on all plugins
|
||||
|
||||
public void ProgramReconfigure()
|
||||
{
|
||||
foreach(Plugin p in plugins)
|
||||
p.Plug.OnProgramReconfigure();
|
||||
foreach(Plugin p in plugins) p.Plug.OnProgramReconfigure();
|
||||
}
|
||||
|
||||
// This calls OnMapReconfigure on all plugins
|
||||
|
||||
public void MapReconfigure()
|
||||
{
|
||||
foreach(Plugin p in plugins)
|
||||
p.Plug.OnMapReconfigure();
|
||||
foreach(Plugin p in plugins) p.Plug.OnMapReconfigure();
|
||||
}
|
||||
|
||||
|
||||
public bool OnCopyBegin()
|
||||
{
|
||||
bool result = true;
|
||||
foreach(Plugin p in plugins) result &= p.Plug.OnCopyBegin(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void OnCopyEnd()
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnCopyEnd();
|
||||
}
|
||||
|
||||
|
||||
public bool OnPasteBegin()
|
||||
{
|
||||
bool result = true;
|
||||
foreach(Plugin p in plugins) result &= p.Plug.OnPasteBegin(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void OnPasteEnd()
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnPasteEnd();
|
||||
}
|
||||
|
||||
|
||||
public bool OnUndoBegin()
|
||||
{
|
||||
bool result = true;
|
||||
foreach(Plugin p in plugins) result &= p.Plug.OnUndoBegin(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void OnUndoEnd()
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnUndoEnd();
|
||||
}
|
||||
|
||||
|
||||
public bool OnRedoBegin()
|
||||
{
|
||||
bool result = true;
|
||||
foreach(Plugin p in plugins) result &= p.Plug.OnRedoBegin(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void OnRedoEnd()
|
||||
{
|
||||
foreach(Plugin p in plugins) p.Plug.OnRedoEnd();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue