From 6f7c310603950f93015ca5f89d4d072dda40d21c Mon Sep 17 00:00:00 2001 From: Dario Wouters Date: Sun, 26 Mar 2023 21:12:14 +0200 Subject: [PATCH] Fixed draw order of polygon prefabs and map areas (#33) --- TsMap/TsMapRenderer.cs | 61 +++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/TsMap/TsMapRenderer.cs b/TsMap/TsMapRenderer.cs index 62c200bd1..e5f9cf0df 100644 --- a/TsMap/TsMapRenderer.cs +++ b/TsMap/TsMapRenderer.cs @@ -4,6 +4,7 @@ using System.Drawing.Drawing2D; using System.Linq; using TsMap.Common; +using TsMap.Helpers; using TsMap.Helpers.Logger; using TsMap.Map.Overlays; @@ -116,7 +117,8 @@ public void Render(Graphics g, Rectangle clip, float scale, PointF startPoint, M var mapAreaStartTime = DateTime.Now.Ticks; if (renderFlags.IsActive(RenderFlags.MapAreas)) { - foreach (var mapArea in _mapper.MapAreas.OrderBy(x => x.DrawOver)) + var drawingQueue = new List(); + foreach (var mapArea in _mapper.MapAreas) { if (!activeDlcGuards.Contains(mapArea.DlcGuard) || mapArea.IsSecret && !renderFlags.IsActive(RenderFlags.SecretRoads) || @@ -135,12 +137,34 @@ public void Render(Graphics g, Rectangle clip, float scale, PointF startPoint, M points.Add(new PointF(node.X, node.Z)); } - Brush fillColor = palette.PrefabLight; - if ((mapArea.ColorIndex & 0x01) != 0) fillColor = palette.PrefabLight; - else if ((mapArea.ColorIndex & 0x02) != 0) fillColor = palette.PrefabDark; - else if ((mapArea.ColorIndex & 0x03) != 0) fillColor = palette.PrefabGreen; + Brush fillColor = palette.PrefabRoad; + var zIndex = mapArea.DrawOver ? 10 : 0; + if ((mapArea.ColorIndex & 0x03) == 3) + { + fillColor = palette.PrefabGreen; + zIndex = mapArea.DrawOver ? 13 : 3; + } + else if ((mapArea.ColorIndex & 0x02) == 2) + { + fillColor = palette.PrefabDark; + zIndex = mapArea.DrawOver ? 12 : 2; + } + else if ((mapArea.ColorIndex & 0x01) == 1) + { + fillColor = palette.PrefabLight; + zIndex = mapArea.DrawOver ? 11 : 1; + } + + drawingQueue.Add(new TsPrefabPolyLook(points) + { + Color = fillColor, + ZIndex = zIndex + }); + } - g.FillPolygon(fillColor, points.ToArray()); + foreach (var mapArea in drawingQueue.OrderBy(p => p.ZIndex)) + { + mapArea.Draw(g); } } var mapAreaTime = DateTime.Now.Ticks - mapAreaStartTime; @@ -207,17 +231,30 @@ public void Render(Graphics g, Rectangle clip, float scale, PointF startPoint, M if (polyPoints.Count < 2) continue; - var colorFlag = prefabItem.Prefab.MapPoints[polyPoints.First().Key].PrefabColorFlags; + var visualFlag = prefabItem.Prefab.MapPoints[polyPoints.First().Key].PrefabColorFlags; Brush fillColor = palette.PrefabLight; - if ((colorFlag & 0x02) != 0) fillColor = palette.PrefabLight; - else if ((colorFlag & 0x04) != 0) fillColor = palette.PrefabDark; - else if ((colorFlag & 0x08) != 0) fillColor = palette.PrefabGreen; + var roadOver = MemoryHelper.IsBitSet(visualFlag, 0); // Road Over flag + var zIndex = roadOver ? 10 : 0; + if (MemoryHelper.IsBitSet(visualFlag, 1)) + { + fillColor = palette.PrefabLight; + } + else if (MemoryHelper.IsBitSet(visualFlag, 2)) + { + fillColor = palette.PrefabDark; + zIndex = roadOver ? 11 : 1; + } + else if (MemoryHelper.IsBitSet(visualFlag, 3)) + { + fillColor = palette.PrefabGreen; + zIndex = roadOver ? 12 : 2; + } // else fillColor = _palette.Error; // Unknown var prefabLook = new TsPrefabPolyLook(polyPoints.Values.ToList()) { - ZIndex = ((colorFlag & 0x01) != 0) ? 3 : 2, + ZIndex = zIndex, Color = fillColor }; @@ -281,7 +318,7 @@ public void Render(Graphics g, Rectangle clip, float scale, PointF startPoint, M TsPrefabLook prefabLook = new TsPrefabPolyLook(cornerCoords) { Color = palette.PrefabRoad, - ZIndex = 4, + ZIndex = MemoryHelper.IsBitSet(mapPoint.PrefabColorFlags, 0) ? 13 : 3, }; prefabItem.AddLook(prefabLook);