Skip to content

Commit 3132306

Browse files
committed
Code improvements.
1 parent a94c2d2 commit 3132306

File tree

2 files changed

+33
-68
lines changed

2 files changed

+33
-68
lines changed

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,18 @@ public class TrainCarOperationsViewerWindow : Window
7070
internal static Texture2D RearAngleCockOpened;
7171
internal static Texture2D RearAngleCockClosed;
7272

73-
public int WindowHeightMin = 0;
74-
public int WindowHeightMax = 0;
75-
public int WindowWidthMin = 0;
76-
public int WindowWidthMax = 0;
73+
public int WindowHeightMin;
74+
public int WindowHeightMax;
75+
public int WindowWidthMin;
76+
public int WindowWidthMax;
7777
public string powerSupplyStatus;
7878
public string batteryStatus;
7979
string circuitBreakerState;
80-
public int spacerRowCount = 0;
81-
public int symbolsRowCount = 0;
82-
public int locoRowCount = 0;
83-
public int rowsCount = 0;
80+
public int spacerRowCount;
81+
public int symbolsRowCount;
82+
public int locoRowCount;
83+
public int rowsCount;
8484
const int SymbolWidth = 32;
85-
public string symbolClicked = "";
8685

8786
public static bool FontChanged;
8887
public static bool FontToBold;
@@ -125,12 +124,12 @@ public struct ListLabel
125124
bool LastPlayerLocomotiveFlippedState;
126125
int carPosition;
127126
public TrainCarOperationsViewerWindow(WindowManager owner)
128-
: base(owner, Window.DecorationSize.X + CarListPadding + (owner.TextFontDefault.Height + 12) * 20, Window.DecorationSize.Y + (owner.TextFontDefault.Height + 12) * 2, Viewer.Catalog.GetString("Train Operations Viewer"))
127+
: base(owner, Window.DecorationSize.X + CarListPadding + ((owner.TextFontDefault.Height + 12) * 20), Window.DecorationSize.Y + ((owner.TextFontDefault.Height + 12) * 2), Viewer.Catalog.GetString("Train Operations Viewer"))
129128
{
130129
WindowHeightMin = Location.Height;
131-
WindowHeightMax = Location.Height + owner.TextFontDefault.Height * 20;
130+
WindowHeightMax = Location.Height + (owner.TextFontDefault.Height * 20);
132131
WindowWidthMin = Location.Width;
133-
WindowWidthMax = Location.Width + owner.TextFontDefault.Height * 20;
132+
WindowWidthMax = Location.Width + (owner.TextFontDefault.Height * 20);
134133
}
135134

136135
protected internal override void Save(BinaryWriter outf)
@@ -229,7 +228,7 @@ private void ModifyWindowSize()
229228
var newWidth = (int)MathHelper.Clamp(desiredWidth, 100, WindowWidthMax);
230229

231230
// Move the dialog up if we're expanding it, or down if not; this keeps the center in the same place.
232-
var newTop = Location.Y + (Location.Height - newHeight) / 2;
231+
var newTop = Location.Y + ((Location.Height - newHeight) / 2);
233232

