Skip to content

Commit

Permalink
Fixed draw order of polygon prefabs and map areas (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariowouters committed Mar 26, 2023
1 parent 3205a74 commit 6f7c310
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions TsMap/TsMapRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<TsPrefabPolyLook>();
foreach (var mapArea in _mapper.MapAreas)
{
if (!activeDlcGuards.Contains(mapArea.DlcGuard) ||
mapArea.IsSecret && !renderFlags.IsActive(RenderFlags.SecretRoads) ||
Expand All @@ -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;
Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6f7c310

Please sign in to comment.