Changed: "Selection Options" window is now resized automatically.

Fixed: parts of UniFileds.UniValuesMatch() logic were inverted. In some cases this resulted in incorrect behavior of "Select Similar" action in UDMF map format.
Fixed, UDMF: alpha should be ignored when applying sector fade/light color gradients.
Ported eevee's fix for incorrect sector geometry occasionally created after dragging map elements (more info: https://github.com/sirjuddington/SLADE/issues/542).
This commit is contained in:
MaxED 2016-06-20 13:36:10 +00:00 committed by spherallic
parent 18517b2257
commit 945553e527
10 changed files with 47 additions and 25 deletions

View file

@ -58,22 +58,24 @@ namespace CodeImp.DoomBuilder.Geometry
} }
//mxd //mxd
public static int InterpolateColor(PixelColor c1, PixelColor c2, float delta) public static PixelColor InterpolateColor(PixelColor c1, PixelColor c2, float delta)
{ {
float invdelta = 1.0f - delta; float invdelta = 1.0f - delta;
byte a = (byte)(c1.a * invdelta + c2.a * delta);
byte r = (byte)(c1.r * invdelta + c2.r * delta); byte r = (byte)(c1.r * invdelta + c2.r * delta);
byte g = (byte)(c1.g * invdelta + c2.g * delta); byte g = (byte)(c1.g * invdelta + c2.g * delta);
byte b = (byte)(c1.b * invdelta + c2.b * delta); byte b = (byte)(c1.b * invdelta + c2.b * delta);
return new PixelColor(255, r, g, b).ToInt(); return new PixelColor(a, r, g, b);
} }
//mxd //mxd
public static int InterpolateColor(PixelColor c1, PixelColor c2, float delta, Mode mode) public static PixelColor InterpolateColor(PixelColor c1, PixelColor c2, float delta, Mode mode)
{ {
byte a = (byte)Math.Round(Interpolate(c1.a, c2.a, delta, mode));
byte r = (byte)Math.Round(Interpolate(c1.r, c2.r, delta, mode)); byte r = (byte)Math.Round(Interpolate(c1.r, c2.r, delta, mode));
byte g = (byte)Math.Round(Interpolate(c1.g, c2.g, delta, mode)); byte g = (byte)Math.Round(Interpolate(c1.g, c2.g, delta, mode));
byte b = (byte)Math.Round(Interpolate(c1.b, c2.b, delta, mode)); byte b = (byte)Math.Round(Interpolate(c1.b, c2.b, delta, mode));
return new PixelColor(255, r, g, b).ToInt(); return new PixelColor(a, r, g, b);
} }
} }
} }

View file

@ -218,7 +218,7 @@ namespace CodeImp.DoomBuilder.Map
float min_dist = float.MaxValue; float min_dist = float.MaxValue;
Linedef nearest = null; Linedef nearest = null;
// Go through map lines // Fire a ray east from the vertex and find the first line it crosses
foreach(Linedef line in General.Map.Map.Linedefs) foreach(Linedef line in General.Map.Map.Linedefs)
{ {
// Ignore if the line is completely left of the vertex // Ignore if the line is completely left of the vertex
@ -238,11 +238,23 @@ namespace CodeImp.DoomBuilder.Map
float dist = Math.Abs(int_x - vr_x); float dist = Math.Abs(int_x - vr_x);
// Check if closest // Check if closest
if(dist < min_dist) if(nearest == null || dist < min_dist)
{ {
min_dist = dist; min_dist = dist;
nearest = line; nearest = line;
} }
else if(Math.Abs(dist - min_dist) < 0.001f)
{
// In the case of a tie, use the distance to each line as a tiebreaker - this fixes cases where the ray hits a vertex
// shared by two lines. Choosing the further line would mean choosing an inner edge, which is clearly wrong.
float line_dist = line.SafeDistanceToSq(vertex_right.Position, true);
float nearest_dist = nearest.SafeDistanceToSq(vertex_right.Position, true);
if(line_dist < nearest_dist)
{
min_dist = dist;
nearest = line;
}
}
} }
// Check for valid line // Check for valid line
@ -250,8 +262,7 @@ namespace CodeImp.DoomBuilder.Map
// Determine the edge side // Determine the edge side
float side = -nearest.SideOfLine(vertex_right.Position); //mxd. SideOfLine logic is inverted in Slade 3 float side = -nearest.SideOfLine(vertex_right.Position); //mxd. SideOfLine logic is inverted in Slade 3
return new LinedefSide(nearest, side > 0); //mxd. The meaning of 0.0 is also inverted!!! return new LinedefSide(nearest, side > 0); //mxd. The meaning of 0.0 is also inverted!!! (I've spent 2 days figuring this out...)
//mxd. I've spent 2 days figuring this out... :(
} }
/// <summary>Find the closest edge within the current outline (that isn't part of the current outline)</summary> /// <summary>Find the closest edge within the current outline (that isn't part of the current outline)</summary>

