Internal: removed some duplicate casts, marked some classes is IDisposable, some streams were disposed more than once.

This commit is contained in:
MaxED 2016-03-18 12:52:12 +00:00 committed by spherallic
parent a4fe857710
commit 75f0f91a88
50 changed files with 436 additions and 473 deletions

View file

@ -172,7 +172,6 @@ namespace CodeImp.DoomBuilder.Actions
// Done with the resource
actionsreader.Dispose();
actionsdata.Dispose();
break; //mxd. Usually we have a single "Actions.cfg", right?
}
}

View file

@ -63,12 +63,11 @@ namespace CodeImp.DoomBuilder.Actions
List<string> lines = new List<string>(2);
// Get a stream from the resource
using(Stream data = asm.GetManifestResourceStream(rn))
Stream data = asm.GetManifestResourceStream(rn);
if(data == null) return;
using(StreamReader reader = new StreamReader(data, Encoding.ASCII))
{
using(StreamReader reader = new StreamReader(data, Encoding.ASCII))
{
while(!reader.EndOfStream) lines.Add(reader.ReadLine());
}
while(!reader.EndOfStream) lines.Add(reader.ReadLine());
}
Dictionary<string, List<string>> group = new Dictionary<string, List<string>>(StringComparer.Ordinal);
@ -119,7 +118,7 @@ namespace CodeImp.DoomBuilder.Actions
//add the last class
hints.Add(asmname + classname, ProcessHints(group));
break;
return;
}
}
}

View file

