Skip to content

Commit 9f1aa4d

Browse files
committed
slight ETCS DMI refactoring
1 parent cb90512 commit 9f1aa4d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using ORTS.Scripting.Api.ETCS;
2828
using System;
2929
using System.Collections.Generic;
30+
using System.Linq;
3031
using static Orts.Viewer3D.RollingStock.Subsystems.ETCS.DriverMachineInterface;
3132

3233
namespace Orts.Viewer3D.RollingStock.Subsystems.ETCS
@@ -36,9 +37,9 @@ public class DriverMachineInterface
3637
public readonly MSTSLocomotive Locomotive;
3738
public readonly bool GaugeOnly;
3839
public readonly Viewer Viewer;
39-
public List<DMIWindow> Windows = new List<DMIWindow>();
40+
public IList<DMIWindow> Windows = new List<DMIWindow>();
4041
float PrevScale = 1;
41-
public ETCSStatus ETCSStatus;
42+
public ETCSStatus ETCSStatus { get; private set; }
4243

4344
bool Active;
4445
public float Scale { get; private set; }
@@ -67,8 +68,8 @@ public class DriverMachineInterface
6768

6869
public Texture2D ColorTexture { get; private set; }
6970

70-
public bool Blinker2Hz;
71-
public bool Blinker4Hz;
71+
public bool Blinker2Hz { get; private set; }
72+
public bool Blinker4Hz { get; private set; }
7273
float BlinkerTime;
7374

7475
public float CurrentTime => (float)Viewer.Simulator.ClockTime;
@@ -114,8 +115,12 @@ public void AddToLayout(DMIWindow window, Point position)
114115
}
115116
public Texture2D LoadTexture(string name)
116117
{
117-
if (MipMapScale == 2) return SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "ETCS", "mipmap-2", name));
118-
else return SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "ETCS", name));
118+
string path;
119+
if (MipMapScale == 2)
120+
path = System.IO.Path.Combine(Viewer.ContentPath, "ETCS", "mipmap-2", name);
121+
else
122+
path = System.IO.Path.Combine(Viewer.ContentPath, "ETCS", name);
123+
return SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, path);
119124
}
120125
public void PrepareFrame(float elapsedSeconds)
121126
{
@@ -306,7 +311,7 @@ public ETCSDefaultWindow(DriverMachineInterface dmi, CabViewControl control) : b
306311
AddToLayout(MessageArea, new Point(54, DMI.IsSoftLayout ? 350 : 365));
307312
AddToLayout(MessageArea.ButtonScrollUp, new Point(54+234, DMI.IsSoftLayout ? 350 : 365));
308313
AddToLayout(MessageArea.ButtonScrollDown, new Point(54+234, MessageArea.Height / 2 + (DMI.IsSoftLayout ? 350 : 365)));
309-
for (int i=0; i<MenuBar.Buttons.Count; i++)
314+
foreach (int i in Enumerable.Range(0, MenuBar.Buttons.Count))
310315
{
311316
AddToLayout(MenuBar.Buttons[i], new Point(580, 15 + 50*i));
312317
}
@@ -603,7 +608,7 @@ public DMITextButton(string caption, string displayName, bool upType, Action pre
603608
}
604609
void SetText()
605610
{
606-
for (int i=0; i<Caption.Length; i++)
611+
foreach (int i in Enumerable.Range(0, Caption.Length))
607612
{
608613
int fontWidth = (int)(CaptionFont.MeasureString(Caption[i]) / Scale);
609614
CaptionText[i] = new TextPrimitive(new Point((Width - fontWidth) / 2, (Height - FontHeightButton) / 2 + FontHeightButton * (2 * i - Caption.Length + 1)), Color.White, Caption[i], CaptionFont);
@@ -684,7 +689,7 @@ public DMITextLabel(string caption, int width, int height, DriverMachineInterfac
684689
}
685690
void SetText()
686691
{
687-
for (int i = 0; i < Caption.Length; i++)
692+
foreach (int i in Enumerable.Range(0, Caption.Length))
688693
{
689694
int fontWidth = (int)(CaptionFont.MeasureString(Caption[i]) / Scale);
690695
CaptionText[i] = new TextPrimitive(new Point((Width - fontWidth) / 2, (Height - FontHeightButton) / 2 + FontHeightButton * (2 * i - Caption.Length + 1)), ColorGrey, Caption[i], CaptionFont);

0 commit comments

Comments
 (0)