View file

@ -224,11 +224,11 @@ namespace CodeImp.DoomBuilder.Map
public static bool UniValuesMatch(UniValue val1, UniValue val2) public static bool UniValuesMatch(UniValue val1, UniValue val2)
{ {
if(val1.Type != val2.Type) return false; if(val1.Type != val2.Type) return false;
if(val1.Value is int) return (int)val1.Value != (int)val2.Value; if(val1.Value is int) return (int)val1.Value == (int)val2.Value;
if(val1.Value is float) return (float)val1.Value != (float)val2.Value; if(val1.Value is float) return (float)val1.Value == (float)val2.Value;
if(val1.Value is bool) return (bool)val1.Value != (bool)val2.Value; if(val1.Value is bool) return (bool)val1.Value == (bool)val2.Value;
if(val1.Value is string) return (string)val1.Value != (string)val2.Value; if(val1.Value is string) return (string)val1.Value == (string)val2.Value;
throw new Exception("Got unknown Custom Field type to compare: " + val1.Value.GetType()); throw new NotImplementedException("Unknown Custom Field type: " + val1.Value.GetType());
} }
/// <summary>This compares types and values of given UniFields by key.</summary> /// <summary>This compares types and values of given UniFields by key.</summary>

View file

@ -2170,7 +2170,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
var form = new SelectSimilarElementOptionsPanel(); var form = new SelectSimilarElementOptionsPanel();
if(form.Setup(this)) form.ShowDialog(); if(form.Setup(this)) form.ShowDialog(General.Interface);
} }
//mxd //mxd

View file

@ -2213,7 +2213,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
s.Fields.BeforeFieldsChange(); s.Fields.BeforeFieldsChange();
float u = index / (orderedselection.Count - 1.0f); float u = index / (orderedselection.Count - 1.0f);
int c = InterpolationTools.InterpolateColor(startcolor, endcolor, u, interpolationmode); int c = InterpolationTools.InterpolateColor(startcolor, endcolor, u, interpolationmode).WithAlpha(0).ToInt(); // No alpha here!
UniFields.SetInteger(s.Fields, key, c, defaultvalue); UniFields.SetInteger(s.Fields, key, c, defaultvalue);
s.UpdateNeeded = true; s.UpdateNeeded = true;
@ -2701,7 +2701,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
var form = new SelectSimilarElementOptionsPanel(); var form = new SelectSimilarElementOptionsPanel();
if(form.Setup(this)) form.ShowDialog(); if(form.Setup(this)) form.ShowDialog(General.Interface);
} }
//mxd //mxd

View file

@ -1690,7 +1690,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
var form = new SelectSimilarElementOptionsPanel(); var form = new SelectSimilarElementOptionsPanel();
if(form.Setup(this)) form.ShowDialog(); if(form.Setup(this)) form.ShowDialog(General.Interface);
} }
#endregion #endregion

View file

@ -1145,7 +1145,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
var form = new SelectSimilarElementOptionsPanel(); var form = new SelectSimilarElementOptionsPanel();
if(form.Setup(this)) form.ShowDialog(); if(form.Setup(this)) form.ShowDialog(General.Interface);
} }
//JBR Perpendicular Vertex //JBR Perpendicular Vertex

View file

