2020using Microsoft . Xna . Framework ;
2121using Orts . Common ;
2222using Orts . Simulation . RollingStocks ;
23+ using Orts . Simulation . RollingStocks . SubSystems . Brakes ;
2324using Orts . Simulation . RollingStocks . SubSystems . Brakes . MSTS ;
2425using Orts . Simulation . RollingStocks . SubSystems . PowerSupplies ;
2526using ORTS . Common ;
@@ -38,48 +39,176 @@ public int CarPosition
3839 }
3940
4041 public CarOperationsWindow ( WindowManager owner )
41- : base ( owner , Window . DecorationSize . X + owner . TextFontDefault . Height * 19 , Window . DecorationSize . Y + owner . TextFontDefault . Height * 11 + ControlLayout . SeparatorSize * 10 , Viewer . Catalog . GetString ( "Car Operation Menu" ) )
42+ : base ( owner , Window . DecorationSize . X + owner . TextFontDefault . Height * 20 , Window . DecorationSize . Y + owner . TextFontDefault . Height * 12 + ControlLayout . SeparatorSize * 11 , Viewer . Catalog . GetString ( "Car Operation Menu" ) )
4243 {
4344 Viewer = owner . Viewer ;
4445 }
4546
4647 protected override ControlLayout Layout ( ControlLayout layout )
4748 {
48- Label ID , buttonHandbrake , buttonTogglePower , buttonToggleMU , buttonToggleBatterySwitch , buttonToggleElectricTrainSupplyCable , buttonToggleBrakeHose , buttonToggleAngleCockA , buttonToggleAngleCockB , buttonToggleBleedOffValve , buttonClose ;
49+ Label ID , buttonHandbrake , buttonTogglePower , buttonToggleMU , buttonToggleBatterySwitch , buttonToggleElectricTrainSupplyCable , buttonToggleFrontBrakeHose , buttonToggleRearBrakeHose , buttonToggleAngleCockA , buttonToggleAngleCockB , buttonToggleBleedOffValve , buttonClose ;
4950
51+ TrainCar trainCar = Viewer . PlayerTrain . Cars [ CarPosition ] ;
52+ BrakeSystem brakeSystem = ( trainCar as MSTSWagon ) . BrakeSystem ;
53+ MSTSLocomotive locomotive = trainCar as MSTSLocomotive ;
54+ MSTSWagon wagon = trainCar as MSTSWagon ;
55+
56+ BrakeSystem rearBrakeSystem = null ;
57+ if ( CarPosition + 1 < Viewer . PlayerTrain . Cars . Count )
58+ {
59+ TrainCar rearTrainCar = Viewer . PlayerTrain . Cars [ CarPosition + 1 ] ;
60+ rearBrakeSystem = ( rearTrainCar as MSTSWagon ) . BrakeSystem ;
61+ }
62+
63+ bool isElectricDieselLocomotive = ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSElectricLocomotive ) || ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSDieselLocomotive ) ;
64+
5065 var vbox = base . Layout ( layout ) . AddLayoutVertical ( ) ;
51- vbox . Add ( ID = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Car ID" ) + " " + ( CarPosition >= Viewer . PlayerTrain . Cars . Count ? " " : Viewer . PlayerTrain . Cars [ CarPosition ] . CarID ) , LabelAlignment . Center ) ) ;
66+ vbox . Add ( ID = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Car ID" ) + " " + ( CarPosition >= Viewer . PlayerTrain . Cars . Count ? " " : Viewer . PlayerTrain . Cars [ CarPosition ] . CarID ) , LabelAlignment . Center ) ) ;
5267 ID . Color = Color . Red ;
5368 vbox . AddHorizontalSeparator ( ) ;
54- vbox . Add ( buttonHandbrake = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Toggle Handbrake" ) , LabelAlignment . Center ) ) ;
69+
70+ // Handbrake
71+ string buttonHandbrakeText = "" ;
72+ if ( ( trainCar as MSTSWagon ) . GetTrainHandbrakeStatus ( ) )
73+ buttonHandbrakeText = Viewer . Catalog . GetString ( "Unset Handbrake" ) ;
74+ else
75+ buttonHandbrakeText = Viewer . Catalog . GetString ( "Set Handbrake" ) ;
76+ vbox . Add ( buttonHandbrake = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , buttonHandbrakeText , LabelAlignment . Center ) ) ;
5577 vbox . AddHorizontalSeparator ( ) ;
56- vbox . Add ( buttonTogglePower = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Toggle Power" ) , LabelAlignment . Center ) ) ;
78+
79+ // Power Supply
80+ if ( locomotive != null )
81+ if ( locomotive . LocomotivePowerSupply . MainPowerSupplyOn )
82+ vbox . Add ( buttonTogglePower = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Power Off" ) , LabelAlignment . Center ) ) ;
83+ else
84+ vbox . Add ( buttonTogglePower = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Power On" ) , LabelAlignment . Center ) ) ;
85+ else
86+ vbox . Add ( buttonTogglePower = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Power On" ) , LabelAlignment . Center ) ) ;
5787 vbox . AddHorizontalSeparator ( ) ;
58- vbox . Add ( buttonToggleMU = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Toggle MU Connection" ) , LabelAlignment . Center ) ) ;
88+
89+ // MU Connection
90+ if ( ( locomotive != null ) && ( locomotive . RemoteControlGroup >= 0 ) )
91+ vbox . Add ( buttonToggleMU = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Disconnect MU Connection" ) , LabelAlignment . Center ) ) ;
92+ else
93+ vbox . Add ( buttonToggleMU = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Connect MU Connection" ) , LabelAlignment . Center ) ) ;
5994 vbox . AddHorizontalSeparator ( ) ;
60- vbox . Add ( buttonToggleBatterySwitch = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Toggle Battery Switch" ) , LabelAlignment . Center ) ) ;
95+
96+ // Battery Switch
97+ if ( ( wagon != null ) && ( wagon . PowerSupply is IPowerSupply ) && ( wagon . PowerSupply . BatterySwitch . On ) )
98+ vbox . Add ( buttonToggleBatterySwitch = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Battery Switch Off" ) , LabelAlignment . Center ) ) ;
99+ else
100+ vbox . Add ( buttonToggleBatterySwitch = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Battery Switch On" ) , LabelAlignment . Center ) ) ;
101+ vbox . AddHorizontalSeparator ( ) ;
102+
103+ // Electric Train Supply Connection
104+ if ( ( wagon . PowerSupply != null ) && wagon . PowerSupply . FrontElectricTrainSupplyCableConnected )
105+ vbox . Add ( buttonToggleElectricTrainSupplyCable = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Disonnect Electric Train Supply" ) , LabelAlignment . Center ) ) ;
106+ else
107+ vbox . Add ( buttonToggleElectricTrainSupplyCable = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Connect Electric Train Supply" ) , LabelAlignment . Center ) ) ;
61108 vbox . AddHorizontalSeparator ( ) ;
62- vbox . Add ( buttonToggleElectricTrainSupplyCable = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Toggle Electric Train Supply Connection" ) , LabelAlignment . Center ) ) ;
109+
110+ // Front Brake Hose
111+ string buttonToggleFronBrakeHoseText = "" ;
112+ if ( brakeSystem . FrontBrakeHoseConnected )
113+ buttonToggleFronBrakeHoseText = Viewer . Catalog . GetString ( "Disconnect Front Brake Hose" ) ;
114+ else
115+ buttonToggleFronBrakeHoseText = Viewer . Catalog . GetString ( "Connect Front Brake Hose" ) ;
116+ vbox . Add ( buttonToggleFrontBrakeHose = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , buttonToggleFronBrakeHoseText , LabelAlignment . Center ) ) ;
63117 vbox . AddHorizontalSeparator ( ) ;
64- vbox . Add ( buttonToggleBrakeHose = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Toggle Brake Hose Connection" ) , LabelAlignment . Center ) ) ;
118+
119+ // Rear Brake Hose
120+ string buttonToggleRearBrakeHoseText = "" ;
121+ if ( ( ( CarPosition + 1 ) < Viewer . PlayerTrain . Cars . Count ) && ( rearBrakeSystem . FrontBrakeHoseConnected ) )
122+ buttonToggleRearBrakeHoseText = Viewer . Catalog . GetString ( "Disconnect Rear Brake Hose" ) ;
123+ else
124+ buttonToggleRearBrakeHoseText = Viewer . Catalog . GetString ( "Connect Rear Brake Hose" ) ;
125+ vbox . Add ( buttonToggleRearBrakeHose = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , buttonToggleRearBrakeHoseText , LabelAlignment . Center ) ) ;
65126 vbox . AddHorizontalSeparator ( ) ;
66- vbox . Add ( buttonToggleAngleCockA = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Open/Close Front Angle Cock" ) , LabelAlignment . Center ) ) ;
127+
128+ // Front Angle Cock
129+ string buttonToggleAngleCockAText = "" ;
130+ if ( brakeSystem . AngleCockAOpen )
131+ buttonToggleAngleCockAText = Viewer . Catalog . GetString ( "Close Front Angle Cock" ) ;
132+ else
133+ buttonToggleAngleCockAText = Viewer . Catalog . GetString ( "Open Front Angle Cock" ) ;
134+ vbox . Add ( buttonToggleAngleCockA = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , buttonToggleAngleCockAText , LabelAlignment . Center ) ) ;
67135 vbox . AddHorizontalSeparator ( ) ;
68- vbox . Add ( buttonToggleAngleCockB = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Open/Close Rear Angle Cock" ) , LabelAlignment . Center ) ) ;
136+
137+ // Rear Angle Cock
138+ string buttonToggleAngleCockBText = "" ;
139+ if ( brakeSystem . AngleCockBOpen )
140+ buttonToggleAngleCockBText = Viewer . Catalog . GetString ( "Close Rear Angle Cock" ) ;
141+ else
142+ buttonToggleAngleCockBText = Viewer . Catalog . GetString ( "Open Rear Angle Cock" ) ;
143+ vbox . Add ( buttonToggleAngleCockB = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , buttonToggleAngleCockBText , LabelAlignment . Center ) ) ;
69144 vbox . AddHorizontalSeparator ( ) ;
70- vbox . Add ( buttonToggleBleedOffValve = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Open/Close Bleed Off Valve" ) , LabelAlignment . Center ) ) ;
145+
146+ // Bleed Off Valve
147+ string buttonToggleBleedOffValveAText = "" ;
148+ if ( brakeSystem . BleedOffValveOpen )
149+ buttonToggleBleedOffValveAText = Viewer . Catalog . GetString ( "Close Bleed Off Valve" ) ;
150+ else
151+ buttonToggleBleedOffValveAText = Viewer . Catalog . GetString ( "Open Bleed Off Valve" ) ;
152+ vbox . Add ( buttonToggleBleedOffValve = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , buttonToggleBleedOffValveAText , LabelAlignment . Center ) ) ;
71153 vbox . AddHorizontalSeparator ( ) ;
154+
155+ // Close button
72156 vbox . Add ( buttonClose = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , Viewer . Catalog . GetString ( "Close window" ) , LabelAlignment . Center ) ) ;
73157
74- buttonHandbrake . Click += new Action < Control , Point > ( buttonHandbrake_Click ) ;
75- buttonTogglePower . Click += new Action < Control , Point > ( buttonTogglePower_Click ) ;
76- buttonToggleMU . Click += new Action < Control , Point > ( buttonToggleMU_Click ) ;
77- buttonToggleBatterySwitch . Click += new Action < Control , Point > ( buttonToggleBatterySwitch_Click ) ;
78- buttonToggleElectricTrainSupplyCable . Click += new Action < Control , Point > ( buttonToggleElectricTrainSupplyCable_Click ) ;
79- buttonToggleBrakeHose . Click += new Action < Control , Point > ( buttonToggleBrakeHose_Click ) ;
158+ // add click controls
159+
160+ // Handbrake
161+ if ( ( trainCar as MSTSWagon ) . HandBrakePresent )
162+ buttonHandbrake . Click += new Action < Control , Point > ( buttonHandbrake_Click ) ;
163+ else
164+ buttonHandbrake . Color = Color . Gray ;
165+
166+ // Power Supply
167+ if ( isElectricDieselLocomotive )
168+ buttonTogglePower . Click += new Action < Control , Point > ( buttonTogglePower_Click ) ;
169+ else
170+ buttonTogglePower . Color = Color . Gray ;
171+
172+ // MU Connection
173+ if ( isElectricDieselLocomotive )
174+ buttonToggleMU . Click += new Action < Control , Point > ( buttonToggleMU_Click ) ;
175+ else
176+ buttonToggleMU . Color = Color . Gray ;
177+
178+ // Battery Switch
179+ if ( ( wagon != null ) && ( wagon . PowerSupply is IPowerSupply ) )
180+ buttonToggleBatterySwitch . Click += new Action < Control , Point > ( buttonToggleBatterySwitch_Click ) ;
181+ else
182+ buttonToggleBatterySwitch . Color = Color . Gray ;
183+
184+ // Electric Train Supply Connection
185+ if ( ( wagon != null ) && ( wagon . PowerSupply != null ) )
186+ buttonToggleElectricTrainSupplyCable . Click += new Action < Control , Point > ( buttonToggleElectricTrainSupplyCable_Click ) ;
187+ else
188+ buttonToggleElectricTrainSupplyCable . Color = Color . Gray ;
189+
190+ // Front Brake Hose
191+ if ( CarPosition > 0 )
192+ buttonToggleFrontBrakeHose . Click += new Action < Control , Point > ( buttonToggleFrontBrakeHose_Click ) ;
193+ else
194+ buttonToggleFrontBrakeHose . Color = Color . Gray ;
195+
196+ // Rear Brake Hose
197+ if ( CarPosition < ( Viewer . PlayerTrain . Cars . Count - 1 ) )
198+ buttonToggleRearBrakeHose . Click += new Action < Control , Point > ( buttonToggleRearBrakeHose_Click ) ;
199+ else
200+ buttonToggleRearBrakeHose . Color = Color . Gray ;
201+
202+ // Front Angle Cock
80203 buttonToggleAngleCockA . Click += new Action < Control , Point > ( buttonToggleAngleCockA_Click ) ;
204+
205+ // Rear Angle Cock
81206 buttonToggleAngleCockB . Click += new Action < Control , Point > ( buttonToggleAngleCockB_Click ) ;
207+
208+ // Bleed Off Valve
82209 buttonToggleBleedOffValve . Click += new Action < Control , Point > ( buttonToggleBleedOffValve_Click ) ;
210+
211+ // Close button
83212 buttonClose . Click += new Action < Control , Point > ( buttonClose_Click ) ;
84213
85214 return vbox ;
@@ -174,7 +303,7 @@ void buttonToggleElectricTrainSupplyCable_Click(Control arg1, Point arg2)
174303 }
175304 }
176305
177- void buttonToggleBrakeHose_Click ( Control arg1 , Point arg2 )
306+ void buttonToggleFrontBrakeHose_Click ( Control arg1 , Point arg2 )
178307 {
179308 new WagonBrakeHoseConnectCommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . FrontBrakeHoseConnected ) ;
180309 if ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . FrontBrakeHoseConnected )
@@ -183,6 +312,15 @@ void buttonToggleBrakeHose_Click(Control arg1, Point arg2)
183312 Viewer . Simulator . Confirmer . Information ( Viewer . Catalog . GetString ( "Front brake hose disconnected" ) ) ;
184313 }
185314
315+ void buttonToggleRearBrakeHose_Click ( Control arg1 , Point arg2 )
316+ {
317+ new WagonBrakeHoseConnectCommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarPosition + 1 ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarPosition + 1 ] as MSTSWagon ) . BrakeSystem . FrontBrakeHoseConnected ) ;
318+ if ( ( Viewer . PlayerTrain . Cars [ CarPosition + 1 ] as MSTSWagon ) . BrakeSystem . FrontBrakeHoseConnected )
319+ Viewer . Simulator . Confirmer . Information ( Viewer . Catalog . GetString ( "Rear brake hose connected" ) ) ;
320+ else
321+ Viewer . Simulator . Confirmer . Information ( Viewer . Catalog . GetString ( "Rear brake hose disconnected" ) ) ;
322+ }
323+
186324 void buttonToggleAngleCockA_Click ( Control arg1 , Point arg2 )
187325 {
188326 new ToggleAngleCockACommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockAOpen ) ;
0 commit comments