2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#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;
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
using System.Collections.Generic;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.IO;
|
2016-05-06 08:47:30 +00:00
|
|
|
using System.Runtime.InteropServices;
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
using System.Windows.Forms;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
2009-07-09 14:03:47 +00:00
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Data;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
2016-11-10 12:07:12 +00:00
|
|
|
using CodeImp.DoomBuilder.Types;
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2017-03-17 15:48:14 +00:00
|
|
|
using CodeImp.DoomBuilder.VisualModes;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
|
|
{
|
|
|
|
public class CopyPasteManager
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2013-12-17 08:19:40 +00:00
|
|
|
private const string CLIPBOARD_DATA_FORMAT = "GZDOOM_BUILDER_GEOMETRY";
|
2016-11-10 12:07:12 +00:00
|
|
|
private const string CLIPBOARD_DATA_FORMAT_DB2 = "DOOM_BUILDER_GEOMETRY";
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Disposing
|
2014-02-21 14:42:12 +00:00
|
|
|
private bool isdisposed;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Last inserted prefab
|
|
|
|
private string lastprefabfile;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
|
|
|
public bool IsPreviousPrefabAvailable { get { return (lastprefabfile != null); } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
internal CopyPasteManager()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
|
|
|
|
// Bind any methods
|
|
|
|
General.Actions.BindMethods(this);
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
internal void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Unbind any methods
|
|
|
|
General.Actions.UnbindMethods(this);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This makes a prefab of the selection. Returns null when cancelled.
|
2014-12-03 23:15:26 +00:00
|
|
|
private static MemoryStream MakePrefab()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnCopyBegin())
|
|
|
|
{
|
|
|
|
// 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.Editing.Mode.OnCopyBegin())
|
|
|
|
{
|
|
|
|
// Copy the marked geometry
|
|
|
|
// This links sidedefs that are not linked to a marked sector to a virtual sector
|
|
|
|
MapSet copyset = General.Map.Map.CloneMarked();
|
|
|
|
|
|
|
|
// Convert flags and activations to UDMF fields, if needed
|
2014-12-29 09:19:20 +00:00
|
|
|
if(!(General.Map.FormatInterface is UniversalMapSetIO)) copyset.TranslateToUDMF(General.Map.FormatInterface.GetType());
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Write data to stream
|
|
|
|
MemoryStream memstream = new MemoryStream();
|
|
|
|
UniversalStreamWriter writer = new UniversalStreamWriter();
|
|
|
|
writer.RememberCustomTypes = false;
|
|
|
|
writer.Write(copyset, memstream, null);
|
|
|
|
|
|
|
|
// Compress the stream
|
|
|
|
memstream.Seek(0, SeekOrigin.Begin);
|
2013-09-11 09:47:53 +00:00
|
|
|
MemoryStream compressed = SharpCompressHelper.CompressStream(memstream);//mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
memstream.Dispose();
|
|
|
|
General.Editing.Mode.OnCopyEnd();
|
|
|
|
General.Plugins.OnCopyEnd();
|
|
|
|
return compressed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aborted
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-07-23 14:52:39 +00:00
|
|
|
// This pastes a prefab. Returns false when paste was cancelled.
|
|
|
|
public void InsertPrefabStream(Stream stream, PasteOptions options)
|
|
|
|
{
|
|
|
|
// Cancel volatile mode
|
|
|
|
General.Editing.DisengageVolatileMode();
|
|
|
|
|
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnPasteBegin(options))
|
|
|
|
{
|
|
|
|
// Ask the editing mode to prepare selection for pasting.
|
|
|
|
if(General.Editing.Mode.OnPasteBegin(options))
|
|
|
|
{
|
|
|
|
Cursor oldcursor = Cursor.Current;
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
|
|
|
if(stream != null)
|
|
|
|
PastePrefab(stream, options);
|
|
|
|
|
|
|
|
General.MainWindow.UpdateInterface();
|
|
|
|
|
|
|
|
Cursor.Current = oldcursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This pastes a prefab. Returns false when paste was cancelled.
|
2014-12-03 23:15:26 +00:00
|
|
|
private static void PastePrefab(Stream filedata, PasteOptions options)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Create undo
|
|
|
|
General.MainWindow.DisplayStatus(StatusType.Action, "Inserted prefab.");
|
|
|
|
General.Map.UndoRedo.CreateUndo("Insert prefab");
|
|
|
|
|
|
|
|
// Decompress stream
|
2014-02-21 14:42:12 +00:00
|
|
|
MemoryStream memstream; //mxd
|
2013-09-11 09:47:53 +00:00
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
try
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
memstream = SharpCompressHelper.DecompressStream(filedata); //mxd
|
|
|
|
memstream.Seek(0, SeekOrigin.Begin);
|
2014-12-03 23:15:26 +00:00
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
General.ErrorLogger.Add(ErrorType.Error, e.GetType().Name + " while reading prefab from file: " + e.Message);
|
|
|
|
General.WriteLogLine(e.StackTrace);
|
|
|
|
General.ShowErrorMessage("Unable to load prefab. See log file for error details.", MessageBoxButtons.OK);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Mark all current geometry
|
|
|
|
General.Map.Map.ClearAllMarks(true);
|
|
|
|
|
|
|
|
// Read data stream
|
2013-08-12 10:15:08 +00:00
|
|
|
UniversalStreamReader reader = new UniversalStreamReader(General.Map.FormatInterface.UIFields); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
reader.StrictChecking = false;
|
2009-06-06 00:05:59 +00:00
|
|
|
General.Map.Map.BeginAddRemove();
|
2015-10-01 21:35:52 +00:00
|
|
|
|
|
|
|
//mxd. UniversalStreamReader can now throw errors
|
|
|
|
try
|
|
|
|
{
|
|
|
|
reader.Read(General.Map.Map, memstream);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
General.ErrorLogger.Add(ErrorType.Error, "Unable to load prefab. " + e.GetType().Name + ": " + e.Message);
|
|
|
|
General.ShowErrorMessage("Unable to load prefab." + Environment.NewLine + Environment.NewLine + e.Message, MessageBoxButtons.OK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
General.Map.Map.EndAddRemove();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// The new geometry is not marked, so invert the marks to get it marked
|
|
|
|
General.Map.Map.InvertAllMarks();
|
|
|
|
|
|
|
|
// Convert UDMF fields back to flags and activations, if needed
|
|
|
|
if(!(General.Map.FormatInterface is UniversalMapSetIO)) General.Map.Map.TranslateFromUDMF();
|
2009-07-09 14:03:47 +00:00
|
|
|
|
|
|
|
// Modify tags and actions if preferred
|
|
|
|
if(options.ChangeTags == PasteOptions.TAGS_REMOVE) Tools.RemoveMarkedTags();
|
|
|
|
if(options.ChangeTags == PasteOptions.TAGS_RENUMBER) Tools.RenumberMarkedTags();
|
|
|
|
if(options.RemoveActions) Tools.RemoveMarkedActions();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
memstream.Dispose();
|
|
|
|
General.Map.Map.UpdateConfiguration();
|
|
|
|
General.Map.ThingsFilter.Update();
|
2009-07-09 14:03:47 +00:00
|
|
|
General.Editing.Mode.OnPasteEnd(options);
|
|
|
|
General.Plugins.OnPasteEnd(options);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This performs the copy. Returns false when copy was cancelled.
|
2020-06-12 22:24:24 +00:00
|
|
|
public static bool DoCopySelection(string desc)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Check if possible to copy/paste
|
|
|
|
if(General.Editing.Mode.Attributes.AllowCopyPaste)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnCopyBegin())
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// 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.Editing.Mode.OnCopyBegin())
|
|
|
|
{
|
|
|
|
General.MainWindow.DisplayStatus(StatusType.Action, desc);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
// Copy the marked geometry
|
|
|
|
// This links sidedefs that are not linked to a marked sector to a virtual sector
|
|
|
|
MapSet copyset = General.Map.Map.CloneMarked();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
// Convert flags and activations to UDMF fields, if needed
|
2014-12-29 09:19:20 +00:00
|
|
|
if(!(General.Map.FormatInterface is UniversalMapSetIO)) copyset.TranslateToUDMF(General.Map.FormatInterface.GetType());
|
2011-12-03 14:49:53 +00:00
|
|
|
|
|
|
|
// Write data to stream
|
|
|
|
MemoryStream memstream = new MemoryStream();
|
2013-12-17 08:19:40 +00:00
|
|
|
ClipboardStreamWriter writer = new ClipboardStreamWriter(); //mxd
|
2016-02-22 08:20:33 +00:00
|
|
|
writer.Write(copyset, memstream);
|
2011-12-03 14:49:53 +00:00
|
|
|
|
2016-05-06 08:47:30 +00:00
|
|
|
try
|
|
|
|
{
|
2020-10-03 21:33:04 +00:00
|
|
|
#if !MONO_WINFORMS
|
2016-05-06 08:47:30 +00:00
|
|
|
DataObject copydata = new DataObject();
|
|
|
|
copydata.SetData(CLIPBOARD_DATA_FORMAT, memstream);
|
|
|
|
Clipboard.SetDataObject(copydata, true, 5, 200);
|
2020-10-03 21:33:04 +00:00
|
|
|
#else
|
|
|
|
Clipboard.SetText(CLIPBOARD_DATA_FORMAT + Convert.ToBase64String(memstream.ToArray()));
|
|
|
|
#endif
|
2016-05-06 08:47:30 +00:00
|
|
|
}
|
|
|
|
catch(ExternalException)
|
|
|
|
{
|
|
|
|
General.Interface.DisplayStatus(StatusType.Warning, "Failed to perform a Clipboard operation...");
|
|
|
|
memstream.Dispose();
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
memstream.Dispose();
|
|
|
|
General.Editing.Mode.OnCopyEnd();
|
|
|
|
General.Plugins.OnCopyEnd();
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Copy not allowed
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Aborted
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This performs the paste. Returns false when paste was cancelled.
|
2020-06-12 22:24:24 +00:00
|
|
|
public static void DoPasteSelection(PasteOptions options)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Check if possible to copy/paste
|
|
|
|
if(General.Editing.Mode.Attributes.AllowCopyPaste)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2020-10-03 21:33:04 +00:00
|
|
|
#if !MONO_WINFORMS
|
2016-11-10 12:07:12 +00:00
|
|
|
bool havepastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT); //mxd
|
|
|
|
bool havedb2pastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT_DB2); //mxd
|
2020-10-03 21:33:04 +00:00
|
|
|
#else
|
|
|
|
bool havepastedata = Clipboard.ContainsText() && Clipboard.GetText().Length > CLIPBOARD_DATA_FORMAT.Length && Clipboard.GetText().Substring(0, CLIPBOARD_DATA_FORMAT.Length) == CLIPBOARD_DATA_FORMAT;
|
|
|
|
bool havedb2pastedata = false;
|
|
|
|
#endif
|
2016-11-10 12:07:12 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
// Anything to paste?
|
2016-11-10 12:07:12 +00:00
|
|
|
if(havepastedata || havedb2pastedata)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Cancel volatile mode
|
|
|
|
General.Editing.DisengageVolatileMode();
|
|
|
|
|
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnPasteBegin(options))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Ask the editing mode to prepare selection for pasting.
|
|
|
|
if(General.Editing.Mode.OnPasteBegin(options.Copy()))
|
2010-08-15 19:43:00 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Create undo
|
|
|
|
General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements.");
|
|
|
|
General.Map.UndoRedo.CreateUndo("Paste");
|
|
|
|
|
|
|
|
// Mark all current geometry
|
|
|
|
General.Map.Map.ClearAllMarks(true);
|
|
|
|
|
2016-02-22 08:20:33 +00:00
|
|
|
// Read from clipboard
|
2016-11-10 12:07:12 +00:00
|
|
|
if(havepastedata)
|
|
|
|
{
|
2020-10-03 21:33:04 +00:00
|
|
|
#if MONO_WINFORMS
|
2016-11-10 12:07:12 +00:00
|
|
|
using(Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT))
|
2020-10-03 21:33:04 +00:00
|
|
|
#else
|
|
|
|
using(Stream memstream = new MemoryStream(Convert.FromBase64String(((string)Clipboard.GetData(DataFormats.Text)).Substring(CLIPBOARD_DATA_FORMAT.Length))))
|
|
|
|
#endif
|
2016-11-10 12:07:12 +00:00
|
|
|
{
|
2020-09-29 21:41:45 +00:00
|
|
|
if (memstream == null) return;
|
|
|
|
|
2016-11-10 12:07:12 +00:00
|
|
|
// Rewind before use
|
|
|
|
memstream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
// Read data stream
|
|
|
|
ClipboardStreamReader reader = new ClipboardStreamReader(); //mxd
|
|
|
|
General.Map.Map.BeginAddRemove();
|
|
|
|
bool success = reader.Read(General.Map.Map, memstream);
|
|
|
|
General.Map.Map.EndAddRemove();
|
|
|
|
if(!success) //mxd
|
|
|
|
{
|
|
|
|
General.Map.UndoRedo.WithdrawUndo(); // This will also mess with the marks...
|
|
|
|
General.Map.Map.ClearAllMarks(true); // So re-mark all current geometry...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// mxd. DB2/DB64 interop
|
|
|
|
else if(havedb2pastedata)
|
2016-02-22 08:20:33 +00:00
|
|
|
{
|
2016-11-10 12:07:12 +00:00
|
|
|
using(Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT_DB2))
|
2016-02-22 08:20:33 +00:00
|
|
|
{
|
2020-09-29 21:41:45 +00:00
|
|
|
if (memstream == null) return;
|
|
|
|
|
2016-11-10 12:07:12 +00:00
|
|
|
// Read data stream
|
|
|
|
UniversalStreamReader reader = new UniversalStreamReader(new Dictionary<MapElementType, Dictionary<string, UniversalType>>());
|
|
|
|
reader.StrictChecking = false;
|
|
|
|
General.Map.Map.BeginAddRemove();
|
|
|
|
reader.Read(General.Map.Map, memstream);
|
|
|
|
General.Map.Map.EndAddRemove();
|
2016-02-22 08:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-10 12:07:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotImplementedException("Unknown clipboard data format!");
|
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
|
|
|
|
// The new geometry is not marked, so invert the marks to get it marked
|
|
|
|
General.Map.Map.InvertAllMarks();
|
|
|
|
|
|
|
|
// Check if anything was pasted
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
List<Thing> things = General.Map.Map.GetMarkedThings(true); //mxd
|
|
|
|
int totalpasted = things.Count;
|
2011-12-03 14:49:53 +00:00
|
|
|
totalpasted += General.Map.Map.GetMarkedVertices(true).Count;
|
|
|
|
totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count;
|
|
|
|
totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count;
|
|
|
|
totalpasted += General.Map.Map.GetMarkedSectors(true).Count;
|
2016-02-22 08:20:33 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
if(totalpasted > 0)
|
|
|
|
{
|
2016-02-22 08:20:33 +00:00
|
|
|
// Convert UDMF fields back to flags and activations, if needed
|
|
|
|
if(!(General.Map.FormatInterface is UniversalMapSetIO)) General.Map.Map.TranslateFromUDMF();
|
|
|
|
|
|
|
|
// Modify tags and actions if preferred
|
|
|
|
if(options.ChangeTags == PasteOptions.TAGS_REMOVE) Tools.RemoveMarkedTags();
|
|
|
|
if(options.ChangeTags == PasteOptions.TAGS_RENUMBER) Tools.RenumberMarkedTags();
|
|
|
|
if(options.RemoveActions) Tools.RemoveMarkedActions();
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
foreach(Thing t in things) t.UpdateConfiguration(); //mxd
|
2011-12-03 14:49:53 +00:00
|
|
|
General.Map.ThingsFilter.Update();
|
|
|
|
General.Editing.Mode.OnPasteEnd(options.Copy());
|
|
|
|
General.Plugins.OnPasteEnd(options);
|
|
|
|
}
|
2010-08-15 19:43:00 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-17 15:48:14 +00:00
|
|
|
// Nothing useful on the clipboard
|
|
|
|
// [ZZ] don't beep if 3D mode is currently engaged. the 3D mode allows you to copy/paste non-geometry stuff.
|
|
|
|
// note that this is a hack and probably needs to be fixed properly by making it beep elsewhere so that the current active mode can decide this.
|
|
|
|
if (!(General.Editing.Mode is VisualMode))
|
|
|
|
{
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Paste not allowed
|
2009-04-19 18:07:22 +00:00
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 21:33:04 +00:00
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2020-10-03 21:33:04 +00:00
|
|
|
#region ================== Actions
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This copies the current selection
|
|
|
|
[BeginAction("copyselection")]
|
|
|
|
public void CopySelection()
|
|
|
|
{
|
|
|
|
DoCopySelection("Copied selected elements.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// This cuts the current selection
|
|
|
|
[BeginAction("cutselection")]
|
|
|
|
public void CutSelection()
|
|
|
|
{
|
|
|
|
// Copy selected geometry
|
|
|
|
if(DoCopySelection("Cut selected elements."))
|
|
|
|
{
|
|
|
|
// Get the delete action and check if it's bound
|
|
|
|
Actions.Action deleteitem = General.Actions["builder_deleteitem"];
|
|
|
|
if(deleteitem.BeginBound)
|
|
|
|
{
|
|
|
|
// Perform delete action
|
|
|
|
deleteitem.Begin();
|
|
|
|
deleteitem.End();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Action not bound
|
|
|
|
General.Interface.DisplayStatus(StatusType.Warning, "Cannot remove that in this mode.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 14:03:47 +00:00
|
|
|
// This pastes what is on the clipboard and marks the new geometry
|
|
|
|
[BeginAction("pasteselectionspecial")]
|
|
|
|
public void PasteSelectionSpecial()
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Check if possible to copy/paste
|
|
|
|
if(General.Editing.Mode.Attributes.AllowCopyPaste)
|
|
|
|
{
|
|
|
|
PasteOptionsForm form = new PasteOptionsForm();
|
|
|
|
DialogResult result = form.ShowDialog(General.MainWindow);
|
|
|
|
if(result == DialogResult.OK) DoPasteSelection(form.Options);
|
|
|
|
form.Dispose();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Paste not allowed
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
2009-07-09 14:03:47 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This pastes what is on the clipboard and marks the new geometry
|
|
|
|
[BeginAction("pasteselection")]
|
|
|
|
public void PasteSelection()
|
|
|
|
{
|
2009-07-09 14:03:47 +00:00
|
|
|
DoPasteSelection(General.Settings.PasteOptions);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This creates a new prefab from selection
|
|
|
|
[BeginAction("createprefab")]
|
|
|
|
public void CreatePrefab()
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Check if possible to copy/paste
|
|
|
|
if(General.Editing.Mode.Attributes.AllowCopyPaste)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
Cursor oldcursor = Cursor.Current;
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
MemoryStream data = MakePrefab();
|
|
|
|
if(data != null)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
Cursor.Current = oldcursor;
|
|
|
|
|
|
|
|
SaveFileDialog savefile = new SaveFileDialog();
|
|
|
|
savefile.Filter = "Doom Builder Prefabs (*.dbprefab)|*.dbprefab";
|
|
|
|
savefile.Title = "Save Prefab As";
|
|
|
|
savefile.AddExtension = true;
|
|
|
|
savefile.CheckPathExists = true;
|
|
|
|
savefile.OverwritePrompt = true;
|
|
|
|
savefile.ValidateNames = true;
|
|
|
|
if(savefile.ShowDialog(General.MainWindow) == DialogResult.OK)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
if(File.Exists(savefile.FileName)) File.Delete(savefile.FileName);
|
|
|
|
File.WriteAllBytes(savefile.FileName, data.ToArray());
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
Cursor.Current = oldcursor;
|
|
|
|
General.ErrorLogger.Add(ErrorType.Error, e.GetType().Name + " while writing prefab to file: " + e.Message);
|
|
|
|
General.WriteLogLine(e.StackTrace);
|
|
|
|
General.ShowErrorMessage("Error while writing prefab to file! See log file for error details.", MessageBoxButtons.OK);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
data.Dispose();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Can't make a prefab right now
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
General.MainWindow.UpdateInterface();
|
|
|
|
Cursor.Current = oldcursor;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Create prefab not allowed
|
2009-04-19 18:07:22 +00:00
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This pastes a prefab from file
|
|
|
|
[BeginAction("insertprefabfile")]
|
|
|
|
public void InsertPrefabFile()
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Check if possible to copy/paste
|
|
|
|
if(General.Editing.Mode.Attributes.AllowCopyPaste)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
PasteOptions options = General.Settings.PasteOptions.Copy();
|
|
|
|
|
|
|
|
// Cancel volatile mode
|
|
|
|
General.Editing.DisengageVolatileMode();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnPasteBegin(options))
|
|
|
|
{
|
|
|
|
// Ask the editing mode to prepare selection for pasting.
|
|
|
|
if(General.Editing.Mode.OnPasteBegin(options))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
Cursor oldcursor = Cursor.Current;
|
|
|
|
|
|
|
|
OpenFileDialog openfile = new OpenFileDialog();
|
|
|
|
openfile.Filter = "Doom Builder Prefabs (*.dbprefab)|*.dbprefab";
|
|
|
|
openfile.Title = "Open Prefab";
|
|
|
|
openfile.AddExtension = false;
|
|
|
|
openfile.CheckFileExists = true;
|
|
|
|
openfile.Multiselect = false;
|
|
|
|
openfile.ValidateNames = true;
|
|
|
|
if(openfile.ShowDialog(General.MainWindow) == DialogResult.OK)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
FileStream stream = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
stream = File.OpenRead(openfile.FileName);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
Cursor.Current = oldcursor;
|
|
|
|
General.ErrorLogger.Add(ErrorType.Error, e.GetType().Name + " while reading prefab from file: " + e.Message);
|
|
|
|
General.WriteLogLine(e.StackTrace);
|
|
|
|
General.ShowErrorMessage("Error while reading prefab from file! See log file for error details.", MessageBoxButtons.OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stream != null)
|
|
|
|
{
|
|
|
|
PastePrefab(stream, options);
|
|
|
|
lastprefabfile = openfile.FileName;
|
2016-01-13 09:34:32 +00:00
|
|
|
stream.Dispose();
|
2011-12-03 14:49:53 +00:00
|
|
|
}
|
|
|
|
General.MainWindow.UpdateInterface();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
|
|
|
|
Cursor.Current = oldcursor;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Insert not allowed
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This pastes the previously inserted prefab
|
|
|
|
[BeginAction("insertpreviousprefab")]
|
|
|
|
public void InsertPreviousPrefab()
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Check if possible to copy/paste
|
|
|
|
if(General.Editing.Mode.Attributes.AllowCopyPaste)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
PasteOptions options = General.Settings.PasteOptions.Copy();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
// Is there a previously inserted prefab?
|
|
|
|
if(IsPreviousPrefabAvailable)
|
|
|
|
{
|
|
|
|
// Does the file still exist?
|
|
|
|
if(File.Exists(lastprefabfile))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Cancel volatile mode
|
|
|
|
General.Editing.DisengageVolatileMode();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2011-12-03 14:49:53 +00:00
|
|
|
// Let the plugins know
|
|
|
|
if(General.Plugins.OnPasteBegin(options))
|
|
|
|
{
|
|
|
|
// Ask the editing mode to prepare selection for pasting.
|
|
|
|
if(General.Editing.Mode.OnPasteBegin(options))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
Cursor oldcursor = Cursor.Current;
|
|
|
|
FileStream stream = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
stream = File.OpenRead(lastprefabfile);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
Cursor.Current = oldcursor;
|
|
|
|
General.ErrorLogger.Add(ErrorType.Error, e.GetType().Name + " while reading prefab from file: " + e.Message);
|
|
|
|
General.WriteLogLine(e.StackTrace);
|
|
|
|
General.ShowErrorMessage("Error while reading prefab from file! See log file for error details.", MessageBoxButtons.OK);
|
|
|
|
}
|
|
|
|
|
2016-01-13 09:34:32 +00:00
|
|
|
if(stream != null)
|
|
|
|
{
|
|
|
|
PastePrefab(stream, options);
|
|
|
|
stream.Dispose();
|
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
General.MainWindow.UpdateInterface();
|
2009-04-19 18:07:22 +00:00
|
|
|
Cursor.Current = oldcursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 14:49:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
lastprefabfile = null;
|
|
|
|
General.MainWindow.UpdateInterface();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-03 14:49:53 +00:00
|
|
|
// Insert not allowed
|
2009-04-19 18:07:22 +00:00
|
|
|
General.MessageBeep(MessageBeepType.Warning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 21:33:04 +00:00
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|