Skip to content

Commit 0f2767e

Browse files
committed
Fix depth of overlays with textures that exceed cell bounds
1 parent 398ff3a commit 0f2767e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/TSMapEditor/Rendering/ObjectRenderers/ObjectRenderer.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using TSMapEditor.CCEngine;
66
using TSMapEditor.GameMath;
7+
using TSMapEditor.Initialization;
78
using TSMapEditor.Models;
89

910
namespace TSMapEditor.Rendering.ObjectRenderers
@@ -283,18 +284,24 @@ public virtual void DrawShadow(T gameObject)
283284

284285
float textureHeight = (regularFrame != null && regularFrame.Texture != null) ? (float)regularFrame.Texture.Height : shadowFrame.Texture.Height;
285286

286-
float depth = GetDepthFromPosition(gameObject);
287+
float depth = GetDepthFromPosition(gameObject, drawingBounds.Bottom);
287288
// depth += GetDepthAddition(gameObject);
288289
depth += textureHeight / Map.HeightInPixelsWithCellHeight;
289290

290291
RenderDependencies.ObjectSpriteRecord.AddGraphicsEntry(new ObjectSpriteEntry(null, texture, drawingBounds, new Color(255, 255, 255, 128), false, true, depth));
291292
}
292293

293-
private float GetDepthFromPosition(T gameObject)
294+
private float GetDepthFromPosition(T gameObject, int bottomDrawPoint)
294295
{
295-
var southernmostCell = GetSouthernmostCell(gameObject);
296+
var southernmostCell = Map.GetTile(gameObject.Position); // GetSouthernmostCell(gameObject);
297+
298+
int height = 0;
299+
if (southernmostCell != null)
300+
{
301+
height = southernmostCell.Level;
302+
}
296303

297-
return CellMath.GetDepthForCell(southernmostCell.CoordsToPoint(), Map);
304+
return ((bottomDrawPoint + Constants.CellSizeY) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace + (height * Constants.DepthRenderStep);
298305
}
299306

300307
private MapTile GetSouthernmostCell(T gameObject)
@@ -406,7 +413,7 @@ protected void DrawShapeImage(T gameObject, ShapeImage image, int frameIndex, Co
406413
}
407414
}
408415

409-
depthAddition += GetDepthFromPosition(gameObject);
416+
depthAddition += GetDepthFromPosition(gameObject, drawingBounds.Bottom);
410417
depthAddition += GetDepthAddition(gameObject);
411418

412419
RenderFrame(gameObject, frame, remapFrame, color, drawRemap, remapColor,
@@ -454,13 +461,13 @@ protected void DrawVoxelModel(T gameObject, VoxelModel model, byte facing, RampT
454461
}
455462
}
456463

457-
depthAddition += GetDepthFromPosition(gameObject);
464+
Rectangle drawingBounds = GetTextureDrawCoords(gameObject, frame, drawPoint);
465+
466+
depthAddition += GetDepthFromPosition(gameObject, drawingBounds.Bottom);
458467
depthAddition += GetDepthAddition(gameObject);
459468

460469
remapColor = ScaleColorToAmbient(remapColor, mapCell.CellLighting);
461470

462-
Rectangle drawingBounds = GetTextureDrawCoords(gameObject, frame, drawPoint);
463-
464471
RenderFrame(gameObject, frame, remapFrame, color, drawRemap, remapColor,
465472
drawingBounds, null, lighting, depthAddition, 0.5f, compensateForBottomGap);
466473
}

0 commit comments

Comments
 (0)