Skip to content

Commit cb90512

Browse files
committed
some ETCS data entry refactoring
1 parent a8a404a commit cb90512

File tree

1 file changed

+19
-13
lines changed
  • Source/RunActivity/Viewer3D/RollingStock/SubSystems/ETCS

1 file changed

+19
-13
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@
2323
using System;
2424
using System.Collections.Generic;
2525
using System.Linq;
26-
using System.Text;
27-
using System.Threading.Tasks;
2826
using Orts.Viewer3D.Popups;
2927

3028
namespace Orts.Viewer3D.RollingStock.SubSystems.ETCS
3129
{
3230
public class Keyboard
3331
{
34-
public readonly List<DMIButton> Keys = new List<DMIButton>();
32+
public readonly IList<DMIButton> Keys = new List<DMIButton>();
3533
public readonly DMIButton MoreKey;
36-
public int CurrentKeyPage;
34+
public int CurrentKeyPage { get; private set; }
3735
public Keyboard(DataEntryField field)
3836
{
3937
MoreKey = new DMIIconButton("NA_23.bmp", "NA_23.bmp", "More", false, () =>
@@ -115,7 +113,7 @@ public class NumericKeyboard : Keyboard
115113
{
116114
public NumericKeyboard(DataEntryField field, bool enhanced = false) : base(field)
117115
{
118-
for (int i = 1; i < 10; i++)
116+
foreach (int i in Enumerable.Range(1, 10 - 1))
119117
{
120118
string digitname = i.ToString();
121119
Keys.Add(new DMITextButton(digitname, digitname, false, () => field.HandleKeyPress(digitname), 102, 50, field.DMI, 16));
@@ -388,7 +386,8 @@ void UpdateText()
388386
}
389387
public void ScaleChanged()
390388
{
391-
Keyboard.Keys.ForEach(x => x.ScaleChanged());
389+
foreach (DMIButton key in Keyboard.Keys)
390+
key.ScaleChanged();
392391
Keyboard.MoreKey.ScaleChanged();
393392
DataArea.ScaleChanged();
394393
if (LabelArea != null)
@@ -445,7 +444,7 @@ public class DataEntryWindow : DMISubwindow
445444
int NumPages => (Fields.Count - 1) / 4 + 1;
446445
int CurrentPage => ActiveField/4;
447446
public int ActiveField;
448-
public readonly List<DataEntryField> Fields = new List<DataEntryField>();
447+
public readonly IList<DataEntryField> Fields = new List<DataEntryField>();
449448
DMIButton[] KeyboardButtons = new DMIButton[12];
450449
DMIButton NextButton;
451450
DMIButton PrevButton;
@@ -601,7 +600,7 @@ public override void Draw(SpriteBatch spriteBatch, Point drawPosition)
601600
{
602601
base.Draw(spriteBatch, drawPosition);
603602
if (!FullScreen) return;
604-
for (int i = 0; i < Fields.Count; i++)
603+
foreach (int i in Enumerable.Range(0, Fields.Count))
605604
{
606605
{
607606
var text = Fields[i].LabelEchoText;
@@ -619,9 +618,11 @@ public override void Draw(SpriteBatch spriteBatch, Point drawPosition)
619618
}
620619
public void PrepareLayout()
621620
{
622-
List<DMIArea> areas = new List<DMIArea>();
623-
areas.Add(CloseButton);
624-
for (int i = 0; i < Fields.Count; i++)
621+
List<DMIArea> areas = new List<DMIArea>
622+
{
623+
CloseButton
624+
};
625+
foreach (int i in Enumerable.Range(0, Fields.Count))
625626
{
626627
if (i != ActiveField) Fields[i].SetSelected(false);
627628
}
@@ -738,11 +739,16 @@ public override void ScaleChanged()
738739
{
739740
base.ScaleChanged();
740741
LabelFont = GetFont(FontHeightLabel);
741-
Fields.ForEach(x => x.ScaleChanged());
742+
foreach (DataEntryField field in Fields)
743+
field.ScaleChanged();
742744
}
743745
public void UnlockNavigationButtons()
744746
{
745-
Fields.ForEach(x => { x.DataArea.Enabled = true; x.DataArea.DelayType = false; });
747+
foreach (DataEntryField field in Fields)
748+
{
749+
field.DataArea.Enabled = true;
750+
field.DataArea.DelayType = false;
751+
}
746752
if (FullScreen)
747753
{
748754
PrevButton.Enabled = CurrentPage > 0;

0 commit comments

Comments
 (0)