2008-05-15 08:56:23 +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;
|
2008-05-29 11:54:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2008-05-15 08:56:23 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using System.Drawing;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
using CodeImp.DoomBuilder.Plugins;
|
2008-06-19 07:25:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Types;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
2008-10-15 11:46:43 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2008-05-15 08:56:23 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
{
|
|
|
|
public class BuilderPlug : Plug
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Static instance
|
|
|
|
private static BuilderPlug me;
|
|
|
|
|
|
|
|
// Main objects
|
|
|
|
private MenusForm menusform;
|
2008-05-15 19:31:11 +00:00
|
|
|
private CurveLinedefsForm curvelinedefsform;
|
2008-09-01 12:14:35 +00:00
|
|
|
private FindReplaceForm findreplaceform;
|
2008-10-23 05:53:34 +00:00
|
|
|
private ErrorCheckForm errorcheckform;
|
2008-05-15 08:56:23 +00:00
|
|
|
|
2008-12-15 22:13:24 +00:00
|
|
|
// Settings
|
|
|
|
private int showvisualthings; // 0 = none, 1 = sprite only, 2 = sprite caged
|
2008-12-31 00:44:04 +00:00
|
|
|
private bool usegravity;
|
2008-12-15 22:13:24 +00:00
|
|
|
|
2008-05-15 08:56:23 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
2008-11-27 12:37:20 +00:00
|
|
|
|
|
|
|
public override string Name { get { return "Doom Builder"; } }
|
2008-05-15 08:56:23 +00:00
|
|
|
public static BuilderPlug Me { get { return me; } }
|
2008-11-27 12:37:20 +00:00
|
|
|
|
2008-05-15 08:56:23 +00:00
|
|
|
public MenusForm MenusForm { get { return menusform; } }
|
2008-05-15 19:31:11 +00:00
|
|
|
public CurveLinedefsForm CurveLinedefsForm { get { return curvelinedefsform; } }
|
2008-09-01 12:14:35 +00:00
|
|
|
public FindReplaceForm FindReplaceForm { get { return findreplaceform; } }
|
2008-10-23 05:53:34 +00:00
|
|
|
public ErrorCheckForm ErrorCheckForm { get { return errorcheckform; } }
|
2008-12-15 22:13:24 +00:00
|
|
|
public int ShowVisualThings { get { return showvisualthings; } set { showvisualthings = value; } }
|
2008-12-31 00:44:04 +00:00
|
|
|
public bool UseGravity { get { return usegravity; } set { usegravity = value; } }
|
2008-11-27 12:37:20 +00:00
|
|
|
|
2008-05-15 08:56:23 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Initialize / Dispose
|
|
|
|
|
|
|
|
// When plugin is initialized
|
|
|
|
public override void OnInitialize()
|
|
|
|
{
|
|
|
|
// Setup
|
|
|
|
me = this;
|
|
|
|
|
2008-12-15 22:13:24 +00:00
|
|
|
// Settings
|
|
|
|
this.showvisualthings = 2;
|
2008-12-31 00:44:04 +00:00
|
|
|
this.usegravity = false;
|
2008-12-15 22:13:24 +00:00
|
|
|
|
2008-05-15 08:56:23 +00:00
|
|
|
// Load menus form and register it
|
|
|
|
menusform = new MenusForm();
|
|
|
|
menusform.Register();
|
2008-05-15 19:31:11 +00:00
|
|
|
|
|
|
|
// Load curve linedefs form
|
|
|
|
curvelinedefsform = new CurveLinedefsForm();
|
2008-09-01 12:14:35 +00:00
|
|
|
|
|
|
|
// Load find/replace form
|
|
|
|
findreplaceform = new FindReplaceForm();
|
2008-10-23 05:53:34 +00:00
|
|
|
|
|
|
|
// Load error checking form
|
|
|
|
errorcheckform = new ErrorCheckForm();
|
2008-05-15 08:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!IsDisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
menusform.Unregister();
|
|
|
|
menusform.Dispose();
|
2008-05-15 19:31:11 +00:00
|
|
|
menusform = null;
|
|
|
|
curvelinedefsform.Dispose();
|
|
|
|
curvelinedefsform = null;
|
2008-09-01 12:14:35 +00:00
|
|
|
findreplaceform.Dispose();
|
|
|
|
findreplaceform = null;
|
2008-10-23 05:53:34 +00:00
|
|
|
errorcheckform.Dispose();
|
|
|
|
errorcheckform = null;
|
2008-05-15 08:56:23 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
me = null;
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
2008-10-08 15:14:02 +00:00
|
|
|
|
2008-10-15 11:46:43 +00:00
|
|
|
// When floor surface geometry is created for classic modes
|
|
|
|
public override void OnSectorFloorSurfaceUpdate(Sector s, ref FlatVertex[] vertices)
|
|
|
|
{
|
|
|
|
ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture);
|
|
|
|
if(img != null)
|
|
|
|
{
|
|
|
|
// Make scalars
|
|
|
|
float sw = 1.0f / img.ScaledWidth;
|
|
|
|
float sh = 1.0f / img.ScaledHeight;
|
|
|
|
|
|
|
|
// Make proper texture coordinates
|
|
|
|
for(int i = 0; i < vertices.Length; i++)
|
|
|
|
{
|
|
|
|
vertices[i].u = vertices[i].u * sw;
|
|
|
|
vertices[i].v = vertices[i].v * sw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When ceiling surface geometry is created for classic modes
|
|
|
|
public override void OnSectorCeilingSurfaceUpdate(Sector s, ref FlatVertex[] vertices)
|
|
|
|
{
|
2008-10-15 17:26:59 +00:00
|
|
|
ImageData img = General.Map.Data.GetFlatImage(s.LongCeilTexture);
|
2008-10-15 11:46:43 +00:00
|
|
|
if(img != null)
|
|
|
|
{
|
|
|
|
// Make scalars
|
|
|
|
float sw = 1.0f / img.ScaledWidth;
|
|
|
|
float sh = 1.0f / img.ScaledHeight;
|
|
|
|
|
|
|
|
// Make proper texture coordinates
|
|
|
|
for(int i = 0; i < vertices.Length; i++)
|
|
|
|
{
|
|
|
|
vertices[i].u = vertices[i].u * sw;
|
|
|
|
vertices[i].v = vertices[i].v * sw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-15 08:56:23 +00:00
|
|
|
// When the editing mode changes
|
2008-10-08 15:14:02 +00:00
|
|
|
public override bool OnModeChange(EditMode oldmode, EditMode newmode)
|
2008-05-15 08:56:23 +00:00
|
|
|
{
|
|
|
|
// Show the correct menu for the new mode
|
|
|
|
menusform.ShowEditingModeMenu(newmode);
|
2008-10-08 15:14:02 +00:00
|
|
|
|
|
|
|
return base.OnModeChange(oldmode, newmode);
|
2008-05-15 08:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2008-06-19 07:25:01 +00:00
|
|
|
|
|
|
|
#region ================== Tools
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-10-23 11:36:00 +00:00
|
|
|
// This finds all class types that inherits from the given type
|
|
|
|
public Type[] FindClasses(Type t)
|
|
|
|
{
|
|
|
|
List<Type> found = new List<Type>();
|
|
|
|
Type[] types;
|
|
|
|
|
|
|
|
// Get all exported types
|
|
|
|
types = Assembly.GetExecutingAssembly().GetTypes();
|
|
|
|
foreach(Type it in types)
|
|
|
|
{
|
|
|
|
// Compare types
|
|
|
|
if(t.IsAssignableFrom(it)) found.Add(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return list
|
|
|
|
return found.ToArray();
|
|
|
|
}
|
|
|
|
|
2008-06-19 07:25:01 +00:00
|
|
|
// This renders the associated sectors/linedefs with the indication color
|
|
|
|
public void PlotAssociations(IRenderer2D renderer, Association asso)
|
|
|
|
{
|
|
|
|
// Tag must be above zero
|
|
|
|
if(asso.tag <= 0) return;
|
|
|
|
|
|
|
|
// Sectors?
|
|
|
|
if(asso.type == UniversalType.SectorTag)
|
|
|
|
{
|
|
|
|
foreach(Sector s in General.Map.Map.Sectors)
|
|
|
|
if(s.Tag == asso.tag) renderer.PlotSector(s, General.Colors.Indication);
|
|
|
|
}
|
|
|
|
// Linedefs?
|
|
|
|
else if(asso.type == UniversalType.LinedefTag)
|
|
|
|
{
|
|
|
|
foreach(Linedef l in General.Map.Map.Linedefs)
|
|
|
|
{
|
|
|
|
if(l.Tag == asso.tag) renderer.PlotLinedef(l, General.Colors.Indication);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-06-19 07:25:01 +00:00
|
|
|
|
|
|
|
// This renders the associated things with the indication color
|
|
|
|
public void RenderAssociations(IRenderer2D renderer, Association asso)
|
|
|
|
{
|
|
|
|
// Tag must be above zero
|
|
|
|
if(asso.tag <= 0) return;
|
|
|
|
|
|
|
|
// Things?
|
|
|
|
if(asso.type == UniversalType.ThingTag)
|
|
|
|
{
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
|
|
|
{
|
|
|
|
if(t.Tag == asso.tag) renderer.RenderThing(t, General.Colors.Indication, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-06-19 07:25:01 +00:00
|
|
|
|
|
|
|
// This renders the associated sectors/linedefs with the indication color
|
|
|
|
public void PlotReverseAssociations(IRenderer2D renderer, Association asso)
|
|
|
|
{
|
|
|
|
// Tag must be above zero
|
|
|
|
if(asso.tag <= 0) return;
|
|
|
|
|
|
|
|
// Linedefs
|
|
|
|
foreach(Linedef l in General.Map.Map.Linedefs)
|
|
|
|
{
|
|
|
|
// Known action on this line?
|
|
|
|
if((l.Action > 0) && General.Map.Config.LinedefActions.ContainsKey(l.Action))
|
|
|
|
{
|
|
|
|
LinedefActionInfo action = General.Map.Config.LinedefActions[l.Action];
|
|
|
|
if((action.Args[0].Type == (int)asso.type) && (l.Args[0] == asso.tag)) renderer.PlotLinedef(l, General.Colors.Indication);
|
|
|
|
if((action.Args[1].Type == (int)asso.type) && (l.Args[1] == asso.tag)) renderer.PlotLinedef(l, General.Colors.Indication);
|
|
|
|
if((action.Args[2].Type == (int)asso.type) && (l.Args[2] == asso.tag)) renderer.PlotLinedef(l, General.Colors.Indication);
|
|
|
|
if((action.Args[3].Type == (int)asso.type) && (l.Args[3] == asso.tag)) renderer.PlotLinedef(l, General.Colors.Indication);
|
|
|
|
if((action.Args[4].Type == (int)asso.type) && (l.Args[4] == asso.tag)) renderer.PlotLinedef(l, General.Colors.Indication);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-22 18:27:50 +00:00
|
|
|
|
2008-06-19 07:25:01 +00:00
|
|
|
|
|
|
|
// This renders the associated things with the indication color
|
|
|
|
public void RenderReverseAssociations(IRenderer2D renderer, Association asso)
|
|
|
|
{
|
|
|
|
// Tag must be above zero
|
|
|
|
if(asso.tag <= 0) return;
|
|
|
|
|
|
|
|
// Things
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
|
|
|
{
|
|
|
|
// Known action on this thing?
|
|
|
|
if((t.Action > 0) && General.Map.Config.LinedefActions.ContainsKey(t.Action))
|
|
|
|
{
|
|
|
|
LinedefActionInfo action = General.Map.Config.LinedefActions[t.Action];
|
|
|
|
if((action.Args[0].Type == (int)asso.type) && (t.Args[0] == asso.tag)) renderer.RenderThing(t, General.Colors.Indication, 1.0f);
|
|
|
|
if((action.Args[1].Type == (int)asso.type) && (t.Args[1] == asso.tag)) renderer.RenderThing(t, General.Colors.Indication, 1.0f);
|
|
|
|
if((action.Args[2].Type == (int)asso.type) && (t.Args[2] == asso.tag)) renderer.RenderThing(t, General.Colors.Indication, 1.0f);
|
|
|
|
if((action.Args[3].Type == (int)asso.type) && (t.Args[3] == asso.tag)) renderer.RenderThing(t, General.Colors.Indication, 1.0f);
|
|
|
|
if((action.Args[4].Type == (int)asso.type) && (t.Args[4] == asso.tag)) renderer.RenderThing(t, General.Colors.Indication, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2008-05-15 08:56:23 +00:00
|
|
|
}
|
|
|
|
}
|