diff --git a/Source/Core/Config/ProgramConfiguration.cs b/Source/Core/Config/ProgramConfiguration.cs index 1c1e9fd785deafd8d2ca50b606c03268b82a29dc..0fcfe05bcf57a671d9dc0a3a070bc31733ab845e 100644 --- a/Source/Core/Config/ProgramConfiguration.cs +++ b/Source/Core/Config/ProgramConfiguration.cs @@ -19,7 +19,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Drawing; using System.IO; using System.Reflection; using System.Windows.Forms; @@ -114,8 +113,6 @@ namespace CodeImp.DoomBuilder.Config private string textlabelfontname; private int textlabelfontsize; private bool textlabelfontbold; - private Font textlabelfont; - private bool textlabelfontupdaterequired; //mxd private ModelRenderMode gzDrawModelsMode; @@ -239,10 +236,9 @@ namespace CodeImp.DoomBuilder.Config public bool ScriptAutoShowAutocompletion { get { return scriptautoshowautocompletion; } internal set { scriptautoshowautocompletion = value; } } //mxd //mxd. Text labels settings - public string TextLabelFontName { get { return textlabelfontname; } internal set { textlabelfontname = value; textlabelfontupdaterequired = true; } } - public int TextLabelFontSize { get { return textlabelfontsize; } internal set { textlabelfontsize = value; textlabelfontupdaterequired = true; } } - public bool TextLabelFontBold { get { return textlabelfontbold; } internal set { textlabelfontbold = value; textlabelfontupdaterequired = true; } } - public Font TextLabelFont { get { return GetTextLabelFont(); } } + public string TextLabelFontName { get { return textlabelfontname; } internal set { textlabelfontname = value; } } + public int TextLabelFontSize { get { return textlabelfontsize; } internal set { textlabelfontsize = value; } } + public bool TextLabelFontBold { get { return textlabelfontbold; } internal set { textlabelfontbold = value; } } //mxd public ModelRenderMode GZDrawModelsMode { get { return gzDrawModelsMode; } internal set { gzDrawModelsMode = value; } } @@ -380,7 +376,6 @@ namespace CodeImp.DoomBuilder.Config textlabelfontname = cfg.ReadSetting("textlabelfontname", "Microsoft Sans Serif"); textlabelfontsize = cfg.ReadSetting("textlabelfontsize", 10); textlabelfontbold = cfg.ReadSetting("textlabelfontbold", false); - textlabelfontupdaterequired = true; //mxd gzDrawModelsMode = (ModelRenderMode)cfg.ReadSetting("gzdrawmodels", (int)ModelRenderMode.ALL); @@ -671,17 +666,6 @@ namespace CodeImp.DoomBuilder.Config internal bool DeleteSetting(string setting) { return cfg.DeleteSetting(setting); } internal bool DeleteSetting(string setting, string pathseperator) { return cfg.DeleteSetting(setting, pathseperator); } - //mxd - private Font GetTextLabelFont() - { - if(textlabelfontupdaterequired) - { - textlabelfont = new Font(new FontFamily(textlabelfontname), textlabelfontsize, (textlabelfontbold ? FontStyle.Bold : FontStyle.Regular)); - textlabelfontupdaterequired = false; - } - return textlabelfont; - } - #endregion #region ================== Default Settings diff --git a/Source/Core/Controls/DockersTabsControl.cs b/Source/Core/Controls/DockersTabsControl.cs index 49fac0faaf7d9296adec2a84a0d1f6770fd19e89..99306141cc1d7571367206726aa748b131d33f98 100644 --- a/Source/Core/Controls/DockersTabsControl.cs +++ b/Source/Core/Controls/DockersTabsControl.cs @@ -146,6 +146,7 @@ namespace CodeImp.DoomBuilder.Controls } graphics.DrawImage(drawimage, bounds.X, bounds.Y); + drawimage.Dispose(); } #endregion diff --git a/Source/Core/Controls/ImageBrowserItem.cs b/Source/Core/Controls/ImageBrowserItem.cs index 5bbb358107c8c838352affb503d530b72156d22a..aafec37e2134636e39799f8552a193c72d77ad28 100644 --- a/Source/Core/Controls/ImageBrowserItem.cs +++ b/Source/Core/Controls/ImageBrowserItem.cs @@ -134,19 +134,21 @@ namespace CodeImp.DoomBuilder.Controls if(General.Settings.ShowTextureSizes && !string.IsNullOrEmpty(imagesize)) { // Setup - Font sizefont = new Font(this.ListView.Font.FontFamily, this.ListView.Font.SizeInPoints - 1); - textsize = g.MeasureString(imagesize, sizefont, bounds.Width * 2); - textpos = new PointF(bounds.Left + textsize.Width / 2, bounds.Top + 1); - imagerect = new Rectangle(bounds.Left + 1, bounds.Top + 1, (int)textsize.Width, (int)textsize.Height); - - // Draw - using(SolidBrush labelbg = new SolidBrush(Color.FromArgb(196, base.ListView.ForeColor))) - { - g.FillRectangle(labelbg, imagerect); - } - using(SolidBrush labelcolor = new SolidBrush(base.ListView.BackColor)) + using(Font sizefont = new Font(this.ListView.Font.FontFamily, this.ListView.Font.SizeInPoints - 1)) { - g.DrawString(imagesize, sizefont, labelcolor, textpos, format); + textsize = g.MeasureString(imagesize, sizefont, bounds.Width * 2); + textpos = new PointF(bounds.Left + textsize.Width / 2, bounds.Top + 1); + imagerect = new Rectangle(bounds.Left + 1, bounds.Top + 1, (int)textsize.Width, (int)textsize.Height); + + // Draw + using(SolidBrush labelbg = new SolidBrush(Color.FromArgb(196, base.ListView.ForeColor))) + { + g.FillRectangle(labelbg, imagerect); + } + using(SolidBrush labelcolor = new SolidBrush(base.ListView.BackColor)) + { + g.DrawString(imagesize, sizefont, labelcolor, textpos, format); + } } } } diff --git a/Source/Core/Controls/NumericTextbox.cs b/Source/Core/Controls/NumericTextbox.cs index fbe3c5c522589b111baf553ccd533425cc807bf3..eb74a977cac1f0c5573079325666d1f15487263c 100644 --- a/Source/Core/Controls/NumericTextbox.cs +++ b/Source/Core/Controls/NumericTextbox.cs @@ -39,7 +39,7 @@ namespace CodeImp.DoomBuilder.Controls private bool allowdecimal; // Allow decimal (float) numbers private bool controlpressed; private int incrementstep; //mxd. Step for +++ and --- prefixes - private readonly ToolTip tooltip; //mxd + private ToolTip tooltip; //mxd #endregion @@ -62,6 +62,17 @@ namespace CodeImp.DoomBuilder.Controls this.tooltip = new ToolTip { AutomaticDelay = 100, AutoPopDelay = 8000, InitialDelay = 100, ReshowDelay = 100 }; } + //mxd + protected override void Dispose(bool disposing) + { + if(disposing) + { + tooltip.Dispose(); + tooltip = null; + } + base.Dispose(disposing); + } + #endregion #region ================== Methods diff --git a/Source/Core/Controls/RenderTargetControl.cs b/Source/Core/Controls/RenderTargetControl.cs index 115592a76e5c7a1f2b2966611a903582e374f642..20c13af9346d95572e73bbd00c376027f08dfcd7 100644 --- a/Source/Core/Controls/RenderTargetControl.cs +++ b/Source/Core/Controls/RenderTargetControl.cs @@ -32,7 +32,7 @@ namespace CodeImp.DoomBuilder.Controls #region ================== Variables - private readonly ToolTip tip; //mxd + private ToolTip tooltip; //mxd #endregion @@ -53,11 +53,18 @@ namespace CodeImp.DoomBuilder.Controls this.SetStyle(ControlStyles.FixedHeight, true); //mxd. Create tooltip - tip = new ToolTip(); - tip.UseAnimation = false; - tip.UseFading = false; - tip.InitialDelay = 0; - tip.AutoPopDelay = 9000; + tooltip = new ToolTip { UseAnimation = false, UseFading = false, InitialDelay = 0, AutoPopDelay = 9000 }; + } + + //mxd + protected override void Dispose(bool disposing) + { + if(disposing) + { + tooltip.Dispose(); + tooltip = null; + } + base.Dispose(disposing); } #endregion @@ -117,14 +124,14 @@ namespace CodeImp.DoomBuilder.Controls //mxd. This shows tooltip at given position public void ShowToolTip(string title, string text, int x, int y) { - tip.ToolTipTitle = title; - tip.Show(text, this, x, y); + tooltip.ToolTipTitle = title; + tooltip.Show(text, this, x, y); } //mxd. This hides it public void HideToolTip() { - tip.Hide(this); + tooltip.Hide(this); } #endregion diff --git a/Source/Core/Map/MapSet.cs b/Source/Core/Map/MapSet.cs index b1b8eb2522ced8b0a5d6f684f35b5f8b17054a6a..8deb24fcf84210dc92db8d352e97aae4a7348fa2 100644 --- a/Source/Core/Map/MapSet.cs +++ b/Source/Core/Map/MapSet.cs @@ -2918,14 +2918,14 @@ namespace CodeImp.DoomBuilder.Map foreach(Sector s in changedsectors) s.UpdateBBox(); foreach(Linedef l in alllines) { - // Remove line when both it's start and end are inside a changed sector and neither side references it + // Remove line when it's start, center and end are inside a changed sector and neither side references it if(l.Start != null && l.End != null && (l.Front == null || !changedsectors.Contains(l.Front.Sector)) && (l.Back == null || !changedsectors.Contains(l.Back.Sector))) { foreach(Sector s in changedsectors) { - if(s.Intersect(l.Start.Position) && s.Intersect(l.End.Position)) + if(s.Intersect(l.Start.Position) && s.Intersect(l.End.Position) && s.Intersect(l.GetCenterPoint())) { Vertex[] tocheck = { l.Start, l.End }; while(lines.Remove(l)); @@ -3078,7 +3078,7 @@ namespace CodeImp.DoomBuilder.Map foreach(Sector s in changedsectors) s.UpdateBBox(); foreach(Linedef l in alllines) { - // Remove line when both it's start and end are inside a changed sector and neither side references it + // Remove line when it's start, center and end are inside a changed sector and neither side references it if(l.Start != null && l.End != null) { if(l.Front == null && l.Back == null) @@ -3090,7 +3090,7 @@ namespace CodeImp.DoomBuilder.Map { foreach(Sector s in changedsectors) { - if(s.Intersect(l.Start.Position) && s.Intersect(l.End.Position)) + if(s.Intersect(l.Start.Position) && s.Intersect(l.End.Position) && s.Intersect(l.GetCenterPoint())) { Vertex[] tocheck = { l.Start, l.End }; l.Dispose(); diff --git a/Source/Core/Rendering/TextLabel.cs b/Source/Core/Rendering/TextLabel.cs index cd6b4d77a75828d077b6116829ac5d2811a8a4e7..1280f1fc896dd3e6d2328d6d6f460d1c2959228d 100644 --- a/Source/Core/Rendering/TextLabel.cs +++ b/Source/Core/Rendering/TextLabel.cs @@ -101,7 +101,7 @@ namespace CodeImp.DoomBuilder.Rendering // Properties public Vector2D Location { get { return location; } set { location = value; updateneeded = true; } } //mxd public string Text { get { return text; } set { if(text != value) { text = value; textsize = Size.Empty; textureupdateneeded = true; } } } - public Font Font { get { return font; } set { font = value; textsize = Size.Empty; textureupdateneeded = true; } } //mxd + public Font Font { get { return font; } set { font.Dispose(); font = value; textsize = Size.Empty; textureupdateneeded = true; } } //mxd public bool TransformCoords { get { return transformcoords; } set { transformcoords = value; updateneeded = true; } } public SizeF TextSize { get { if(textureupdateneeded) Update(General.Map.Renderer2D.TranslateX, General.Map.Renderer2D.TranslateY, General.Map.Renderer2D.Scale, -General.Map.Renderer2D.Scale); return textsize; } } public TextAlignmentX AlignX { get { return alignx; } set { alignx = value; updateneeded = true; } } @@ -124,6 +124,7 @@ namespace CodeImp.DoomBuilder.Rendering set { scale = value; + font.Dispose(); font = new Font(new FontFamily(General.Settings.TextLabelFontName), (float)Math.Round(scale * 0.75f), (General.Settings.TextLabelFontBold ? FontStyle.Bold : FontStyle.Regular)); textsize = Size.Empty; textureupdateneeded = true; @@ -145,7 +146,7 @@ namespace CodeImp.DoomBuilder.Rendering { // Initialize this.text = ""; - this.font = General.Settings.TextLabelFont; //mxd + this.font = new Font(new FontFamily(General.Settings.TextLabelFontName), General.Settings.TextLabelFontSize, (General.Settings.TextLabelFontBold ? FontStyle.Bold : FontStyle.Regular)); //General.Settings.TextLabelFont; //mxd this.location = new Vector2D(); //mxd this.color = new PixelColor(255, 255, 255, 255); this.backcolor = new PixelColor(128, 0, 0, 0); @@ -169,7 +170,7 @@ namespace CodeImp.DoomBuilder.Rendering { // Initialize this.text = ""; - this.font = General.Settings.TextLabelFont; + this.font = new Font(new FontFamily(General.Settings.TextLabelFontName), General.Settings.TextLabelFontSize, (General.Settings.TextLabelFontBold ? FontStyle.Bold : FontStyle.Regular)); // General.Settings.TextLabelFont; this.location = new Vector2D(); this.color = new PixelColor(255, 255, 255, 255); this.backcolor = new PixelColor(128, 0, 0, 0); @@ -195,6 +196,7 @@ namespace CodeImp.DoomBuilder.Rendering { // Clean up UnloadResource(); + font.Dispose(); // Unregister resource General.Map.Graphics.UnregisterResource(this); diff --git a/Source/Core/Windows/FlagsForm.cs b/Source/Core/Windows/FlagsForm.cs index 7d4035ee2cefa2921dd561090f86612363bebf1c..4eee992c146b33d84b1dacc4378998d6710064ca 100644 --- a/Source/Core/Windows/FlagsForm.cs +++ b/Source/Core/Windows/FlagsForm.cs @@ -63,10 +63,10 @@ namespace CodeImp.DoomBuilder.Windows string str = s.Trim(); //mxd. Negative flag? - bool setflag = true; + CheckState setflag = CheckState.Checked; if(str.StartsWith("!")) { - setflag = false; + setflag = CheckState.Unchecked; str = str.Substring(1, str.Length - 1); } @@ -75,7 +75,7 @@ namespace CodeImp.DoomBuilder.Windows foreach(CheckBox c in flags.Checkboxes) { - if(c.Text == flagdefs[str]) c.Checked = setflag; + if(c.Text == flagdefs[str]) c.CheckState = setflag; } } } diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragGeometryMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragGeometryMode.cs index b8c6c3e633d13183ff39b457bd758ea4987fbca8..841d2734a63135b1dff2c8ea5934d2c990020530 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DragGeometryMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragGeometryMode.cs @@ -420,7 +420,7 @@ namespace CodeImp.DoomBuilder.BuilderModes MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptogridincrement, snaptonearest, snaptocardinaldirection); // Stitch geometry - General.Map.Map.StitchGeometry(General.Settings.MergeGeometryMode); + if(snaptonearest) General.Map.Map.StitchGeometry(General.Settings.MergeGeometryMode); // Snap to map format accuracy General.Map.Map.SnapAllToAccuracy(); diff --git a/Source/Plugins/BuilderModes/FindReplace/FindLinedefFlags.cs b/Source/Plugins/BuilderModes/FindReplace/FindLinedefFlags.cs index b068abf6e62b286a98a86a77fefd6a82bf87ebde..85e38f113f7ea2e5b457f7c819333aeaa6dcec77 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindLinedefFlags.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindLinedefFlags.cs @@ -54,7 +54,11 @@ namespace CodeImp.DoomBuilder.BuilderModes // This is called when the browse button is pressed public override string Browse(string initialvalue) { - return FlagsForm.ShowDialog(Form.ActiveForm, initialvalue, General.Map.Config.LinedefFlags); + //mxd. Combine regular and activation flags + Dictionary<string, string> flags = new Dictionary<string, string>(General.Map.Config.LinedefFlags); + foreach(LinedefActivateInfo ai in General.Map.Config.LinedefActivates) flags.Add(ai.Key, ai.Title); + + return FlagsForm.ShowDialog(Form.ActiveForm, initialvalue, flags); } // This is called to perform a search (and replace) @@ -120,7 +124,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(KeyValuePair<string, bool> group in findflagslist) { // ...and check if the flag doesn't match - if((group.Value && !l.IsFlagSet(group.Key)) || l.IsFlagSet(group.Key)) + if(group.Value != l.IsFlagSet(group.Key)) { match = false; break; diff --git a/Source/Plugins/BuilderModes/FindReplace/FindSectorFlags.cs b/Source/Plugins/BuilderModes/FindReplace/FindSectorFlags.cs index 33e1dc62ce6a80e651296e5b7bd073d8735ebd33..0cc2b44b6d5e5ceef0357c155d8531d0d6528d49 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindSectorFlags.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindSectorFlags.cs @@ -98,7 +98,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(KeyValuePair<string, bool> group in findflagslist) { // ...and check if the flag doesn't match - if((group.Value && !s.IsFlagSet(group.Key)) || s.IsFlagSet(group.Key)) + if(group.Value != s.IsFlagSet(group.Key)) { match = false; break; diff --git a/Source/Plugins/BuilderModes/FindReplace/FindSidedefFlags.cs b/Source/Plugins/BuilderModes/FindReplace/FindSidedefFlags.cs index ff51f54f474aed088bd675982c29de6539cbc900..97daf3707a2d4644fde3e4db4b67848811b2563d 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindSidedefFlags.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindSidedefFlags.cs @@ -97,7 +97,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(KeyValuePair<string, bool> group in findflagslist) { // ...and check if the flag doesn't match - if((group.Value && !sd.IsFlagSet(group.Key)) || sd.IsFlagSet(group.Key)) + if(group.Value != sd.IsFlagSet(group.Key)) { match = false; break; diff --git a/Source/Plugins/BuilderModes/FindReplace/FindThingFlags.cs b/Source/Plugins/BuilderModes/FindReplace/FindThingFlags.cs index ea292ca404c2446114ca29ec7842ad0ac9c15496..466cb999b78322b2f62b2427cd4f2f243ec41457 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindThingFlags.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindThingFlags.cs @@ -128,7 +128,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(KeyValuePair<string, bool> group in findflagslist) { // ...and check if the flag doesn't match - if((group.Value && !t.IsFlagSet(group.Key)) || t.IsFlagSet(group.Key)) + if(group.Value != t.IsFlagSet(group.Key)) { match = false; break; diff --git a/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.Designer.cs b/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.Designer.cs index e8c0083eaeec4c029a0bb1c7d45f14c490a83649..c4e364815ebd7a1e787831c7f9aad09bd0383e86 100644 --- a/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.Designer.cs +++ b/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.Designer.cs @@ -16,6 +16,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(disposing && (components != null)) { components.Dispose(); + mode = null; //mxd } base.Dispose(disposing); } @@ -119,6 +120,7 @@ namespace CodeImp.DoomBuilder.BuilderModes this.tooltip.SetToolTip(this.preciseposition, "When checked, thing and vertex positions will be set using floating point precisi" + "on.\r\nOtherwise, they will be rounded to the nearest integer."); this.preciseposition.UseVisualStyleBackColor = true; + this.preciseposition.CheckedChanged += new System.EventHandler(this.preciseposition_CheckedChanged); // // orgposy // diff --git a/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.cs b/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.cs index 24f9a1ffb7d28b450d4d4e2ccab5f686b0f3334b..6f12af9f391ed8be7bf9115baba4f90c274ce8d2 100644 --- a/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.cs +++ b/Source/Plugins/BuilderModes/Interface/EditSelectionPanel.cs @@ -33,7 +33,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables // Editing mode - private readonly EditSelectionMode mode; + private EditSelectionMode mode; // Input private bool userinput; @@ -59,17 +59,18 @@ namespace CodeImp.DoomBuilder.BuilderModes this.mode = mode; //mxd + preventchanges = true; if(General.Map.UDMF) { preciseposition.Checked = mode.UsePrecisePosition; preciseposition.Enabled = true; - preciseposition.CheckedChanged += preciseposition_CheckedChanged; } else { preciseposition.Checked = false; preciseposition.Enabled = false; } + preventchanges = false; //mxd. Otherwise the focus will go to one of TextBoxes // and stay there forever preventing tab collapsing when in collapsed mode @@ -377,6 +378,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd private void preciseposition_CheckedChanged(object sender, EventArgs e) { + if(preventchanges) return; mode.UsePrecisePosition = preciseposition.Checked; General.Interface.FocusDisplay(); } diff --git a/Source/Plugins/BuilderModes/Interface/FindReplaceForm.cs b/Source/Plugins/BuilderModes/Interface/FindReplaceForm.cs index eab6f4444a6238a9d32ff9e286468b7606b0a5d7..1196087ae7ef3ae1533e96826fb88b09640b34fc 100644 --- a/Source/Plugins/BuilderModes/Interface/FindReplaceForm.cs +++ b/Source/Plugins/BuilderModes/Interface/FindReplaceForm.cs @@ -289,6 +289,9 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.Focus(); General.Editing.CancelMode(); } + + //mxd + hintfont.Dispose(); } // Close button clicked diff --git a/Source/Plugins/ColorPicker/BuilderPlug.cs b/Source/Plugins/ColorPicker/BuilderPlug.cs index eaea6adae31034d97928d84e86001b4aaba61e1c..c7d71d8b8f0543904ab931c1219aa6a89dba5110 100644 --- a/Source/Plugins/ColorPicker/BuilderPlug.cs +++ b/Source/Plugins/ColorPicker/BuilderPlug.cs @@ -17,7 +17,7 @@ namespace CodeImp.DoomBuilder.ColorPicker private static BuilderPlug me; public static BuilderPlug Me { get { return me; } } - public override int MinimumRevision { get { return 1869; } } + public override int MinimumRevision { get { return 2600; } } public override string Name { get { return "Color Picker"; } } @@ -40,25 +40,25 @@ namespace CodeImp.DoomBuilder.ColorPicker public override void OnMapOpenEnd() { base.OnMapOpenEnd(); - toolsform.Register(); + if(!General.Map.DOOM) toolsform.Register(); } public override void OnMapNewEnd() { base.OnMapNewEnd(); - toolsform.Register(); + if(!General.Map.DOOM) toolsform.Register(); } public override void OnMapCloseEnd() { base.OnMapCloseEnd(); - toolsform.Unregister(); + if(!General.Map.DOOM) toolsform.Unregister(); } public override void OnReloadResources() { base.OnReloadResources(); - toolsform.Register(); + if(!General.Map.DOOM) toolsform.Register(); } public override void Dispose() @@ -80,7 +80,7 @@ namespace CodeImp.DoomBuilder.ColorPicker [BeginAction("togglelightpannel")] private void ToggleLightPannel() { - if(General.Editing.Mode == null) return; + if(General.Editing.Mode == null || General.Map.DOOM) return; string currentModeName = General.Editing.Mode.GetType().Name; //display one of colorPickers or tell the user why we can't do that diff --git a/Source/Plugins/SoundPropagationMode/BuilderPlug.cs b/Source/Plugins/SoundPropagationMode/BuilderPlug.cs index f5989a71d4b1b2d92a9113eddb9e25179e40d2d4..08ca5f57ba1dddc2e4c8157085ad5724f5fc78e1 100644 --- a/Source/Plugins/SoundPropagationMode/BuilderPlug.cs +++ b/Source/Plugins/SoundPropagationMode/BuilderPlug.cs @@ -46,6 +46,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode #region ================== Constants internal const int SOUND_ENVIROMNEMT_THING_TYPE = 9048; //mxd + internal const float LINE_LENGTH_SCALER = 0.001f; //mxd #endregion diff --git a/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs b/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs index a832a8ff084bc5fbec3b47071b5e293f45f6908c..3b7e76bbaf7127d212b3cbc9423c25c8b2460a96 100644 --- a/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs +++ b/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs @@ -38,6 +38,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode ButtonGroup = "000_editing", UseByDefault = true, SafeStartMode = false, + SupportedMapFormats = new[] { "UniversalMapSetIO" }, //mxd Volatile = false)] public class SoundEnvironmentMode : ClassicMode @@ -104,12 +105,6 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode } panel.HighlightSoundEnvironment(highlightedsoundenvironment); - - // Show highlight info - if((highlighted != null) && !highlighted.IsDisposed) - General.Interface.ShowSectorInfo(highlighted); - else - General.Interface.HideInfo(); } private void UpdateData() @@ -188,7 +183,6 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode //mxd. If a linedef is highlighted, toggle the sound blocking flag, if a sound environment is clicked, select it in the tree view protected override void OnSelectEnd() { - if(!General.Map.UDMF) return; if(highlightedline != null) { // Make undo @@ -276,6 +270,8 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode worker.Dispose(); General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ColorConfiguration); General.Interface.RemoveDocker(docker); + panel.Dispose(); //mxd + panel = null; //mxd // Hide highlight info General.Interface.HideInfo(); @@ -301,7 +297,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode else c = General.Colors.Linedefs.WithAlpha(General.Settings.DoubleSidedAlphaByte); - renderer.PlotLine(ld.Start.Position, ld.End.Position, c); + renderer.PlotLine(ld.Start.Position, ld.End.Position, c, BuilderPlug.LINE_LENGTH_SCALER); } // Since there will usually be way less blocking linedefs than total linedefs, it's presumably @@ -310,17 +306,16 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode { foreach(Linedef ld in BuilderPlug.Me.BlockingLinedefs) { - renderer.PlotLine(ld.Start.Position, ld.End.Position, BuilderPlug.Me.BlockSoundColor); + renderer.PlotLine(ld.Start.Position, ld.End.Position, BuilderPlug.Me.BlockSoundColor, BuilderPlug.LINE_LENGTH_SCALER); } } //mxd. Render highlighted line if(highlightedline != null) { - renderer.PlotLine(highlightedline.Start.Position, highlightedline.End.Position, General.Colors.Highlight); + renderer.PlotLine(highlightedline.Start.Position, highlightedline.End.Position, General.Colors.Highlight, BuilderPlug.LINE_LENGTH_SCALER); } - renderer.PlotVerticesSet(General.Map.Map.Vertices); renderer.Finish(); } @@ -399,7 +394,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode // Highlight if not the same if(l.Back.Sector != highlighted) Highlight(l.Back.Sector); } - else + else if(highlighted != null) { // Highlight nothing Highlight(null); @@ -413,14 +408,14 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode // Highlight if not the same if(l.Front.Sector != highlighted) Highlight(l.Front.Sector); } - else + else if(highlighted != null) { // Highlight nothing Highlight(null); } } } - else + else if(highlighted != null) { // Highlight nothing Highlight(null); @@ -429,10 +424,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode //mxd. Find the nearest linedef within default highlight range l = General.Map.Map.NearestLinedefRange(mousemappos, 20 / renderer.Scale); //mxd. We are not interested in single-sided lines, unless they have zoneboundary flag... - if(l != null && ((l.Front == null || l.Back == null) && (General.Map.UDMF && !l.IsFlagSet(ZoneBoundaryFlag)))) - { - l = null; - } + if(l != null && ((l.Front == null || l.Back == null) && !l.IsFlagSet(ZoneBoundaryFlag))) l = null; //mxd. Set as highlighted bool redrawrequired = false; @@ -465,8 +457,20 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode redrawrequired = true; } - //mxd. Redraw display? - if(redrawrequired) General.Interface.RedrawDisplay(); + //mxd + if(redrawrequired) + { + // Show highlight info + if(highlightedline != null && !highlightedline.IsDisposed) + General.Interface.ShowLinedefInfo(highlightedline); + else if(highlighted != null && !highlighted.IsDisposed) + General.Interface.ShowSectorInfo(highlighted); + else + General.Interface.HideInfo(); + + // Redraw display + General.Interface.RedrawDisplay(); + } } } diff --git a/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs b/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs index 1646d69edf49e6abfe4efbfd743552a2d23f9539..dfc141401a1a7f43a566c2e8bea781841d388722 100644 --- a/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs +++ b/Source/Plugins/SoundPropagationMode/SoundPropagationDomain.cs @@ -12,9 +12,8 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode { #region ================== Variables - private List<Sector> sectors; - private List<Sector> adjacentsectors; - private List<Linedef> blockinglines; + private HashSet<Sector> sectors; + private HashSet<Sector> adjacentsectors; private FlatVertex[] level1geometry; private FlatVertex[] level2geometry; @@ -22,11 +21,11 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode #region ================== Properties - public List<Sector> Sectors { get { return sectors; } } - public List<Sector> AdjacentSectors { get { return adjacentsectors; } } - public List<Linedef> BlockingLines { get { return blockinglines; } } + public HashSet<Sector> Sectors { get { return sectors; } } + public HashSet<Sector> AdjacentSectors { get { return adjacentsectors; } } public FlatVertex[] Level1Geometry { get { return level1geometry; } } public FlatVertex[] Level2Geometry { get { return level2geometry; } } + public int Color { get; set; } //mxd #endregion @@ -34,9 +33,8 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode public SoundPropagationDomain(Sector sector) { - sectors = new List<Sector>(); - adjacentsectors = new List<Sector>(); - blockinglines = new List<Linedef>(); + sectors = new HashSet<Sector>(); + adjacentsectors = new HashSet<Sector>(); CreateSoundPropagationDomain(sector); } @@ -48,6 +46,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode private void CreateSoundPropagationDomain(Sector sourcesector) { List<Sector> sectorstocheck = new List<Sector> { sourcesector }; + HashSet<Linedef> blockinglines = new HashSet<Linedef>(); //mxd while(sectorstocheck.Count > 0) { @@ -57,7 +56,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode foreach(Sidedef sd in sector.Sidedefs) { bool blocksound = sd.Line.IsFlagSet(SoundPropagationMode.BlockSoundFlag); - if(blocksound) blockinglines.Add(sd.Line); + if(blocksound && sd.Other != null) blockinglines.Add(sd.Line); // If the line is one sided, the sound can travel nowhere, so try the next one if(sd.Other == null || blocksound) continue; @@ -119,7 +118,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode // Check if the sound will be blocked because of sector floor and ceiling heights // (like closed doors, raised lifts etc.) return (s1.CeilHeight <= s2.FloorHeight || s1.FloorHeight >= s2.CeilHeight || - s2.CeilHeight <= s2.FloorHeight || s1.CeilHeight <= s1.FloorHeight); + s2.CeilHeight <= s2.FloorHeight || s1.CeilHeight <= s1.FloorHeight); } #endregion diff --git a/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs b/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs index b5e156b3d662218021090ac88ac644be88497b71..058d8e7f02febae810014dadbbf9557e0d5b63f6 100644 --- a/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs +++ b/Source/Plugins/SoundPropagationMode/SoundPropagationMode.cs @@ -83,7 +83,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode BuilderPlug.Me.DataIsDirty = false; List<FlatVertex> vertsList = new List<FlatVertex>(); - // Go for all selected sectors + // Go for all sectors foreach(Sector s in General.Map.Map.Sectors) vertsList.AddRange(s.FlatVertices); overlayGeometry = vertsList.ToArray(); @@ -98,14 +98,6 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode highlighted = s; UpdateSoundPropagation(); - - // Show highlight info - if((highlighted != null) && !highlighted.IsDisposed) - General.Interface.ShowSectorInfo(highlighted); - else - General.Interface.HideInfo(); - - General.Interface.RedrawDisplay(); } //mxd @@ -120,31 +112,28 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode private void UpdateSoundPropagation() { huntingThings.Clear(); - BuilderPlug.Me.BlockingLinedefs.Clear(); foreach(Linedef ld in General.Map.Map.Linedefs) - if(ld.IsFlagSet(BlockSoundFlag)) - BuilderPlug.Me.BlockingLinedefs.Add(ld); - - if(highlighted == null || highlighted.IsDisposed) return; - - if(!sector2domain.ContainsKey(highlighted)) { - SoundPropagationDomain spd = new SoundPropagationDomain(highlighted); - foreach(Sector s in spd.Sectors) sector2domain[s] = spd; - propagationdomains.Add(spd); + if(ld.IsFlagSet(BlockSoundFlag)) BuilderPlug.Me.BlockingLinedefs.Add(ld); } - foreach(Sector adjacent in sector2domain[highlighted].AdjacentSectors) + //mxd. Create sound propagation for the whole map + int counter = 0; + foreach(Sector sector in General.Map.Map.Sectors) { - if(!sector2domain.ContainsKey(adjacent)) + if(!sector2domain.ContainsKey(sector)) { - SoundPropagationDomain aspd = new SoundPropagationDomain(adjacent); - foreach(Sector s in aspd.Sectors) sector2domain[s] = aspd; + SoundPropagationDomain spd = new SoundPropagationDomain(sector); + foreach(Sector s in spd.Sectors) sector2domain[s] = spd; + spd.Color = BuilderPlug.Me.DistinctColors[counter++ % BuilderPlug.Me.DistinctColors.Count].WithAlpha(255).ToInt(); + propagationdomains.Add(spd); } } + if(highlighted == null || highlighted.IsDisposed) return; + //mxd. Create the list of sectors, which will be affected by noise made in highlighted sector SoundPropagationDomain curdomain = sector2domain[highlighted]; Dictionary<int, Sector> noisysectors = new Dictionary<int, Sector>(curdomain.Sectors.Count); @@ -245,30 +234,19 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode // and can make it harder to see the sound environment propagation foreach(Linedef ld in General.Map.Map.Linedefs) { - PixelColor c; - - if(ld.IsFlagSet(General.Map.Config.ImpassableFlag)) - c = General.Colors.Linedefs; - else - c = General.Colors.Linedefs.WithAlpha(General.Settings.DoubleSidedAlphaByte); - - renderer.PlotLine(ld.Start.Position, ld.End.Position, c); + PixelColor c = (ld.IsFlagSet(General.Map.Config.ImpassableFlag) ? + General.Colors.Linedefs : General.Colors.Linedefs.WithAlpha(General.Settings.DoubleSidedAlphaByte)); + renderer.PlotLine(ld.Start.Position, ld.End.Position, c, BuilderPlug.LINE_LENGTH_SCALER); } // Since there will usually be way less blocking linedefs than total linedefs, it's presumably // faster to draw them on their own instead of checking if each linedef is in BlockingLinedefs foreach(Linedef ld in BuilderPlug.Me.BlockingLinedefs) - { - renderer.PlotLine(ld.Start.Position, ld.End.Position, BuilderPlug.Me.BlockSoundColor); - } + renderer.PlotLine(ld.Start.Position, ld.End.Position, BuilderPlug.Me.BlockSoundColor, BuilderPlug.LINE_LENGTH_SCALER); //mxd. Render highlighted line if(highlightedline != null) - { - renderer.PlotLine(highlightedline.Start.Position, highlightedline.End.Position, General.Colors.Highlight); - } - - renderer.PlotVerticesSet(General.Map.Map.Vertices); + renderer.PlotLine(highlightedline.Start.Position, highlightedline.End.Position, General.Colors.Highlight, BuilderPlug.LINE_LENGTH_SCALER); renderer.Finish(); } @@ -279,26 +257,24 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode renderer.RenderThingSet(General.Map.ThingsFilter.HiddenThings, General.Settings.HiddenThingsAlpha); renderer.RenderThingSet(General.Map.ThingsFilter.VisibleThings, General.Settings.InactiveThingsAlpha); foreach(Thing thing in huntingThings) - { renderer.RenderThing(thing, General.Colors.Selection, General.Settings.ActiveThingsAlpha); - } renderer.Finish(); } if(renderer.StartOverlay(true)) { - renderer.RenderGeometry(overlayGeometry, null, true); - + // Render highlighted domain and domains adjacent to it if(highlighted != null && !highlighted.IsDisposed) { + renderer.RenderGeometry(overlayGeometry, null, true); //mxd + SoundPropagationDomain spd = sector2domain[highlighted]; renderer.RenderGeometry(spd.Level1Geometry, null, true); foreach(Sector s in spd.AdjacentSectors) { SoundPropagationDomain aspd = sector2domain[s]; - if(!renderedspds.Contains(aspd)) { renderer.RenderGeometry(aspd.Level2Geometry, null, true); @@ -306,7 +282,13 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode } } - RenderColoredSector(highlighted, BuilderPlug.Me.HighlightColor.WithAlpha(128)); + renderer.RenderHighlight(highlighted.FlatVertices, BuilderPlug.Me.HighlightColor.WithAlpha(128).ToInt()); //mxd + } + else + { + //mxd. Render all domains using domain colors + foreach(SoundPropagationDomain spd in propagationdomains) + renderer.RenderHighlight(spd.Level1Geometry, spd.Color); } renderer.Finish(); @@ -315,19 +297,6 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode renderer.Present(); } - private void RenderColoredSector(Sector sector, PixelColor color) - { - RenderColoredSector(sector.FlatVertices, color); - } - - private void RenderColoredSector(FlatVertex[] flatvertices, PixelColor color) - { - FlatVertex[] fv = new FlatVertex[flatvertices.Length]; - flatvertices.CopyTo(fv, 0); - for(int i = 0; i < fv.Length; i++) fv[i].c = color.ToInt(); - renderer.RenderGeometry(fv, null, true); - } - //mxd. If a linedef is highlighted, toggle the sound blocking flag protected override void OnSelectEnd() { @@ -374,6 +343,15 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode { General.Interface.SetCursor(Cursors.Default); + //mxd. Find the nearest linedef within default highlight range + Linedef nl = General.Map.Map.NearestLinedefRange(mousemappos, 20 / renderer.Scale); + //mxd. We are not interested in single-sided lines (unless they have "blocksound" flag set)... + if(nl != null && (nl.Front == null || nl.Back == null) && !nl.IsFlagSet(BlockSoundFlag)) nl = null; + + //mxd. Set as highlighted + bool redrawrequired = (highlightedline != nl); + highlightedline = nl; + // Find the nearest linedef within highlight range Linedef l = General.Map.Map.NearestLinedef(mousemappos); if(l != null) @@ -386,12 +364,17 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode if(l.Back != null) { // Highlight if not the same - if(l.Back.Sector != highlighted) Highlight(l.Back.Sector); + if(l.Back.Sector != highlighted) + { + Highlight(l.Back.Sector); + redrawrequired = true; //mxd + } } - else + else if(highlighted != null) { // Highlight nothing Highlight(null); + redrawrequired = true; //mxd } } else @@ -400,30 +383,39 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode if(l.Front != null) { // Highlight if not the same - if(l.Front.Sector != highlighted) Highlight(l.Front.Sector); + if(l.Front.Sector != highlighted) + { + Highlight(l.Front.Sector); + redrawrequired = true; //mxd + } } - else + else if(highlighted != null) { // Highlight nothing Highlight(null); + redrawrequired = true; //mxd } } } - else + else if(highlighted != null) { // Highlight nothing Highlight(null); + redrawrequired = true; //mxd } - //mxd. Find the nearest linedef within default highlight range - l = General.Map.Map.NearestLinedefRange(mousemappos, 20 / renderer.Scale); - //mxd. We are not interested in single-sided lines (unless they have "blocksound" flag set)... - if(l != null && (l.Front == null || l.Back == null) && !l.IsFlagSet(BlockSoundFlag)) l = null; - - //mxd. Set as highlighted - if(highlightedline != l) + //mxd + if(redrawrequired) { - highlightedline = l; + // Show highlight info + if(highlightedline != null && !highlightedline.IsDisposed) + General.Interface.ShowLinedefInfo(highlightedline); + else if(highlighted != null && !highlighted.IsDisposed) + General.Interface.ShowSectorInfo(highlighted); + else + General.Interface.HideInfo(); + + // Redraw display General.Interface.RedrawDisplay(); } } @@ -445,10 +437,10 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode [BeginAction("soundpropagationcolorconfiguration")] public void ConfigureColors() { - ColorConfiguration cc = new ColorConfiguration(); - if(cc.ShowDialog((Form)General.Interface) == DialogResult.OK) + using(ColorConfiguration cc = new ColorConfiguration()) { - General.Interface.RedrawDisplay(); + if(cc.ShowDialog((Form)General.Interface) == DialogResult.OK) + General.Interface.RedrawDisplay(); } }