From 2458ea3d320d1d14bcb32d567e8fb8d9e196e49d Mon Sep 17 00:00:00 2001 From: MaxED <j.maxed@gmail.com> Date: Thu, 19 May 2016 21:44:39 +0000 Subject: [PATCH] Changed, internal, UDMF: local texture offsets and scale are now copied when merging sidedefs. Changed, internal: made TextLabel and IRenderer2D public properties compatible with DB2 implementation. Fixed some more cases when sidedefs belonging to linedefs, which were moved on top of existing linedefs, were incorrectly reassigned when applying Edit Selection and Drag Geometry modes. Fixed, Map Analysis mode: error checks must be updated after switching map format. --- Source/Core/Map/Sidedef.cs | 27 ++++++++++ Source/Core/Rendering/IRenderer2D.cs | 3 +- Source/Core/Rendering/Renderer2D.cs | 4 ++ Source/Core/Rendering/TextLabel.cs | 49 ++++++++++++++++++- .../ClassicModes/DragLinedefsMode.cs | 28 +++++------ .../ClassicModes/DragVerticesMode.cs | 6 +-- .../ClassicModes/EditSelectionMode.cs | 40 +++++++-------- .../BuilderModes/General/BuilderPlug.cs | 6 +++ 8 files changed, 120 insertions(+), 43 deletions(-) diff --git a/Source/Core/Map/Sidedef.cs b/Source/Core/Map/Sidedef.cs index c3bafcbaa..e6d1a7831 100644 --- a/Source/Core/Map/Sidedef.cs +++ b/Source/Core/Map/Sidedef.cs @@ -599,6 +599,15 @@ namespace CodeImp.DoomBuilder.Map // Counts as a half coice for copying offsets copyoffsets += 1; + + //mxd. Also copy UDMF offsets and scale + if(General.Map.UDMF) + { + UniFields.SetFloat(s.Fields, "offsetx_top", Fields.GetValue("offsetx_top", 0f), 0f); + UniFields.SetFloat(s.Fields, "offsety_top", Fields.GetValue("offsety_top", 0f), 0f); + UniFields.SetFloat(s.Fields, "scalex_top", Fields.GetValue("scalex_top", 1.0f), 1.0f); + UniFields.SetFloat(s.Fields, "scaley_top", Fields.GetValue("scaley_top", 1.0f), 1.0f); + } } // Middle texture set? @@ -610,6 +619,15 @@ namespace CodeImp.DoomBuilder.Map // Counts for copying offsets copyoffsets += 2; + + //mxd. Also copy UDMF offsets and scale + if(General.Map.UDMF) + { + UniFields.SetFloat(s.Fields, "offsetx_mid", Fields.GetValue("offsetx_mid", 0f), 0f); + UniFields.SetFloat(s.Fields, "offsety_mid", Fields.GetValue("offsety_mid", 0f), 0f); + UniFields.SetFloat(s.Fields, "scalex_mid", Fields.GetValue("scalex_mid", 1.0f), 1.0f); + UniFields.SetFloat(s.Fields, "scaley_mid", Fields.GetValue("scaley_mid", 1.0f), 1.0f); + } } // Lower texture set? @@ -621,6 +639,15 @@ namespace CodeImp.DoomBuilder.Map // Counts as a half coice for copying offsets copyoffsets += 1; + + //mxd. Also copy UDMF offsets and scale + if(General.Map.UDMF) + { + UniFields.SetFloat(s.Fields, "offsetx_bottom", Fields.GetValue("offsetx_bottom", 0f), 0f); + UniFields.SetFloat(s.Fields, "offsety_bottom", Fields.GetValue("offsety_bottom", 0f), 0f); + UniFields.SetFloat(s.Fields, "scalex_bottom", Fields.GetValue("scalex_bottom", 1.0f), 1.0f); + UniFields.SetFloat(s.Fields, "scaley_bottom", Fields.GetValue("scaley_bottom", 1.0f), 1.0f); + } } // Copy offsets also? diff --git a/Source/Core/Rendering/IRenderer2D.cs b/Source/Core/Rendering/IRenderer2D.cs index 044be3bae..bef6a2a6d 100644 --- a/Source/Core/Rendering/IRenderer2D.cs +++ b/Source/Core/Rendering/IRenderer2D.cs @@ -73,7 +73,8 @@ namespace CodeImp.DoomBuilder.Rendering void RenderLine(Vector2D start, Vector2D end, float thickness, PixelColor c, bool transformcoords); void RenderArrows(ICollection<Line3D> line); //mxd void RenderArrows(ICollection<Line3D> line, bool transformcoords); //mxd - void RenderText(ITextLabel text); + void RenderText(TextLabel text); //mxd, DB2 compatibility + void RenderText(ITextLabel text); //mxd void RenderText(IList<ITextLabel> labels); //mxd void RenderGeometry(FlatVertex[] vertices, ImageData texture, bool transformcoords); void RenderHighlight(FlatVertex[] vertices, int color); //mxd diff --git a/Source/Core/Rendering/Renderer2D.cs b/Source/Core/Rendering/Renderer2D.cs index c7695f04a..b339ed3ce 100644 --- a/Source/Core/Rendering/Renderer2D.cs +++ b/Source/Core/Rendering/Renderer2D.cs @@ -1624,6 +1624,10 @@ namespace CodeImp.DoomBuilder.Rendering graphics.Shaders.Things2D.End(); } + //mxd. This renders text (DB2 compatibility) + [Obsolete("Method is deprecated, please use RenderText(ITextLabel label) method instead.")] + public void RenderText(TextLabel label){ RenderText((ITextLabel)label); } + // This renders text public void RenderText(ITextLabel label) { diff --git a/Source/Core/Rendering/TextLabel.cs b/Source/Core/Rendering/TextLabel.cs index b15167297..cd6b4d77a 100644 --- a/Source/Core/Rendering/TextLabel.cs +++ b/Source/Core/Rendering/TextLabel.cs @@ -87,6 +87,9 @@ namespace CodeImp.DoomBuilder.Rendering //mxd. Rendering private bool skiprendering; + + //mxd. Compatibility + private float scale; // Disposing private bool isdisposed; @@ -109,7 +112,27 @@ namespace CodeImp.DoomBuilder.Rendering public Texture Texture { get { return texture; } } //mxd public VertexBuffer VertexBuffer { get { return textbuffer; } } public bool SkipRendering { get { return skiprendering; } } //mxd - + + //mxd. Compatibility settings + [Obsolete("Backcolor property is deprecated, please use BackColor property instead.")] + public PixelColor Backcolor { get { return BackColor; } set { BackColor = value.WithAlpha(128); } } + + [Obsolete("Scale property is deprecated, please assign the font directly using Font property instead.")] + public float Scale + { + get { return scale; } + set + { + scale = value; + 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; + } + } + + [Obsolete("Rectangle property is deprecated, please use Location property instead.")] + public RectangleF Rectangle { get { return new RectangleF(location.x, location.y, 0f, 0f); } set { location = new Vector2D(value.X, value.Y); updateneeded = true; } } + // Disposing public bool IsDisposed { get { return isdisposed; } } @@ -140,6 +163,30 @@ namespace CodeImp.DoomBuilder.Rendering GC.SuppressFinalize(this); } + //mxd. Compatibility constructor... + [Obsolete("TextLabel(int capacity) is deprecated, please use TextLabel() instead.")] + public TextLabel(int unused) + { + // Initialize + this.text = ""; + this.font = General.Settings.TextLabelFont; + this.location = new Vector2D(); + this.color = new PixelColor(255, 255, 255, 255); + this.backcolor = new PixelColor(128, 0, 0, 0); + this.alignx = TextAlignmentX.Center; + this.aligny = TextAlignmentY.Top; + this.textsize = SizeF.Empty; + this.texturesize = Size.Empty; + this.updateneeded = true; + this.textureupdateneeded = true; + + // Register as resource + General.Map.Graphics.RegisterResource(this); + + // We have no destructor + GC.SuppressFinalize(this); + } + // Diposer public void Dispose() { diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs index ebd9dce6e..3f2b1fbe1 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs @@ -115,25 +115,21 @@ namespace CodeImp.DoomBuilder.BuilderModes // When not cancelled if(!cancelled) { - //mxd. Reattach/add/remove sidedefs only when there are no unstable lines in selection - if(unstablelines.Count == 0) - { - // Get new lines from linedef marks... - HashSet<Linedef> newlines = new HashSet<Linedef>(General.Map.Map.GetMarkedLinedefs(true)); + //mxd. Get new lines from linedef marks... + HashSet<Linedef> newlines = new HashSet<Linedef>(General.Map.Map.GetMarkedLinedefs(true)); - // Marked lines were created during linedef splitting - HashSet<Linedef> changedlines = new HashSet<Linedef>(selectedlines); - changedlines.UnionWith(newlines); - - // Add sectors, which have all their linedefs selected (otherwise those would be destroyed after moving the selection) - HashSet<Sector> toadjust = General.Map.Map.GetUnselectedSectorsFromLinedefs(changedlines); + //mxd. Marked lines were created during linedef splitting + HashSet<Linedef> changedlines = new HashSet<Linedef>(selectedlines); + changedlines.UnionWith(newlines); - // Process outer sidedefs - Tools.AdjustOuterSidedefs(toadjust, changedlines); + //mxd. Add sectors, which have all their linedefs selected (otherwise those would be destroyed after moving the selection) + HashSet<Sector> toadjust = General.Map.Map.GetUnselectedSectorsFromLinedefs(changedlines); - // Split outer sectors - Tools.SplitOuterSectors(changedlines); - } + //mxd. Reattach/add/remove outer sidedefs + Tools.AdjustOuterSidedefs(toadjust, changedlines); + + //mxd. Split outer sectors + Tools.SplitOuterSectors(changedlines); // If only a single linedef was selected, deselect it now if(selectedlines.Count == 1) General.Map.Map.ClearSelectedLinedefs(); diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs index 70c466fb3..e67e465be 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs @@ -106,8 +106,8 @@ namespace CodeImp.DoomBuilder.BuilderModes // When not cancelled if(!cancelled) { - //mxd. Reattach/add/remove sidedefs only when there are no unstable lines in selection - if(stablelines.Count > 0 && unstablelines.Count == 0) + //mxd. If linedefs were dragged, reattach/add/remove sidedefs + if(stablelines.Count > 0) { // Get new lines from linedef marks... HashSet<Linedef> newlines = new HashSet<Linedef>(General.Map.Map.GetMarkedLinedefs(true)); @@ -121,7 +121,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(changedlines.Count > 0) { - // Process outer sidedefs + // Reattach/add/remove outer sidedefs Tools.AdjustOuterSidedefs(toadjust, changedlines); // Split outer sectors diff --git a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs index 924257e66..235fd65fd 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs @@ -1488,32 +1488,28 @@ namespace CodeImp.DoomBuilder.BuilderModes // Snap to map format accuracy General.Map.Map.SnapAllToAccuracy(General.Map.UDMF && usepreciseposition); - //mxd. Reattach/add/remove sidedefs only when there are no unstable lines in selection - if(unstablelines.Count == 0) - { - // Update cached values - General.Map.Map.Update(); - - // Get new lines from linedef marks... - HashSet<Linedef> newlines = new HashSet<Linedef>(General.Map.Map.GetMarkedLinedefs(true)); + //mxd. Update cached values + General.Map.Map.Update(); - // Marked lines were created during linedef splitting - HashSet<Linedef> changedlines = new HashSet<Linedef>(selectedlines); - changedlines.UnionWith(newlines); + //mxd. Get new lines from linedef marks... + HashSet<Linedef> newlines = new HashSet<Linedef>(General.Map.Map.GetMarkedLinedefs(true)); - // Update outer sides of the selection - if(changedlines.Count > 0) - { - // Get affected sectors - HashSet<Sector> affectedsectors = new HashSet<Sector>(General.Map.Map.GetSelectedSectors(true)); - affectedsectors.UnionWith(General.Map.Map.GetUnselectedSectorsFromLinedefs(changedlines)); + //mxd. Marked lines were created during linedef splitting + HashSet<Linedef> changedlines = new HashSet<Linedef>(selectedlines); + changedlines.UnionWith(newlines); - // Process outer sidedefs - Tools.AdjustOuterSidedefs(affectedsectors, new HashSet<Linedef>(changedlines)); + //mxd. Update outer sides of the selection + if(changedlines.Count > 0) + { + // Get affected sectors + HashSet<Sector> affectedsectors = new HashSet<Sector>(General.Map.Map.GetSelectedSectors(true)); + affectedsectors.UnionWith(General.Map.Map.GetUnselectedSectorsFromLinedefs(changedlines)); - // Split outer sectors - Tools.SplitOuterSectors(changedlines); - } + // Reattach/add/remove outer sidedefs + Tools.AdjustOuterSidedefs(affectedsectors, new HashSet<Linedef>(changedlines)); + + // Split outer sectors + Tools.SplitOuterSectors(changedlines); } // Update cached values diff --git a/Source/Plugins/BuilderModes/General/BuilderPlug.cs b/Source/Plugins/BuilderModes/General/BuilderPlug.cs index ebcb26ac1..44b403060 100644 --- a/Source/Plugins/BuilderModes/General/BuilderPlug.cs +++ b/Source/Plugins/BuilderModes/General/BuilderPlug.cs @@ -493,6 +493,12 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. Save settings SaveUISettings(); } + + //mxd. Error checks may need to be reinitialized + public override void OnMapReconfigure() + { + errorcheckform = null; + } // Redo performed public override void OnRedoEnd() -- GitLab