UltimateZoneBuilder/Source/BuilderModes/ErrorChecks/ErrorResult.cs

194 lines
4.9 KiB
C#
Raw Normal View History

2008-10-23 11:36:00 +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 CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.Config;
using System.Drawing;
2008-10-23 11:36:00 +00:00
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
{
public class ErrorResult
{
#region ================== Variables
2008-10-23 19:08:55 +00:00
protected string description;
protected List<MapElement> viewobjects;
2008-10-23 19:08:55 +00:00
2008-10-23 11:36:00 +00:00
#endregion
#region ================== Properties
2008-10-23 19:08:55 +00:00
public string Description { get { return description; } }
// Override these properties to create buttons
public virtual int Buttons { get { return 0; } }
public virtual string Button1Text { get { return ""; } }
public virtual string Button2Text { get { return ""; } }
public virtual string Button3Text { get { return ""; } }
2008-10-23 11:36:00 +00:00
#endregion
#region ================== Constructor / Destructor
// Constructor
public ErrorResult()
{
// Initialize
viewobjects = new List<MapElement>(1);
2008-10-23 11:36:00 +00:00
}
#endregion
#region ================== Methods
2008-10-23 19:08:55 +00:00
// When the first button is clicked
2008-10-24 05:50:37 +00:00
// Return true when map geometry or things have been added/removed so that the checker can restart
public virtual bool Button1Click()
2008-10-23 19:08:55 +00:00
{
2008-10-24 05:50:37 +00:00
return false;
2008-10-23 19:08:55 +00:00
}
// When the second button is clicked
2008-10-24 05:50:37 +00:00
// Return true when map geometry or things have been added/removed so that the checker can restart
public virtual bool Button2Click()
2008-10-23 19:08:55 +00:00
{
2008-10-24 05:50:37 +00:00
return false;
2008-10-23 19:08:55 +00:00
}
// When the third button is clicked
2008-10-24 05:50:37 +00:00
// Return true when map geometry or things have been added/removed so that the checker can restart
public virtual bool Button3Click()
2008-10-23 19:08:55 +00:00
{
2008-10-24 05:50:37 +00:00
return false;
2008-10-23 19:08:55 +00:00
}
2008-10-23 11:36:00 +00:00
// This must return the string that is displayed in the listbox
public override string ToString()
{
return "Unknown result";
}
2008-10-23 22:01:07 +00:00
// This is called for rendering
public virtual void PlotSelection(IRenderer2D renderer)
{
}
// This is called for rendering
public virtual void RenderThingsSelection(IRenderer2D renderer)
{
}
// This is called for rendering
public virtual void RenderOverlaySelection(IRenderer2D renderer)
{
}
2008-10-23 11:36:00 +00:00
// Call this to zoom in on the given selection
public void ZoomToObject()
{
List<Vector2D> points = new List<Vector2D>();
RectangleF area = MapSet.CreateEmptyArea();
// Add all points to a list
foreach(MapElement obj in viewobjects)
{
if(obj is Vertex)
{
points.Add((obj as Vertex).Position);
}
else if(obj is Linedef)
{
points.Add((obj as Linedef).Start.Position);
points.Add((obj as Linedef).End.Position);
}
else if(obj is Sidedef)
{
points.Add((obj as Sidedef).Line.Start.Position);
points.Add((obj as Sidedef).Line.End.Position);
}
else if(obj is Sector)
{
Sector s = (obj as Sector);
foreach(Sidedef sd in s.Sidedefs)
{
points.Add(sd.Line.Start.Position);
points.Add(sd.Line.End.Position);
}
}
else if(obj is Thing)
{
Thing t = (obj as Thing);
Vector2D p = (Vector2D)t.Position;
points.Add(p);
points.Add(p + new Vector2D(t.Size * 2.0f, t.Size * 2.0f));
points.Add(p + new Vector2D(t.Size * 2.0f, -t.Size * 2.0f));
points.Add(p + new Vector2D(-t.Size * 2.0f, t.Size * 2.0f));
points.Add(p + new Vector2D(-t.Size * 2.0f, -t.Size * 2.0f));
}
else
{
General.Fail("Unknown object given to zoom in on.");
}
}
// Make a view area from the points
foreach(Vector2D p in points) area = MapSet.IncreaseArea(area, p);
// Make the area square, using the largest side
if(area.Width > area.Height)
{
float delta = area.Width - area.Height;
area.Y -= delta * 0.5f;
area.Height += delta;
}
else
{
float delta = area.Height - area.Width;
area.X -= delta * 0.5f;
area.Width += delta;
}
// Add padding
area.Inflate(100f, 100f);
// Zoom to area
ClassicMode editmode = (General.Editing.Mode as ClassicMode);
editmode.CenterOnArea(area, 0.6f);
}
2008-10-23 11:36:00 +00:00
#endregion
}
}