UltimateZoneBuilder/Source/BuilderModes/Testing/WAuthorMode.cs

390 lines
9.6 KiB
C#
Raw Normal View History

2008-01-16 06:33:20 +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;
2008-01-16 06:33:20 +00:00
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Actions;
2008-01-16 06:33:20 +00:00
#endregion
namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
[EditMode(SwitchAction = "wauthormode",
ButtonDesc = "WadAuthor Mode",
ButtonImage = "WAuthor.png",
ButtonOrder = int.MinValue + 4,
ConfigSpecific = true)]
public class WAuthorMode : ClassicMode
{
#region ================== Constants
protected const float LINEDEF_HIGHLIGHT_RANGE = 10f;
protected const float VERTEX_HIGHLIGHT_RANGE = 8f;
protected const float THING_HIGHLIGHT_RANGE = 2f;
#endregion
#region ================== Variables
// Tools
protected WAuthorTools tools;
// Highlighted item
protected object highlighted;
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor
public WAuthorMode()
{
// Initialize
tools = new WAuthorTools();
// Enable this and you'll have a floating window
//tools.Show(General.Interface);
//General.Interface.Focus();
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
tools.Dispose();
// Dispose base
base.Dispose();
}
}
#endregion
#region ================== Methods
// Cancel mode
public override void OnCancel()
2008-01-16 06:33:20 +00:00
{
base.OnCancel();
2008-01-16 06:33:20 +00:00
// Return to this mode
General.Map.ChangeMode(new WAuthorMode());
}
// Mode engages
public override void OnEngage()
2008-01-16 06:33:20 +00:00
{
base.OnEngage();
2008-01-16 06:33:20 +00:00
}
// Mode disengages
public override void OnDisengage()
2008-01-16 06:33:20 +00:00
{
base.OnDisengage();
2008-01-16 06:33:20 +00:00
// Clear selected vertices
General.Map.Map.ClearAllSelected();
// Hide highlight info
General.Interface.HideInfo();
}
// This redraws the display
public unsafe override void OnRedrawDisplay()
2008-01-16 06:33:20 +00:00
{
// Render lines and vertices
if(renderer.StartPlotter(true))
2008-01-16 06:33:20 +00:00
{
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if((highlighted != null) && !(highlighted is Thing)) DrawHighlight(true);
renderer.Finish();
}
// Render things
if(renderer.StartThings(true))
{
renderer.RenderThingSet(General.Map.Map.Things, 1.0f);
if((highlighted != null) && (highlighted is Thing)) DrawHighlight(true);
2008-01-16 06:33:20 +00:00
renderer.Finish();
}
renderer.Present();
2008-01-16 06:33:20 +00:00
}
// This draws the highlighted item
protected void DrawHighlight(bool highlightcolor)
{
// With highlight color
if(highlightcolor)
{
// Vertex
if(highlighted is Vertex)
{
if((highlighted as Vertex).IsDisposed) return;
renderer.PlotVertex(highlighted as Vertex, ColorCollection.HIGHLIGHT);
2008-01-16 06:33:20 +00:00
}
// Linedef
else if(highlighted is Linedef)
{
if((highlighted as Linedef).IsDisposed) return;
renderer.PlotLinedef((highlighted as Linedef), General.Colors.Highlight);
renderer.PlotVertex((highlighted as Linedef).Start, renderer.DetermineVertexColor((highlighted as Linedef).Start));
renderer.PlotVertex((highlighted as Linedef).End, renderer.DetermineVertexColor((highlighted as Linedef).End));
2008-01-16 06:33:20 +00:00
}
// Sector
else if(highlighted is Sector)
{
if((highlighted as Sector).IsDisposed) return;
renderer.PlotSector((highlighted as Sector), General.Colors.Highlight);
2008-01-16 06:33:20 +00:00
}
// Thing
else if(highlighted is Thing)
{
if((highlighted as Thing).IsDisposed) return;
renderer.RenderThing((highlighted as Thing), General.Colors.Highlight, 1.0f);
2008-01-16 06:33:20 +00:00
}
}
// With original color
else
{
// Vertex
if(highlighted is Vertex)
{
if((highlighted as Vertex).IsDisposed) return;
renderer.PlotVertex(highlighted as Vertex, renderer.DetermineVertexColor(highlighted as Vertex));
2008-01-16 06:33:20 +00:00
}
// Linedef
else if(highlighted is Linedef)
{
if((highlighted as Linedef).IsDisposed) return;
renderer.PlotLinedef((highlighted as Linedef), renderer.DetermineLinedefColor((highlighted as Linedef)));
renderer.PlotVertex((highlighted as Linedef).Start, renderer.DetermineVertexColor((highlighted as Linedef).Start));
renderer.PlotVertex((highlighted as Linedef).End, renderer.DetermineVertexColor((highlighted as Linedef).End));
2008-01-16 06:33:20 +00:00
}
// Sector
else if(highlighted is Sector)
{
if((highlighted as Sector).IsDisposed) return;
renderer.PlotSector((highlighted as Sector));
2008-01-16 06:33:20 +00:00
}
// Thing
else if(highlighted is Thing)
{
if((highlighted as Thing).IsDisposed) return;
renderer.RenderThing((highlighted as Thing), renderer.DetermineThingColor((highlighted as Thing)), 1.0f);
2008-01-16 06:33:20 +00:00
}
}
}
// This highlights a new item
protected void Highlight(object h)
{
bool renderresult;
2008-01-16 06:33:20 +00:00
// Changes?
if(highlighted != h)
{
if(highlighted != null)
2008-01-16 06:33:20 +00:00
{
// Start update
if(highlighted is Thing)
renderresult = renderer.StartThings(false);
else
renderresult = renderer.StartPlotter(false);
2008-01-16 06:33:20 +00:00
// Undraw previous highlight
if(renderresult)
{
DrawHighlight(false);
renderer.Finish();
}
}
// Set new highlight
highlighted = h;
2008-01-16 06:33:20 +00:00
if(highlighted != null)
{
// Start update
if(highlighted is Thing)
renderresult = renderer.StartThings(false);
else
renderresult = renderer.StartPlotter(false);
2008-01-16 06:33:20 +00:00
// Undraw previous highlight
if(renderresult)
{
DrawHighlight(true);
renderer.Finish();
}
2008-01-16 06:33:20 +00:00
}
// Hide info
General.Interface.HideInfo();
// Anything highlighted?
if(highlighted != null)
{
// Show highlight info
if(highlighted is Vertex)
General.Interface.ShowVertexInfo(highlighted as Vertex);
else if(highlighted is Linedef)
General.Interface.ShowLinedefInfo(highlighted as Linedef);
else if(highlighted is Sector)
General.Interface.ShowSectorInfo(highlighted as Sector);
else if(highlighted is Thing)
General.Interface.ShowThingInfo(highlighted as Thing);
}
renderer.Present();
2008-01-16 06:33:20 +00:00
}
}
// Mouse moves
public override void OnMouseMove(MouseEventArgs e)
2008-01-16 06:33:20 +00:00
{
base.OnMouseMove(e);
2008-01-16 06:33:20 +00:00
// Not holding any buttons?
if(e.Button == MouseButtons.None)
{
// Find the nearest items within highlight range
Vertex v = General.Map.Map.NearestVertexSquareRange(mousemappos, VERTEX_HIGHLIGHT_RANGE / renderer.Scale);
Thing t = General.Map.Map.NearestThingSquareRange(mousemappos, THING_HIGHLIGHT_RANGE / renderer.Scale);
Linedef l = General.Map.Map.NearestLinedef(mousemappos);
Sector s;
// Check on which side of the linedef the mouse is
float side = l.SideOfLine(mousemappos);
if(side > 0)
{
// Is there a sidedef here?
if(l.Back != null) s = l.Back.Sector;
else s = null;
}
else
{
// Is there a sidedef here?
if(l.Front != null) s = l.Front.Sector;
else s = null;
}
// Both a vertex and thing in range?
if((v != null) && (t != null))
{
// Highlight closest
float vd = v.DistanceToSq(mousemappos);
float td = t.DistanceToSq(mousemappos);
if(vd < td) Highlight(v); else Highlight(t);
}
// Vertex in range?
else if(v != null)
{
// Highlight vertex
Highlight(v);
}
// Thing in range?
else if(t != null)
{
// Highlight thing
Highlight(t);
}
else
{
// Linedef within in range?
float ld = l.DistanceTo(mousemappos, true);
if(ld < (LINEDEF_HIGHLIGHT_RANGE / renderer.Scale))
{
// Highlight line
Highlight(l);
}
// Mouse inside a sector?
else if(s != null)
{
// Highlight sector
Highlight(s);
}
else
{
// Highlight nothing
Highlight(null);
}
}
}
}
// Maybe i'll finish this later, or not even include this mode at all, not sure yet.
// Mouse leaves
public override void OnMouseLeave(EventArgs e)
2008-01-16 06:33:20 +00:00
{
base.OnMouseLeave(e);
2008-01-16 06:33:20 +00:00
// Highlight nothing
Highlight(null);
}
// Mouse button pressed
public override void OnMouseDown(MouseEventArgs e)
2008-01-16 06:33:20 +00:00
{
base.OnMouseDown(e);
2008-01-16 06:33:20 +00:00
}
// Mouse released
public override void OnMouseUp(MouseEventArgs e)
2008-01-16 06:33:20 +00:00
{
base.OnMouseUp(e);
2008-01-16 06:33:20 +00:00
// This shows a popup menu
tools.LinedefPopup.Show(Cursor.Position);
}
// Mouse wants to drag
protected override void OnDragStart(MouseEventArgs e)
2008-01-16 06:33:20 +00:00
{
base.OnDragStart(e);
2008-01-16 06:33:20 +00:00
}
#endregion
}
}