mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
- added dragging mode for sectors
- changed "diposed" typos to "disposed" and i'm still too lazy to fix it in my template
This commit is contained in:
parent
a878520a7f
commit
a670efca20
10 changed files with 221 additions and 17 deletions
|
@ -34,6 +34,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LinedefsMode\DragLinedefsMode.cs" />
|
||||
<Compile Include="SectorsMode\DragSectorsMode.cs" />
|
||||
<Compile Include="Shared\DragGeometryMode.cs" />
|
||||
<Compile Include="Testing\TriangulatorMode.cs" />
|
||||
<Compile Include="VisualMode\BaseVisualMode.cs" />
|
||||
|
|
166
Source/BuilderModes/SectorsMode/DragSectorsMode.cs
Normal file
166
Source/BuilderModes/SectorsMode/DragSectorsMode.cs
Normal file
|
@ -0,0 +1,166 @@
|
|||
|
||||
#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 CodeImp.DoomBuilder.Interface;
|
||||
using CodeImp.DoomBuilder.IO;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using CodeImp.DoomBuilder.Rendering;
|
||||
using CodeImp.DoomBuilder.Geometry;
|
||||
using System.Drawing;
|
||||
using CodeImp.DoomBuilder.Editing;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||
{
|
||||
// No action or button for this mode, it is automatic.
|
||||
// The EditMode attribute does not have to be specified unless the
|
||||
// mode must be activated by class name rather than direct instance.
|
||||
// In that case, just specifying the attribute like this is enough:
|
||||
[EditMode]
|
||||
|
||||
public class DragSectorsMode : DragGeometryMode
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private ICollection<Linedef> selectedlines;
|
||||
private ICollection<Linedef> unselectedlines;
|
||||
private ICollection<Sector> selectedsectors;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor to start dragging immediately
|
||||
public DragSectorsMode(EditMode basemode, Sector dragitem, Vector2D dragstartmappos)
|
||||
{
|
||||
// Get the nearest vertex for snapping
|
||||
Vertex nearest = General.Map.Map.NearestVertex(dragstartmappos);
|
||||
|
||||
// Get selected lines
|
||||
selectedlines = General.Map.Map.GetLinedefsSelection(true);
|
||||
unselectedlines = General.Map.Map.GetLinedefsSelection(false);
|
||||
selectedsectors = General.Map.Map.GetSectorsSelection(true);
|
||||
|
||||
// Initialize
|
||||
base.StartDrag(basemode, nearest, dragstartmappos,
|
||||
General.Map.Map.GetVerticesFromLinesSelection(true),
|
||||
General.Map.Map.GetVerticesFromLinesSelectionEx(false));
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Disposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// Mode engages
|
||||
public override void Engage()
|
||||
{
|
||||
base.Engage();
|
||||
}
|
||||
|
||||
// Disenagaging
|
||||
public override void Disengage()
|
||||
{
|
||||
base.Disengage();
|
||||
|
||||
// When not cancelled
|
||||
if(!cancelled)
|
||||
{
|
||||
// If only a single sector was selected, deselect it now
|
||||
if(selectedsectors.Count == 1) General.Map.Map.ClearSelectedSectors();
|
||||
}
|
||||
}
|
||||
|
||||
// This redraws the display
|
||||
public unsafe override void RedrawDisplay()
|
||||
{
|
||||
bool viewchanged = false;
|
||||
|
||||
// Start rendering
|
||||
if(renderer.Start(true, viewchanged))
|
||||
{
|
||||
// Uncomment this to see triangulation
|
||||
/*
|
||||
foreach(Sector s in General.Map.Map.Sectors)
|
||||
{
|
||||
for(int i = 0; i < s.Triangles.Count; i += 3)
|
||||
{
|
||||
renderer.RenderLine(s.Triangles[i + 0], s.Triangles[i + 1], General.Colors.Selection);
|
||||
renderer.RenderLine(s.Triangles[i + 1], s.Triangles[i + 2], General.Colors.Selection);
|
||||
renderer.RenderLine(s.Triangles[i + 2], s.Triangles[i + 0], General.Colors.Selection);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Redraw things when view changed
|
||||
if(CheckViewChanged())
|
||||
{
|
||||
renderer.SetThingsRenderOrder(false);
|
||||
renderer.RenderThingSet(General.Map.Map.Things);
|
||||
}
|
||||
|
||||
// Render lines and vertices
|
||||
renderer.RenderLinedefSet(unselectedlines);
|
||||
renderer.RenderLinedefSet(selectedlines);
|
||||
renderer.RenderVerticesSet(General.Map.Map.Vertices);
|
||||
|
||||
// Draw the dragged item highlighted
|
||||
// This is important to know, because this item is used
|
||||
// for snapping to the grid and snapping to nearest items
|
||||
renderer.RenderVertex(dragitem, ColorCollection.HIGHLIGHT);
|
||||
|
||||
// Done
|
||||
renderer.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -81,6 +81,22 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
|||
|
||||
#region ================== Methods
|
||||
|
||||
// This selectes or deselects a sector
|
||||
protected void SelectSector(Sector s, bool selectstate)
|
||||
{
|
||||
// Flip selection
|
||||
s.Selected = selectstate;
|
||||
|
||||
// Make update lines selection
|
||||
foreach(Sidedef sd in s.Sidedefs)
|
||||
{
|
||||
bool front, back;
|
||||
if(sd.Line.Front != null) front = sd.Line.Front.Sector.Selected; else front = false;
|
||||
if(sd.Line.Back != null) back = sd.Line.Back.Sector.Selected; else back = false;
|
||||
sd.Line.Selected = front | back;
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel mode
|
||||
public override void Cancel()
|
||||
{
|
||||
|
@ -239,7 +255,6 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
|||
public override void MouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.MouseDown(e);
|
||||
bool front, back;
|
||||
|
||||
// Which button is used?
|
||||
if(e.Button == EditMode.SELECT_BUTTON)
|
||||
|
@ -248,15 +263,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
|||
if((highlighted != null) && !highlighted.IsDisposed)
|
||||
{
|
||||
// Flip selection
|
||||
highlighted.Selected = !highlighted.Selected;
|
||||
|
||||
// Make update lines selection
|
||||
foreach(Sidedef sd in highlighted.Sidedefs)
|
||||
{
|
||||
if(sd.Line.Front != null) front = sd.Line.Front.Sector.Selected; else front = false;
|
||||
if(sd.Line.Back != null) back = sd.Line.Back.Sector.Selected; else back = false;
|
||||
sd.Line.Selected = front | back;
|
||||
}
|
||||
SelectSector(highlighted, !highlighted.Selected);
|
||||
|
||||
// Update display
|
||||
if(renderer.Start(false, false))
|
||||
|
@ -286,6 +293,36 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mouse wants to drag
|
||||
protected override void DragStart(MouseEventArgs e)
|
||||
{
|
||||
base.DragStart(e);
|
||||
|
||||
// Which button is used?
|
||||
if(e.Button == EditMode.SELECT_BUTTON)
|
||||
{
|
||||
// Make selection
|
||||
|
||||
}
|
||||
else if(e.Button == EditMode.EDIT_BUTTON)
|
||||
{
|
||||
// Anything highlighted?
|
||||
if((highlighted != null) && !highlighted.IsDisposed)
|
||||
{
|
||||
// Highlighted item not selected?
|
||||
if(!highlighted.Selected)
|
||||
{
|
||||
// Select only this sector for dragging
|
||||
General.Map.Map.ClearSelectedSectors();
|
||||
SelectSector(highlighted, true);
|
||||
}
|
||||
|
||||
// Start dragging the selection
|
||||
General.Map.ChangeMode(new DragSectorsMode(new SectorsMode(), highlighted, mousedownmappos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace CodeImp.DoomBuilder.Editing
|
|||
this.camanglez = Angle2D.PI;
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public override void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public virtual void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
General.Map.Graphics.RegisterResource(this);
|
||||
}
|
||||
|
||||
// Diposer
|
||||
// Disposer
|
||||
public virtual void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
|
|
Loading…
Reference in a new issue