Skip to content

Commit b4353a3

Browse files
committed
Automatic merge of T1.5.1-905-gaf8fb30c5 and 14 pull requests
- Pull request #570 at 3539862: Experimental glTF 2.0 support with PBR lighting - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at 9c456aa: Blueprint/train car operations UI window - Pull request #885 at 8f94333: feat: Add notifications to Menu - Pull request #886 at 6c0785b: Scene viewer extension to TrackViewer - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #903 at 9bead33: Downloading route content (Github, zip) - Pull request #911 at 6834af0: docs: Add refactoring as a special type of PR - Pull request #916 at 992cc97: Distributed Power Air Brake Synchronization - Pull request #919 at b90e3b9: Added mouse wheel support for controls which can be moved by pressing t… - Pull request #920 at a94e403: Update RailDriver in Manual - Pull request #923 at d0208cd: Add curve squeal to route
16 parents 2772fc6 + af8fb30 + 3539862 + d00beb9 + f92de76 + 9c456aa + 8f94333 + 6c0785b + 1f5ba4c + 5866028 + 9bead33 + 6834af0 + 992cc97 + b90e3b9 + a94e403 + d0208cd commit b4353a3

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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>

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,13 @@ void HandleUserInput(ElapsedTime elapsedTime)
14201420
if ((Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer)
14211421
{
14221422
if (mouseRenderer.IsMouseWithin())
1423-
{
1423+
{
1424+
var UserCommandControlTypes = (PlayerLocomotiveViewer as MSTSLocomotiveViewer).UserCommandControlTypes;
1425+
if (UserCommandControlTypes.ContainsKey(controlRenderer.Control.ControlType.Type))
1426+
{
1427+
continue;
1428+
}
1429+
14241430
if ((controlRenderer.Control.Screens == null || controlRenderer.Control.Screens[0] == "all"))
14251431
{
14261432
MouseChangingControl = mouseRenderer;

0 commit comments

Comments
 (0)