mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-03-01 07:11:36 +00:00
Classic modes: you can now hold ALT key while dragging map items to lock movement to grid increments relative to initial position.
This commit is contained in:
parent
00688d4c7c
commit
f2c0d0a4c8
2 changed files with 50 additions and 30 deletions
|
@ -653,6 +653,12 @@ namespace CodeImp.DoomBuilder.Map
|
||||||
|
|
||||||
// This returns all points at which the line intersects with the grid
|
// This returns all points at which the line intersects with the grid
|
||||||
public List<Vector2D> GetGridIntersections()
|
public List<Vector2D> GetGridIntersections()
|
||||||
|
{
|
||||||
|
return GetGridIntersections(new Vector2D());
|
||||||
|
}
|
||||||
|
|
||||||
|
// This returns all points at which the line intersects with the grid
|
||||||
|
public List<Vector2D> GetGridIntersections(Vector2D gridoffset)
|
||||||
{
|
{
|
||||||
List<Vector2D> coords = new List<Vector2D>();
|
List<Vector2D> coords = new List<Vector2D>();
|
||||||
Vector2D v = new Vector2D();
|
Vector2D v = new Vector2D();
|
||||||
|
@ -686,7 +692,7 @@ namespace CodeImp.DoomBuilder.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go for all vertical grid lines in between line start and end
|
// Go for all vertical grid lines in between line start and end
|
||||||
gx = General.Map.Grid.GetHigher(minx);
|
gx = General.Map.Grid.GetHigher(minx) + gridoffset.x;
|
||||||
if(gx < maxx)
|
if(gx < maxx)
|
||||||
{
|
{
|
||||||
for(; gx < maxx; gx += General.Map.Grid.GridSizeF)
|
for(; gx < maxx; gx += General.Map.Grid.GridSizeF)
|
||||||
|
@ -701,7 +707,7 @@ namespace CodeImp.DoomBuilder.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go for all horizontal grid lines in between line start and end
|
// Go for all horizontal grid lines in between line start and end
|
||||||
gy = General.Map.Grid.GetHigher(miny);
|
gy = General.Map.Grid.GetHigher(miny) + gridoffset.y;
|
||||||
if(gy < maxy)
|
if(gy < maxy)
|
||||||
{
|
{
|
||||||
for(; gy < maxy; gy += General.Map.Grid.GridSizeF)
|
for(; gy < maxy; gy += General.Map.Grid.GridSizeF)
|
||||||
|
|
|
@ -40,6 +40,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
// Mouse position on map where dragging started
|
// Mouse position on map where dragging started
|
||||||
private Vector2D dragstartmappos;
|
private Vector2D dragstartmappos;
|
||||||
|
|
||||||
|
//mxd. Offset from nearest grid intersection to dragstartmappos
|
||||||
|
private Vector2D dragstartoffset;
|
||||||
|
|
||||||
// Item used as reference for snapping to the grid
|
// Item used as reference for snapping to the grid
|
||||||
protected Vertex dragitem;
|
protected Vertex dragitem;
|
||||||
private Vector2D dragitemposition;
|
private Vector2D dragitemposition;
|
||||||
|
@ -77,6 +80,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
// Options
|
// Options
|
||||||
private bool snaptogrid; // SHIFT to toggle
|
private bool snaptogrid; // SHIFT to toggle
|
||||||
private bool snaptonearest; // CTRL to enable
|
private bool snaptonearest; // CTRL to enable
|
||||||
|
private bool snaptogridincrement; //mxd. ALT to toggle
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -133,6 +137,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
// Get the nearest vertex for snapping
|
// Get the nearest vertex for snapping
|
||||||
dragitem = MapSet.NearestVertex(selectedverts, dragstartmappos);
|
dragitem = MapSet.NearestVertex(selectedverts, dragstartmappos);
|
||||||
|
|
||||||
|
//mxd. Get drag offset
|
||||||
|
dragstartoffset = dragitem.Position - General.Map.Grid.SnappedToGrid(dragitem.Position);
|
||||||
|
|
||||||
// Lines to snap to
|
// Lines to snap to
|
||||||
snaptolines = General.Map.Map.LinedefsFromMarkedVertices(true, false, false);
|
snaptolines = General.Map.Map.LinedefsFromMarkedVertices(true, false, false);
|
||||||
|
|
||||||
|
@ -202,7 +209,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
|
|
||||||
// This moves the selected geometry relatively
|
// This moves the selected geometry relatively
|
||||||
// Returns true when geometry has actually moved
|
// Returns true when geometry has actually moved
|
||||||
private bool MoveGeometryRelative(Vector2D offset, bool snapgrid, bool snapnearest)
|
private bool MoveGeometryRelative(Vector2D offset, bool snapgrid, bool snapgridincrement, bool snapnearest)
|
||||||
{
|
{
|
||||||
Vector2D oldpos = dragitem.Position;
|
Vector2D oldpos = dragitem.Position;
|
||||||
Vector2D anchorpos = dragitemposition + offset;
|
Vector2D anchorpos = dragitemposition + offset;
|
||||||
|
@ -236,6 +243,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
|
|
||||||
// Do not snap to grid!
|
// Do not snap to grid!
|
||||||
snapgrid = false;
|
snapgrid = false;
|
||||||
|
snaptogridincrement = false; //mxd
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -244,10 +252,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
if(nl != null)
|
if(nl != null)
|
||||||
{
|
{
|
||||||
// Snap to grid?
|
// Snap to grid?
|
||||||
if(snaptogrid)
|
if(snaptogrid || snapgridincrement)
|
||||||
{
|
{
|
||||||
// Get grid intersection coordinates
|
// Get grid intersection coordinates
|
||||||
List<Vector2D> coords = nl.GetGridIntersections();
|
List<Vector2D> coords = nl.GetGridIntersections(snapgridincrement ? dragstartoffset : new Vector2D());
|
||||||
|
|
||||||
// Find nearest grid intersection
|
// Find nearest grid intersection
|
||||||
float found_distance = float.MaxValue;
|
float found_distance = float.MaxValue;
|
||||||
|
@ -270,6 +278,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
|
|
||||||
// Do not snap to grid anymore
|
// Do not snap to grid anymore
|
||||||
snapgrid = false;
|
snapgrid = false;
|
||||||
|
snapgridincrement = false; //mxd
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -283,14 +292,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snap to grid?
|
// Snap to grid or grid increment?
|
||||||
if(snapgrid)
|
if(snapgrid || snapgridincrement)
|
||||||
{
|
{
|
||||||
// Move the dragged item
|
// Move the dragged item
|
||||||
dragitem.Move(anchorpos);
|
dragitem.Move(anchorpos);
|
||||||
|
|
||||||
// Snap item to grid
|
// Snap item to grid increment
|
||||||
|
if(snapgridincrement) //mxd
|
||||||
|
{
|
||||||
|
dragitem.Move(General.Map.Grid.SnappedToGrid(dragitem.Position + dragstartoffset) - dragstartoffset);
|
||||||
|
}
|
||||||
|
else // Or to the grid itself
|
||||||
|
{
|
||||||
dragitem.SnapToGrid();
|
dragitem.SnapToGrid();
|
||||||
|
}
|
||||||
|
|
||||||
// Adjust the offset
|
// Adjust the offset
|
||||||
offset += dragitem.Position - anchorpos;
|
offset += dragitem.Position - anchorpos;
|
||||||
|
@ -303,24 +319,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
if (offset.y + br.y < General.Map.Config.BottomBoundary) offset.y = General.Map.Config.BottomBoundary - br.y;
|
if (offset.y + br.y < General.Map.Config.BottomBoundary) offset.y = General.Map.Config.BottomBoundary - br.y;
|
||||||
|
|
||||||
// Drag item moved?
|
// Drag item moved?
|
||||||
if(!snapgrid || (dragitem.Position != oldpos))
|
if((!snapgrid && !snapgridincrement) || (dragitem.Position != oldpos))
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// Move selected geometry
|
// Move selected geometry
|
||||||
foreach(Vertex v in selectedverts)
|
foreach(Vertex v in selectedverts)
|
||||||
{
|
{
|
||||||
// Move vertex from old position relative to the
|
// Move vertex from old position relative to the mouse position change since drag start
|
||||||
// mouse position change since drag start
|
v.Move(oldpositions[i++] + offset);
|
||||||
v.Move(oldpositions[i] + offset);
|
|
||||||
|
|
||||||
// Next
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//mxd. Move selected things
|
//mxd. Move selected things
|
||||||
i = 0;
|
i = 0;
|
||||||
foreach(Thing t in selectedthings) {
|
foreach(Thing t in selectedthings)
|
||||||
|
{
|
||||||
t.Move(oldthingpositions[i++] + offset);
|
t.Move(oldthingpositions[i++] + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,18 +345,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
// Moved
|
// Moved
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// No changes
|
// No changes
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Cancelled
|
// Cancelled
|
||||||
public override void OnCancel()
|
public override void OnCancel()
|
||||||
{
|
{
|
||||||
// Move geometry back to original position
|
// Move geometry back to original position
|
||||||
MoveGeometryRelative(new Vector2D(0f, 0f), false, false);
|
MoveGeometryRelative(new Vector2D(0f, 0f), false, false, false);
|
||||||
|
|
||||||
// Resume normal undo/redo recording
|
// Resume normal undo/redo recording
|
||||||
General.Map.UndoRedo.IgnorePropChanges = false;
|
General.Map.UndoRedo.IgnorePropChanges = false;
|
||||||
|
@ -381,7 +392,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
Cursor.Current = Cursors.AppStarting;
|
Cursor.Current = Cursors.AppStarting;
|
||||||
|
|
||||||
// Move geometry back to original position
|
// Move geometry back to original position
|
||||||
MoveGeometryRelative(new Vector2D(0f, 0f), false, false);
|
MoveGeometryRelative(new Vector2D(0f, 0f), false, false, false);
|
||||||
|
|
||||||
// Resume normal undo/redo recording
|
// Resume normal undo/redo recording
|
||||||
General.Map.UndoRedo.IgnorePropChanges = false;
|
General.Map.UndoRedo.IgnorePropChanges = false;
|
||||||
|
@ -390,7 +401,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
General.Map.UndoRedo.CreateUndo("Drag geometry");
|
General.Map.UndoRedo.CreateUndo("Drag geometry");
|
||||||
|
|
||||||
// Move selected geometry to final position
|
// Move selected geometry to final position
|
||||||
MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptonearest);
|
MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptogridincrement, snaptonearest);
|
||||||
|
|
||||||
// Stitch geometry
|
// Stitch geometry
|
||||||
if(snaptonearest) General.Map.Map.StitchGeometry();
|
if(snaptonearest) General.Map.Map.StitchGeometry();
|
||||||
|
@ -497,9 +508,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
{
|
{
|
||||||
snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
|
snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
|
||||||
snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
|
snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
|
||||||
|
snaptogridincrement = General.Interface.AltState; //mxd
|
||||||
|
|
||||||
// Move selected geometry
|
// Move selected geometry
|
||||||
if(MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptonearest))
|
if(MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptogridincrement, snaptonearest))
|
||||||
{
|
{
|
||||||
// Update cached values
|
// Update cached values
|
||||||
General.Map.Map.Update(true, false);
|
General.Map.Map.Update(true, false);
|
||||||
|
@ -526,7 +538,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
public override void OnMouseMove(MouseEventArgs e)
|
public override void OnMouseMove(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseMove(e);
|
base.OnMouseMove(e);
|
||||||
if(panning) return; //mxd. Skip all this jass while panning
|
if(panning) return; //mxd. Skip all this jazz while panning
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
// When a key is released
|
// When a key is released
|
||||||
|
@ -534,7 +546,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
{
|
{
|
||||||
base.OnKeyUp(e);
|
base.OnKeyUp(e);
|
||||||
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
||||||
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge))) Update();
|
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge)) ||
|
||||||
|
(snaptogridincrement != General.Interface.AltState)) Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a key is pressed
|
// When a key is pressed
|
||||||
|
@ -542,7 +555,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
{
|
{
|
||||||
base.OnKeyDown(e);
|
base.OnKeyDown(e);
|
||||||
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
||||||
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge))) Update();
|
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge)) ||
|
||||||
|
(snaptogridincrement != General.Interface.AltState)) Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue