@@ -234,48 +234,61 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
234
234
if ( UserInput . IsPressed ( UserCommand . DebugResetWheelSlip ) ) { Locomotive . Train . SignalEvent ( Event . _ResetWheelSlip ) ; }
235
235
if ( UserInput . IsPressed ( UserCommand . DebugToggleAdvancedAdhesion ) ) { Locomotive . Train . SignalEvent ( Event . _ResetWheelSlip ) ; Locomotive . Simulator . UseAdvancedAdhesion = ! Locomotive . Simulator . UseAdvancedAdhesion ; }
236
236
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 )
254
258
Locomotive . SetDirection ( Direction . Forward ) ;
255
- else if ( UserInput . RDState . DirectionPercent < - 50 )
259
+ else if ( external . Direction . Value < - 0.5f )
256
260
Locomotive . SetDirection ( Direction . Reverse ) ;
257
261
else
258
262
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
+ {
267
267
// 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 )
269
269
{
270
270
Locomotive . Headlight ++ ;
271
271
Locomotive . SignalEvent ( Event . LightSwitchToggle ) ;
272
272
}
273
- if ( Locomotive . Headlight > UserInput . RDState . Lights - 1 )
273
+ if ( Locomotive . Headlight > external . Lights . Value - 1 )
274
274
{
275
275
Locomotive . Headlight -- ;
276
276
Locomotive . SignalEvent ( Event . LightSwitchToggle ) ;
277
277
}
278
278
}
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
+ }
279
292
}
280
293
281
294
foreach ( var command in UserInputCommands . Keys )
@@ -1973,7 +1986,7 @@ public class CabViewDiscreteRenderer : CabViewControlRenderer, ICabViewMouseCont
1973
1986
/// <summary>
1974
1987
/// Function calculating response value for mouse events (movement, left-click), determined by configured style.
1975
1988
/// </summary>
1976
- readonly Func < float , float > ChangedValue ;
1989
+ public Func < float , float > ChangedValue ;
1977
1990
1978
1991
public CabViewDiscreteRenderer ( Viewer viewer , MSTSLocomotive locomotive , CVCWithFrames control , CabShader shader )
1979
1992
: base ( viewer , locomotive , control , shader )
0 commit comments