mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
more copy/paste code
This commit is contained in:
parent
ed829d6ca8
commit
a71999542e
5 changed files with 160 additions and 15 deletions
|
@ -99,7 +99,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
General.Map.Map.SelectMarkedGeometry(true, true);
|
||||
|
||||
// Switch to EditSelectionMode
|
||||
General.Map.ChangeMode("EditSelectionMode");
|
||||
EditSelectionMode editmode = new EditSelectionMode();
|
||||
editmode.Pasting = true;
|
||||
General.Map.ChangeMode(editmode);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -83,8 +83,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
|
||||
#region ================== Variables
|
||||
|
||||
// Mode switching
|
||||
// Modes
|
||||
private bool modealreadyswitching = false;
|
||||
private bool pasting = false;
|
||||
|
||||
// Highlighted vertex
|
||||
private Vertex highlighted;
|
||||
|
@ -133,6 +134,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
|
||||
// Just keep the base mode button checked
|
||||
public override string EditModeButtonName { get { return General.Map.PreviousStableMode.Name; } }
|
||||
|
||||
public bool Pasting { get { return pasting; } set { pasting = value; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -657,6 +660,23 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
basesize = size;
|
||||
baseoffset = offset;
|
||||
|
||||
// When pasting, we want to move the geometry so it is visible
|
||||
if(pasting)
|
||||
{
|
||||
// Mouse in screen?
|
||||
if(mouseinside)
|
||||
{
|
||||
offset = mousemappos - size / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2D viewmappos = new Vector2D(renderer.OffsetX, renderer.OffsetY);
|
||||
offset = viewmappos - size / 2;
|
||||
}
|
||||
|
||||
UpdateGeometry();
|
||||
}
|
||||
|
||||
// Set presentation
|
||||
if(selectedthings.Count > 0)
|
||||
renderer.SetPresentation(Presentation.Things);
|
||||
|
@ -717,6 +737,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
// Make undo
|
||||
General.Map.UndoRedo.CreateUndo("Edit selection", UndoGroup.None, 0);
|
||||
|
||||
// Mark the selected geometry
|
||||
General.Map.Map.ClearAllMarks(false);
|
||||
General.Map.Map.MarkAllSelectedGeometry(true);
|
||||
|
||||
// Move geometry to new position
|
||||
UpdateGeometry();
|
||||
General.Map.Map.Update(true, true);
|
||||
|
@ -727,6 +751,105 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
// Snap to map format accuracy
|
||||
General.Map.Map.SnapAllToAccuracy();
|
||||
|
||||
// When pasting, we want to join with the parent sector
|
||||
if(pasting)
|
||||
{
|
||||
// Go for all linedefs in the new geometry
|
||||
ICollection<Linedef> newlines = General.Map.Map.GetMarkedLinedefs(true);
|
||||
foreach(Linedef l in newlines)
|
||||
{
|
||||
// Missing sector on the front?
|
||||
if((l.Front == null) && l.Front.Marked)
|
||||
{
|
||||
bool joined = false;
|
||||
|
||||
// Find a way to join a sector here
|
||||
List<LinedefSide> sectorlines = SectorTools.FindPotentialSectorAt(l, true);
|
||||
if(sectorlines != null)
|
||||
{
|
||||
// We don't always want to join a sector
|
||||
// So first check if any of the surrounding lines originally have sidedefs
|
||||
Sidedef joinsidedef = null;
|
||||
foreach(LinedefSide ls in sectorlines)
|
||||
{
|
||||
if(ls.Front && (ls.Line.Front != null))
|
||||
{
|
||||
joinsidedef = ls.Line.Front;
|
||||
break;
|
||||
}
|
||||
else if(!ls.Front && (ls.Line.Back != null))
|
||||
{
|
||||
joinsidedef = ls.Line.Back;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Join?
|
||||
if(joinsidedef != null)
|
||||
{
|
||||
// Join the new sector
|
||||
Sector newsector = SectorTools.JoinSector(sectorlines, joinsidedef);
|
||||
joined = true;
|
||||
|
||||
// Remove mark from sidedefs so that it is not used to join a sector again
|
||||
foreach(Sidedef sd in newsector.Sidedefs) sd.Marked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Not joined any sector?
|
||||
if(!joined)
|
||||
{
|
||||
// Flip the linedef and correct the sided flags
|
||||
l.FlipVertices();
|
||||
l.FlipSidedefs();
|
||||
l.ApplySidedFlags();
|
||||
}
|
||||
}
|
||||
|
||||
// Missing sector on the back?
|
||||
if((l.Back == null) && l.Back.Marked && l.IsFlagSet(General.Map.Config.DoubleSidedFlag))
|
||||
{
|
||||
bool joined = false;
|
||||
|
||||
// Find a way to join a sector here
|
||||
List<LinedefSide> sectorlines = SectorTools.FindPotentialSectorAt(l, false);
|
||||
if(sectorlines != null)
|
||||
{
|
||||
// We don't always want to join a sector
|
||||
// So first check if any of the surrounding lines originally have sidedefs
|
||||
Sidedef joinsidedef = null;
|
||||
foreach(LinedefSide ls in sectorlines)
|
||||
{
|
||||
if(ls.Front && (ls.Line.Front != null))
|
||||
{
|
||||
joinsidedef = ls.Line.Front;
|
||||
break;
|
||||
}
|
||||
else if(!ls.Front && (ls.Line.Back != null))
|
||||
{
|
||||
joinsidedef = ls.Line.Back;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Join?
|
||||
if(joinsidedef != null)
|
||||
{
|
||||
// Join the new sector
|
||||
Sector newsector = SectorTools.JoinSector(sectorlines, joinsidedef);
|
||||
joined = true;
|
||||
|
||||
// Remove mark from sidedefs so that it is not used to join a sector again
|
||||
foreach(Sidedef sd in newsector.Sidedefs) sd.Marked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Correct the sided flags if not joined a sector
|
||||
if(!joined) l.ApplySidedFlags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update cached values
|
||||
General.Map.Map.Update();
|
||||
|
||||
|
|
|
@ -133,6 +133,9 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
// Anything to paste?
|
||||
if(Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT))
|
||||
{
|
||||
// Cancel volatile mode
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Let the plugins know
|
||||
if(General.Plugins.OnPasteBegin())
|
||||
{
|
||||
|
|
|
@ -707,11 +707,11 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
#region ================== Management
|
||||
|
||||
// This cancels a volatile mode
|
||||
internal static bool CancelVolatileMode()
|
||||
// This cancels a volatile mode, as if the user presses cancel
|
||||
public static bool CancelVolatileMode()
|
||||
{
|
||||
// Volatile mode?
|
||||
if((map != null) && (map.Mode != null) && map.Mode.Attributes.Volatile)
|
||||
if((map != null) & (map.Mode != null) && map.Mode.Attributes.Volatile)
|
||||
{
|
||||
// Cancel
|
||||
map.Mode.OnCancel();
|
||||
|
@ -724,6 +724,23 @@ namespace CodeImp.DoomBuilder
|
|||
}
|
||||
}
|
||||
|
||||
// This disengages a volatile mode, leaving the choice to cancel or accept to the editing mode
|
||||
public static bool DisengageVolatileMode()
|
||||
{
|
||||
// Volatile mode?
|
||||
if((map != null) & (map.Mode != null) && map.Mode.Attributes.Volatile)
|
||||
{
|
||||
// Change back to normal mode
|
||||
map.ChangeMode(map.PreviousStableMode.Name);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mode is not volatile
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// This creates a new map
|
||||
[BeginAction("newmap")]
|
||||
internal static void NewMap()
|
||||
|
@ -732,7 +749,7 @@ namespace CodeImp.DoomBuilder
|
|||
MapOptionsForm optionswindow;
|
||||
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Ask the user to save changes (if any)
|
||||
if(General.AskSaveMap())
|
||||
|
@ -783,7 +800,7 @@ namespace CodeImp.DoomBuilder
|
|||
internal static bool CloseMap()
|
||||
{
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Ask the user to save changes (if any)
|
||||
if(General.AskSaveMap())
|
||||
|
@ -823,7 +840,7 @@ namespace CodeImp.DoomBuilder
|
|||
OpenFileDialog openfile;
|
||||
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Open map file dialog
|
||||
openfile = new OpenFileDialog();
|
||||
|
@ -849,7 +866,7 @@ namespace CodeImp.DoomBuilder
|
|||
OpenMapOptionsForm openmapwindow;
|
||||
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Ask the user to save changes (if any)
|
||||
if(General.AskSaveMap())
|
||||
|
@ -908,7 +925,7 @@ namespace CodeImp.DoomBuilder
|
|||
bool result = false;
|
||||
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Check if a wad file is known
|
||||
if(map.FilePathName == "")
|
||||
|
@ -950,7 +967,7 @@ namespace CodeImp.DoomBuilder
|
|||
bool result = false;
|
||||
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Show save as dialog
|
||||
savefile = new SaveFileDialog();
|
||||
|
@ -994,7 +1011,7 @@ namespace CodeImp.DoomBuilder
|
|||
bool result = false;
|
||||
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Show save as dialog
|
||||
savefile = new SaveFileDialog();
|
||||
|
|
|
@ -832,7 +832,7 @@ namespace CodeImp.DoomBuilder
|
|||
#endregion
|
||||
|
||||
#region ================== Editing Modes
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This cancels the current mode.
|
||||
/// </summary>
|
||||
|
@ -949,7 +949,7 @@ namespace CodeImp.DoomBuilder
|
|||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
|
||||
// This changes thing filter
|
||||
internal void ChangeThingFilter(ThingsFilter newfilter)
|
||||
{
|
||||
|
@ -1036,7 +1036,7 @@ namespace CodeImp.DoomBuilder
|
|||
internal void ShowMapOptions()
|
||||
{
|
||||
// Cancel volatile mode, if any
|
||||
General.CancelVolatileMode();
|
||||
General.DisengageVolatileMode();
|
||||
|
||||
// Show map options dialog
|
||||
MapOptionsForm optionsform = new MapOptionsForm(options);
|
||||
|
|
Loading…
Reference in a new issue