@ -228,10 +228,12 @@
this.Controls.Add(this.enableall); this.Controls.Add(this.enableall);
this.Controls.Add(this.apply); this.Controls.Add(this.apply);
this.Controls.Add(this.cancel); this.Controls.Add(this.cancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(300, 200); this.MinimumSize = new System.Drawing.Size(396, 200);
this.Name = "SelectSimilarElementOptionsPanel"; this.Name = "SelectSimilarElementOptionsPanel";
this.Opacity = 1;
this.ShowIcon = false; this.ShowIcon = false;
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;

View file

@ -11,7 +11,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
public partial class SelectSimilarElementOptionsPanel : DelayedForm public partial class SelectSimilarElementOptionsPanel : DelayedForm
{ {
private static Size size = Size.Empty;
private static Point location = Point.Empty; private static Point location = Point.Empty;
private static readonly object[] flags = { private static readonly object[] flags = {
new SectorPropertiesCopySettings(), new SectorPropertiesCopySettings(),
@ -30,10 +29,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
InitializeComponent(); InitializeComponent();
//apply window size and location //apply window size and location
if(!size.IsEmpty && !location.IsEmpty) if(!location.IsEmpty)
{ {
this.StartPosition = FormStartPosition.Manual; this.StartPosition = FormStartPosition.Manual;
this.Size = size;
this.Location = location; this.Location = location;
} }
@ -79,6 +77,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
//fill flags //fill flags
showntabs = new List<TabPage>(); showntabs = new List<TabPage>();
int maxheight = int.MinValue;
foreach(TabPage page in activetabs) foreach(TabPage page in activetabs)
{ {
CheckboxArrayControl curControl = page.Controls[0] as CheckboxArrayControl; CheckboxArrayControl curControl = page.Controls[0] as CheckboxArrayControl;
@ -102,9 +101,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
curControl.PositionCheckboxes(); curControl.PositionCheckboxes();
showntabs.Add(page); showntabs.Add(page);
// Store height
maxheight = Math.Max(maxheight, curControl.GetHeight());
} }
} }
// Apply height
if(maxheight != int.MinValue)
{
this.Height += maxheight - activetabs[0].Controls[0].Height;
}
// Got anything to show? // Got anything to show?
if(showntabs.Count == 0) return SetupFailed("This action doesn't support current editing mode..."); if(showntabs.Count == 0) return SetupFailed("This action doesn't support current editing mode...");
@ -124,7 +132,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
private void SelectSimilarElementOptionsPanel_FormClosing(object sender, FormClosingEventArgs e) private void SelectSimilarElementOptionsPanel_FormClosing(object sender, FormClosingEventArgs e)
{ {
size = this.Size;
location = this.Location; location = this.Location;
} }

View file

@ -314,7 +314,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
float cz = data.Ceiling.plane.GetZ(v.x, v.y); float cz = data.Ceiling.plane.GetZ(v.x, v.y);
float delta = 1.0f - (((v.z - cgz) / (cz - cgz)) * 0.9f); float delta = 1.0f - (((v.z - cgz) / (cz - cgz)) * 0.9f);
PixelColor vc = PixelColor.FromInt(v.c); PixelColor vc = PixelColor.FromInt(v.c);
v.c = InterpolationTools.InterpolateColor(GetGlowColor(data.CeilingGlow, vc), vc, delta); v.c = InterpolationTools.InterpolateColor(GetGlowColor(data.CeilingGlow, vc), vc, delta).WithAlpha(255).ToInt();
} }
} }
@ -329,7 +329,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
float fz = data.Floor.plane.GetZ(v.x, v.y); float fz = data.Floor.plane.GetZ(v.x, v.y);
float delta = 1.0f - (((v.z - fz) / (fgz - fz)) * 0.9f); float delta = 1.0f - (((v.z - fz) / (fgz - fz)) * 0.9f);
PixelColor vc = PixelColor.FromInt(v.c); PixelColor vc = PixelColor.FromInt(v.c);
v.c = InterpolationTools.InterpolateColor(vc, GetGlowColor(data.FloorGlow, vc), delta); v.c = InterpolationTools.InterpolateColor(vc, GetGlowColor(data.FloorGlow, vc), delta).WithAlpha(255).ToInt();
} }
} }