Skip to content

Commit 3dd9c9e

Browse files
committed
Fix draw offset and improve input handling of objects on bridges
1 parent 5e97c4d commit 3dd9c9e

File tree

14 files changed

+102
-28
lines changed

14 files changed

+102
-28
lines changed

src/TSMapEditor/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static class Constants
1010
public static int CellSizeY = 24;
1111
public const int CellSizeInLeptons = 256;
1212
public static int CellHeight => CellSizeY / 2;
13+
public static int HighBridgeHeight = 4;
1314
public static int TileColorBufferSize = 576;
1415

1516
public static int RenderPixelPadding = 50;

src/TSMapEditor/Models/CellTag.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public CellTag(Point2D position, Tag tag)
1717
Tag = tag;
1818
}
1919

20+
public bool IsOnBridge() => false;
21+
2022
public Point2D Position { get; set; }
2123
public Tag Tag { get; set; }
2224

src/TSMapEditor/Models/Foot.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public Foot(T objectType) : base(objectType) { }
2626
/// Is this unit available for recruitment for TeamTypes that have Autocreate=yes?
2727
/// </summary>
2828
public bool AutocreateYesRecruitable { get; set; }
29+
30+
public override bool IsOnBridge() => High;
2931
}
3032
}

src/TSMapEditor/Models/GameObject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public override int GetHashCode()
5353

5454
public virtual bool HasShadow() => false;
5555

56+
public virtual bool IsOnBridge() => false;
57+
5658
public virtual Color GetRemapColor() => Color.White;
5759
}
5860
}

src/TSMapEditor/Models/House.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public BaseNode(string structureTypeName, Point2D location)
2121
public string StructureTypeName { get; set; }
2222
public Point2D Position { get; set; }
2323

24+
public bool IsOnBridge() => false;
25+
2426
public static BaseNode FromIniString(string iniString)
2527
{
2628
if (string.IsNullOrWhiteSpace(iniString))

src/TSMapEditor/Models/IPositioned.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ namespace TSMapEditor.Models
55
public interface IPositioned
66
{
77
Point2D Position { get; set; }
8+
9+
bool IsOnBridge();
810
}
911
}

src/TSMapEditor/Models/Waypoint.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public string EditorColor
5959

6060
public Color XNAColor;
6161

62+
public bool IsOnBridge() => false;
63+
6264
public static Waypoint ParseWaypoint(string id, string coordsString)
6365
{
6466
int waypointIndex = Conversions.IntFromString(id, -1);

src/TSMapEditor/Rendering/MapView.cs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,49 +1193,51 @@ public void DrawTechnoRangeIndicators(TechnoBase techno)
11931193
double range = techno.GetWeaponRange();
11941194
if (range > 0.0)
11951195
{
1196-
DrawRangeIndicator(techno.Position, range, techno.Owner.XNAColor);
1196+
DrawRangeIndicator(techno, range, techno.Owner.XNAColor);
11971197
}
11981198

11991199
range = techno.GetGuardRange();
12001200
if (range > 0.0)
12011201
{
1202-
DrawRangeIndicator(techno.Position, range, techno.Owner.XNAColor * 0.25f);
1202+
DrawRangeIndicator(techno, range, techno.Owner.XNAColor * 0.25f);
12031203
}
12041204

12051205
range = techno.GetGapGeneratorRange();
12061206
if (range > 0.0)
12071207
{
1208-
DrawRangeIndicator(techno.Position, range, Color.Black * 0.75f);
1208+
DrawRangeIndicator(techno, range, Color.Black * 0.75f);
12091209
}
12101210

12111211
range = techno.GetCloakGeneratorRange();
12121212
if (range > 0.0)
12131213
{
1214-
DrawRangeIndicator(techno.Position, range, techno.GetRadialColor());
1214+
DrawRangeIndicator(techno, range, techno.GetRadialColor());
12151215
}
12161216

12171217
range = techno.GetSensorArrayRange();
12181218
if (range > 0.0)
12191219
{
1220-
DrawRangeIndicator(techno.Position, range, techno.GetRadialColor());
1220+
DrawRangeIndicator(techno, range, techno.GetRadialColor());
12211221
}
12221222
}
12231223

1224-
private void DrawRangeIndicator(Point2D cellCoords, double range, Color color)
1224+
private void DrawRangeIndicator(TechnoBase techno, double range, Color color)
12251225
{
12261226
Point2D center = EditorState.Is2DMode ?
1227-
CellMath.CellCenterPointFromCellCoords(cellCoords, Map) :
1228-
CellMath.CellCenterPointFromCellCoords_3D(cellCoords, Map);
1227+
CellMath.CellCenterPointFromCellCoords(techno.Position, Map) :
1228+
CellMath.CellCenterPointFromCellCoords_3D(techno.Position, Map);
1229+
1230+
int bridgeHeightOffset = techno.IsOnBridge() ? (Constants.CellHeight * Constants.HighBridgeHeight) : 0;
12291231

12301232
// Range is specified in "tile edge lengths",
12311233
// so we need a bit of trigonometry
12321234
double horizontalPixelRange = Constants.CellSizeX / Math.Sqrt(2.0);
12331235
double verticalPixelRange = Constants.CellSizeY / Math.Sqrt(2.0);
12341236

12351237
int startX = center.X - (int)(range * horizontalPixelRange);
1236-
int startY = center.Y - (int)(range * verticalPixelRange);
1238+
int startY = center.Y - bridgeHeightOffset - (int)(range * verticalPixelRange);
12371239
int endX = center.X + (int)(range * horizontalPixelRange);
1238-
int endY = center.Y + (int)(range * verticalPixelRange);
1240+
int endY = center.Y - bridgeHeightOffset + (int)(range * verticalPixelRange);
12391241

12401242
// startX = Camera.ScaleIntWithZoom(startX - Camera.TopLeftPoint.X);
12411243
// startY = Camera.ScaleIntWithZoom(startY - Camera.TopLeftPoint.Y);
@@ -1283,15 +1285,23 @@ public void DrawOnTileUnderCursor(MapTile tileUnderCursor, CursorAction cursorAc
12831285

12841286
if (startCell != null)
12851287
{
1286-
startDrawPoint -= new Point2D(0, startCell.Level * Constants.CellHeight);
1288+
if (!EditorState.Is2DMode)
1289+
startDrawPoint -= new Point2D(0, startCell.Level * Constants.CellHeight);
1290+
1291+
if (draggedOrRotatedObject.IsOnBridge())
1292+
startDrawPoint -= new Point2D(0, Constants.HighBridgeHeight * Constants.CellHeight);
12871293

12881294
if (draggedOrRotatedObject.WhatAmI() == RTTIType.Infantry)
12891295
startDrawPoint += CellMath.GetSubCellOffset(((Infantry)draggedOrRotatedObject).SubCell) - new Point2D(0, Constants.CellHeight / 2);
12901296
}
12911297

12921298
Point2D endDrawPoint = CellMath.CellTopLeftPointFromCellCoords(tileUnderCursor.CoordsToPoint(), Map) + cameraAndCellCenterOffset;
12931299

1294-
endDrawPoint -= new Point2D(0, tileUnderCursor.Level * Constants.CellHeight);
1300+
if (!EditorState.Is2DMode)
1301+
endDrawPoint -= new Point2D(0, tileUnderCursor.Level * Constants.CellHeight);
1302+
1303+
if (draggedOrRotatedObject.IsOnBridge())
1304+
endDrawPoint -= new Point2D(0, Constants.HighBridgeHeight * Constants.CellHeight);
12951305

12961306
startDrawPoint = startDrawPoint.ScaleBy(Camera.ZoomLevel);
12971307
endDrawPoint = endDrawPoint.ScaleBy(Camera.ZoomLevel);
@@ -1313,15 +1323,23 @@ public void DrawOnTileUnderCursor(MapTile tileUnderCursor, CursorAction cursorAc
13131323

13141324
if (startCell != null)
13151325
{
1316-
startDrawPoint -= new Point2D(0, Map.GetTile(draggedOrRotatedObject.Position).Level * Constants.CellHeight);
1326+
if (!EditorState.Is2DMode)
1327+
startDrawPoint -= new Point2D(0, Map.GetTile(draggedOrRotatedObject.Position).Level * Constants.CellHeight);
1328+
1329+
if (draggedOrRotatedObject.IsOnBridge())
1330+
startDrawPoint -= new Point2D(0, Constants.HighBridgeHeight * Constants.CellHeight);
13171331

13181332
if (draggedOrRotatedObject.WhatAmI() == RTTIType.Infantry)
13191333
startDrawPoint += CellMath.GetSubCellOffset(((Infantry)draggedOrRotatedObject).SubCell) - new Point2D(0, Constants.CellHeight / 2);
13201334
}
13211335

13221336
Point2D endDrawPoint = CellMath.CellTopLeftPointFromCellCoords(tileUnderCursor.CoordsToPoint(), Map) + cameraAndCellCenterOffset;
13231337

1324-
endDrawPoint -= new Point2D(0, tileUnderCursor.Level * Constants.CellHeight);
1338+
if (!EditorState.Is2DMode)
1339+
endDrawPoint -= new Point2D(0, tileUnderCursor.Level * Constants.CellHeight);
1340+
1341+
if (draggedOrRotatedObject.IsOnBridge())
1342+
endDrawPoint -= new Point2D(0, Constants.HighBridgeHeight * Constants.CellHeight);
13251343

13261344
startDrawPoint = startDrawPoint.ScaleBy(Camera.ZoomLevel);
13271345
endDrawPoint = endDrawPoint.ScaleBy(Camera.ZoomLevel);
@@ -1361,7 +1379,16 @@ private void DrawTileCursor(MapTile tileUnderCursor)
13611379
Color lineColor = new Color(96, 168, 96, 128);
13621380
Point2D cellTopLeftPoint = CellMath.CellTopLeftPointFromCellCoords(new Point2D(tileUnderCursor.X, tileUnderCursor.Y), Map) - Camera.TopLeftPoint;
13631381

1364-
int height = EditorState.Is2DMode ? 0 : tileUnderCursor.Level * Constants.CellHeight;
1382+
int height = 0;
1383+
1384+
if (!EditorState.Is2DMode)
1385+
{
1386+
height = tileUnderCursor.Level * Constants.CellHeight;
1387+
1388+
var techno = tileUnderCursor.GetTechno();
1389+
if (techno != null && techno.IsOnBridge())
1390+
height += Constants.HighBridgeHeight * Constants.CellHeight;
1391+
}
13651392

13661393
cellTopLeftPoint = new Point2D((int)(cellTopLeftPoint.X * Camera.ZoomLevel), (int)((cellTopLeftPoint.Y - height) * Camera.ZoomLevel));
13671394

src/TSMapEditor/Rendering/ObjectRenderers/InfantryRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public override Point2D GetDrawPoint(Infantry gameObject)
4141
{
4242
Point2D drawPoint = base.GetDrawPoint(gameObject);
4343
Point2D subCellOffset = CellMath.GetSubCellOffset(gameObject.SubCell);
44-
4544
return drawPoint + subCellOffset;
4645
}
4746

src/TSMapEditor/Rendering/ObjectRenderers/ObjectRenderer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ public virtual Point2D GetDrawPoint(T gameObject)
9090
Point2D drawPointWithoutCellHeight = CellMath.CellTopLeftPointFromCellCoords(gameObject.Position, Map);
9191

9292
var mapCell = Map.GetTile(gameObject.Position);
93-
int heightOffset = RenderDependencies.EditorState.Is2DMode ? 0 : mapCell.Level * Constants.CellHeight;
93+
int heightOffset = 0;
94+
95+
if (!RenderDependencies.EditorState.Is2DMode)
96+
{
97+
heightOffset = mapCell.Level * Constants.CellHeight;
98+
99+
if (gameObject.IsOnBridge())
100+
heightOffset += Constants.CellHeight * Constants.HighBridgeHeight;
101+
}
102+
94103
Point2D drawPoint = new Point2D(drawPointWithoutCellHeight.X, drawPointWithoutCellHeight.Y - heightOffset);
95104

96105
return drawPoint;

0 commit comments

Comments
 (0)