Skip to content

Commit a8a404a

Browse files
committed
prefer Enumerable.Range()
1 parent fc1ac83 commit a8a404a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Source/RunActivity/Viewer3D/RollingStock/SubSystems/ETCS/PlanningWindow.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
using System;
2121
using System.Collections.Generic;
22+
using System.Linq;
2223
using Microsoft.Xna.Framework;
2324
using Microsoft.Xna.Framework.Graphics;
2425
using Orts.Viewer3D.Popups;
@@ -92,8 +93,10 @@ public LocatedTexture(Texture2D texture, int x, int y)
9293
public PlanningWindow(DriverMachineInterface dmi) : base(dmi, 246, 300)
9394
{
9495
ButtonScaleUp = new DMIIconButton("NA_03.bmp", "NA_05.bmp", Viewer.Catalog.GetString("Scale Up"), true, ScaleUp, 40, 15, dmi);
95-
ButtonScaleDown = new DMIIconButton("NA_04.bmp", "NA_06.bmp", Viewer.Catalog.GetString("Scale Down"), true, ScaleDown, 40, 15, dmi);
96-
ButtonScaleDown.ExtendedSensitiveArea = new Rectangle(0, 15, 0, 0);
96+
ButtonScaleDown = new DMIIconButton("NA_04.bmp", "NA_06.bmp", Viewer.Catalog.GetString("Scale Down"), true, ScaleDown, 40, 15, dmi)
97+
{
98+
ExtendedSensitiveArea = new Rectangle(0, 15, 0, 0)
99+
};
97100
ButtonScaleUp.ExtendedSensitiveArea = new Rectangle(0, 0, 0, 15);
98101
ButtonScaleUp.ShowButtonBorder = false;
99102
ButtonScaleDown.ShowButtonBorder = false;
@@ -134,7 +137,7 @@ public override void Draw(SpriteBatch spriteBatch, Point position)
134137
}
135138

136139
// Distance lines
137-
for (int i = 0; i < 9; i++)
140+
foreach (int i in Enumerable.Range(0, 9))
138141
{
139142
if (i == 0 || i == 5 || i == 8) DrawIntRectangle(spriteBatch, position, 40, LinePositions[i], 200, 2, ColorMediumGrey);
140143
else DrawIntRectangle(spriteBatch, position, 40, LinePositions[i], 200, 1, ColorDarkGrey);
@@ -190,7 +193,7 @@ void CreateGradient(List<GradientProfileElement> GradientProfile)
190193
{
191194
var gradientText = new List<TextPrimitive>();
192195
var gradientRectangles = new Dictionary<Point, bool>();
193-
for (int i = 0; i + 1 < GradientProfile.Count; i++)
196+
foreach (int i in Enumerable.Range(0, GradientProfile.Count - 1))
194197
{
195198
GradientProfileElement e = GradientProfile[i];
196199
if (e.DistanceToTrainM > MaxViewingDistanceM) break;
@@ -231,7 +234,7 @@ void CreatePASP(List<PlanningTarget> SpeedTargets)
231234
bool oth2 = false;
232235
float widthFactor = 1;
233236
float allowedSpeedMpS = prev_pasp.TargetSpeedMpS;
234-
for (int i = 1; i < SpeedTargets.Count; i++)
237+
foreach (int i in Enumerable.Range(1, SpeedTargets.Count - 1))
235238
{
236239
PlanningTarget cur = SpeedTargets[i];
237240
PlanningTarget prev = SpeedTargets[i - 1];
@@ -277,10 +280,10 @@ void CreateTargetSpeeds(List<PlanningTarget> speedTargets)
277280
var speedTargetText = new List<TextPrimitive>(speedTargets.Count);
278281
var speedTargetTextures = new List<LocatedTexture>(speedTargets.Count);
279282
int ld = 0;
280-
for (int i = 1; i < speedTargets.Count; i++)
283+
foreach (int i in Enumerable.Range(1, speedTargets.Count - 1))
281284
{
282285
bool overlap = false;
283-
for (int j = 1; j < speedTargets.Count; j++)
286+
foreach (int j in Enumerable.Range(1, speedTargets.Count - 1))
284287
{
285288
if (i != j && CheckTargetOverlap(speedTargets[i], speedTargets[j]))
286289
{
@@ -317,7 +320,7 @@ void CreateTrackConditions(List<PlanningTrackCondition> trackConditions)
317320
{
318321
var trackConditionTextures = new List<LocatedTexture>(trackConditions.Count);
319322
int[] prevObject = { LinePositions[0] + 10, LinePositions[0] + 10, LinePositions[0] + 10 };
320-
for (int i = 0; i < trackConditions.Count; i++)
323+
foreach (int i in Enumerable.Range(0, trackConditions.Count))
321324
{
322325
PlanningTrackCondition condition = trackConditions[i];
323326
int posy = GetPlanningHeight(condition.DistanceToTrainM) - 35;
@@ -471,7 +474,7 @@ void SetFont()
471474
void SetDistanceText()
472475
{
473476
var distanceScaleText = new List<TextPrimitive>(DistanceScaleText.Count);
474-
for (int i = 0; i < 9; i++)
477+
foreach (int i in Enumerable.Range(0, 9))
475478
{
476479
if (i == 0 || i > 4)
477480
{

0 commit comments

Comments
 (0)