diff --git a/Source/Core/IO/DoomMapSetIO.cs b/Source/Core/IO/DoomMapSetIO.cs index c0f0949..52b4a2f 100644 --- a/Source/Core/IO/DoomMapSetIO.cs +++ b/Source/Core/IO/DoomMapSetIO.cs @@ -104,6 +104,7 @@ namespace CodeImp.DoomBuilder.IO public override Dictionary VertexSlopeTypes { get { return vertexSlopeTypes; } } public override int SlopeVertexType { get { return 9500; } } public override int Custom3DFloorType { get { return 160; } } + public override int ColormapType { get { return -1; } } #endregion diff --git a/Source/Core/IO/HexenMapSetIO.cs b/Source/Core/IO/HexenMapSetIO.cs index 8660cbd..5ee63a3 100644 --- a/Source/Core/IO/HexenMapSetIO.cs +++ b/Source/Core/IO/HexenMapSetIO.cs @@ -104,6 +104,7 @@ namespace CodeImp.DoomBuilder.IO public override Dictionary VertexSlopeTypes { get { return vertexSlopeTypes; } } public override int SlopeVertexType { get { return 9500; } } public override int Custom3DFloorType { get { return 160; } } + public override int ColormapType { get { return -1; } } #endregion diff --git a/Source/Core/IO/IMapSetIO.cs b/Source/Core/IO/IMapSetIO.cs index c6c9a35..82d72ba 100644 --- a/Source/Core/IO/IMapSetIO.cs +++ b/Source/Core/IO/IMapSetIO.cs @@ -76,5 +76,6 @@ namespace CodeImp.DoomBuilder.IO Dictionary VertexSlopeTypes { get; } int SlopeVertexType { get; } int Custom3DFloorType { get; } + int ColormapType { get; } } } diff --git a/Source/Core/IO/MapSetIO.cs b/Source/Core/IO/MapSetIO.cs index 5d2e783..2425cb3 100644 --- a/Source/Core/IO/MapSetIO.cs +++ b/Source/Core/IO/MapSetIO.cs @@ -97,6 +97,7 @@ namespace CodeImp.DoomBuilder.IO public abstract Dictionary VertexSlopeTypes { get; } public abstract int SlopeVertexType { get; } public abstract int Custom3DFloorType { get; } + public abstract int ColormapType { get; } #endregion diff --git a/Source/Core/IO/SRB2MapSetIO.cs b/Source/Core/IO/SRB2MapSetIO.cs index c330bce..377143a 100644 --- a/Source/Core/IO/SRB2MapSetIO.cs +++ b/Source/Core/IO/SRB2MapSetIO.cs @@ -142,6 +142,7 @@ namespace CodeImp.DoomBuilder.IO public override int SlopeVertexType { get { return 750; } } public override int MaxThingHeight { get { return 4095; } } public override int MinThingHeight { get { return 0; } } + public override int ColormapType { get { return 606; } } #endregion #region ================== Reading diff --git a/Source/Core/IO/UniversalMapSetIO.cs b/Source/Core/IO/UniversalMapSetIO.cs index 3391287..4d75c57 100644 --- a/Source/Core/IO/UniversalMapSetIO.cs +++ b/Source/Core/IO/UniversalMapSetIO.cs @@ -154,6 +154,7 @@ namespace CodeImp.DoomBuilder.IO public override Dictionary VertexSlopeTypes { get { return vertexSlopeTypes; } } public override int SlopeVertexType { get { return 9500; } } public override int Custom3DFloorType { get { return 160; } } + public override int ColormapType { get { return -1; } } #endregion diff --git a/Source/Core/Map/Linedef.cs b/Source/Core/Map/Linedef.cs index 00ba08e..06edde7 100644 --- a/Source/Core/Map/Linedef.cs +++ b/Source/Core/Map/Linedef.cs @@ -95,6 +95,7 @@ namespace CodeImp.DoomBuilder.Map public bool IsSlope { get { return General.Map.FormatInterface.SlopeTypes.ContainsKey(Action); } } public bool IsSlopeCopy { get { return General.Map.FormatInterface.SlopeCopyTypes.ContainsKey(Action); } } public bool IsVertexSlope { get { return General.Map.FormatInterface.VertexSlopeTypes.ContainsKey(Action); } } + public bool IsColormap { get { return Action == General.Map.FormatInterface.ColormapType; } } public int Tag { get { return tags[0]; } set { BeforePropsChange(); tags[0] = value; if((value < General.Map.FormatInterface.MinTag) || (value > General.Map.FormatInterface.MaxTag)) throw new ArgumentOutOfRangeException("Tag", "Invalid tag number"); } } //mxd public List Tags { get { return tags; } set { BeforePropsChange(); tags = value; } } //mxd public float LengthSq { get { return lengthsq; } } @@ -833,6 +834,25 @@ namespace CodeImp.DoomBuilder.Map return result; } + //Read color value from texture name (#RRGGBBA) + public void ParseColor(string tex, out int color, out int alpha) + { + color = 0x000000; + alpha = 255; + if (tex.StartsWith("#") && tex.Length >= 7) + { + string colorString = tex.Substring(1,6); + Regex r = new Regex("^[A-F0-9]*$"); + if (r.IsMatch(colorString)) color = Convert.ToInt32(colorString, 16); + if (tex.Length == 8) + { + char alphaChar = tex.ToUpper()[7]; + if (alphaChar >= 'A' && alphaChar <= 'Z') alpha = (int)(((float)(alphaChar - 'A' + 10) / 25) * 255); + else if (alphaChar >= '0' && alphaChar <= '9') alpha = (int)(((float)(alphaChar - '0') / 25) * 255); + } + } + } + //Set slope arguments for SRB2-style slopes. See http://zdoom.org/wiki/Plane_Align. public void SetSlopeArgs() { diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index 9b4164d..eff65a8 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -948,58 +948,83 @@ namespace CodeImp.DoomBuilder.BuilderModes } } - // MascaraSnake: Vertex slopes, SRB2-style - if (General.Map.SRB2 && l.IsVertexSlope) + if (General.Map.SRB2) { - l.SetVertexSlopeArgs(); - bool slopefloor = l.Args[1] == 0; - List slopevertices = new List(3); - Sector s = (l.Args[0] == 0) ? l.Front.Sector : l.Back.Sector; - - //If NOKNUCKLES is set, use tag, X offset and Y offset to search for slope vertices. - if (l.IsFlagSet("8192")) + //MascaraSnake: Colormap + if (l.IsColormap && l.Front != null) { - bool foundtag = false; - bool foundxoffset = false; - bool foundyoffset = false; - foreach (Thing t in General.Map.Map.Things) + int sectortag = l.Tag; + int color; + int alpha; + l.ParseColor(l.Front.HighTexture, out color, out alpha); + if (sectortags.ContainsKey(sectortag)) { - if (t.IsSlopeVertex) + List sectors = sectortags[sectortag]; + foreach (Sector s in sectors) { - if (!foundtag && (int)t.AngleDoom == l.Tag) - { - slopevertices.Add(t); - foundtag = true; - } - if (!foundxoffset && (int)t.AngleDoom == l.Front.OffsetX) - { - slopevertices.Add(t); - foundxoffset = true; - } - if (!foundyoffset && (int)t.AngleDoom == l.Front.OffsetY) - { - slopevertices.Add(t); - foundyoffset = true; - } + s.Fields.BeforeFieldsChange(); + if (s.Fields.ContainsKey("lightcolor")) s.Fields["lightcolor"] = new UniValue(UniversalType.Color, color); + else s.Fields.Add("lightcolor", new UniValue(UniversalType.Color, color)); + //TODO: Find out why the alpha value is ignored. + /*if (s.Fields.ContainsKey("lightalpha")) s.Fields["lightalpha"] = new UniValue(UniversalType.Integer, alpha); + else s.Fields.Add("lightalpha", new UniValue(UniversalType.Integer, alpha));*/ } } - } - //Otherwise, just use tag. - else + + // MascaraSnake: Vertex slopes, SRB2-style + if (l.IsVertexSlope) { - foreach (Thing t in General.Map.Map.Things) + l.SetVertexSlopeArgs(); + bool slopefloor = l.Args[1] == 0; + List slopevertices = new List(3); + Sector s = (l.Args[0] == 0) ? l.Front.Sector : l.Back.Sector; + + //If NOKNUCKLES is set, use tag, X offset and Y offset to search for slope vertices. + if (l.IsFlagSet("8192")) { - if (t.IsSlopeVertex && (int)t.AngleDoom == l.Tag) slopevertices.Add(t); + bool foundtag = false; + bool foundxoffset = false; + bool foundyoffset = false; + foreach (Thing t in General.Map.Map.Things) + { + if (t.IsSlopeVertex) + { + if (!foundtag && (int)t.AngleDoom == l.Tag) + { + slopevertices.Add(t); + foundtag = true; + } + if (!foundxoffset && (int)t.AngleDoom == l.Front.OffsetX) + { + slopevertices.Add(t); + foundxoffset = true; + } + if (!foundyoffset && (int)t.AngleDoom == l.Front.OffsetY) + { + slopevertices.Add(t); + foundyoffset = true; + } + } + } + + } + //Otherwise, just use tag. + else + { + foreach (Thing t in General.Map.Map.Things) + { + if (t.IsSlopeVertex && (int)t.AngleDoom == l.Tag) slopevertices.Add(t); + } + } + if (slopevertices.Count >= 3) + { + SectorData sd = GetSectorData(s); + sd.AddEffectSRB2ThingVertexSlope(slopevertices, slopefloor); } } - if (slopevertices.Count >= 3) - { - SectorData sd = GetSectorData(s); - sd.AddEffectSRB2ThingVertexSlope(slopevertices, slopefloor); - } } - + // MascaraSnake: 3D floor handling // ========== Sector 3D floor (see http://zdoom.org/wiki/Sector_Set3dFloor) ========== if (l.Is3DFloor) diff --git a/Source/Plugins/BuilderModes/VisualModes/SectorData.cs b/Source/Plugins/BuilderModes/VisualModes/SectorData.cs index 360ed6c..98aaead 100644 --- a/Source/Plugins/BuilderModes/VisualModes/SectorData.cs +++ b/Source/Plugins/BuilderModes/VisualModes/SectorData.cs @@ -267,6 +267,7 @@ namespace CodeImp.DoomBuilder.BuilderModes bool fabs = sector.Fields.GetValue("lightfloorabsolute", false); int clight = sector.Fields.GetValue("lightceiling", 0); bool cabs = sector.Fields.GetValue("lightceilingabsolute", false); + //int alpha = sector.Fields.GetValue("lightalpha", 255); // Determine colors & light levels PixelColor lightcolor = PixelColor.FromInt(color);