@ -75,7 +75,7 @@ namespace CodeImp.DoomBuilder.Config
if(argdic["enum"] is IDictionary)
{
// Create anonymous enum
this.enumlist = new EnumList(argdic["enum"] as IDictionary);
this.enumlist = new EnumList((IDictionary)argdic["enum"]);
}
else
{

View file

@ -793,7 +793,7 @@ namespace CodeImp.DoomBuilder.Config
if(de.Value is IDictionary)
{
// Add option
geneffectoptions.Add(new GeneralizedOption("gen_sectortypes", "", de.Key.ToString(), de.Value as IDictionary));
geneffectoptions.Add(new GeneralizedOption("gen_sectortypes", "", de.Key.ToString(), (IDictionary)de.Value));
}
else
{

View file

@ -194,25 +194,21 @@ namespace CodeImp.DoomBuilder.Controls
// Tabs don't process keys
protected override void OnKeyDown(KeyEventArgs ke)
{
if(this.Parent is DockersControl)
{
// Only absorb the key press when no focused on an input control, otherwise
// the input controls may not receive certain keys such as delete and arrow keys
DockersControl docker = (this.Parent as DockersControl);
if(!docker.IsFocused) ke.Handled = true;
}
DockersControl docker = this.Parent as DockersControl;
// Only absorb the key press when no focused on an input control, otherwise
// the input controls may not receive certain keys such as delete and arrow keys
if(docker != null && !docker.IsFocused) ke.Handled = true;
}
// Tabs don't process keys
protected override void OnKeyUp(KeyEventArgs e)
{
if(this.Parent is DockersControl)
{
// Only absorb the key press when no focused on an input control, otherwise
// the input controls may not receive certain keys such as delete and arrow keys
DockersControl docker = (this.Parent as DockersControl);
if(!docker.IsFocused) e.Handled = true;
}
DockersControl docker = this.Parent as DockersControl;
// Only absorb the key press when no focused on an input control, otherwise
// the input controls may not receive certain keys such as delete and arrow keys
if(docker != null && !docker.IsFocused) e.Handled = true;
}
#endregion

View file

@ -867,10 +867,10 @@ namespace CodeImp.DoomBuilder.Controls
private void ApplyEnums(bool hide)
{
// Enums combobox shown?
if((enumscombo.Visible) && (enumscombo.Tag is FieldsEditorRow))
if(enumscombo.Visible && (enumscombo.Tag is FieldsEditorRow))
{
// Get the row
FieldsEditorRow frow = (enumscombo.Tag as FieldsEditorRow);
FieldsEditorRow frow = (FieldsEditorRow)enumscombo.Tag;
// Take the selected value and apply it
ApplyValue(frow, enumscombo.Text);

View file

@ -490,13 +490,13 @@ namespace CodeImp.DoomBuilder.Controls
editor.GrabFocus();
}
//mxd
private void functionbar_SelectedIndexChanged(object sender, EventArgs e)
{
if (!preventchanges && editor.FunctionBar.SelectedItem is ScriptItem)
{
ScriptItem si = editor.FunctionBar.SelectedItem as ScriptItem;
editor.EnsureLineVisible(editor.LineFromPosition(si.CursorPosition));
//mxd
private void functionbar_SelectedIndexChanged(object sender, EventArgs e)
{
if(!preventchanges && editor.FunctionBar.SelectedItem is ScriptItem)
{
ScriptItem si = (ScriptItem)editor.FunctionBar.SelectedItem;
editor.EnsureLineVisible(editor.LineFromPosition(si.CursorPosition));
editor.SelectionStart = si.CursorPosition;
editor.SelectionEnd = si.CursorPosition;

View file

@ -337,7 +337,6 @@ namespace CodeImp.DoomBuilder.Controls
// Done with the resource
lexersreader.Dispose();
lexersdata.Dispose();
}
//mxd. We are done here

View file

@ -16,6 +16,7 @@
#region ================== Namespaces
using System;
using System.Collections.Generic;
using System.IO;
using CodeImp.DoomBuilder.Config;
@ -25,7 +26,7 @@ using CodeImp.DoomBuilder.GZBuilder.Data;
namespace CodeImp.DoomBuilder.Data
{
internal abstract class DataReader
internal abstract class DataReader : IDisposable
{
#region ================== Constants

View file

@ -41,15 +41,16 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
// Dimensions of a single preview image
private int maxpreviewwidth = 64;
private int maxpreviewheight = 64;
private readonly int maxpreviewwidth;
private readonly int maxpreviewheight;
// Images
private List<Bitmap> images;
// Processing
private Queue<ImageData> imageque;
private static object syncroot = new object(); //mxd
// Disposing
private bool isdisposed;
@ -196,7 +197,7 @@ namespace CodeImp.DoomBuilder.Data
targetpos.Y += (maxpreviewheight - image.Height) >> 1;
// Draw from atlas to target
lock(image)
lock(syncroot)
{
target.DrawImageUnscaled(image, targetpos.X, targetpos.Y);
}
@ -211,7 +212,7 @@ namespace CodeImp.DoomBuilder.Data
lock(images) { image = images[previewindex]; }
// Make a copy
lock(image)
lock(syncroot)
{
return new Bitmap(image);
}

View file

@ -119,10 +119,9 @@ namespace CodeImp.DoomBuilder.Editing
this.renderer2d = (Renderer2D)General.Map.Renderer2D;
// If the current mode is a ClassicMode, copy mouse properties
if(General.Editing.Mode is ClassicMode)
ClassicMode oldmode = General.Editing.Mode as ClassicMode;
if(oldmode != null)
{
ClassicMode oldmode = General.Editing.Mode as ClassicMode;
// Copy mouse properties
mousepos = oldmode.mousepos;
mousemappos = oldmode.mousemappos;

View file

@ -30,7 +30,7 @@ using CodeImp.DoomBuilder.Geometry;
namespace CodeImp.DoomBuilder.Editing
{
public class GridSetup
public class GridSetup : IDisposable
{
#region ================== Constants
@ -95,12 +95,12 @@ namespace CodeImp.DoomBuilder.Editing
}
// Disposer
internal void Dispose()
public void Dispose()
{
if(!isdisposed)
{
// Dispose image if needed
if(backimage is FileImage) (backimage as FileImage).Dispose();
if(backimage is FileImage) backimage.Dispose();
// Clean up
backimage = null;
@ -208,7 +208,7 @@ namespace CodeImp.DoomBuilder.Editing
internal void LinkBackground()
{
// Dispose image if needed
if(backimage is FileImage) (backimage as FileImage).Dispose();
if(backimage is FileImage) backimage.Dispose();
// Where to load background from?
switch(backsource)

View file

@ -202,20 +202,13 @@ namespace CodeImp.DoomBuilder.Editing
ClearRedos();
General.WriteLogLine("All undo and redo levels cleared.");
//mxd
if (ss != null)
{
ss.Dispose();
ss = null;
}
if (stream != null)
{
stream.Dispose();
stream = null;
}
// Done
isdisposed = true;
//mxd
if(snapshot != null) { snapshot.Dispose(); snapshot = null; }
if(ss != null) { ss.Dispose(); ss = null; }
if(stream != null) { stream.Dispose(); stream = null; }
// Done
isdisposed = true;
}
}

View file

@ -193,11 +193,8 @@ namespace CodeImp.DoomBuilder.GZBuilder.Windows
area.Inflate(100f, 100f);
// Zoom to area
if(General.Editing.Mode is ClassicMode)
{
ClassicMode editmode = (General.Editing.Mode as ClassicMode);
editmode.CenterOnArea(area, 0.6f);
}
ClassicMode mode = General.Editing.Mode as ClassicMode;
if(mode != null) mode.CenterOnArea(area, 0.6f);
}
#endregion

View file

@ -111,11 +111,8 @@ namespace CodeImp.DoomBuilder.GZBuilder.Windows
area.Inflate(100f, 100f);
// Zoom to area
if(General.Editing.Mode is ClassicMode)
{
ClassicMode editmode = (General.Editing.Mode as ClassicMode);
editmode.CenterOnArea(area, 0.6f);
}
ClassicMode mode = General.Editing.Mode as ClassicMode;
if(mode != null) mode.CenterOnArea(area, 0.6f);
}
private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)

View file

@ -71,7 +71,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3
//done
ms.Close();
ms.Dispose();
break;
}
}
@ -126,7 +125,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3
}
ms.Close();
ms.Dispose();
//got errors?
if(!String.IsNullOrEmpty(result.Errors))
@ -912,7 +910,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3
Bitmap bitmap = fir.ReadAsBitmap(ms);
ms.Close();
ms.Dispose();
if(bitmap != null)
{
@ -931,7 +928,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3
texture = Texture.FromStream(device, ms);
ms.Close();
ms.Dispose();
}
return texture;

View file

@ -68,22 +68,22 @@ namespace CodeImp.DoomBuilder
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MessageBeep(MessageBeepType type);
[DllImport("kernel32.dll")]
internal extern static IntPtr LoadLibrary(string filename);
//[DllImport("kernel32.dll")]
//internal extern static IntPtr LoadLibrary(string filename);
[DllImport("kernel32.dll")]
internal extern static bool FreeLibrary(IntPtr moduleptr);
//[DllImport("kernel32.dll")]
//internal extern static bool FreeLibrary(IntPtr moduleptr);
[DllImport("user32.dll")]
internal static extern IntPtr CreateWindowEx(uint exstyle, string classname, string windowname, uint style,
//[DllImport("user32.dll")]
/*internal static extern IntPtr CreateWindowEx(uint exstyle, string classname, string windowname, uint style,
int x, int y, int width, int height, IntPtr parentptr, int menu,
IntPtr instanceptr, string param);
IntPtr instanceptr, string param);*/
[DllImport("user32.dll")]
internal static extern bool DestroyWindow(IntPtr windowptr);
//[DllImport("user32.dll")]
//internal static extern bool DestroyWindow(IntPtr windowptr);
[DllImport("user32.dll")]
internal static extern int SetWindowPos(IntPtr windowptr, int insertafterptr, int x, int y, int cx, int cy, int flags);
//[DllImport("user32.dll")]
//internal static extern int SetWindowPos(IntPtr windowptr, int insertafterptr, int x, int y, int cx, int cy, int flags);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string longpath, [MarshalAs(UnmanagedType.LPTStr)]StringBuilder shortpath, uint buffersize);
@ -1349,9 +1349,9 @@ namespace CodeImp.DoomBuilder
mainwindow.AddHintsDocker(); //mxd
//mxd. Center map in screen or on stored coordinates. Done here to avoid the view jerking around when updating the interface.
if(Editing.Mode is ClassicMode)
ClassicMode mode = Editing.Mode as ClassicMode;
if(mode != null)
{
ClassicMode mode = Editing.Mode as ClassicMode;
if(options != null && options.ViewPosition.IsFinite() && !float.IsNaN(options.ViewScale))
mode.CenterOnCoordinates(options.ViewPosition, options.ViewScale);
else

View file

@ -536,9 +536,9 @@ namespace CodeImp.DoomBuilder
options.ReadSelectionGroups();
// Center map in screen or on stored coordinates
if(General.Editing.Mode is ClassicMode)
ClassicMode mode = General.Editing.Mode as ClassicMode;
if(mode != null)
{
ClassicMode mode = General.Editing.Mode as ClassicMode;
mode.OnRedoEnd();
if(options.ViewPosition.IsFinite() && !float.IsNaN(options.ViewScale))

View file

@ -66,27 +66,25 @@ namespace CodeImp.DoomBuilder
// Get remote revision number
int remoterev;
using(MemoryStream stream = DownloadWebFile(Path.Combine(url, "Version.txt")))
MemoryStream stream = DownloadWebFile(Path.Combine(url, "Version.txt"));
if(stream == null)
{
if(stream == null)
{
e.Result = "Update check failed: failed to retrieve remote revision info.";
e.Cancel = true;
return;
}
ShowResult("Update check failed: failed to retrieve remote revision info.\nCheck your Internet connection and try again.");
e.Cancel = true;
return;
}
string s;
using(StreamReader reader = new StreamReader(stream))
{
s = reader.ReadToEnd();
}
string s;
using(StreamReader reader = new StreamReader(stream))
{
s = reader.ReadToEnd();
}
if(!int.TryParse(s, out remoterev))
{
e.Result = "Update check failed: failed to retrieve remote revision number.";
e.Cancel = true;
return;
}
if(!int.TryParse(s, out remoterev))
{
ShowResult("Update check failed: failed to retrieve remote revision number.");
e.Cancel = true;
return;
}
if(remoterev > localrev)

View file

@ -73,7 +73,6 @@ namespace CodeImp.DoomBuilder.IO
// Done
udmfcfgreader.Dispose();
udmfcfg.Dispose();
break;
}
}

View file

@ -222,7 +222,6 @@ namespace CodeImp.DoomBuilder.IO
{
basestream = null;
base.Close();
this.Dispose();
}
// This reads a single byte from the stream

View file

@ -90,7 +90,6 @@ namespace CodeImp.DoomBuilder.IO
// Done
udmfcfgreader.Dispose();
udmfcfg.Dispose();
break;
}
}

View file

@ -118,7 +118,6 @@ namespace CodeImp.DoomBuilder.IO
// Done
udmfcfgreader.Dispose();
udmfcfg.Dispose();
break;
}
}
@ -600,8 +599,8 @@ namespace CodeImp.DoomBuilder.IO
// Make list
foreach(UniversalEntry e in collection)
{
if(!(e.Value is UniversalCollection) || (e.Key != entryname)) continue; //mxd
list.Add(e.Value as UniversalCollection);
UniversalCollection uc = e.Value as UniversalCollection;
if(uc != null && e.Key == entryname) list.Add(uc);
}
return list;

View file

@ -97,7 +97,6 @@ namespace CodeImp.DoomBuilder.IO
// Done
udmfcfgreader.Dispose();
udmfcfg.Dispose();
break;
}
}

