mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 22:01:45 +00:00
Changed, Draw Lines/Rectangle/Circle/Curve modes: line length labels are now repositioned to stay on screen when line's start or end is not visible.
Added, Map Analysis mode: added "Check map size" check. It will generate a warning when map's width or height is larger than 32767 m.u.
This commit is contained in:
parent
c0fbf5e71e
commit
b37457dbc1
8 changed files with 193 additions and 20 deletions
|
@ -37,6 +37,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
float Scale { get; }
|
||||
int VertexSize { get; }
|
||||
ViewMode ViewMode { get; }
|
||||
Size ViewportSize { get; } //mxd
|
||||
|
||||
// View methods
|
||||
Vector2D DisplayToMap(Vector2D mousepos);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#region ================== Namespaces
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using CodeImp.DoomBuilder.Geometry;
|
||||
|
||||
|
@ -46,6 +47,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Disposing
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
public static bool FullBrightness { get { return fullbrightness; } set { fullbrightness = value; } } //mxd
|
||||
public Size ViewportSize { get { return graphics.RenderTarget.Size; } } //mxd
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -225,6 +225,7 @@
|
|||
<Compile Include="ClassicModes\DrawRectangleMode.cs" />
|
||||
<Compile Include="ClassicModes\FlatAlignMode.cs" />
|
||||
<Compile Include="ClassicModes\FloorAlignMode.cs" />
|
||||
<Compile Include="ErrorChecks\CheckMapSize.cs" />
|
||||
<Compile Include="ErrorChecks\CheckMissingFlats.cs" />
|
||||
<Compile Include="ErrorChecks\CheckMissingTextures.cs" />
|
||||
<Compile Include="ErrorChecks\CheckOverlappingVertices.cs" />
|
||||
|
@ -236,6 +237,7 @@
|
|||
<Compile Include="ErrorChecks\CheckUnknownThings.cs" />
|
||||
<Compile Include="ErrorChecks\CheckUnusedTextures.cs" />
|
||||
<Compile Include="ErrorChecks\CheckUnusedThings.cs" />
|
||||
<Compile Include="ErrorChecks\ResultMapTooBig.cs" />
|
||||
<Compile Include="ErrorChecks\ResultMissingFlat.cs" />
|
||||
<Compile Include="ErrorChecks\ResultNoErrors.cs" />
|
||||
<Compile Include="ErrorChecks\ResultSectorInvalid.cs" />
|
||||
|
|
|
@ -74,9 +74,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
DrawnVertex curp = GetCurrentPosition();
|
||||
float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale;
|
||||
|
||||
// Update active label position (mxd)
|
||||
// Update label positions (mxd)
|
||||
if(labels.Count > 0)
|
||||
{
|
||||
// Update labels for already drawn lines
|
||||
for(int i = 0; i < labels.Count - 1; i++)
|
||||
SetLabelPosition(labels[i], points[i].pos, points[i + 1].pos);
|
||||
|
||||
// Update label for active line
|
||||
SetLabelPosition(labels[labels.Count - 1], points[points.Count - 1].pos, curp.pos);
|
||||
}
|
||||
|
||||
// Render drawing lines
|
||||
if(renderer.StartOverlay(true))
|
||||
|
|
|
@ -138,9 +138,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
DrawnVertex curp = GetCurrentPosition();
|
||||
float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale;
|
||||
|
||||
// Update active label position (mxd)
|
||||
if (labels.Count > 0)
|
||||
// Update label positions (mxd)
|
||||
if(labels.Count > 0)
|
||||
{
|
||||
// Update labels for already drawn lines
|
||||
for(int i = 0; i < labels.Count - 1; i++)
|
||||
SetLabelPosition(labels[i], points[i].pos, points[i + 1].pos);
|
||||
|
||||
// Update label for active line
|
||||
SetLabelPosition(labels[labels.Count - 1], points[points.Count - 1].pos, curp.pos);
|
||||
}
|
||||
|
||||
// Render drawing lines
|
||||
if(renderer.StartOverlay(true))
|
||||
|
@ -209,6 +216,43 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
//mxd
|
||||
protected void SetLabelPosition(LineLengthLabel label, Vector2D start, Vector2D end)
|
||||
{
|
||||
// Check if start/end point is on screen...
|
||||
Vector2D lt = General.Map.Renderer2D.DisplayToMap(new Vector2D(0.0f, General.Map.Renderer2D.ViewportSize.Height));
|
||||
Vector2D rb = General.Map.Renderer2D.DisplayToMap(new Vector2D(General.Map.Renderer2D.ViewportSize.Width, 0.0f));
|
||||
RectangleF viewport = new RectangleF(lt.x, lt.y, rb.x - lt.x, rb.y - lt.y);
|
||||
bool startvisible = viewport.Contains(start.x, start.y);
|
||||
bool endvisible = viewport.Contains(end.x, end.y);
|
||||
|
||||
// Do this only when one point is visible, an the other isn't
|
||||
if((!startvisible && endvisible) || (startvisible && !endvisible))
|
||||
{
|
||||
Line2D drawnline = new Line2D(start, end);
|
||||
Line2D[] viewportsides = new[] {
|
||||
new Line2D(lt, rb.x, lt.y), // top
|
||||
new Line2D(lt.x, rb.y, rb.x, rb.y), // bottom
|
||||
new Line2D(lt, lt.x, rb.y), // left
|
||||
new Line2D(rb.x, lt.y, rb.x, rb.y), // right
|
||||
};
|
||||
|
||||
float u;
|
||||
foreach(Line2D side in viewportsides)
|
||||
{
|
||||
// Modify the start point so it stays on screen
|
||||
if(!startvisible && side.GetIntersection(drawnline, out u))
|
||||
{
|
||||
start = drawnline.GetCoordinatesAt(u);
|
||||
break;
|
||||
}
|
||||
|
||||
// Modify the end point so it stays on screen
|
||||
if(!endvisible && side.GetIntersection(drawnline, out u))
|
||||
{
|
||||
end = drawnline.GetCoordinatesAt(u);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector2D perpendicular = (end - start).GetPerpendicular();
|
||||
float angle = perpendicular.GetAngle();
|
||||
float offset = label.TextLabel.TextSize.Width * Math.Abs((float)Math.Sin(angle)) + label.TextLabel.TextSize.Height * Math.Abs((float)Math.Cos(angle));
|
||||
|
@ -560,7 +604,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
// Render things
|
||||
if(renderer.StartThings(true))
|
||||
{
|
||||
renderer.RenderThingSet(General.Map.Map.Things, Presentation.THINGS_ALPHA);
|
||||
renderer.RenderThingSet(General.Map.ThingsFilter.SortedHiddenThings, Presentation.THINGS_HIDDEN_ALPHA);
|
||||
renderer.RenderThingSet(General.Map.ThingsFilter.SortedVisibleThings, Presentation.THINGS_ALPHA);
|
||||
renderer.Finish();
|
||||
}
|
||||
|
||||
|
@ -572,7 +617,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
public override void OnMouseMove(MouseEventArgs 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();
|
||||
}
|
||||
|
||||
|
|
57
Source/Plugins/BuilderModes/ErrorChecks/CheckMapSize.cs
Normal file
57
Source/Plugins/BuilderModes/ErrorChecks/CheckMapSize.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using CodeImp.DoomBuilder.Geometry;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
using System.Threading;
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
|
||||
{
|
||||
[ErrorChecker("Check map size", true, 50)]
|
||||
public class CheckMapSize : ErrorChecker
|
||||
{
|
||||
private const int PROGRESS_STEP = 1000;
|
||||
internal const int MAXIMUM_DISTANCE = 32767;
|
||||
|
||||
// Constructor
|
||||
public CheckMapSize()
|
||||
{
|
||||
// Total progress is done when all vertices are checked
|
||||
SetTotalProgress(General.Map.Map.Vertices.Count / PROGRESS_STEP);
|
||||
}
|
||||
|
||||
// This runs the check
|
||||
public override void Run()
|
||||
{
|
||||
int progress = 0;
|
||||
int stepprogress = 0;
|
||||
|
||||
float minx = int.MaxValue;
|
||||
float maxx = int.MinValue;
|
||||
float miny = int.MaxValue;
|
||||
float maxy = int.MinValue;
|
||||
|
||||
// Go for all vertices
|
||||
foreach(Vertex v in General.Map.Map.Vertices)
|
||||
{
|
||||
if(v.Position.x < minx) minx = v.Position.x;
|
||||
if(v.Position.x > maxx) maxx = v.Position.x;
|
||||
if(v.Position.y < miny) miny = v.Position.y;
|
||||
if(v.Position.y > maxy) maxy = v.Position.y;
|
||||
|
||||
// Handle thread interruption
|
||||
try { Thread.Sleep(0); } catch(ThreadInterruptedException) { return; }
|
||||
|
||||
// We are making progress!
|
||||
if((++progress / PROGRESS_STEP) > stepprogress)
|
||||
{
|
||||
stepprogress = (progress / PROGRESS_STEP);
|
||||
AddProgress(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Map elements should not be more than 32767 mu apart
|
||||
if(maxx - minx > MAXIMUM_DISTANCE || maxy - miny > MAXIMUM_DISTANCE)
|
||||
{
|
||||
SubmitResult(new ResultMapTooBig(new Vector2D(minx, miny), new Vector2D(maxx, maxy)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,8 +63,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
|
||||
#region ================== Methods
|
||||
|
||||
|
||||
|
||||
// When the first button is clicked
|
||||
// Return true when map geometry or things have been added/removed so that the checker can restart
|
||||
public virtual bool Button1Click(bool batchMode)
|
||||
|
@ -93,22 +91,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
}
|
||||
|
||||
// This is called for rendering
|
||||
public virtual void PlotSelection(IRenderer2D renderer)
|
||||
public virtual void PlotSelection(IRenderer2D renderer) { }
|
||||
|
||||
// This is called for rendering (mxd. And never used!)
|
||||
/*public virtual void RenderThingsSelection(IRenderer2D renderer)
|
||||
{
|
||||
}
|
||||
}*/
|
||||
|
||||
// This is called for rendering
|
||||
public virtual void RenderThingsSelection(IRenderer2D renderer)
|
||||
{
|
||||
}
|
||||
|
||||
// This is called for rendering
|
||||
public virtual void RenderOverlaySelection(IRenderer2D renderer)
|
||||
{
|
||||
}
|
||||
public virtual void RenderOverlaySelection(IRenderer2D renderer) { }
|
||||
|
||||
// Call this to zoom in on the given selection
|
||||
public RectangleF GetZoomArea()
|
||||
public virtual RectangleF GetZoomArea()
|
||||
{
|
||||
List<Vector2D> points = new List<Vector2D>();
|
||||
RectangleF area = MapSet.CreateEmptyArea();
|
||||
|
|
65
Source/Plugins/BuilderModes/ErrorChecks/ResultMapTooBig.cs
Normal file
65
Source/Plugins/BuilderModes/ErrorChecks/ResultMapTooBig.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#region ================== Namespaces
|
||||
|
||||
using System.Drawing;
|
||||
using CodeImp.DoomBuilder.Geometry;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.ErrorChecks
|
||||
{
|
||||
public class ResultMapTooBig : ErrorResult
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
private readonly bool toowide;
|
||||
private readonly bool toohigh;
|
||||
private readonly Vector2D min;
|
||||
private readonly Vector2D max;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public override int Buttons { get { return 0; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Destructor
|
||||
|
||||
public ResultMapTooBig(Vector2D min, Vector2D max)
|
||||
{
|
||||
// Initialize
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.toowide = max.x - min.x > CheckMapSize.MAXIMUM_DISTANCE;
|
||||
this.toohigh = max.y - min.y > CheckMapSize.MAXIMUM_DISTANCE;
|
||||
description = "Map is too big.";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
public override RectangleF GetZoomArea()
|
||||
{
|
||||
const float scaler = 0.5f;
|
||||
return new RectangleF(min.x * scaler, min.y * scaler, (max.x - min.x) * scaler, (max.y - min.y) * scaler);
|
||||
}
|
||||
|
||||
// This sets if this result is displayed in ErrorCheckForm (mxd)
|
||||
internal override void Hide(bool hide)
|
||||
{
|
||||
hidden = hide;
|
||||
}
|
||||
|
||||
// This must return the string that is displayed in the listbox
|
||||
public override string ToString()
|
||||
{
|
||||
if(toowide && toohigh) return "Map's width and height is bigger than " + CheckMapSize.MAXIMUM_DISTANCE + " m.u. This can cause rendering and physics issues.";
|
||||
if(toowide) return "Map is wider than than " + CheckMapSize.MAXIMUM_DISTANCE + " m.u. This can cause rendering and physics issues.";
|
||||
return "Map is taller than " + CheckMapSize.MAXIMUM_DISTANCE + " m.u. This can cause rendering and physics issues.";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue