Skip to content

Commit f6f069f

Browse files
committed
Render infantry and vehicles on bridges above bridges
1 parent 2b2afb7 commit f6f069f

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/TSMapEditor/Rendering/ObjectRenderers/InfantryRenderer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ protected override CommonDrawParams GetDrawParams(Infantry gameObject)
2323

2424
protected override float GetDepthAddition(Infantry gameObject)
2525
{
26+
if (gameObject.High)
27+
{
28+
// Add extra depth to the unit so it is rendered above the bridge.
29+
// Why are we adding exactly this much?
30+
// Because it happened to work - this is at least currently no smart mathematical formula.
31+
int height = Constants.CellSizeY * 7;
32+
return ((height / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace) + (4 * Constants.DepthRenderStep) + Constants.DepthEpsilon * ObjectDepthAdjustments.Vehicle;
33+
}
34+
2635
return Constants.DepthEpsilon * ObjectDepthAdjustments.Infantry;
2736
}
2837

src/TSMapEditor/Rendering/ObjectRenderers/UnitRenderer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ protected override float GetDepthFromPosition(Unit gameObject, Rectangle drawing
5555

5656
protected override float GetDepthAddition(Unit gameObject)
5757
{
58+
if (gameObject.High)
59+
{
60+
// Add extra depth to the unit so it is rendered above the bridge.
61+
// Why are we adding exactly this much?
62+
// Because it happened to work - this is at least currently no smart mathematical formula.
63+
int height = Constants.CellSizeY * 7;
64+
return ((height / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace) + (4 * Constants.DepthRenderStep) + Constants.DepthEpsilon * ObjectDepthAdjustments.Vehicle;
65+
}
66+
5867
return Constants.DepthEpsilon * ObjectDepthAdjustments.Vehicle;
5968
}
6069

src/TSMapEditor/UI/Windows/InfantryOptionsWindow.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ private void BtnOK_LeftClick(object sender, EventArgs e)
128128
infantry.Mission = ddMission.SelectedItem == null ? infantry.Mission : ddMission.SelectedItem.Text;
129129
infantry.Veterancy = (int)ddVeterancy.SelectedItem.Tag;
130130

131+
bool refresh = false;
132+
131133
if (ddSubCell.SelectedIndex != (int)infantry.SubCell && ddSubCell.SelectedIndex >= 0 && ddSubCell.SelectedIndex < (int)SubCell.Count)
132134
{
133135
var infantryCell = map.GetTile(infantry.Position);
@@ -136,11 +138,21 @@ private void BtnOK_LeftClick(object sender, EventArgs e)
136138
infantryCell.MoveInfantryToSubCell(infantry, (SubCell)ddSubCell.SelectedIndex);
137139
}
138140

139-
mapView.AddRefreshPoint(infantryCell.CoordsToPoint());
141+
refresh = true;
142+
}
143+
144+
if (infantry.High != chkOnBridge.Checked)
145+
{
146+
infantry.High = chkOnBridge.Checked;
147+
refresh = true;
148+
}
149+
150+
if (refresh)
151+
{
152+
mapView.AddRefreshPoint(infantry.Position);
140153
}
141154

142155
infantry.Group = tbGroup.Value;
143-
infantry.High = chkOnBridge.Checked;
144156
infantry.AutocreateNoRecruitable = chkAutocreateNoRecruitable.Checked;
145157
infantry.AutocreateYesRecruitable = chkAutocreateYesRecruitable.Checked;
146158
infantry.AttachedTag = (Tag)attachedTagSelector.Tag;

src/TSMapEditor/UI/Windows/VehicleOptionsWindow.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ public VehicleOptionsWindow(WindowManager windowManager, Map map, EditorState ed
1919
this.map = map;
2020
this.editorState = editorState;
2121
this.setFollowerCursorAction = new SetFollowerCursorAction(cursorActionTarget);
22+
this.cursorActionTarget = cursorActionTarget;
2223
}
2324

2425
public event EventHandler<TagEventArgs> TagOpened;
2526

2627
private readonly Map map;
2728
private readonly EditorState editorState;
2829
private readonly SetFollowerCursorAction setFollowerCursorAction;
30+
private readonly ICursorActionTarget cursorActionTarget;
2931

3032
private XNATrackbar trbStrength;
3133
private XNALabel lblStrengthValue;
@@ -148,7 +150,13 @@ private void BtnOK_LeftClick(object sender, EventArgs e)
148150
unit.Veterancy = (int)ddVeterancy.SelectedItem.Tag;
149151
unit.Group = tbGroup.Value;
150152
unit.FollowerUnit = followerSelector.Tag as Unit;
151-
unit.High = chkOnBridge.Checked;
153+
154+
if (unit.High != chkOnBridge.Checked)
155+
{
156+
unit.High = chkOnBridge.Checked;
157+
cursorActionTarget.AddRefreshPoint(unit.Position);
158+
}
159+
152160
unit.AutocreateNoRecruitable = chkAutocreateNoRecruitable.Checked;
153161
unit.AutocreateYesRecruitable = chkAutocreateYesRecruitable.Checked;
154162
unit.AttachedTag = (Tag)attachedTagSelector.Tag;

0 commit comments

Comments
 (0)