View file

@ -342,9 +342,11 @@ namespace CodeImp.DoomBuilder.IO
// Close the reader
r.Close();
}
// Close the file
fs.Dispose();
else
{
// Close the file
fs.Dispose();
}
}
// This flushes writing changes

View file

@ -294,16 +294,16 @@ namespace CodeImp.DoomBuilder.Map
}
}
//mxd. Is that really needed?..
~MapOptions()
{
// Clean up
this.resources = null;
this.scriptfilesettings = null; //mxd
this.scriptlumpsettings = null; //mxd
}
#endregion
//mxd. Is that really needed?..
/*~MapOptions()
{
// Clean up
this.resources = null;
this.scriptfilesettings = null; //mxd
this.scriptlumpsettings = null; //mxd
}*/
#endregion
#region ================== Methods

View file

@ -1438,7 +1438,7 @@ namespace CodeImp.DoomBuilder.Map
string s = groupinfo["vertices"] as string;
if(!string.IsNullOrEmpty(s))
{
List<int> indices = GetIndices(groupinfo["vertices"] as string);
List<int> indices = GetIndices(s);
foreach(int index in indices)
{
if(index > vertices.Length) continue;
@ -1452,7 +1452,7 @@ namespace CodeImp.DoomBuilder.Map
string s = groupinfo["linedefs"] as string;
if(!string.IsNullOrEmpty(s))
{
List<int> indices = GetIndices(groupinfo["linedefs"] as string);
List<int> indices = GetIndices(s);
foreach(int index in indices)
{
if(index > linedefs.Length) continue;
@ -1466,7 +1466,7 @@ namespace CodeImp.DoomBuilder.Map
string s = groupinfo["sectors"] as string;
if(!string.IsNullOrEmpty(s))
{
List<int> indices = GetIndices(groupinfo["sectors"] as string);
List<int> indices = GetIndices(s);
foreach(int index in indices)
{
if(index > sectors.Length) continue;
@ -1480,7 +1480,7 @@ namespace CodeImp.DoomBuilder.Map
string s = groupinfo["things"] as string;
if(!string.IsNullOrEmpty(s))
{
List<int> indices = GetIndices(groupinfo["things"] as string);
List<int> indices = GetIndices(s);
foreach(int index in indices)
{
if(index > things.Length) continue;

View file

@ -23,7 +23,7 @@ using SlimDX.Direct3D9;
namespace CodeImp.DoomBuilder.Rendering
{
internal class ShaderManager : ID3DResource
internal class ShaderManager : ID3DResource, IDisposable
{
#region ================== Constants

View file

@ -100,7 +100,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Done
fontreader.Dispose();
fontdata.Dispose();
break;
}
}

View file

@ -114,7 +114,7 @@ namespace CodeImp.DoomBuilder.VisualModes
//mxd. Synch camera position to cursor position or center of the screen in 2d-mode
if(General.Settings.GZSynchCameras && General.Editing.Mode is ClassicMode)
{
ClassicMode oldmode = General.Editing.Mode as ClassicMode;
ClassicMode oldmode = (ClassicMode)General.Editing.Mode;
if(oldmode.IsMouseInside)
initialcameraposition = new Vector2D(oldmode.MouseMapPos.x, oldmode.MouseMapPos.y);
@ -483,18 +483,13 @@ namespace CodeImp.DoomBuilder.VisualModes
if(target.picked == null) return new Vector2D(float.NaN, float.NaN);
//now find where exactly did we hit
if(target.picked is VisualGeometry)
{
VisualGeometry vg = target.picked as VisualGeometry;
return GetIntersection(start, start + delta, vg.BoundingBox[0], new Vector3D(vg.Vertices[0].nx, vg.Vertices[0].ny, vg.Vertices[0].nz));
}
if(target.picked is VisualThing)
{
VisualThing vt = target.picked as VisualThing;
return GetIntersection(start, start + delta, vt.CenterV3D, D3DDevice.V3D(vt.Center - vt.PositionV3));
}
// Now find where exactly did we hit
VisualGeometry vg = target.picked as VisualGeometry;
if(vg != null) return GetIntersection(start, start + delta, vg.BoundingBox[0], new Vector3D(vg.Vertices[0].nx, vg.Vertices[0].ny, vg.Vertices[0].nz));
VisualThing vt = target.picked as VisualThing;
if(vt != null) return GetIntersection(start, start + delta, vt.CenterV3D, D3DDevice.V3D(vt.Center - vt.PositionV3));
return new Vector2D(float.NaN, float.NaN);
}

View file

@ -239,10 +239,10 @@ namespace CodeImp.DoomBuilder.Windows
if(tabs.SelectedTab == tabactions)
{
// Action node selected?
if((actions.SelectedNode != null) && (actions.SelectedNode.Tag is LinedefActionInfo))
if(actions.SelectedNode != null && (actions.SelectedNode.Tag is LinedefActionInfo))
{
// Our result
selectedaction = (actions.SelectedNode.Tag as LinedefActionInfo).Index;
selectedaction = ((LinedefActionInfo)actions.SelectedNode.Tag).Index;
}
}
// Generalized action

View file

@ -201,7 +201,7 @@ namespace CodeImp.DoomBuilder.Windows
if((effects.SelectedItems.Count > 0) && (effects.SelectedItems[0].Tag is SectorEffectInfo))
{
// Our result
selectedeffect = (effects.SelectedItems[0].Tag as SectorEffectInfo).Index;
selectedeffect = ((SectorEffectInfo)effects.SelectedItems[0].Tag).Index;
}
}
// Generalized action

View file

@ -447,9 +447,9 @@ namespace CodeImp.DoomBuilder.Windows
this.Update();
if(sender is ToolStripItem)
General.Actions.InvokeAction((sender as ToolStripItem).Tag.ToString());
General.Actions.InvokeAction(((ToolStripItem)sender).Tag.ToString());
else if(sender is Control)
General.Actions.InvokeAction((sender as Control).Tag.ToString());
General.Actions.InvokeAction(((Control)sender).Tag.ToString());
else
General.Fail("InvokeTaggedAction used on an unexpected control.");
@ -933,13 +933,14 @@ namespace CodeImp.DoomBuilder.Windows
if(General.Map != null && General.Editing.Mode is ClassicMode)
{
// Requested from menu?
if(sender is ToolStripMenuItem)
ToolStripMenuItem item = sender as ToolStripMenuItem;
if(item != null)
{
// Get integral zoom level
int zoom = int.Parse((sender as ToolStripMenuItem).Tag.ToString(), CultureInfo.InvariantCulture);
int zoom = int.Parse(item.Tag.ToString(), CultureInfo.InvariantCulture);
// Zoom now
(General.Editing.Mode as ClassicMode).SetZoom(zoom / 100f);
((ClassicMode)General.Editing.Mode).SetZoom(zoom / 100f);
}
}
}
@ -949,7 +950,7 @@ namespace CodeImp.DoomBuilder.Windows
{
// In classic mode?
if(General.Map != null && General.Editing.Mode is ClassicMode)
(General.Editing.Mode as ClassicMode).CenterInScreen();
((ClassicMode)General.Editing.Mode).CenterInScreen();
}
// This changes grid display
@ -968,10 +969,11 @@ namespace CodeImp.DoomBuilder.Windows
if(General.Editing.Mode is ClassicMode)
{
// Requested from menu?
if(sender is ToolStripMenuItem)
ToolStripMenuItem item = sender as ToolStripMenuItem;
if(item != null)
{
// Get integral zoom level
int size = int.Parse((sender as ToolStripMenuItem).Tag.ToString(), CultureInfo.InvariantCulture);
int size = int.Parse(item.Tag.ToString(), CultureInfo.InvariantCulture);
//mxd. Disable automatic grid resizing
DisableDynamicGridResize();
@ -2472,7 +2474,7 @@ namespace CodeImp.DoomBuilder.Windows
else if(menuitem.Tag is EditModeInfo)
{
// Action with this name available?
EditModeInfo modeinfo = (menuitem.Tag as EditModeInfo);
EditModeInfo modeinfo = (EditModeInfo)menuitem.Tag;
string actionname = modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly);
if(General.Actions.Exists(actionname))
{
@ -2497,11 +2499,11 @@ namespace CodeImp.DoomBuilder.Windows
// Tag set for this item?
if(item.Tag is string)
{
// Check if the tag doe not already begin with the assembly name
if(!(item.Tag as string).StartsWith(plugin.Name + "_", StringComparison.OrdinalIgnoreCase))
// Check if the tag does not already begin with the assembly name
if(!((string)item.Tag).StartsWith(plugin.Name + "_", StringComparison.OrdinalIgnoreCase))
{
// Change the tag to a fully qualified action name
item.Tag = plugin.Name.ToLowerInvariant() + "_" + (item.Tag as string);
item.Tag = plugin.Name.ToLowerInvariant() + "_" + (string)item.Tag;
}
}
@ -3459,10 +3461,10 @@ namespace CodeImp.DoomBuilder.Windows
buttontoggleinfo.Image = Resources.InfoPanelCollapse; //mxd
labelcollapsedinfo.Visible = false;
itemtoggleinfo.Checked = true;
if(lastinfoobject is Vertex) ShowVertexInfo(lastinfoobject as Vertex);
else if(lastinfoobject is Linedef) ShowLinedefInfo(lastinfoobject as Linedef);
else if(lastinfoobject is Sector) ShowSectorInfo(lastinfoobject as Sector);
else if(lastinfoobject is Thing) ShowThingInfo(lastinfoobject as Thing);
if(lastinfoobject is Vertex) ShowVertexInfo((Vertex)lastinfoobject);
else if(lastinfoobject is Linedef) ShowLinedefInfo((Linedef)lastinfoobject);
else if(lastinfoobject is Sector) ShowSectorInfo((Sector)lastinfoobject);
else if(lastinfoobject is Thing) ShowThingInfo((Thing)lastinfoobject);
else HideInfo();
}
@ -3509,19 +3511,19 @@ namespace CodeImp.DoomBuilder.Windows
modename.Refresh();
statistics.Visible = showModeName; //mxd
//mxd. let the plugins know
//mxd. Let the plugins know
General.Plugins.OnHighlightLost();
}
// This refreshes info
public void RefreshInfo()
{
if(lastinfoobject is Vertex) ShowVertexInfo(lastinfoobject as Vertex);
else if(lastinfoobject is Linedef) ShowLinedefInfo(lastinfoobject as Linedef);
else if(lastinfoobject is Sector) ShowSectorInfo(lastinfoobject as Sector);
else if(lastinfoobject is Thing) ShowThingInfo(lastinfoobject as Thing);
if(lastinfoobject is Vertex) ShowVertexInfo((Vertex)lastinfoobject);
else if(lastinfoobject is Linedef) ShowLinedefInfo((Linedef)lastinfoobject);
else if(lastinfoobject is Sector) ShowSectorInfo((Sector)lastinfoobject);
else if(lastinfoobject is Thing) ShowThingInfo((Thing)lastinfoobject);
//mxd. let the plugins know
//mxd. Let the plugins know
General.Plugins.OnHighlightRefreshed(lastinfoobject);
}

View file

@ -58,12 +58,12 @@ namespace CodeImp.DoomBuilder.Windows
}
// Destructor
~PreferencesController()
/*~PreferencesController()
{
form = null;
OnAccept = null;
OnCancel = null;
}
}*/
#endregion

View file

@ -351,7 +351,7 @@ namespace CodeImp.DoomBuilder.Windows
if((filtercategory.SelectedIndex > -1) && (filtercategory.SelectedItem is ThingCategoryData))
{
// Set new category name
f.CategoryName = (filtercategory.SelectedItem as ThingCategoryData).Category.Name; //mxd
f.CategoryName = ((ThingCategoryData)filtercategory.SelectedItem).Category.Name; //mxd
}
else
{

View file

@ -157,6 +157,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
public override void OnDisengage()
{
if(hintlabel != null) hintlabel.Dispose();
base.OnDisengage();
}
private void OptionsPanelOnValueChanged(object sender, EventArgs eventArgs)
{
triangulate = panel.Triangulate;

View file

@ -428,6 +428,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
public override void OnDisengage()
{
if(hintlabel != null) hintlabel.Dispose();
base.OnDisengage();
}
public override void OnHelp()
{
General.ShowHelp("/gzdb/features/classic_modes/mode_drawrect.html");

View file

@ -331,13 +331,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
private void Highlight(MapElement h)
{
// Undraw previous highlight
if((highlighted != null) && !highlighted.IsDisposed)
if(highlighted != null && !highlighted.IsDisposed)
{
if(highlighted is Vertex)
{
if(renderer.StartPlotter(false))
{
renderer.PlotVertex((highlighted as Vertex), renderer.DetermineVertexColor((highlighted as Vertex)));
renderer.PlotVertex((Vertex)highlighted, renderer.DetermineVertexColor((Vertex)highlighted));
renderer.Finish();
}
}
@ -345,7 +345,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
if(renderer.StartThings(false))
{
renderer.RenderThing((highlighted as Thing), renderer.DetermineThingColor((highlighted as Thing)), Presentation.THINGS_ALPHA);
renderer.RenderThing((Thing)highlighted, renderer.DetermineThingColor((Thing)highlighted), Presentation.THINGS_ALPHA);
renderer.Finish();
}
}
@ -355,13 +355,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
highlighted = h;
// Render highlighted item
if((highlighted != null) && !highlighted.IsDisposed)
if(highlighted != null && !highlighted.IsDisposed)
{
if(highlighted is Vertex)
{
if(renderer.StartPlotter(false))
{
renderer.PlotVertex((highlighted as Vertex), ColorCollection.HIGHLIGHT);
renderer.PlotVertex((Vertex)highlighted, ColorCollection.HIGHLIGHT);
renderer.Finish();
}
}
@ -369,7 +369,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
if(renderer.StartThings(false))
{
renderer.RenderThing((highlighted as Thing), General.Colors.Highlight, Presentation.THINGS_ALPHA);
renderer.RenderThing((Thing)highlighted, General.Colors.Highlight, Presentation.THINGS_ALPHA);
renderer.Finish();
}
}
@ -1564,7 +1564,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
renderer.PlotVerticesSet(General.Map.Map.Vertices);
if(highlighted is Vertex) renderer.PlotVertex((highlighted as Vertex), ColorCollection.HIGHLIGHT);
if(highlighted is Vertex) renderer.PlotVertex((Vertex)highlighted, ColorCollection.HIGHLIGHT);
renderer.Finish();
}
@ -1573,9 +1573,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
renderer.RenderThingSet(General.Map.ThingsFilter.HiddenThings, Presentation.THINGS_HIDDEN_ALPHA);
renderer.RenderThingSet(General.Map.ThingsFilter.VisibleThings, Presentation.THINGS_ALPHA);
if(highlighted is Thing) renderer.RenderThing((highlighted as Thing), General.Colors.Highlight, Presentation.THINGS_ALPHA);
renderer.RenderNiGHTSPath();
renderer.Finish();
if(highlighted is Thing) renderer.RenderThing((Thing)highlighted, General.Colors.Highlight, Presentation.THINGS_ALPHA);
renderer.RenderNiGHTSPath();
renderer.Finish();
}
// Render selection

View file

@ -466,11 +466,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ParallelLinedef); //JBR
// Going to EditSelectionMode?
if (General.Editing.NewMode is EditSelectionMode)
EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode;
if(mode != null)
{
// Not pasting anything?
EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode);
if(!editmode.Pasting)
if(!mode.Pasting)
{
// No selection made? But we have a highlight!
if((General.Map.Map.GetSelectedLinedefs(true).Count == 0) && (highlighted != null))
@ -1626,7 +1626,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
sortedlist.Reverse();
//mxd. Gather our ordered sectors
List<Sector> sectorslist = new List<Sector>(sortedlist.Count());
List<Sector> sectorslist = new List<Sector>(sortedlist.Count);
sectorslist.AddRange(sortedlist.Select(pair => pair.Key));
//mxd. Flip the lines

View file

@ -592,11 +592,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
//mxd
public override void SelectMapElement(SelectableElement element)
public override void SelectMapElement(SelectableElement element)
{
if(element is Sector)
Sector sector = element as Sector;
if(sector != null)
{
SelectSector(element as Sector, true, true);
SelectSector(sector, true, true);
// Update overlay
UpdateOverlaySurfaces();
@ -719,11 +720,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Map.Map.ClearSelectedLinedefs();
// Going to EditSelectionMode?
if(General.Editing.NewMode is EditSelectionMode)
EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode;
if(mode != null)
{
// Not pasting anything?
EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode);
if(!editmode.Pasting)
if(!mode.Pasting)
{
// No selection made? But we have a highlight!
if((General.Map.Map.GetSelectedSectors(true).Count == 0) && (highlighted != null))

View file

@ -162,11 +162,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
if (highlighted != null) highlighted.Highlighted = false;
// Going to EditSelectionMode?
if(General.Editing.NewMode is EditSelectionMode)
EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode;
if(mode != null)
{
// Not pasting anything?
EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode);
if(!editmode.Pasting)
if(!mode.Pasting)
{
// No selection made? But we have a highlight!
if((General.Map.Map.GetSelectedThings(true).Count == 0) && (highlighted != null))

View file

@ -130,11 +130,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ParallelLinedef); //JBR
// Going to EditSelectionMode?
if (General.Editing.NewMode is EditSelectionMode)
EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode;
if(mode != null)
{
// Not pasting anything?
EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode);
if(!editmode.Pasting)
if(!mode.Pasting)
{
// No selection made? But we have a highlight!
if((General.Map.Map.GetSelectedVertices(true).Count == 0) && (highlighted != null))

View file

@ -70,21 +70,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
if(obj is Vertex)
{
points.Add((obj as Vertex).Position);
points.Add(((Vertex)obj).Position);
}
else if(obj is Linedef)
{
points.Add((obj as Linedef).Start.Position);
points.Add((obj as Linedef).End.Position);
points.Add(((Linedef)obj).Start.Position);
points.Add(((Linedef)obj).End.Position);
}
else if(obj is Sidedef)
{
points.Add((obj as Sidedef).Line.Start.Position);
points.Add((obj as Sidedef).Line.End.Position);
points.Add(((Sidedef)obj).Line.Start.Position);
points.Add(((Sidedef)obj).Line.End.Position);
}
else if(obj is Sector)
{
Sector s = (obj as Sector);
Sector s = (Sector)obj;
foreach(Sidedef sd in s.Sidedefs)
{
points.Add(sd.Line.Start.Position);
@ -93,7 +93,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
else if(obj is Thing)
{
Thing t = (obj as Thing);
Thing t = (Thing)obj;
Vector2D p = t.Position;
points.Add(p);
points.Add(p + new Vector2D(t.Size * 2.0f, t.Size * 2.0f));

View file

@ -145,7 +145,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
public void Register()
{
// Add the menus to the core
foreach(ToolStripMenuItem i in menus)
foreach(ToolStripItem i in menus)
General.Interface.AddMenu(i);
// Add the buttons to the core
@ -153,7 +153,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.AddButton(b);
//mxd. Export menu
foreach(ToolStripMenuItem i in exportmenuitems)
foreach(ToolStripItem i in exportmenuitems)
General.Interface.AddMenu(i, MenuSection.FileExport);
//mxd. Copy-paste propserties items
@ -165,7 +165,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
public void Unregister()
{
// Remove the menus from the core
foreach(ToolStripMenuItem i in menus)
foreach(ToolStripItem i in menus)
General.Interface.RemoveMenu(i);
// Remove the buttons from the core
@ -173,7 +173,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.RemoveButton(b);
//mxd. Export menu
foreach(ToolStripMenuItem i in exportmenuitems)
foreach(ToolStripItem i in exportmenuitems)
General.Interface.RemoveMenu(i);
//mxd. Copy-paste propserties items
@ -184,7 +184,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// This hides all menus
public void HideAllMenus()
{
foreach(ToolStripMenuItem m in menus) m.Visible = false;
foreach(ToolStripItem m in menus) m.Visible = false;
}
// This hides all except one menu

View file

@ -281,15 +281,15 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
if(!(mode.HighlightedObject is BaseVisualSector)) return;
//do we need to align this? (and also grab texture scale while we are at it)
// Do we need to align this? (and also grab texture scale while we are at it)
float scaleX, scaleY;
bool isFloor = (geometrytype == VisualGeometryType.FLOOR);
if(mode.HighlightedTarget is VisualFloor)
{
VisualFloor target = mode.HighlightedTarget as VisualFloor;
VisualFloor target = (VisualFloor)mode.HighlightedTarget;
//check texture
// Check texture
if(target.Sector.Sector.FloorTexture != (isFloor ? Sector.Sector.FloorTexture : Sector.Sector.CeilTexture)) return;
scaleX = target.Sector.Sector.Fields.GetValue("xscalefloor", 1.0f);
@ -297,9 +297,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
else
{
VisualCeiling target = mode.HighlightedTarget as VisualCeiling;
VisualCeiling target = (VisualCeiling)mode.HighlightedTarget;
//check texture
// Check texture
if(target.Sector.Sector.CeilTexture != (isFloor ? Sector.Sector.FloorTexture : Sector.Sector.CeilTexture)) return;
scaleX = target.Sector.Sector.Fields.GetValue("xscaleceiling", 1.0f);

View file

@ -147,20 +147,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
get
{
// Geometry picked?
if(target.picked is VisualGeometry)
VisualGeometry vg = target.picked as VisualGeometry;
if(vg != null)
{
VisualGeometry pickedgeo = (target.picked as VisualGeometry);
if(pickedgeo.Sidedef != null) return pickedgeo.Sidedef;
if(pickedgeo.Sector != null) return pickedgeo.Sector;
if(vg.Sidedef != null) return vg.Sidedef;
if(vg.Sector != null) return vg.Sector;
return null;
}
// Thing picked?
if(target.picked is VisualThing)
{
VisualThing pickedthing = (target.picked as VisualThing);
return pickedthing.Thing;
}
VisualThing vt = target.picked as VisualThing;
if(vt != null) return vt.Thing;
return null;
}
@ -212,12 +208,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Not already disposed?
if(!isdisposed)
{
// Clean up
bsp.Dispose();
bsp = null;
// Done
base.Dispose();
// Clean up
selectioninfoupdatetimer.Dispose(); //mxd
// Done
base.Dispose();
}
}
@ -477,18 +472,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Geometry picked?
if(target.picked is VisualGeometry)
{
VisualGeometry pickedgeo = (target.picked as VisualGeometry);
VisualGeometry pickedgeo = (VisualGeometry)target.picked;
// Sidedef?
if(pickedgeo is BaseVisualGeometrySidedef)
{
BaseVisualGeometrySidedef pickedsidedef = (pickedgeo as BaseVisualGeometrySidedef);
BaseVisualGeometrySidedef pickedsidedef = (BaseVisualGeometrySidedef)pickedgeo;
General.Interface.ShowLinedefInfo(pickedsidedef.GetControlLinedef(), pickedsidedef.Sidedef); //mxd
}
// Sector?
else if(pickedgeo is BaseVisualGeometrySector)
{
BaseVisualGeometrySector pickedsector = (pickedgeo as BaseVisualGeometrySector);
BaseVisualGeometrySector pickedsector = (BaseVisualGeometrySector)pickedgeo;
bool isceiling = (pickedsector is VisualCeiling); //mxd
General.Interface.ShowSectorInfo(pickedsector.Level.sector, isceiling, !isceiling);
}
@ -497,14 +492,16 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.HideInfo();
}
}
// Thing picked?
else if(target.picked is VisualThing)
{ // Thing picked?
VisualThing pickedthing = (target.picked as VisualThing);
{
VisualThing pickedthing = (VisualThing)target.picked;
General.Interface.ShowThingInfo(pickedthing.Thing);
}
else if(target.picked is VisualVertex) //mxd
//mxd. Vertex picked?
else if(target.picked is VisualVertex)
{
VisualVertex pickedvert = (target.picked as VisualVertex);
VisualVertex pickedvert = (VisualVertex)target.picked;
General.Interface.ShowVertexInfo(pickedvert.Vertex);
}
}
@ -1715,8 +1712,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd. As well as geometry...
foreach(KeyValuePair<Sector, VisualSector> group in visiblesectors)
{
if(group.Value is BaseVisualSector)
(group.Value as BaseVisualSector).Rebuild();
BaseVisualSector vs = group.Value as BaseVisualSector;
if(vs != null) vs.Rebuild();
}
RebuildSelectedObjectsList();
@ -1737,7 +1734,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd. As well as geometry...
foreach(KeyValuePair<Sector, VisualSector> group in visiblesectors)
{
if(group.Value is BaseVisualSector) (group.Value as BaseVisualSector).Rebuild();
BaseVisualSector vs = group.Value as BaseVisualSector;
if(vs != null) vs.Rebuild();
}
RebuildSelectedObjectsList();
@ -1909,22 +1907,22 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
List<IVisualEventReceiver> objs = new List<IVisualEventReceiver>();
foreach(IVisualEventReceiver i in selectedobjects)
{
if (includesectors && (i is BaseVisualGeometrySector) /*&& ((BaseVisualGeometrySector)i).Triangles > 0*/) objs.Add(i);
else if (includesidedefs && (i is BaseVisualGeometrySidedef) /*&& ((BaseVisualGeometrySidedef)i).Triangles > 0*/) objs.Add(i);
else if (includethings && (i is BaseVisualThing)) objs.Add(i);
else if (includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd
}
{
if(includesectors && (i is BaseVisualGeometrySector)) objs.Add(i);
else if(includesidedefs && (i is BaseVisualGeometrySidedef)) objs.Add(i);
else if(includethings && (i is BaseVisualThing)) objs.Add(i);
else if(includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd
}
// Add highlight?
if (selectedobjects.Count == 0)
{
IVisualEventReceiver i = (target.picked as IVisualEventReceiver);
if (includesectors && (i is BaseVisualGeometrySector) /*&& ((BaseVisualGeometrySector)i).Triangles > 0*/) objs.Add(i);
else if (includesidedefs && (i is BaseVisualGeometrySidedef) /*&& ((BaseVisualGeometrySidedef)i).Triangles > 0*/) objs.Add(i);
else if (includethings && (i is BaseVisualThing)) objs.Add(i);
else if (includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd
}
if(includesectors && (i is BaseVisualGeometrySector)) objs.Add(i);
else if(includesidedefs && (i is BaseVisualGeometrySidedef)) objs.Add(i);
else if(includethings && (i is BaseVisualThing)) objs.Add(i);
else if(includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd
}
return objs;
}
@ -1935,22 +1933,21 @@ namespace CodeImp.DoomBuilder.BuilderModes
Dictionary<Sidedef, bool> processed = new Dictionary<Sidedef, bool>();
List<IVisualEventReceiver> result = new List<IVisualEventReceiver>();
foreach(IVisualEventReceiver obj in objs)
foreach(IVisualEventReceiver i in objs)
{
if(!(obj is BaseVisualGeometrySidedef))
BaseVisualGeometrySidedef sidedef = i as BaseVisualGeometrySidedef;
if(sidedef != null)
{
result.Add(obj);
}
else
{
Sidedef side = (obj as BaseVisualGeometrySidedef).Sidedef;
if(!processed.ContainsKey(side))
if (!processed.ContainsKey(sidedef.Sidedef))
{
processed.Add(side, false);
result.Add(obj);
processed.Add(sidedef.Sidedef, false);
result.Add(i);
}
}
else
{
result.Add(i);
}
}
return result;
@ -1963,21 +1960,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
List<Sector> sectors = new List<Sector>();
foreach(IVisualEventReceiver i in selectedobjects)
{
if(i is BaseVisualGeometrySector)
BaseVisualGeometrySector sector = i as BaseVisualGeometrySector;
if(sector != null && !added.ContainsKey(sector.Level.sector))
{
Sector s = (i as BaseVisualGeometrySector).Level.sector;
if(!added.ContainsKey(s))
{
sectors.Add(s);
added.Add(s, 0);
}
sectors.Add(sector.Level.sector);
added.Add(sector.Level.sector, 0);
}
}
// Add highlight?
if((selectedobjects.Count == 0) && (target.picked is BaseVisualGeometrySector))
{
Sector s = (target.picked as BaseVisualGeometrySector).Level.sector;
Sector s = ((BaseVisualGeometrySector)target.picked).Level.sector;
if(!added.ContainsKey(s)) sectors.Add(s);
}
@ -1991,9 +1985,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
List<Linedef> linedefs = new List<Linedef>();
foreach(IVisualEventReceiver i in selectedobjects)
{
if(i is BaseVisualGeometrySidedef)
BaseVisualGeometrySidedef sidedef = i as BaseVisualGeometrySidedef;
if(sidedef != null)
{
Linedef l = (i as BaseVisualGeometrySidedef).GetControlLinedef(); //mxd
Linedef l = sidedef.GetControlLinedef(); //mxd
if(!added.ContainsKey(l))
{
linedefs.Add(l);
@ -2005,7 +2000,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Add highlight?
if((selectedobjects.Count == 0) && (target.picked is BaseVisualGeometrySidedef))
{
Linedef l = (target.picked as BaseVisualGeometrySidedef).GetControlLinedef(); //mxd
Linedef l = ((BaseVisualGeometrySidedef)target.picked).GetControlLinedef(); //mxd
if(!added.ContainsKey(l)) linedefs.Add(l);
}
@ -2019,21 +2014,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
List<Sidedef> sidedefs = new List<Sidedef>();
foreach(IVisualEventReceiver i in selectedobjects)
{
if(i is BaseVisualGeometrySidedef)
BaseVisualGeometrySidedef sidedef = i as BaseVisualGeometrySidedef;
if(sidedef != null && !added.ContainsKey(sidedef.Sidedef))
{
Sidedef sd = (i as BaseVisualGeometrySidedef).Sidedef;
if(!added.ContainsKey(sd))
{
sidedefs.Add(sd);
added.Add(sd, 0);
}
sidedefs.Add(sidedef.Sidedef);
added.Add(sidedef.Sidedef, 0);
}
}
// Add highlight?
if((selectedobjects.Count == 0) && (target.picked is BaseVisualGeometrySidedef))
{
Sidedef sd = (target.picked as BaseVisualGeometrySidedef).Sidedef;
Sidedef sd = ((BaseVisualGeometrySidedef)target.picked).Sidedef;
if(!added.ContainsKey(sd)) sidedefs.Add(sd);
}
@ -2047,21 +2039,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
List<Thing> things = new List<Thing>();
foreach(IVisualEventReceiver i in selectedobjects)
{
if(i is BaseVisualThing)
BaseVisualThing thing = i as BaseVisualThing;
if(thing != null && !added.ContainsKey(thing.Thing))
{
Thing t = (i as BaseVisualThing).Thing;
if(!added.ContainsKey(t))
{
things.Add(t);
added.Add(t, 0);
}
things.Add(thing.Thing);
added.Add(thing.Thing, 0);
}
}
// Add highlight?
if((selectedobjects.Count == 0) && (target.picked is BaseVisualThing))
{
Thing t = (target.picked as BaseVisualThing).Thing;
Thing t = ((BaseVisualThing)target.picked).Thing;
if(!added.ContainsKey(t)) things.Add(t);
}
@ -2091,9 +2080,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Add highlight?
if((selectedobjects.Count == 0) && (target.picked is BaseVisualVertex))
{
Vertex v = (target.picked as BaseVisualVertex).Vertex;
if(!added.ContainsKey(v))
verts.Add(v);
Vertex v = ((BaseVisualVertex)target.picked).Vertex;
if(!added.ContainsKey(v)) verts.Add(v);
}
return verts;

View file

@ -294,12 +294,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
base.Texture = Sprite;
// Determine sprite size and offset
float radius = Sprite.ScaledWidth * 0.5f;
float height = Sprite.ScaledHeight;
if(Sprite is SpriteImage)
float radius = sprite.ScaledWidth * 0.5f;
float height = sprite.ScaledHeight;
SpriteImage spriteimg = sprite as SpriteImage;
if(spriteimg != null)
{
offsetx = radius - (Sprite as SpriteImage).OffsetX;
offsety = (Sprite as SpriteImage).OffsetY - height;
offsetx = radius - spriteimg.OffsetX;
offsety = spriteimg.OffsetY - height;
}
// Scale by thing type/actor scale

View file

@ -67,7 +67,7 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
#region ================== Methods
// This returns a unique temp filename
public static string MakeTempFilename(string extension)
/*public static string MakeTempFilename(string extension)
{
string filename;
const string chars = "abcdefghijklmnopqrstuvwxyz1234567890";
@ -85,7 +85,7 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
// Return the filename
return filename;
}
}*/
#endregion
}

View file

@ -129,8 +129,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
nodes[i].leftsubsector = (leftindex & 0x8000) != 0;
}
nodesreader.Close();
nodesstream.Close();
nodesstream.Dispose();
// Add additional properties to nodes
nodes[nodes.Length - 1].parent = -1;
@ -161,8 +159,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
segs[i].offset = segsreader.ReadInt16();
}
segsreader.Close();
segsstream.Close();
segsstream.Dispose();
// Load the vertexes structure
MemoryStream vertsstream = General.Map.GetLumpData("VERTEXES");
@ -185,8 +181,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
verts[i].y = vertsreader.ReadInt16();
}
vertsreader.Close();
vertsstream.Close();
vertsstream.Dispose();
// Load the subsectors structure
MemoryStream ssecstream = General.Map.GetLumpData("SSECTORS");
@ -209,8 +203,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
ssectors[i].firstseg = ssecreader.ReadUInt16();
}
ssecreader.Close();
ssecstream.Close();
ssecstream.Dispose();
// Link all segs to their subsectors
for(int i = 0; i < ssectors.Length; i++)
@ -229,175 +221,175 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
private bool LoadZNodes()
{
List<string> supportedFormats = new List<string> { "XNOD", "XGLN", "XGL2", "XGL3" };
using(MemoryStream stream = General.Map.GetLumpData("ZNODES"))
MemoryStream stream = General.Map.GetLumpData("ZNODES");
//boilerplate...
if(stream.Length < 4)
{
//boilerplate...
if(stream.Length < 4)
MessageBox.Show("ZNODES lump is empty.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error);
stream.Close();
return false;
}
using(BinaryReader reader = new BinaryReader(stream))
{
//read signature
nodesformat = new string(reader.ReadChars(4));
if(!supportedFormats.Contains(nodesformat))
{
MessageBox.Show("ZNODES lump is empty.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("\"" + nodesformat + "\" node format is not supported.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
using(BinaryReader reader = new BinaryReader(stream))
uint vertsCount = reader.ReadUInt32();
uint newVertsCount = reader.ReadUInt32();
//boilerplate...
if(vertsCount != General.Map.Map.Vertices.Count)
{
//read signature
nodesformat = new string(reader.ReadChars(4));
if(!supportedFormats.Contains(nodesformat))
{
MessageBox.Show("\"" + nodesformat + "\" node format is not supported.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
uint vertsCount = reader.ReadUInt32();
uint newVertsCount = reader.ReadUInt32();
//boilerplate...
if(vertsCount != General.Map.Map.Vertices.Count)
{
MessageBox.Show("Error while reading ZNODES: vertices count in ZNODES lump (" + vertsCount + ") doesn't match with map's vertices count (" + General.Map.Map.Vertices.Count + ")!", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
//add map vertices
verts = new Vector2D[vertsCount + newVertsCount];
int counter = 0;
foreach(Vertex v in General.Map.Map.Vertices) verts[counter++] = v.Position;
//read extra vertices
for(int i = counter; i < counter + newVertsCount; i++)
{
verts[i].x = reader.ReadInt32() / 65536.0f;
verts[i].y = reader.ReadInt32() / 65536.0f;
}
//read subsectors
uint ssecCount = reader.ReadUInt32();
ssectors = new Subsector[ssecCount];
int firstseg = 0;
for(int i = 0; i < ssectors.Length; i++)
{
ssectors[i].numsegs = (int)reader.ReadUInt32();
ssectors[i].firstseg = firstseg;
firstseg += ssectors[i].numsegs;
}
//read segments. offset and angle are unused anyway
uint segsCount = reader.ReadUInt32();
segs = new Seg[segsCount];
switch(nodesformat)
{
case "XGLN":
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = (int)reader.ReadUInt32();
reader.BaseStream.Position += 4; //skip partner
segs[i].lineindex = reader.ReadUInt16();
segs[i].leftside = reader.ReadBoolean();
}
break;
case "XGL3":
case "XGL2":
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = (int)reader.ReadUInt32();
reader.BaseStream.Position += 4; //skip partner
uint lineindex = reader.ReadUInt32();
segs[i].lineindex = (lineindex == 0xFFFFFFFF ? -1 : (int)lineindex);
segs[i].leftside = reader.ReadBoolean();
}
break;
case "XNOD":
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = (int)reader.ReadUInt32();
segs[i].endvertex = (int)reader.ReadUInt32();
segs[i].lineindex = reader.ReadUInt16();
segs[i].leftside = reader.ReadBoolean();
}
break;
}
//set second vertex, angle and reverse segs order
if(nodesformat == "XGLN" || nodesformat == "XGL2" || nodesformat == "XGL3")
{
int index = 0;
foreach(Subsector ss in ssectors)
{
//set the last vert
int lastseg = ss.firstseg + ss.numsegs - 1;
segs[lastseg].endvertex = segs[ss.firstseg].startvertex;
//set the rest
for(int i = ss.firstseg + 1; i <= lastseg; i++) segs[i - 1].endvertex = segs[i].startvertex;
//set angle and subsector index
for(int i = ss.firstseg; i <= lastseg; i++)
{
segs[i].angle = Vector2D.GetAngle(verts[segs[i].endvertex], verts[segs[i].startvertex]);
segs[i].ssector = index;
}
index++;
}
}
//read nodes
uint nodesCount = reader.ReadUInt32();
//boilerplate...
if(nodesCount < 1)
{
MessageBox.Show("The map has only one subsector.", "Why are you doing this, Stanley?..", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
nodes = new Node[nodesCount];
for(int i = 0; i < nodes.Length; i++)
{
if(nodesformat == "XGL3")
{
nodes[i].linestart.x = reader.ReadInt32() / 65536.0f;
nodes[i].linestart.y = reader.ReadInt32() / 65536.0f;
nodes[i].linedelta.x = reader.ReadInt32() / 65536.0f;
nodes[i].linedelta.y = reader.ReadInt32() / 65536.0f;
}
else
{
nodes[i].linestart.x = reader.ReadInt16();
nodes[i].linestart.y = reader.ReadInt16();
nodes[i].linedelta.x = reader.ReadInt16();
nodes[i].linedelta.y = reader.ReadInt16();
}
float top = reader.ReadInt16();
float bot = reader.ReadInt16();
float left = reader.ReadInt16();
float right = reader.ReadInt16();
nodes[i].rightbox = new RectangleF(left, top, (right - left), (bot - top));
top = reader.ReadInt16();
bot = reader.ReadInt16();
left = reader.ReadInt16();
right = reader.ReadInt16();
nodes[i].leftbox = new RectangleF(left, top, (right - left), (bot - top));
uint rightindex = reader.ReadUInt32();
uint leftindex = reader.ReadUInt32();
nodes[i].rightchild = (int)(rightindex & 0x7FFFFFFF);
nodes[i].leftchild = (int)(leftindex & 0x7FFFFFFF);
nodes[i].rightsubsector = (rightindex & 0x80000000) != 0;
nodes[i].leftsubsector = (leftindex & 0x80000000) != 0;
}
// Add additional properties to nodes
nodes[nodes.Length - 1].parent = -1;
RecursiveSetupNodes(nodes.Length - 1);
MessageBox.Show("Error while reading ZNODES: vertices count in ZNODES lump (" + vertsCount + ") doesn't match with map's vertices count (" + General.Map.Map.Vertices.Count + ")!", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
//add map vertices
verts = new Vector2D[vertsCount + newVertsCount];
int counter = 0;
foreach(Vertex v in General.Map.Map.Vertices) verts[counter++] = v.Position;
//read extra vertices
for(int i = counter; i < counter + newVertsCount; i++)
{
verts[i].x = reader.ReadInt32() / 65536.0f;
verts[i].y = reader.ReadInt32() / 65536.0f;
}
//read subsectors
uint ssecCount = reader.ReadUInt32();
ssectors = new Subsector[ssecCount];
int firstseg = 0;
for(int i = 0; i < ssectors.Length; i++)
{
ssectors[i].numsegs = (int)reader.ReadUInt32();
ssectors[i].firstseg = firstseg;
firstseg += ssectors[i].numsegs;
}
//read segments. offset and angle are unused anyway
uint segsCount = reader.ReadUInt32();
segs = new Seg[segsCount];
switch(nodesformat)
{
case "XGLN":
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = (int)reader.ReadUInt32();
reader.BaseStream.Position += 4; //skip partner
segs[i].lineindex = reader.ReadUInt16();
segs[i].leftside = reader.ReadBoolean();
}
break;
case "XGL3":
case "XGL2":
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = (int)reader.ReadUInt32();
reader.BaseStream.Position += 4; //skip partner
uint lineindex = reader.ReadUInt32();
segs[i].lineindex = (lineindex == 0xFFFFFFFF ? -1 : (int)lineindex);
segs[i].leftside = reader.ReadBoolean();
}
break;
case "XNOD":
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = (int)reader.ReadUInt32();
segs[i].endvertex = (int)reader.ReadUInt32();
segs[i].lineindex = reader.ReadUInt16();
segs[i].leftside = reader.ReadBoolean();
}
break;
}
//set second vertex, angle and reverse segs order
if(nodesformat == "XGLN" || nodesformat == "XGL2" || nodesformat == "XGL3")
{
int index = 0;
foreach(Subsector ss in ssectors)
{
//set the last vert
int lastseg = ss.firstseg + ss.numsegs - 1;
segs[lastseg].endvertex = segs[ss.firstseg].startvertex;
//set the rest
for(int i = ss.firstseg + 1; i <= lastseg; i++) segs[i - 1].endvertex = segs[i].startvertex;
//set angle and subsector index
for(int i = ss.firstseg; i <= lastseg; i++)
{
segs[i].angle = Vector2D.GetAngle(verts[segs[i].endvertex], verts[segs[i].startvertex]);
segs[i].ssector = index;
}
index++;
}
}
//read nodes
uint nodesCount = reader.ReadUInt32();
//boilerplate...
if(nodesCount < 1)
{
MessageBox.Show("The map has only one subsector.", "Why are you doing this, Stanley?..", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
nodes = new Node[nodesCount];
for(int i = 0; i < nodes.Length; i++)
{
if(nodesformat == "XGL3")
{
nodes[i].linestart.x = reader.ReadInt32() / 65536.0f;
nodes[i].linestart.y = reader.ReadInt32() / 65536.0f;
nodes[i].linedelta.x = reader.ReadInt32() / 65536.0f;
nodes[i].linedelta.y = reader.ReadInt32() / 65536.0f;
}
else
{
nodes[i].linestart.x = reader.ReadInt16();
nodes[i].linestart.y = reader.ReadInt16();
nodes[i].linedelta.x = reader.ReadInt16();
nodes[i].linedelta.y = reader.ReadInt16();
}
float top = reader.ReadInt16();
float bot = reader.ReadInt16();
float left = reader.ReadInt16();
float right = reader.ReadInt16();
nodes[i].rightbox = new RectangleF(left, top, (right - left), (bot - top));
top = reader.ReadInt16();
bot = reader.ReadInt16();
left = reader.ReadInt16();
right = reader.ReadInt16();
nodes[i].leftbox = new RectangleF(left, top, (right - left), (bot - top));
uint rightindex = reader.ReadUInt32();
uint leftindex = reader.ReadUInt32();
nodes[i].rightchild = (int)(rightindex & 0x7FFFFFFF);
nodes[i].leftchild = (int)(leftindex & 0x7FFFFFFF);
nodes[i].rightsubsector = (rightindex & 0x80000000) != 0;
nodes[i].leftsubsector = (leftindex & 0x80000000) != 0;
}
// Add additional properties to nodes
nodes[nodes.Length - 1].parent = -1;
RecursiveSetupNodes(nodes.Length - 1);
}
return true;

View file

@ -252,6 +252,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode
base.OnDisengage();
worker.CancelAsync();
worker.Dispose();
General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ColorConfiguration);
General.Interface.RemoveDocker(docker);