@@ -234,48 +234,61 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
234234 if ( UserInput . IsPressed ( UserCommand . DebugResetWheelSlip ) ) { Locomotive . Train . SignalEvent ( Event . _ResetWheelSlip ) ; }
235235 if ( UserInput . IsPressed ( UserCommand . DebugToggleAdvancedAdhesion ) ) { Locomotive . Train . SignalEvent ( Event . _ResetWheelSlip ) ; Locomotive . Simulator . UseAdvancedAdhesion = ! Locomotive . Simulator . UseAdvancedAdhesion ; }
236236
237- if ( UserInput . RDState != null )
238- {
239- if ( UserInput . RDState . BailOff )
240- {
241- Locomotive . SetBailOff ( true ) ;
242- }
243- if ( UserInput . RDState . Changed )
244- {
245- Locomotive . AlerterReset ( ) ;
246-
247- Locomotive . SetThrottlePercentWithSound ( UserInput . RDState . ThrottlePercent ) ;
248- Locomotive . SetTrainBrakePercent ( UserInput . RDState . TrainBrakePercent ) ;
249- Locomotive . SetEngineBrakePercent ( UserInput . RDState . EngineBrakePercent ) ;
250- // Locomotive.SetBrakemanBrakePercent(UserInput.RDState.BrakemanBrakePercent); // For Raildriver control not complete for this value?
251- if ( Locomotive . CombinedControlType != MSTSLocomotive . CombinedControl . ThrottleAir )
252- Locomotive . SetDynamicBrakePercentWithSound ( UserInput . RDState . DynamicBrakePercent ) ;
253- if ( UserInput . RDState . DirectionPercent > 50 )
237+ ExternalDeviceState [ ] externalDevices = { UserInput . RDState , UserInput . WebDeviceState } ;
238+ foreach ( var external in externalDevices )
239+ {
240+ if ( external == null ) continue ;
241+ if ( external . Throttle . Changed )
242+ Locomotive . SetThrottlePercentWithSound ( external . Throttle . Value * 100 ) ;
243+ if ( external . TrainBrake . Changed )
244+ Locomotive . SetTrainBrakePercent ( external . TrainBrake . Value * 100 ) ;
245+ if ( external . EngineBrake . Changed )
246+ Locomotive . SetEngineBrakePercent ( external . EngineBrake . Value * 100 ) ;
247+ // Locomotive.SetBrakemanBrakePercent(external.BrakemanBrakePercent); // For Raildriver control not complete for this value?
248+ if ( external . DynamicBrake . Changed && Locomotive . CombinedControlType != MSTSLocomotive . CombinedControl . ThrottleAir )
249+ Locomotive . SetDynamicBrakePercentWithSound ( external . DynamicBrake . Value * 100 ) ;
250+
251+ if ( external . Direction . Changed )
252+ {
253+ if ( Locomotive is MSTSSteamLocomotive steam )
254+ {
255+ steam . SetCutoffPercent ( UserInput . RDState . Direction . Value * 100 ) ;
256+ }
257+ else if ( external . Direction . Value > 0.5f )
254258 Locomotive . SetDirection ( Direction . Forward ) ;
255- else if ( UserInput . RDState . DirectionPercent < - 50 )
259+ else if ( external . Direction . Value < - 0.5f )
256260 Locomotive . SetDirection ( Direction . Reverse ) ;
257261 else
258262 Locomotive . SetDirection ( Direction . N ) ;
259- if ( UserInput . RDState . Emergency )
260- new EmergencyPushButtonCommand ( Viewer . Log , true ) ;
261- else
262- new EmergencyPushButtonCommand ( Viewer . Log , false ) ;
263- if ( UserInput . RDState . Wipers == 1 && Locomotive . Wiper )
264- Locomotive . SignalEvent ( Event . WiperOff ) ;
265- if ( UserInput . RDState . Wipers != 1 && ! Locomotive . Wiper )
266- Locomotive . SignalEvent ( Event . WiperOn ) ;
263+ }
264+
265+ if ( external . Lights . Changed )
266+ {
267267 // changing Headlight more than one step at a time doesn't work for some reason
268- if ( Locomotive . Headlight < UserInput . RDState . Lights - 1 )
268+ if ( Locomotive . Headlight < external . Lights . Value - 1 )
269269 {
270270 Locomotive . Headlight ++ ;
271271 Locomotive . SignalEvent ( Event . LightSwitchToggle ) ;
272272 }
273- if ( Locomotive . Headlight > UserInput . RDState . Lights - 1 )
273+ if ( Locomotive . Headlight > external . Lights . Value - 1 )
274274 {
275275 Locomotive . Headlight -- ;
276276 Locomotive . SignalEvent ( Event . LightSwitchToggle ) ;
277277 }
278278 }
279+ // Handle other cabcontrols
280+ foreach ( var kvp in external . CabControls )
281+ {
282+ if ( _CabRenderer == null ) break ;
283+ if ( ! kvp . Value . Changed ) continue ;
284+ if ( _CabRenderer . ControlMap . TryGetValue ( kvp . Key , out var renderer ) && renderer is CabViewDiscreteRenderer discrete )
285+ {
286+ var oldChanged = discrete . ChangedValue ;
287+ discrete . ChangedValue = ( val ) => kvp . Value . Value ;
288+ discrete . HandleUserInput ( ) ;
289+ discrete . ChangedValue = oldChanged ;
290+ }
291+ }
279292 }
280293
281294 foreach ( var command in UserInputCommands . Keys )
@@ -1973,7 +1986,7 @@ public class CabViewDiscreteRenderer : CabViewControlRenderer, ICabViewMouseCont
19731986 /// <summary>
19741987 /// Function calculating response value for mouse events (movement, left-click), determined by configured style.
19751988 /// </summary>
1976- readonly Func < float , float > ChangedValue ;
1989+ public Func < float , float > ChangedValue ;
19771990
19781991 public CabViewDiscreteRenderer ( Viewer viewer , MSTSLocomotive locomotive , CVCWithFrames control , CabShader shader )
19791992 : base ( viewer , locomotive , control , shader )
0 commit comments