@@ -59,6 +59,13 @@ public class MSTSLocomotiveViewer : MSTSWagonViewer
5959 public bool lemergencybuttonpressed = false ;
6060 CruiseControlViewer CruiseControlViewer ;
6161
62+ public Dictionary < CABViewControlTypes , UserCommand [ ] > UserCommandControlTypes = new Dictionary < CABViewControlTypes , UserCommand [ ] > ( ) ;
63+
64+ private bool IsMouseWheelChanged ;
65+ private DateTime MouseWheelChangedTime ;
66+ private int MouseWheelClicks ;
67+ private UserCommand MouseWheelCommand ;
68+
6269 public MSTSLocomotiveViewer ( Viewer viewer , MSTSLocomotive car )
6370 : base ( viewer , car )
6471 {
@@ -142,19 +149,33 @@ public override void InitializeUserInputCommands()
142149 // Steam locomotives handle these differently, and might have set them already
143150 if ( ! UserInputCommands . ContainsKey ( UserCommand . ControlForwards ) )
144151 UserInputCommands . Add ( UserCommand . ControlForwards , new Action [ ] { Noop , ( ) => ReverserControlForwards ( ) } ) ;
152+
145153 if ( ! UserInputCommands . ContainsKey ( UserCommand . ControlBackwards ) )
154+ {
146155 UserInputCommands . Add ( UserCommand . ControlBackwards , new Action [ ] { Noop , ( ) => ReverserControlBackwards ( ) } ) ;
156+ UserCommandControlTypes . Add ( CABViewControlTypes . DIRECTION , new UserCommand [ ] { UserCommand . ControlForwards , UserCommand . ControlBackwards } ) ;
157+ }
147158
148159 UserInputCommands . Add ( UserCommand . ControlThrottleIncrease , new Action [ ] { ( ) => Locomotive . StopThrottleIncrease ( ) , ( ) => Locomotive . StartThrottleIncrease ( ) } ) ;
149160 UserInputCommands . Add ( UserCommand . ControlThrottleDecrease , new Action [ ] { ( ) => Locomotive . StopThrottleDecrease ( ) , ( ) => Locomotive . StartThrottleDecrease ( ) } ) ;
161+ UserCommandControlTypes . Add ( CABViewControlTypes . THROTTLE , new UserCommand [ ] { UserCommand . ControlThrottleIncrease , UserCommand . ControlThrottleDecrease } ) ;
162+ UserCommandControlTypes . Add ( CABViewControlTypes . CP_HANDLE , new UserCommand [ ] { UserCommand . ControlThrottleIncrease , UserCommand . ControlThrottleDecrease } ) ;
163+
150164 UserInputCommands . Add ( UserCommand . ControlThrottleZero , new Action [ ] { Noop , ( ) => Locomotive . ThrottleToZero ( ) } ) ;
165+
151166 UserInputCommands . Add ( UserCommand . ControlGearUp , new Action [ ] { ( ) => StopGearBoxIncrease ( ) , ( ) => StartGearBoxIncrease ( ) } ) ;
152167 UserInputCommands . Add ( UserCommand . ControlGearDown , new Action [ ] { ( ) => StopGearBoxDecrease ( ) , ( ) => StartGearBoxDecrease ( ) } ) ;
168+
153169 UserInputCommands . Add ( UserCommand . ControlTrainBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopTrainBrakeIncrease ( ) , ( ) => Locomotive . StartTrainBrakeIncrease ( null ) } ) ;
154170 UserInputCommands . Add ( UserCommand . ControlTrainBrakeDecrease , new Action [ ] { ( ) => Locomotive . StopTrainBrakeDecrease ( ) , ( ) => Locomotive . StartTrainBrakeDecrease ( null ) } ) ;
171+ UserCommandControlTypes . Add ( CABViewControlTypes . TRAIN_BRAKE , new UserCommand [ ] { UserCommand . ControlTrainBrakeIncrease , UserCommand . ControlTrainBrakeDecrease } ) ;
172+
155173 UserInputCommands . Add ( UserCommand . ControlTrainBrakeZero , new Action [ ] { Noop , ( ) => Locomotive . StartTrainBrakeDecrease ( 0 , true ) } ) ;
174+
156175 UserInputCommands . Add ( UserCommand . ControlEngineBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopEngineBrakeIncrease ( ) , ( ) => Locomotive . StartEngineBrakeIncrease ( null ) } ) ;
157176 UserInputCommands . Add ( UserCommand . ControlEngineBrakeDecrease , new Action [ ] { ( ) => Locomotive . StopEngineBrakeDecrease ( ) , ( ) => Locomotive . StartEngineBrakeDecrease ( null ) } ) ;
177+ UserCommandControlTypes . Add ( CABViewControlTypes . ENGINE_BRAKE , new UserCommand [ ] { UserCommand . ControlEngineBrakeIncrease , UserCommand . ControlEngineBrakeDecrease } ) ;
178+
158179 UserInputCommands . Add ( UserCommand . ControlBrakemanBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopBrakemanBrakeIncrease ( ) , ( ) => Locomotive . StartBrakemanBrakeIncrease ( null ) } ) ;
159180 UserInputCommands . Add ( UserCommand . ControlBrakemanBrakeDecrease , new Action [ ] { ( ) => Locomotive . StopBrakemanBrakeDecrease ( ) , ( ) => Locomotive . StartBrakemanBrakeDecrease ( null ) } ) ;
160181 UserInputCommands . Add ( UserCommand . ControlDynamicBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopDynamicBrakeIncrease ( ) , ( ) => Locomotive . StartDynamicBrakeIncrease ( null ) } ) ;
@@ -313,7 +334,7 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
313334
314335 foreach ( var command in UserInputCommands . Keys )
315336 {
316- if ( UserInput . IsPressed ( command ) )
337+ if ( UserInput . IsPressed ( command ) || IsMouseWheelRotated ( command ) )
317338 {
318339 UserInputCommands [ command ] [ 1 ] ( ) ;
319340 //Debrief eval
@@ -332,7 +353,59 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
332353 //Debrief eval
333354 if ( lemergencybuttonpressed && ! Locomotive . EmergencyButtonPressed ) lemergencybuttonpressed = false ;
334355 }
356+ else if ( IsMouseWheelChanged && ( DateTime . Now . Subtract ( MouseWheelChangedTime ) . TotalMilliseconds > ( 500 * MouseWheelClicks ) ) && ( command == MouseWheelCommand ) )
357+ {
358+ UserInputCommands [ command ] [ 0 ] ( ) ;
359+ //Debrief eval
360+ if ( lemergencybuttonpressed && ! Locomotive . EmergencyButtonPressed ) lemergencybuttonpressed = false ;
361+ IsMouseWheelChanged = false ;
362+ }
363+ }
364+ }
365+
366+ bool IsMouseWheelRotated ( UserCommand command )
367+ {
368+ if ( UserInput . IsMouseWheelChanged )
369+ {
370+ if ( Viewer . Camera is CabCamera && ( this as MSTSLocomotiveViewer ) . _hasCabRenderer )
371+ {
372+ var cabRenderer = ( this as MSTSLocomotiveViewer ) . _CabRenderer ;
373+ foreach ( var controlRenderer in cabRenderer . ControlMap . Values )
374+ {
375+ if ( ( Viewer . Camera as CabCamera ) . SideLocation == controlRenderer . Control . CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer )
376+ {
377+ if ( mouseRenderer . IsMouseWithin ( ) )
378+ {
379+ UserCommand [ ] userCommands ;
380+ UserCommandControlTypes . TryGetValue ( controlRenderer . Control . ControlType . Type , out userCommands ) ;
381+ if ( userCommands != null )
382+ {
383+ // check if user command (e.g. ControlThrottleIncrease) equals control type (e.g. THROTTLE)
384+ if ( ( ( command == userCommands [ 0 ] ) && ( UserInput . MouseWheelChange > 0 ) ) ||
385+ ( ( command == userCommands [ 1 ] ) && ( UserInput . MouseWheelChange < 0 ) ) )
386+ {
387+ if ( ! IsMouseWheelChanged )
388+ {
389+ IsMouseWheelChanged = true ;
390+ MouseWheelChangedTime = DateTime . Now ;
391+ MouseWheelClicks = 1 ;
392+ MouseWheelCommand = command ;
393+ }
394+ else
395+ {
396+ MouseWheelClicks += 1 ;
397+ }
398+ return true ;
399+ }
400+ }
401+ break ;
402+ }
403+ }
404+ }
405+ }
335406 }
407+
408+ return false ;
336409 }
337410
338411 /// <summary>
0 commit comments