UltimateZoneBuilder/Source/Plugins/GZDoomEditing/General/BuilderPlug.cs

221 lines
7.8 KiB
C#
Raw Normal View History

2010-09-01 20:08:07 +00:00

#region ================== Copyright (c) 2010 Pascal vd Heiden
/*
* Copyright (c) 2010 Pascal vd Heiden
* 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.Collections.ObjectModel;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.Windows;
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;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Types;
using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Data;
#endregion
namespace CodeImp.DoomBuilder.GZDoomEditing
{
public class BuilderPlug : Plug
{
#region ================== Variables
// Static instance
private static BuilderPlug me;
// Settings
private int showvisualthings; // 0 = none, 1 = sprite only, 2 = sprite caged
private int changeheightbysidedef; // 0 = nothing, 1 = change ceiling, 2 = change floor
private bool visualmodeclearselection;
private bool usegravity;
private bool usehighlight;
// Copy/paste
private string copiedtexture;
private string copiedflat;
private Point copiedoffsets;
private VertexProperties copiedvertexprops;
private SectorProperties copiedsectorprops;
private SidedefProperties copiedsidedefprops;
private LinedefProperties copiedlinedefprops;
private ThingProperties copiedthingprops;
2010-09-01 20:08:07 +00:00
#endregion
#region ================== Properties
// Static property to access the BuilderPlug
public static BuilderPlug Me { get { return me; } }
2010-09-10 13:17:38 +00:00
// This is the lowest Doom Builder core revision that is required for this plugin to work
public override int MinimumRevision { get { return 1394; } }
2010-09-10 13:17:38 +00:00
// Settings
public int ShowVisualThings { get { return showvisualthings; } set { showvisualthings = value; } }
public int ChangeHeightBySidedef { get { return changeheightbysidedef; } }
public bool VisualModeClearSelection { get { return visualmodeclearselection; } }
public bool UseGravity { get { return usegravity; } set { usegravity = value; } }
public bool UseHighlight { get { return usehighlight; } set { usehighlight = value; } }
// Copy/paste
public string CopiedTexture { get { return copiedtexture; } set { copiedtexture = value; } }
public string CopiedFlat { get { return copiedflat; } set { copiedflat = value; } }
public Point CopiedOffsets { get { return copiedoffsets; } set { copiedoffsets = value; } }
public VertexProperties CopiedVertexProps { get { return copiedvertexprops; } set { copiedvertexprops = value; } }
public SectorProperties CopiedSectorProps { get { return copiedsectorprops; } set { copiedsectorprops = value; } }
public SidedefProperties CopiedSidedefProps { get { return copiedsidedefprops; } set { copiedsidedefprops = value; } }
public LinedefProperties CopiedLinedefProps { get { return copiedlinedefprops; } set { copiedlinedefprops = value; } }
public ThingProperties CopiedThingProps { get { return copiedthingprops; } set { copiedthingprops = value; } }
2010-09-01 20:08:07 +00:00
#endregion
#region ================== Initialize / Dispose
// This event is called when the plugin is initialized
public override void OnInitialize()
{
base.OnInitialize();
// Keep a static reference
me = this;
2010-09-02 20:42:38 +00:00
// Settings
showvisualthings = 2;
usegravity = false;
usehighlight = true;
LoadSettings();
2010-09-01 20:08:07 +00:00
}
// This is called when the plugin is terminated
public override void Dispose()
{
base.Dispose();
}
#endregion
#region ================== Methods
// This loads the plugin settings
private void LoadSettings()
{
changeheightbysidedef = General.Settings.ReadPluginSetting("changeheightbysidedef", 0);
visualmodeclearselection = General.Settings.ReadPluginSetting("visualmodeclearselection", false);
}
#endregion
#region ================== Events
// When the Preferences dialog is closed
public override void OnClosePreferences(PreferencesController controller)
{
base.OnClosePreferences(controller);
// Apply settings that could have been changed
LoadSettings();
}
#endregion
2010-09-01 20:08:07 +00:00
#region ================== Classic Mode Surfaces
2010-09-01 20:08:07 +00:00
// This is called when the vertices are created for the classic mode surfaces
public override void OnSectorFloorSurfaceUpdate(Sector s, ref FlatVertex[] vertices)
{
ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture);
if((img != null) && img.IsImageLoaded)
{
2010-09-16 11:39:16 +00:00
// Fetch ZDoom fields
Vector2D offset = new Vector2D(s.Fields.GetValue("xpanningfloor", 0.0f),
s.Fields.GetValue("ypanningfloor", 0.0f));
Vector2D scale = new Vector2D(s.Fields.GetValue("xscalefloor", 1.0f),
s.Fields.GetValue("yscalefloor", 1.0f));
float rotate = s.Fields.GetValue("rotationfloor", 0.0f);
int color = s.Fields.GetValue("lightcolor", -1);
int light = s.Fields.GetValue("lightfloor", 0);
bool absolute = s.Fields.GetValue("lightfloorabsolute", false);
2010-09-01 20:08:07 +00:00
// Setup the vertices with the given settings
2010-09-16 11:39:16 +00:00
SetupSurfaceVertices(vertices, s, img, offset, scale, rotate, color, light, absolute);
2010-09-01 20:08:07 +00:00
}
}
// This is called when the vertices are created for the classic mode surfaces
public override void OnSectorCeilingSurfaceUpdate(Sector s, ref FlatVertex[] vertices)
{
ImageData img = General.Map.Data.GetFlatImage(s.LongFloorTexture);
if((img != null) && img.IsImageLoaded)
{
2010-09-16 11:39:16 +00:00
// Fetch ZDoom fields
Vector2D offset = new Vector2D(s.Fields.GetValue("xpanningceiling", 0.0f),
s.Fields.GetValue("ypanningceiling", 0.0f));
Vector2D scale = new Vector2D(s.Fields.GetValue("xscaleceiling", 1.0f),
s.Fields.GetValue("yscaleceiling", 1.0f));
float rotate = s.Fields.GetValue("rotationceiling", 0.0f);
int color = s.Fields.GetValue("lightcolor", -1);
int light = s.Fields.GetValue("lightceiling", 0);
bool absolute = s.Fields.GetValue("lightceilingabsolute", false);
2010-09-01 20:08:07 +00:00
// Setup the vertices with the given settings
2010-09-16 11:39:16 +00:00
SetupSurfaceVertices(vertices, s, img, offset, scale, rotate, color, light, absolute);
2010-09-01 20:08:07 +00:00
}
}
// This applies the given values on the vertices
2010-09-16 11:39:16 +00:00
private void SetupSurfaceVertices(FlatVertex[] vertices, Sector s, ImageData img, Vector2D offset,
Vector2D scale, float rotate, int color, int light, bool absolute)
2010-09-01 20:08:07 +00:00
{
// Prepare for math!
rotate = Angle2D.DegToRad(rotate);
Vector2D texscale = new Vector2D(1.0f / img.ScaledWidth, 1.0f / img.ScaledHeight);
if(!absolute) light = s.Brightness + light;
PixelColor lightcolor = PixelColor.FromInt(color);
PixelColor brightness = PixelColor.FromInt(General.Map.Renderer2D.CalculateBrightness(light));
PixelColor finalcolor = PixelColor.Modulate(lightcolor, brightness);
color = finalcolor.WithAlpha(255).ToInt();
// Do the math for all vertices
for(int i = 0; i < vertices.Length; i++)
{
Vector2D pos = new Vector2D(vertices[i].x, vertices[i].y);
pos = pos.GetRotated(rotate);
pos.y = -pos.y;
pos = (pos + offset) * scale * texscale;
vertices[i].u = pos.x;
vertices[i].v = pos.y;
vertices[i].c = color;
}
}
#endregion
}
}