/
TrainCarOperationsWindow.cs
1073 lines (972 loc) · 51.6 KB
/
TrainCarOperationsWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// COPYRIGHT 2010, 2011, 2012, 2013, 2014, 2015 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
// This file is the responsibility of the 3D & Environment Team.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Orts.Common;
using Orts.Simulation.Physics;
using Orts.Simulation.RollingStocks;
using Orts.Simulation.RollingStocks.SubSystems.Brakes;
using Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS;
using ORTS.Common;
using ORTS.Common.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Orts.Viewer3D.Popups.TrainCarOperationsWindow;
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
namespace Orts.Viewer3D.Popups
{
public class TrainCarOperationsWindow : Window
{
const int CarListPadding = 2;
internal static Texture2D ArrowRight;
internal static Texture2D ArrowLeft;
//internal static Texture2D BatChanging;//TO DO:
internal static Texture2D BattAlwaysOn;
internal static Texture2D BattOff;
internal static Texture2D BattOn;
internal static Texture2D BleedOffValveOpened;
internal static Texture2D BleedOffValveClosed;
internal static Texture2D BleedOffValveNotAvailable;
internal static Texture2D BrakeHoseCon;
internal static Texture2D BrakeHoseDis;
internal static Texture2D BrakeHoseFirstDis;
internal static Texture2D BrakeHoseLastDis;
internal static Texture2D Coupler;
internal static Texture2D CouplerFront;
internal static Texture2D CouplerRear;
internal static Texture2D Empty;
internal static Texture2D ETSconnected;
internal static Texture2D ETSdisconnected;
internal static Texture2D FrontAngleCockClosed;
internal static Texture2D FrontAngleCockOpened;
internal static Texture2D HandBrakeNotAvailable;
internal static Texture2D HandBrakeNotSet;
internal static Texture2D HandBrakeSet;
internal static Texture2D MUconnected;
internal static Texture2D MUdisconnected;
internal static Texture2D PowerChanging;
internal static Texture2D PowerOff;
internal static Texture2D PowerOn;
internal static Texture2D RearAngleCockClosed;
internal static Texture2D RearAngleCockOpened;
public int DisplaySizeY;
public bool LayoutUpdated = false;
public bool AllSymbolsMode = true;
public int LocoRowCount;
public int RowsCount;
public int SeparatorCount;
public int SpacerRowCount;
public int SymbolsRowCount;
public int CarPositionVisible;
public ControlLayout Client;
public int CurrentCarPosition;
public int LabelTop;
public bool LastRowVisible = false;
public int LocalScrollPosition;
public int SelectedCarPosition;
const int SymbolSize = 16;
public int WindowHeightMax;
public int WindowHeightMin;
public int WindowWidthMax;
public int WindowWidthMin;
public int CurrentDisplaySizeY;
public bool IsFullScreen = false;
public int RowHeight;
public int OldPositionHeight;
public bool UpdateTrainCarOperation = false;
public List<int> LabelPositionTop = new List<int>();
//Rectangle carLabelPosition;
public string CarLabelText;
public int CarPosition;
public int CarUIDLenght;
public int DesiredHeight;
public static bool FontChanged;
public static bool FontToBold;
public ControlLayoutVertical Vbox;
//Electrical power
public string BatteryStatus;
public string CircuitBreakerState;
public bool MainPowerSupplyOn;
public string PowerSupplyStatus;
public bool PowerSupplyUpdating;
public bool SupplyStatusChanged;
public bool UpdatingPowerSupply = false;
public bool WarningEnabled = false;
public bool CarIdClicked = false;
public bool ModifiedSetting
{
set;
get;
}
public List<bool> WarningCarPosition = new List<bool>();
public struct ListLabel
{
public string CarID;
public int CarIDWidth;
}
public List<ListLabel> Labels = new List<ListLabel>();
Train PlayerTrain;
int LastPlayerTrainCars;
bool LastPlayerLocomotiveFlippedState;
public TrainCarOperationsWindow(WindowManager owner)
: base(owner, Window.DecorationSize.X + CarListPadding + (owner.TextFontDefault.Height * 15), Window.DecorationSize.Y + (owner.TextFontDefault.Height * 5), Viewer.Catalog.GetString("Train Car Operations"))
{
WindowHeightMin = Location.Height;
WindowHeightMax = Location.Height + (owner.TextFontDefault.Height * 20);
WindowWidthMin = Location.Width;
WindowWidthMax = Location.Width + (owner.TextFontDefault.Height * 20);
CurrentDisplaySizeY = Owner.Viewer.DisplaySize.Y;
}
protected internal override void Save(BinaryWriter outf)
{
base.Save(outf);
outf.Write(Location.X);
outf.Write(Location.Y);
outf.Write(Location.Width);
outf.Write(Location.Height);
outf.Write(SelectedCarPosition);
}
protected internal override void Restore(BinaryReader inf)
{
base.Restore(inf);
Rectangle LocationRestore;
LocationRestore.X = inf.ReadInt32();
LocationRestore.Y = inf.ReadInt32();
LocationRestore.Width = inf.ReadInt32();
LocationRestore.Height = inf.ReadInt32();
SelectedCarPosition = inf.ReadInt32();
// Display window
SizeTo(LocationRestore.Width, LocationRestore.Height);
MoveTo(LocationRestore.X, LocationRestore.Y);
}
protected internal override void Initialize()
{
base.Initialize();
// Reset window size
if (Visible) UpdateWindowSize();
if (Coupler == null)
{
// TO DO: This should happen on the loader thread.
ArrowRight = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsArrowLeft.png"));
ArrowLeft = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsArrowRight.png"));
Coupler = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsCoupler.png"));//-
CouplerFront = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsCouplerFront.png"));
CouplerRear = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsCouplerRear.png"));
Empty = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsEmpty.png"));
HandBrakeNotAvailable = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsHandBrakeNotAvailable.png"));
HandBrakeNotSet = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsHandBrakeNoSet.png"));//-
HandBrakeSet = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsHandBrakeSet.png"));//-
BrakeHoseCon = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBrakeHoseCon.png"));
BrakeHoseDis = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBrakeHoseDis.png"));
BrakeHoseFirstDis = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBrakeHoseFirstDis.png"));
BrakeHoseLastDis = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBrakeHoseLastDis.png"));
FrontAngleCockOpened = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsFrontAngleCockOpened.png"));
FrontAngleCockClosed = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsFrontAngleCockClosed.png"));
BleedOffValveClosed = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBleedOffValveClosed.png"));//-
BleedOffValveOpened = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBleedOffValveOpened.png"));//-
BleedOffValveNotAvailable = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBleedOffValveNotAvailable.png"));
RearAngleCockClosed = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsRearAngleCockClosed.png"));
RearAngleCockOpened = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsRearAngleCockOpened.png"));
PowerChanging = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsPowerChanging.png"));
PowerOff = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsPowerOff.png"));
PowerOn = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsPowerOn.png"));
MUconnected = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsMUconnected.png"));
MUdisconnected = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsMUdisconnected.png"));
ETSconnected = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsETSconnected.png"));
ETSdisconnected = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsETSdisconnected.png"));
BattOff = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBattOff.png"));
BattOn = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBattOn.png"));
BattAlwaysOn = SharedTextureManager.Get(Owner.Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperationsBattAlwaysOn.png"));
}
}
private void UpdateWindowSize()
{
ModifyWindowSize();
}
void updateLayoutSize()
{
Labels.Clear();
if (PlayerTrain != null)
{
int carPosition = 0;
foreach (var car in PlayerTrain.Cars)
{
var carUid = car.CarID;
var carUIDWidth = FontToBold ? Owner.TextFontDefaultBold.MeasureString(carUid.TrimEnd())
: Owner.TextFontDefault.MeasureString(carUid.TrimEnd());
Labels.Add(new ListLabel
{
CarID = carUid,
CarIDWidth = carUIDWidth
});
carPosition++;
}
ModifyWindowSize();
}
}
/// <summary>
/// Modify window size
/// </summary>
private void ModifyWindowSize()
{
if (SymbolsRowCount > 0)
{
var textWidth = Owner.TextFontDefault.Height;
CarUIDLenght = Labels.Max(x => x.CarIDWidth);
DisplaySizeY = Owner.Viewer.DisplaySize.Y;
IsFullScreen = Owner.Viewer.RenderProcess.isFullScreen;
// Validates rows with windows DPI settings
var dpiScale = System.Drawing.Graphics.FromHwnd(IntPtr.Zero).DpiY / 96;
var separatorSize = ControlLayout.SeparatorSize;
DesiredHeight = FontToBold ? (Owner.TextFontDefaultBold.Height * (RowsCount + 1)) + (separatorSize * (SeparatorCount + 3))
: (Owner.TextFontDefault.Height * (RowsCount + 1)) + (separatorSize * (SeparatorCount + 3));
var desiredWidth = (SymbolsRowCount * SymbolSize) + (SpacerRowCount * (textWidth / 2)) + CarUIDLenght + (textWidth * 2);
// Takes the height of the TrainOperationsViewer as the margin area.
RowHeight = textWidth + separatorSize;
var midlayoutRow = (CarPositionVisible * RowHeight) / 2;
var marginTraincarViewer = Owner.Viewer.TrainCarOperationsViewerWindow.windowHeight + 32;//32 = imageHeight
marginTraincarViewer = dpiScale == 1 ? marginTraincarViewer + (IsFullScreen ? separatorSize : separatorSize)
: dpiScale == 1.75 ? marginTraincarViewer + (IsFullScreen ? separatorSize : textWidth)
: marginTraincarViewer;
WindowHeightMax = DisplaySizeY - marginTraincarViewer;
var newHeight = MathHelper.Clamp(DesiredHeight, ((textWidth + separatorSize) * 3) + separatorSize, WindowHeightMax);
var newWidth = MathHelper.Clamp(desiredWidth, 100, WindowWidthMax);
// Move the dialog up if we're expanding it, or down if not; this keeps the center in the same place.
var newTop = Location.Y + ((Location.Height - newHeight) / 2);
// Display window
SizeTo(newWidth, newHeight);
MoveTo(Location.X, newTop);
}
}
protected override ControlLayout Layout(ControlLayout layout)
{
var textHeight = Owner.TextFontDefault.Height;
var trainCarViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
Vbox = base.Layout(layout).AddLayoutVertical();
LocoRowCount = 0;
SpacerRowCount = 0;
SymbolsRowCount = 0;
WarningCarPosition.Clear();
if (PlayerTrain != null)
{
int carPosition = 0;
ControlLayout scrollbox;
scrollbox = PlayerTrain.Cars.Count == 1 ? Vbox.AddLayoutHorizontal(Vbox.RemainingHeight)
: Vbox.AddLayoutScrollboxVertical(Vbox.RemainingWidth);
{
var line = Vbox.AddLayoutHorizontalLineOfText();
void AddSpace()
{
line.AddSpace(textHeight / 2, line.RemainingHeight);
}
if (LabelPositionTop.Count == 0)
{
var n = scrollbox.Position.Y;// first row
for (var i = 0; i < PlayerTrain.Cars.Count; i++)
{ // Position of each row
LabelPositionTop.Add(n);
n += (textHeight + ControlLayout.SeparatorSize);
}
}
// reset WarningCarPosition
WarningCarPosition = Enumerable.Repeat(false, PlayerTrain.Cars.Count).ToList();
foreach (var car in PlayerTrain.Cars)
{
TrainCar trainCar = PlayerTrain.Cars[carPosition];
BrakeSystem brakeSystem = (trainCar as MSTSWagon).BrakeSystem;
MSTSLocomotive locomotive = trainCar as MSTSLocomotive;
MSTSWagon wagon = trainCar as MSTSWagon;
bool isElectricDieselLocomotive = (trainCar is MSTSElectricLocomotive) || (trainCar is MSTSDieselLocomotive);
line = scrollbox.AddLayoutHorizontalLineOfText();
{
var carLabel = new buttonLoco(CarUIDLenght + textHeight, textHeight, Owner.Viewer, car, carPosition, LabelAlignment.Center);
carLabel.Click += new Action<Control, Point>(carLabel_Click);
if (car == PlayerTrain.LeadLocomotive || car is MSTSLocomotive || car.WagonType == TrainCar.WagonTypes.Tender) carLabel.Color = Color.Green;
if (car.BrakesStuck || ((car is MSTSLocomotive) && (car as MSTSLocomotive).PowerReduction > 0)) carLabel.Color = Color.Red;
// Left arrow
line.Add(new buttonArrowLeft(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
// Front brake hose
line.Add(new buttonFrontBrakeHose(0, 0, SymbolSize, Owner.Viewer, car, carPosition));
// Front angle cock
line.Add(new buttonFrontAngleCock(0, 0, SymbolSize, Owner.Viewer, car, carPosition));
AddSpace();
// Front coupler
line.Add(new buttonCouplerFront(0, 0, SymbolSize, Owner.Viewer, car));
// Car label
line.Add(carLabel);
// Rear coupler
line.Add(new buttonCouplerRear(0, 0, SymbolSize, Owner.Viewer, car));
AddSpace();
// Rear angle cock
line.Add(new buttonRearAngleCock(0, 0, SymbolSize, Owner.Viewer, car, carPosition));
// Rear brake hose
line.Add(new buttonRearBrakeHose(0, 0, SymbolSize, Owner.Viewer, car, carPosition));
AddSpace();
// Handbrake
line.Add(new buttonHandBrake(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
// Bleed off valve
line.Add(new buttonBleedOffValve(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
if (AllSymbolsMode)//Allows to display all symbols
{
// Electric train supply connection (ETS)
if (PlayerTrain.Cars.Count() > 1 && wagon.PowerSupply != null)
{
line.Add(new buttonToggleElectricTrainSupplyCable(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
}
if (isElectricDieselLocomotive)
{
if (locomotive.GetMultipleUnitsConfiguration() != null)
{
line.Add(new buttonToggleMU(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
}
line.Add(new buttonTogglePower(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
if ((wagon != null) && (wagon.PowerSupply is IPowerSupply))
{
line.Add(new buttonToggleBatterySwitch(0, 0, SymbolSize, Owner.Viewer, carPosition));
AddSpace();
}
}
}
// Right arrow
line.Add(new buttonArrowRight(0, 0, textHeight, Owner.Viewer, carPosition));
AddSpace();
AddSpace();
// Set color to cyan
var color = carLabel.Color;
if (WarningCarPosition[carPosition])
{
carLabel.Color = Color.Cyan;
WarningEnabled = true;
}
else
carLabel.Color = color;
if (car != PlayerTrain.Cars.Last())
scrollbox.AddHorizontalSeparator();
carPosition++;
}
// Recount
var tempspacerRowCount = line.Controls.Where(c => c is Spacer).Count();
var templocoRowCount = line.Controls.Where(c => c is Label).Count();
var tempsymbolsRowCount = line.Controls.Where(c => c is Image).Count();
SpacerRowCount = SpacerRowCount < tempspacerRowCount ? tempspacerRowCount : SpacerRowCount;
LocoRowCount = LocoRowCount < templocoRowCount ? templocoRowCount : LocoRowCount;
SymbolsRowCount = SymbolsRowCount < tempsymbolsRowCount ? tempsymbolsRowCount : SymbolsRowCount;
}
Client = ControlLayoutScrollboxVertical.NewClient;
RowsCount = Client.Controls.Where(c => c is ControlLayoutHorizontal).Count();
SeparatorCount = Client.Controls.Where(c => c is Separator).Count();
}
}
return Vbox;
}
public void topCarPositionVisible()
{ // Allows to find the last carposition, visible at the window bottom.
if ((!LastRowVisible && LabelTop >= 0) || LabelTop > DisplaySizeY)
{
for (int carPosition = 0; carPosition < RowsCount; carPosition++)
{
var labelTop = carPosition * RowHeight;
if (labelTop > Vbox.Position.Height - Owner.TextFontDefault.Height)
{
if (!LastRowVisible && labelTop > 0)
{
LastRowVisible = true;
CarPositionVisible = carPosition - 1;
OldPositionHeight = Vbox.Position.Height;
break;
}
}
}
}
}
public void localScrollLayout(int selectedCarPosition)
{
var trainCarViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
LocalScrollPosition = 0;
if (CarPositionVisible > 0 && selectedCarPosition >= CarPositionVisible)// Not related with CarID
{
Client = ControlLayoutScrollboxVertical.NewClient;
var xcarPosition = CarPositionVisible;
while (selectedCarPosition != xcarPosition)
{
SetScrollPosition(LocalScrollPosition + RowHeight);
xcarPosition++;
}
CurrentCarPosition = trainCarViewer.CarPosition;// Not related with CarID
}
}
public int ScrollSize
{
get
{
return Client.CurrentTop - Vbox.Position.Height;
}
}
public void SetScrollPosition(int position)
{
position = Math.Max(0, Math.Min(Math.Max(0, ScrollSize), position));
Client.MoveBy(0, LocalScrollPosition - position);
LocalScrollPosition = position;
}
void carLabel_Click(Control arg1, Point arg2)
{
}
public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
{
base.PrepareFrame(elapsedTime, updateFull);
if (updateFull)
{
var trainCarViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
var carOperations = Owner.Viewer.CarOperationsWindow;
trainCarViewer.TrainCarOperationsChanged = !trainCarViewer.Visible && trainCarViewer.TrainCarOperationsChanged ? false : trainCarViewer.TrainCarOperationsChanged;
CurrentDisplaySizeY = DisplaySizeY;
if (Owner.Viewer.DisplaySize.Y != DisplaySizeY || ModifiedSetting || trainCarViewer.CouplerChanged)
{
LastRowVisible = false;
SupplyStatusChanged = false;
Layout();
updateLayoutSize();
}
if (OldPositionHeight != Vbox.Position.Height)
{
LastRowVisible = false;
topCarPositionVisible();
localScrollLayout(SelectedCarPosition);
}
UserCommand ? controlDiesel = GetPressedKey(UserCommand.ControlDieselHelper, UserCommand.ControlDieselPlayer, UserCommand.ControlInitializeBrakes);
if (controlDiesel == UserCommand.ControlDieselHelper || controlDiesel == UserCommand.ControlDieselPlayer || controlDiesel == UserCommand.ControlInitializeBrakes)
{
Layout();
PowerSupplyStatus = Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus();
ModifiedSetting = true;
}
var carsCountChanged = Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars;
if (PlayerTrain != Owner.Viewer.PlayerTrain || carsCountChanged || (Owner.Viewer.PlayerLocomotive != null &&
LastPlayerLocomotiveFlippedState != Owner.Viewer.PlayerLocomotive.Flipped))
{
PlayerTrain = Owner.Viewer.PlayerTrain;
if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count || !LayoutUpdated)
{
LayoutUpdated = true;
Layout();
localScrollLayout(SelectedCarPosition);
updateLayoutSize();
ModifiedSetting = carsCountChanged;
}
LastPlayerTrainCars = Owner.Viewer.PlayerTrain.Cars.Count;
if (Owner.Viewer.PlayerLocomotive != null) LastPlayerLocomotiveFlippedState = Owner.Viewer.PlayerLocomotive.Flipped;
}
// Updates power supply status
else if (SelectedCarPosition <= CarPositionVisible && SelectedCarPosition == CarPosition)
{
var powerSupplyStatusChanged = PowerSupplyStatus != null && PowerSupplyStatus != Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus();
var batteyStatusChanged = BatteryStatus != null && BatteryStatus != Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus();
var circuitBreakerStateChanged = CircuitBreakerState != null && CircuitBreakerState != (Owner.Viewer.PlayerTrain.Cars[CarPosition] as MSTSElectricLocomotive).ElectricPowerSupply.CircuitBreaker.State.ToString();
if (powerSupplyStatusChanged || batteyStatusChanged || circuitBreakerStateChanged)
{
var Status = Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus();
if (Status != null && Status != PowerSupplyStatus)
{
PowerSupplyStatus = Status;
Layout();
}
}
}
if (trainCarViewer.TrainCarOperationsChanged || trainCarViewer.TrainCarOperationsChanged || trainCarViewer.RearBrakeHoseChanged
|| trainCarViewer.FrontBrakeHoseChanged || ModifiedSetting || CarIdClicked || carOperations.CarOperationChanged)
{
Layout();
localScrollLayout(SelectedCarPosition);
updateLayoutSize();
ModifiedSetting = false;
CarIdClicked = false;
// Avoids bug
trainCarViewer.TrainCarOperationsChanged = WarningEnabled;
carOperations.CarOperationChanged = carOperations.Visible && carOperations.CarOperationChanged;
}
if (CarPosition != trainCarViewer.CarPosition && Owner.Viewer.TrainCarOperationsWebpage.Connections > 0)
{
// Required to scroll the main window from the web version
UpdateTrainCarOperation = true;
CarPosition = trainCarViewer.CarPosition;
LabelTop = LabelPositionTop[SelectedCarPosition];
Layout();
localScrollLayout(SelectedCarPosition);
}
//Resize this window after the font has been changed externally
else if (MultiPlayerWindow.FontChanged)
{
MultiPlayerWindow.FontChanged = false;
FontToBold = !FontToBold;
UpdateWindowSize();
}
}
}
public void updateWarningCarPosition(int carPosition, Texture2D texture, Texture2D symbolSet)
{
var trainCarOperations = Owner.Viewer.TrainCarOperationsWindow;
if (!trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.WarningCarPosition[carPosition] = texture == symbolSet;
}
}
private static UserCommand? GetPressedKey(params UserCommand[] keysToTest) => keysToTest
.Where((UserCommand key) => UserInput.IsDown(key))
.FirstOrDefault();
}
class buttonArrowRight : Image
{
readonly Viewer Viewer;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly int CarPosition;
public buttonArrowRight(int x, int y, int size, Viewer viewer, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
CarPosition = carPosition;
// Coupler changed requires to modify the arrow position
var trainCarViewerCarPosition = TrainCarViewer.CouplerChanged ? TrainCarViewer.NewCarPosition : TrainCarViewer.CarPosition;
if (TrainCarViewer.CouplerChanged && trainCarViewerCarPosition == CarPosition)
{
Texture = TrainCarViewer.Visible ? Viewer.TrainCarOperationsWindow.AllSymbolsMode ? ArrowRight : ArrowLeft : Empty;
Viewer.TrainCarOperationsWindow.CarIdClicked = true;
TrainCarViewer.CarPosition = trainCarViewerCarPosition;
}
else
Texture = TrainCarViewer.Visible && trainCarViewerCarPosition == CarPosition? Viewer.TrainCarOperationsWindow.AllSymbolsMode ? ArrowRight : ArrowLeft : Empty;
Source = new Rectangle(0, 0, size, size);
Click += new Action<Control, Point>(buttonArrowRight_Click);
}
void buttonArrowRight_Click(Control arg1, Point arg2)
{
Viewer.TrainCarOperationsWindow.AllSymbolsMode = !Viewer.TrainCarOperationsWindow.AllSymbolsMode;
if (TrainCarViewer.Visible && TrainCarViewer.CarPosition == CarPosition)
{
Texture = Viewer.TrainCarOperationsWindow.AllSymbolsMode ? ArrowRight : ArrowLeft;
Viewer.TrainCarOperationsWindow.ModifiedSetting = true;
}
}
}
class buttonArrowLeft : Image
{
readonly Viewer Viewer;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly int CarPosition;
public buttonArrowLeft(int x, int y, int size, Viewer viewer, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
CarPosition = carPosition;
Texture = Empty;
// Coupler changed requires to modify arrow position
var trainCarViewerCarPosition = TrainCarViewer.CouplerChanged ? TrainCarViewer.NewCarPosition : TrainCarViewer.CarPosition;
if (TrainCarViewer.CouplerChanged && trainCarViewerCarPosition == CarPosition)
{
Texture = trainCarViewerCarPosition == CarPosition ? ArrowLeft : Empty;
Viewer.TrainCarOperationsWindow.CarIdClicked = true;
TrainCarViewer.CarPosition = trainCarViewerCarPosition;
}
else
Texture = trainCarViewerCarPosition == CarPosition ? ArrowLeft : Empty;
Source = new Rectangle(0, 0, size, size);
Click += new Action<Control, Point>(buttonArrowLeft_Click);
}
void buttonArrowLeft_Click(Control arg1, Point arg2)
{
FontChanged = true;
FontToBold = !FontToBold;
Viewer.TrainCarOperationsWindow.ModifiedSetting = true;
}
}
class buttonCouplerFront : Image
{
readonly Viewer Viewer;
readonly bool First;
public buttonCouplerFront(int x, int y, int size, Viewer viewer, TrainCar car)
: base(x, y, size, size)
{
Viewer = viewer;
First = car == Viewer.PlayerTrain.Cars.First();
Texture = First ? CouplerFront : Coupler;
Source = new Rectangle(0, 0, size, size);
}
}
class buttonCouplerRear : Image
{
readonly Viewer Viewer;
readonly bool Last;
public buttonCouplerRear(int x, int y, int size, Viewer viewer, TrainCar car)
: base(x, y, size, size)
{
Viewer = viewer;
Last = car == Viewer.PlayerTrain.Cars.Last();
Texture = Last ? CouplerRear : Coupler;
Source = new Rectangle(0, 0, size, size);
}
}
class buttonLoco : Label
{
readonly Viewer Viewer;
readonly CarOperationsWindow CarOperations;
readonly TrainCarOperationsWindow TrainCar;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly int CarPosition;
public buttonLoco(int x, int y, Viewer viewer, TrainCar car, int carPosition, LabelAlignment alignment)
: base(x, y, "", alignment)
{
Viewer = viewer;
CarOperations = Viewer.CarOperationsWindow;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
TrainCar = Viewer.TrainCarOperationsWindow;
CarPosition = carPosition;
Text = car.CarID;
Click += new Action<Control, Point>(buttonLabel_Click);
}
public void buttonLabel_Click(Control arg1, Point arg2)
{
Control control = arg1;
TrainCar.CarLabelText = Text;
TrainCarViewer.CarPosition = CarPosition;
TrainCarViewer.Visible = true;
TrainCar.CarIdClicked = true;
// required by localScrollLayout()
TrainCar.SelectedCarPosition = CarPosition;
TrainCar.LabelTop = control.Position.Top;
//Sync CarOperation
if (CarOperations.Visible)
CarOperations.CarPosition = CarPosition;
}
}
class buttonHandBrake : Image
{
readonly Viewer Viewer;
public buttonHandBrake(int x, int y, int size, Viewer viewer, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
Texture = (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).HandBrakePresent ? (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).GetTrainHandbrakeStatus() ? HandBrakeSet : HandBrakeNotSet : HandBrakeNotAvailable;
Source = new Rectangle(0, 0, size, size);
var trainCarOperations = Viewer.TrainCarOperationsWindow;
if (!trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.updateWarningCarPosition(carPosition, Texture, HandBrakeSet);
}
}
}
class buttonFrontBrakeHose : Image
{
readonly Viewer Viewer;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly CarOperationsWindow CarOperations;
readonly int CarPosition;
readonly bool First;
public buttonFrontBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
CarOperations = Viewer.CarOperationsWindow;
CarPosition = carPosition;
First = car == viewer.PlayerTrain.Cars.First();
Texture = First ? BrakeHoseFirstDis : (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected ? BrakeHoseCon : BrakeHoseDis;
// Allows compatibility with CarOperationWindow
var brakeHoseChanged = CarOperations.FrontBrakeHoseChanged || CarOperations.RearBrakeHoseChanged;
if (brakeHoseChanged && !TrainCarViewer.Visible && CarOperations.Visible && CarOperations.CarPosition >= 1 && CarOperations.CarPosition == CarPosition)
{
var rearBrakeHose = CarOperations.RearBrakeHoseChanged;
if (rearBrakeHose)
{
new WagonBrakeHoseRearConnectCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarOperations.CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarOperations.CarPosition] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected);
CarOperations.RearBrakeHoseChanged = false;
}
else
{
new WagonBrakeHoseRearConnectCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarOperations.CarPosition - 1] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarOperations.CarPosition - 1] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected);
CarOperations.FrontBrakeHoseChanged = false;
}
Viewer.TrainCarOperationsWindow.ModifiedSetting = true;
TrainCarViewer.TrainCarOperationsChanged = true;
}
// Updates from train operations viewer
var viewerCarposition = TrainCarViewer.CarPosition;
if (TrainCarViewer.Visible && TrainCarViewer.FrontBrakeHoseChanged && viewerCarposition >= 1)
{
new WagonBrakeHoseRearConnectCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[viewerCarposition - 1] as MSTSWagon), !(Viewer.PlayerTrain.Cars[viewerCarposition - 1] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected);
TrainCarViewer.FrontBrakeHoseChanged = false;
}
Source = new Rectangle(0, 0, size, size);
var trainCarOperations = Viewer.TrainCarOperationsWindow;
if (!First && !trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.updateWarningCarPosition(carPosition, Texture, BrakeHoseDis);
}
}
}
class buttonRearBrakeHose : Image
{
readonly Viewer Viewer;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly bool Last;
public buttonRearBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
Last = car == viewer.PlayerTrain.Cars.Last();
Texture = Last ? BrakeHoseLastDis : (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected ? BrakeHoseCon : BrakeHoseDis;
// Update from viewer
var viewerCarposition = TrainCarViewer.CarPosition;
if (TrainCarViewer.Visible && TrainCarViewer.RearBrakeHoseChanged && viewerCarposition < Viewer.PlayerTrain.Cars.Count - 1)
{
new WagonBrakeHoseConnectCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[viewerCarposition + 1] as MSTSWagon), !(Viewer.PlayerTrain.Cars[viewerCarposition + 1] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected);
TrainCarViewer.RearBrakeHoseChanged = false;
}
Source = new Rectangle(0, 0, size, size);
var trainCarOperations = Viewer.TrainCarOperationsWindow;
if (!Last && !trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.updateWarningCarPosition(carPosition, Texture, BrakeHoseDis);
}
}
}
class buttonFrontAngleCock : Image
{
readonly Viewer Viewer;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly bool First;
public buttonFrontAngleCock(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
First = car == viewer.PlayerTrain.Cars.First();
Texture = !TrainCarViewer.TrainCarOperationsChanged && First ? FrontAngleCockClosed : (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).BrakeSystem.AngleCockAOpen ? FrontAngleCockOpened : FrontAngleCockClosed;
Source = new Rectangle(0, 0, size, size);
var trainCarOperations = Viewer.TrainCarOperationsWindow;
if (!First && !trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.updateWarningCarPosition(carPosition, Texture, FrontAngleCockClosed);
}
}
}
class buttonRearAngleCock : Image
{
readonly Viewer Viewer;
readonly bool Last;
public buttonRearAngleCock(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
Last = car == viewer.PlayerTrain.Cars.Last();
Texture = Last ? RearAngleCockClosed : (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).BrakeSystem.AngleCockBOpen ? RearAngleCockOpened : RearAngleCockClosed;
Source = new Rectangle(0, 0, size, size);
var trainCarOperations = Viewer.TrainCarOperationsWindow;
if (!Last && !trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.updateWarningCarPosition(carPosition, Texture, RearAngleCockClosed);
}
}
}
class buttonBleedOffValve : Image
{
readonly Viewer Viewer;
readonly int CarPosition;
public buttonBleedOffValve(int x, int y, int size, Viewer viewer, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
CarPosition = carPosition;
var carOperationsPosition = Viewer.CarOperationsWindow.CarPosition;
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem is SingleTransferPipe
|| Viewer.PlayerTrain.Cars.Count() == 1)
{
Texture = BleedOffValveNotAvailable;
}
else
{
if (!Viewer.TrainCarOperationsViewerWindow.Visible && Viewer.CarOperationsWindow.Visible && CarPosition == carOperationsPosition)
Texture = (viewer.PlayerTrain.Cars[carOperationsPosition] as MSTSWagon).BrakeSystem.BleedOffValveOpen ? BleedOffValveOpened : BleedOffValveClosed;
else
Texture = (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).BrakeSystem.BleedOffValveOpen ? BleedOffValveOpened : BleedOffValveClosed;
}
Source = new Rectangle(0, 0, size, size);
var trainCarOperations = Viewer.TrainCarOperationsWindow;
if (!trainCarOperations.WarningCarPosition[carPosition])
{
trainCarOperations.updateWarningCarPosition(carPosition, Texture, BleedOffValveOpened);
}
}
}
class buttonTogglePower : Image
{
readonly Viewer Viewer;
readonly TrainCarOperationsWindow TrainCarOperations;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly int CarPosition;
public buttonTogglePower(int x, int y, int size, Viewer viewer, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
TrainCarOperations = Viewer.TrainCarOperationsWindow;
CarPosition = carPosition;
if ((Viewer.PlayerTrain.Cars[CarPosition] is MSTSElectricLocomotive)
|| (Viewer.PlayerTrain.Cars[CarPosition] is MSTSDieselLocomotive))
{
Texture = LocomotiveStatus(CarPosition);
if (CarPosition == TrainCarViewer.CarPosition)
{
MSTSLocomotive locomotive = Viewer.PlayerTrain.Cars[CarPosition] as MSTSLocomotive;
TrainCarOperations.MainPowerSupplyOn = locomotive.LocomotivePowerSupply.MainPowerSupplyOn;
}
}
else
Texture = Empty;
Source = new Rectangle(0, 0, size, size);
}
public Texture2D LocomotiveStatus(int CarPosition)
{
string locomotiveStatus = Viewer.PlayerTrain.Cars[CarPosition].GetStatus();
foreach (string data in locomotiveStatus.Split('\n').Where((string d) => !string.IsNullOrWhiteSpace(d)))
{
string[] parts = data.Split(new string[] { " = " }, 2, StringSplitOptions.None);
string keyPart = parts[0];
string valuePart = parts?[1];
if (keyPart.Contains(Viewer.Catalog.GetString("Engine")))
{
TrainCarOperations.PowerSupplyStatus = locomotiveStatus;
Texture = valuePart.Contains(Viewer.Catalog.GetString("Running")) ? PowerOn
: valuePart.Contains(Viewer.Catalog.GetString("Stopped")) ? PowerOff
: PowerChanging;
if (CarPosition == TrainCarViewer.CarPosition)
{
TrainCarOperations.PowerSupplyUpdating = Texture == PowerChanging;
}
break;
}
else if (keyPart.Contains(Viewer.Catalog.GetString("Power")))
{
TrainCarViewer.PowerSupplyStatus = locomotiveStatus;
var powerStatus = valuePart.Contains(Viewer.Catalog.GetString("On"));
Texture = powerStatus ? PowerOn : PowerOff;
if (CarPosition == TrainCarViewer.CarPosition)
TrainCarOperations.SupplyStatusChanged = TrainCarOperations.MainPowerSupplyOn != powerStatus;
break;
}
}
return Texture;
}
}
class buttonToggleMU : Image
{
readonly Viewer Viewer;
readonly int CarPosition;
public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
: base(x, y, size, size)
{
Viewer = viewer;
CarPosition = carPosition;
var multipleUnitsConfiguration = Viewer.PlayerLocomotive.GetMultipleUnitsConfiguration();
if ((Viewer.PlayerTrain.Cars[CarPosition] is MSTSDieselLocomotive) && multipleUnitsConfiguration != null)
{
Texture = (Viewer.PlayerTrain.Cars[CarPosition] as MSTSLocomotive).RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ? MUconnected : MUdisconnected;
}
else
{
Texture = Empty;
}
Source = new Rectangle(0, 0, size, size);
}