234233
// Display window
235234
SizeTo(newWidth, newHeight);
@@ -290,7 +289,6 @@ void AddSpace(bool full)
290289
}
291290
else
292291
{
293-
//AddSpace(false);
294292
line.Add(new buttonFrontBrakeHose(0, 0, textHeight, Owner.Viewer, car, CarPosition));
295293
line.Add(new buttonFrontAngleCock(0, 0, textHeight, Owner.Viewer, car, CarPosition));
296294
line.Add(new buttonCouplerFront(0, 0, textHeight, Owner.Viewer, car, CarPosition));
@@ -356,7 +354,6 @@ void buttonClose_Click(Control arg1, Point arg2)
356354
carPosition = CarPosition;
357355
Visible = false;
358356
}
359-
360357
public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
361358
{
362359
base.PrepareFrame(elapsedTime, updateFull);
@@ -377,7 +374,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
377374

378375
LastPlayerTrainCars = Owner.Viewer.PlayerTrain.Cars.Count;
379376
if (Owner.Viewer.PlayerLocomotive != null) LastPlayerLocomotiveFlippedState = Owner.Viewer.PlayerLocomotive.Flipped;
380-
//
377+
381378
Layout();
382379
UpdateWindowSize();
383380
}
@@ -389,7 +386,6 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
389386
{
390387
Owner.Viewer.FrontCamera.Activate();
391388
}
392-
393389
carPosition = CarPosition;
394390
Layout();
395391
UpdateWindowSize();
@@ -457,8 +453,6 @@ void TrainCarOperationsCouplerFront_Click(Control arg1, Point arg2)
457453
}
458454
else
459455
{
460-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Coupler Front");
461-
462456
new UncoupleCommand(Viewer.Log, CarPosition);
463457
if (Viewer.CarOperationsWindow.CarPosition > CarPosition)
464458
Viewer.CarOperationsWindow.Visible = false;
@@ -493,8 +487,6 @@ void TrainCarOperationsCouplerRear_Click(Control arg1, Point arg2)
493487
}
494488
else
495489
{
496-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Coupler Rear");
497-
498490
new UncoupleCommand(Viewer.Log, CarPosition);
499491
if (Viewer.CarOperationsWindow.CarPosition > CarPosition)
500492
Viewer.CarOperationsWindow.Visible = false;
@@ -546,8 +538,6 @@ void buttonHandBrake_Click(Control arg1, Point arg2)
546538
{
547539
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).HandBrakePresent)
548540
{
549-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Handbrake");
550-
551541
new WagonHandbrakeCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).GetTrainHandbrakeStatus());
552542
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).GetTrainHandbrakeStatus())
553543
{
@@ -612,10 +602,8 @@ public buttonFrontBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car,
612602
void buttonFrontBrakeHose_Click(Control arg1, Point arg2)
613603
{
614604
if (First) return;
615-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Front brake hose");
616605

617606
new WagonBrakeHoseConnectCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected);
618-
619607
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected)
620608
{
621609
Viewer.Simulator.Confirmer.Information(Viewer.Catalog.GetString("Front brake hose connected"));
@@ -651,7 +639,7 @@ public buttonRearBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car,
651639
void buttonRearBrakeHose_Click(Control arg1, Point arg2)
652640
{
653641
if (Last) return;
654-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Rear brake hose");
642+
655643
new WagonBrakeHoseRearConnectCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected);
656644
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected)
657645
{
@@ -688,10 +676,8 @@ public buttonFrontAngleCock(int x, int y, int size, Viewer viewer, TrainCar car,
688676

689677
void buttonFrontAngleCock_Click(Control arg1, Point arg2)
690678
{
691-
if (First)
692-
return;
679+
if (First) return;
693680

694-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Front angle cock");
695681
new ToggleAngleCockACommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockAOpen);
696682
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockAOpen)
697683
{
@@ -727,10 +713,8 @@ public buttonRearAngleCock(int x, int y, int size, Viewer viewer, TrainCar car,
727713

728714
void buttonRearAngleCock_Click(Control arg1, Point arg2)
729715
{
730-
if (Last)
731-
return;
716+
if (Last) return;
732717

733-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Rear angle cock");
734718
new ToggleAngleCockBCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpen);
735719
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpen)
736720
{
@@ -778,7 +762,6 @@ void buttonBleedOffValve_Click(Control arg1, Point arg2)
778762
Texture = BleedOffValveNotAvailable;
779763
return;
780764
}
781-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Bleed off valve");
782765
new ToggleBleedOffValveCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.BleedOffValveOpen);
783766
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.BleedOffValveOpen)
784767
{
@@ -870,7 +853,6 @@ public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
870853
}
871854
void buttonToggleMU_Click(Control arg1, Point arg2)
872855
{
873-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("MU signal");
874856
if (Viewer.PlayerTrain.Cars[CarPosition] is MSTSDieselLocomotive)
875857
{
876858
MSTSLocomotive locomotive = Viewer.PlayerTrain.Cars[CarPosition] as MSTSLocomotive;
@@ -914,7 +896,6 @@ public buttonTogglePower(int x, int y, int size, Viewer viewer, int carPosition)
914896
}
915897
void buttonTogglePower_Click(Control arg1, Point arg2)
916898
{
917-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Power");
918899
if ((Viewer.PlayerTrain.Cars[CarPosition] is MSTSElectricLocomotive)
919900
|| (Viewer.PlayerTrain.Cars[CarPosition] is MSTSDieselLocomotive))
920901
{
@@ -1002,7 +983,6 @@ public ToggleBatterySwitch(int x, int y, int size, Viewer viewer, int carPositio
1002983
}
1003984
void ToggleBatterySwitch_Click(Control arg1, Point arg2)
1004985
{
1005-
TrainCarViewer.symbolClicked = Viewer.Catalog.GetString("Battery Switch");
1006986
if (Viewer.PlayerTrain.Cars[CarPosition] is MSTSWagon wagon
1007987
&& wagon.PowerSupply is IPowerSupply)
1008988
{

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public class TrainCarOperationsWindow : Window
7171
internal static Texture2D RearAngleCockOpened;
7272

7373

74-
public int DisplaySizeY = 0;
74+
public int DisplaySizeY;
7575
public bool LayoutUpdated = false;
7676
public bool allSymbolsMode = true;
77-
public int locoRowCount = 0;
78-
public int rowsCount = 0;
79-
public int separatorCount = 0;
80-
public int spacerRowCount = 0;
81-
public int symbolsRowCount = 0;
77+
public int locoRowCount;
78+
public int rowsCount;
79+
public int separatorCount;
80+
public int spacerRowCount;
81+
public int symbolsRowCount;
8282

8383
public int carPositionVisible;
8484
public ControlLayout Client;
@@ -89,19 +89,19 @@ public class TrainCarOperationsWindow : Window
8989
public int selectedCarPosition;
9090
const int symbolSize = 16;
9191

92-
public int WindowHeightMax = 0;
93-
public int WindowHeightMin = 0;
94-
public int WindowWidthMax = 0;
95-
public int WindowWidthMin = 0;
92+
public int WindowHeightMax;
93+
public int WindowHeightMin;
94+
public int WindowWidthMax;
95+
public int WindowWidthMin;
9696
public int currentDisplaySizeY;
9797
public bool isFullScreen = false;
9898
public int rowHeight;
9999
public int oldPositionHeight;
100100

101101
//Rectangle carLabelPosition;
102102
public string carLabelText;
103-
public int CarPosition = 0;
104-
public int CarUIDLenght = 0;
103+
public int CarPosition;
104+
public int CarUIDLenght;
105105
public int desiredHeight;
106106
public static bool FontChanged;
107107
public static bool FontToBold;
@@ -132,31 +132,17 @@ public struct ListLabel
132132
}
133133
public List<ListLabel> Labels = new List<ListLabel>();
134134

135-
public struct ListSettings
136-
{
137-
public bool BleedOffValve;
138-
public string CarID;
139-
public bool HandBrakeSet;
140-
public bool FrontBrakeHose;
141-
public bool RearBrakeHose;
142-
public bool FrontAngleCock;
143-
public bool RearAngleCock;
144-
145-
}
146-
public List<ListSettings> CarOperations = new List<ListSettings>();
147-
public List<ListSettings> TrainCarOperations = new List<ListSettings>();
148-
149135
Train PlayerTrain;
150136
int LastPlayerTrainCars;
151137
bool LastPlayerLocomotiveFlippedState;
152138

153139
public TrainCarOperationsWindow(WindowManager owner)
154-
: base(owner, Window.DecorationSize.X + CarListPadding + owner.TextFontDefault.Height * 15, Window.DecorationSize.Y + owner.TextFontDefault.Height * 5, Viewer.Catalog.GetString("Train Car Operations "))
140+
: base(owner, Window.DecorationSize.X + CarListPadding + (owner.TextFontDefault.Height * 15), Window.DecorationSize.Y + (owner.TextFontDefault.Height * 5), Viewer.Catalog.GetString("Train Car Operations"))
155141
{
156142
WindowHeightMin = Location.Height;
157-
WindowHeightMax = Location.Height + owner.TextFontDefault.Height * 20;
143+
WindowHeightMax = Location.Height + (owner.TextFontDefault.Height * 20);
158144
WindowWidthMin = Location.Width;
159-
WindowWidthMax = Location.Width + owner.TextFontDefault.Height * 20;
145+
WindowWidthMax = Location.Width + (owner.TextFontDefault.Height * 20);
160146
currentDisplaySizeY = Owner.Viewer.DisplaySize.Y;
161147
}
162148
protected internal override void Save(BinaryWriter outf)
@@ -240,7 +226,7 @@ private void UpdateWindowSize()
240226
void updateLayoutSize()
241227
{
242228
Labels.Clear();
243-
CarOperations.Clear();
229+
244230
if (PlayerTrain != null)
245231
{
246232
int carPosition = 0;
@@ -273,7 +259,6 @@ private void ModifyWindowSize()
273259

274260
DisplaySizeY = Owner.Viewer.DisplaySize.Y;
275261
isFullScreen = Owner.Viewer.RenderProcess.isFullScreen;
276-
// Owner.Viewer.GraphicsDevice.DisplayMode.Height == DisplaySizeY;
277262

278263
// Validates rows with windows DPI settings
279264
var dpiScale = System.Drawing.Graphics.FromHwnd(IntPtr.Zero).DpiY / 96;
@@ -296,7 +281,7 @@ private void ModifyWindowSize()
296281
var newWidth = MathHelper.Clamp(desiredWidth, 100, WindowWidthMax);
297282

298283
// Move the dialog up if we're expanding it, or down if not; this keeps the center in the same place.
299-
var newTop = Location.Y + (Location.Height - newHeight) / 2;
284+
var newTop = Location.Y + ((Location.Height - newHeight) / 2);
300285

301286
// Display window
302287
SizeTo(newWidth, newHeight);

0 commit comments

Comments
 (0)