Skip to content

Commit 47dc49e

Browse files
committed
some ETCS text messages refactoring
1 parent e2e2fc2 commit 47dc49e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
using System;
2626
using System.Collections.Generic;
2727
using System.Linq;
28-
using System.Text;
29-
using System.Threading.Tasks;
30-
using static Orts.Viewer3D.RollingStock.Subsystems.ETCS.DriverMachineInterface;
3128

3229
namespace Orts.Viewer3D.RollingStock.SubSystems.ETCS
3330
{
@@ -132,7 +129,8 @@ void SetDatePrimitive(float timestampS, int row)
132129
int totalseconds = (int)timestampS;
133130
int hour = (totalseconds / 3600) % 24;
134131
int minute = (totalseconds / 60) % 60;
135-
DisplayedTimes[row] = new TextPrimitive(new Point(3, (row + 1) * RowHeight - (int)FontHeightTimestamp), Color.White, (hour < 10 ? "0" : "") + hour.ToString() + ":" + (minute < 10 ? "0" : "") + minute.ToString(), FontTimestamp);
132+
var text = $"{(hour < 10 ? "0" : "")}{hour}:{(minute < 10 ? "0" : "")}{minute}";
133+
DisplayedTimes[row] = new TextPrimitive(new Point(3, (row + 1) * RowHeight - (int)FontHeightTimestamp), Color.White, text, FontTimestamp);
136134
}
137135
void SetTextPrimitive(string text, int row, bool isBold)
138136
{
@@ -160,7 +158,7 @@ string[] GetRowSeparated(string text, bool isBold)
160158
}
161159
void SetMessages()
162160
{
163-
for (int i = 0; i < MaxTextLines; i++)
161+
foreach (int i in Enumerable.Range(0, MaxTextLines))
164162
{
165163
DisplayedTexts[i] = null;
166164
DisplayedTimes[i] = null;
@@ -173,7 +171,7 @@ void SetMessages()
173171
CurrentPage = 0;
174172
SetDatePrimitive(msg.TimestampS, 0);
175173
string[] text = GetRowSeparated(msg.Text, false);
176-
for (int j = 0; j < text.Length && j < MaxTextLines; j++)
174+
foreach (int j in Enumerable.Range(0, Math.Min(text.Length, MaxTextLines)))
177175
{
178176
SetTextPrimitive(text[j], j, false);
179177
}
@@ -185,7 +183,7 @@ void SetMessages()
185183
{
186184
if (!MessageList[0].Displayed) CurrentPage = 0;
187185
int row = 0;
188-
for (int i=0; i<MessageList.Count; i++)
186+
foreach (int i in Enumerable.Range(0, MessageList.Count))
189187
{
190188
var msg = MessageList[i];
191189
string[] text = GetRowSeparated(msg.Text, msg.FirstGroup);
@@ -194,11 +192,11 @@ void SetMessages()
194192
msg.Displayed = true;
195193
SetDatePrimitive(msg.TimestampS, row % MaxTextLines);
196194
}
197-
for (int j = 0; j < text.Length; j++)
195+
foreach (string c in text)
198196
{
199197
if (CurrentPage * MaxTextLines <= row && row < (CurrentPage + 1) * MaxTextLines)
200198
{
201-
SetTextPrimitive(text[j], row % MaxTextLines, msg.FirstGroup);
199+
SetTextPrimitive(c, row % MaxTextLines, msg.FirstGroup);
202200
}
203201
row++;
204202
}

0 commit comments

Comments
 (0)