From 7ab0a86a92c72cfc365920607050153f7b9debe4 Mon Sep 17 00:00:00 2001 From: MaxED <j.maxed@gmail.com> Date: Sat, 2 Jul 2016 22:27:20 +0000 Subject: [PATCH] Added, Find & Replace mode, UDMF: added Linedef activation flags to the "Find Linedef flags" search mode flags list. Changed, Sound Propagation mode: all sound zones are now shown when no sector is highlighted. Changed, Sound Environments mode: the mode is now available only in UDMF map format. Changed, Color Picker plugin: the plugin functionality is no longer available in Doom map format. Restored the ability to create superimposed lines by dragging them with "Snap to Geometry" mode disabled. Fixed, Sound Propagation mode: fixed a crash when a single-sided linedef had "Block Sound" flag. Fixed, Find & Replace mode: in some cases "Find Sector/Sidedef/Linedef/Thing flags" search modes failed to find map elements with required flags. Fixed, Edit Selection mode: in some cases incorrect geometry was created after applying multipart sector edit when "Replace with Dragged Geometry" mode was enabled. Fixed a crash caused by eventual GDI font objects overflow. --- Source/Core/Config/ProgramConfiguration.cs | 22 +-- Source/Core/Controls/DockersTabsControl.cs | 1 + Source/Core/Controls/ImageBrowserItem.cs | 26 ++-- Source/Core/Controls/NumericTextbox.cs | 13 +- Source/Core/Controls/RenderTargetControl.cs | 25 ++-- Source/Core/Map/MapSet.cs | 8 +- Source/Core/Rendering/TextLabel.cs | 8 +- Source/Core/Windows/FlagsForm.cs | 6 +- .../ClassicModes/DragGeometryMode.cs | 2 +- .../FindReplace/FindLinedefFlags.cs | 8 +- .../FindReplace/FindSectorFlags.cs | 2 +- .../FindReplace/FindSidedefFlags.cs | 2 +- .../FindReplace/FindThingFlags.cs | 2 +- .../Interface/EditSelectionPanel.Designer.cs | 2 + .../Interface/EditSelectionPanel.cs | 6 +- .../BuilderModes/Interface/FindReplaceForm.cs | 3 + Source/Plugins/ColorPicker/BuilderPlug.cs | 12 +- .../SoundPropagationMode/BuilderPlug.cs | 1 + .../SoundEnvironmentMode.cs | 44 +++--- .../SoundPropagationDomain.cs | 21 ++- .../SoundPropagationMode.cs | 140 +++++++++--------- 21 files changed, 184 insertions(+), 170 deletions(-) diff --git a/Source/Core/Config/ProgramConfiguration.cs b/Source/Core/Config/ProgramConfiguration.cs index 1c1e9fd78..0fcfe05bc 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 49fac0faa..99306141c 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 5bbb35810..aafec37e2 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 fbe3c5c52..eb74a977c 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 115592a76..20c13af93 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 b1b8eb252..8deb24fcf 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 cd6b4d77a..1280f1fc8 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 7d4035ee2..4eee992c1 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 b8c6c3e63..841d2734a 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 b068abf6e..85e38f113 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 33e1dc62c..0cc2b44b6 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 ff51f54f4..97daf3707 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 ea292ca40..466cb999b 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 e8c0083ea..c4e364815 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 24f9a1ffb..6f12af9f3 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 eab6f4444..1196087ae 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 eaea6adae..c7d71d8b8 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 f5989a71d..08ca5f57b 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 a832a8ff0..3b7e76bba 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 1646d69ed..dfc141401 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 b5e156b3d..058d8e7f0 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(); } } -- GitLab