UltimateZoneBuilder/Source/Plugins/GZDoomEditing/ClassicModes/FlatAlignMode.cs

165 lines
3.9 KiB
C#
Raw Normal View History

2011-12-06 15:35:11 +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;
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.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using System.Drawing;
using CodeImp.DoomBuilder.Actions;
#endregion
namespace CodeImp.DoomBuilder.GZDoomEditing
{
[EditMode(DisplayName = "Flat Align Mode",
SwitchAction = "flatalignmode",
ButtonImage = "VisualModeZ.png",
ButtonOrder = int.MinValue + 210,
2011-12-07 06:57:38 +00:00
ButtonGroup = "000_editing",
Volatile = true)]
2011-12-06 15:35:11 +00:00
public class FlatAlignMode : BaseClassicMode
{
#region ================== Constants
#endregion
#region ================== Variables
2011-12-07 06:57:38 +00:00
private ICollection<Sector> selection;
2011-12-06 15:35:11 +00:00
#endregion
#region ================== Constructor / Disposer
2011-12-07 06:57:38 +00:00
// Constructor
public FlatAlignMode()
{
}
2011-12-06 15:35:11 +00:00
#endregion
#region ================== Methods
#endregion
#region ================== Events
// Mode engages
public override void OnEngage()
{
base.OnEngage();
2011-12-07 06:57:38 +00:00
// Presentation
2011-12-06 15:35:11 +00:00
renderer.SetPresentation(Presentation.Standard);
2011-12-07 06:57:38 +00:00
// Selection
General.Map.Map.ConvertSelection(SelectionType.Sectors);
General.Map.Map.SelectionType = SelectionType.Sectors;
if(General.Map.Map.SelectedSectorsCount == 0)
{
// Find the nearest linedef within highlight range
Linedef l = General.Map.Map.NearestLinedef(mousemappos);
if(l != null)
{
Sector selectsector = null;
// Check on which side of the linedef the mouse is and which sector there is
float side = l.SideOfLine(mousemappos);
if((side > 0) && (l.Back != null))
selectsector = l.Back.Sector;
else if((side <= 0) && (l.Front != null))
selectsector = l.Front.Sector;
// Select the sector!
if(selectsector != null)
{
selectsector.Selected = true;
foreach(Sidedef sd in selectsector.Sidedefs)
sd.Line.Selected = true;
}
}
}
// Get sector selection
selection = General.Map.Map.GetSelectedSectors(true);
if(selection.Count == 0)
{
General.Interface.MessageBeep(MessageBeepType.Default);
General.Interface.DisplayStatus(StatusType.Info, "A selected sector is required for this action.");
General.Editing.CancelMode();
}
// Find the nearest texture corner
2011-12-06 15:35:11 +00:00
}
// Mode disengages
public override void OnDisengage()
{
base.OnDisengage();
// Hide highlight info
General.Interface.HideInfo();
}
// This redraws the display
public override void OnRedrawDisplay()
{
renderer.RedrawSurface();
// Render lines
if(renderer.StartPlotter(true))
{
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
renderer.Finish();
}
// Render things
if(renderer.StartThings(true))
{
renderer.RenderThingSet(General.Map.ThingsFilter.HiddenThings, Presentation.THINGS_HIDDEN_ALPHA);
renderer.RenderThingSet(General.Map.ThingsFilter.VisibleThings, 1.0f);
renderer.Finish();
}
// Render overlay
if(renderer.StartOverlay(true))
{
renderer.Finish();
}
renderer.Present();
}
#endregion
}
}