@@ -60,6 +60,13 @@ public class MSTSLocomotiveViewer : MSTSWagonViewer
6060 public bool lemergencybuttonpressed = false ;
6161 CruiseControlViewer CruiseControlViewer ;
6262
63+ public Dictionary < CABViewControlTypes , UserCommand [ ] > UserCommandControlTypes = new Dictionary < CABViewControlTypes , UserCommand [ ] > ( ) ;
64+
65+ private bool IsMouseWheelChanged ;
66+ private DateTime MouseWheelChangedTime ;
67+ private int MouseWheelClicks ;
68+ private UserCommand MouseWheelCommand ;
69+
6370 public MSTSLocomotiveViewer ( Viewer viewer , MSTSLocomotive car )
6471 : base ( viewer , car )
6572 {
@@ -143,19 +150,33 @@ public override void InitializeUserInputCommands()
143150 // Steam locomotives handle these differently, and might have set them already
144151 if ( ! UserInputCommands . ContainsKey ( UserCommand . ControlForwards ) )
145152 UserInputCommands . Add ( UserCommand . ControlForwards , new Action [ ] { Noop , ( ) => ReverserControlForwards ( ) } ) ;
153+
146154 if ( ! UserInputCommands . ContainsKey ( UserCommand . ControlBackwards ) )
155+ {
147156 UserInputCommands . Add ( UserCommand . ControlBackwards , new Action [ ] { Noop , ( ) => ReverserControlBackwards ( ) } ) ;
157+ UserCommandControlTypes . Add ( CABViewControlTypes . DIRECTION , new UserCommand [ ] { UserCommand . ControlForwards , UserCommand . ControlBackwards } ) ;
158+ }
148159
149160 UserInputCommands . Add ( UserCommand . ControlThrottleIncrease , new Action [ ] { ( ) => Locomotive . StopThrottleIncrease ( ) , ( ) => Locomotive . StartThrottleIncrease ( ) } ) ;
150161 UserInputCommands . Add ( UserCommand . ControlThrottleDecrease , new Action [ ] { ( ) => Locomotive . StopThrottleDecrease ( ) , ( ) => Locomotive . StartThrottleDecrease ( ) } ) ;
162+ UserCommandControlTypes . Add ( CABViewControlTypes . THROTTLE , new UserCommand [ ] { UserCommand . ControlThrottleIncrease , UserCommand . ControlThrottleDecrease } ) ;
163+ UserCommandControlTypes . Add ( CABViewControlTypes . CP_HANDLE , new UserCommand [ ] { UserCommand . ControlThrottleIncrease , UserCommand . ControlThrottleDecrease } ) ;
164+
151165 UserInputCommands . Add ( UserCommand . ControlThrottleZero , new Action [ ] { Noop , ( ) => Locomotive . ThrottleToZero ( ) } ) ;
166+
152167 UserInputCommands . Add ( UserCommand . ControlGearUp , new Action [ ] { ( ) => StopGearBoxIncrease ( ) , ( ) => StartGearBoxIncrease ( ) } ) ;
153168 UserInputCommands . Add ( UserCommand . ControlGearDown , new Action [ ] { ( ) => StopGearBoxDecrease ( ) , ( ) => StartGearBoxDecrease ( ) } ) ;
169+
154170 UserInputCommands . Add ( UserCommand . ControlTrainBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopTrainBrakeIncrease ( ) , ( ) => Locomotive . StartTrainBrakeIncrease ( null ) } ) ;
155171 UserInputCommands . Add ( UserCommand . ControlTrainBrakeDecrease , new Action [ ] { ( ) => Locomotive . StopTrainBrakeDecrease ( ) , ( ) => Locomotive . StartTrainBrakeDecrease ( null ) } ) ;
172+ UserCommandControlTypes . Add ( CABViewControlTypes . TRAIN_BRAKE , new UserCommand [ ] { UserCommand . ControlTrainBrakeIncrease , UserCommand . ControlTrainBrakeDecrease } ) ;
173+
156174 UserInputCommands . Add ( UserCommand . ControlTrainBrakeZero , new Action [ ] { Noop , ( ) => Locomotive . StartTrainBrakeDecrease ( 0 , true ) } ) ;
175+
157176 UserInputCommands . Add ( UserCommand . ControlEngineBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopEngineBrakeIncrease ( ) , ( ) => Locomotive . StartEngineBrakeIncrease ( null ) } ) ;
158177 UserInputCommands . Add ( UserCommand . ControlEngineBrakeDecrease , new Action [ ] { ( ) => Locomotive . StopEngineBrakeDecrease ( ) , ( ) => Locomotive . StartEngineBrakeDecrease ( null ) } ) ;
178+ UserCommandControlTypes . Add ( CABViewControlTypes . ENGINE_BRAKE , new UserCommand [ ] { UserCommand . ControlEngineBrakeIncrease , UserCommand . ControlEngineBrakeDecrease } ) ;
179+
159180 UserInputCommands . Add ( UserCommand . ControlBrakemanBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopBrakemanBrakeIncrease ( ) , ( ) => Locomotive . StartBrakemanBrakeIncrease ( null ) } ) ;
160181 UserInputCommands . Add ( UserCommand . ControlBrakemanBrakeDecrease , new Action [ ] { ( ) => Locomotive . StopBrakemanBrakeDecrease ( ) , ( ) => Locomotive . StartBrakemanBrakeDecrease ( null ) } ) ;
161182 UserInputCommands . Add ( UserCommand . ControlDynamicBrakeIncrease , new Action [ ] { ( ) => Locomotive . StopDynamicBrakeIncrease ( ) , ( ) => Locomotive . StartDynamicBrakeIncrease ( null ) } ) ;
@@ -314,7 +335,7 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
314335
315336 foreach ( var command in UserInputCommands . Keys )
316337 {
317- if ( UserInput . IsPressed ( command ) )
338+ if ( UserInput . IsPressed ( command ) || IsMouseWheelRotated ( command ) )
318339 {
319340 UserInputCommands [ command ] [ 1 ] ( ) ;
320341 //Debrief eval
@@ -333,7 +354,59 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
333354 //Debrief eval
334355 if ( lemergencybuttonpressed && ! Locomotive . EmergencyButtonPressed ) lemergencybuttonpressed = false ;
335356 }
357+ else if ( IsMouseWheelChanged && ( DateTime . Now . Subtract ( MouseWheelChangedTime ) . TotalMilliseconds > ( 500 * MouseWheelClicks ) ) && ( command == MouseWheelCommand ) )
358+ {
359+ UserInputCommands [ command ] [ 0 ] ( ) ;
360+ //Debrief eval
361+ if ( lemergencybuttonpressed && ! Locomotive . EmergencyButtonPressed ) lemergencybuttonpressed = false ;
362+ IsMouseWheelChanged = false ;
363+ }
364+ }
365+ }
366+
367+ bool IsMouseWheelRotated ( UserCommand command )
368+ {
369+ if ( UserInput . IsMouseWheelChanged )
370+ {
371+ if ( Viewer . Camera is CabCamera && ( this as MSTSLocomotiveViewer ) . _hasCabRenderer )
372+ {
373+ var cabRenderer = ( this as MSTSLocomotiveViewer ) . _CabRenderer ;
374+ foreach ( var controlRenderer in cabRenderer . ControlMap . Values )
375+ {
376+ if ( ( Viewer . Camera as CabCamera ) . SideLocation == controlRenderer . Control . CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer )
377+ {
378+ if ( mouseRenderer . IsMouseWithin ( ) )
379+ {
380+ UserCommand [ ] userCommands ;
381+ UserCommandControlTypes . TryGetValue ( controlRenderer . Control . ControlType . Type , out userCommands ) ;
382+ if ( userCommands != null )
383+ {
384+ // check if user command (e.g. ControlThrottleIncrease) equals control type (e.g. THROTTLE)
385+ if ( ( ( command == userCommands [ 0 ] ) && ( UserInput . MouseWheelChange > 0 ) ) ||
386+ ( ( command == userCommands [ 1 ] ) && ( UserInput . MouseWheelChange < 0 ) ) )
387+ {
388+ if ( ! IsMouseWheelChanged )
389+ {
390+ IsMouseWheelChanged = true ;
391+ MouseWheelChangedTime = DateTime . Now ;
392+ MouseWheelClicks = 1 ;
393+ MouseWheelCommand = command ;
394+ }
395+ else
396+ {
397+ MouseWheelClicks += 1 ;
398+ }
399+ return true ;
400+ }
401+ }
402+ break ;
403+ }
404+ }
405+ }
406+ }
336407 }
408+
409+ return false ;
337410 }
338411
339412 /// <summary>
0 commit comments