Skip to content

Commit ed601b5

Browse files
committed
Windows animation for wagon windows
1 parent bc1ffd8 commit ed601b5

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,12 @@ public void SetCommandReceivers()
733733
EOTMountCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
734734
}
735735

736+
public void SetWagonCommandReceivers(MSTSWagon wag)
737+
{
738+
ToggleWindowLeftCommand.Receiver = wag;
739+
ToggleWindowRightCommand.Receiver = wag;
740+
}
741+
736742
public TrainCar SetPlayerLocomotive(Train playerTrain)
737743
{
738744
TrainCar PlayerLocomotive = null;

Source/RunActivity/Viewer3D/AnimatedPart.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ public float UpdateAndReturnState(bool state, ElapsedTime elapsedTime)
150150
return AnimationKey / FrameCount;
151151
}
152152

153+
/// <summary>
154+
/// Returns the animation key fraction (between 0 and 1)
155+
/// </summary>
156+
public float AnimationKeyFraction()
157+
{
158+
return AnimationKey / FrameCount;
159+
}
160+
153161
/// <summary>
154162
/// Updates an animated part that loops (e.g. running gear), changing by the given amount.
155163
/// </summary>

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ protected virtual List<TrainCar> GetCameraCars()
833833
protected virtual void SetCameraCar(TrainCar car)
834834
{
835835
attachedCar = car;
836+
Viewer.Simulator.SetWagonCommandReceivers((MSTSWagon)car);
836837
}
837838

838839
protected virtual bool IsCameraFlipped()

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public class MSTSWagonViewer : TrainCarViewer
7070
AnimatedPart LeftDoor;
7171
AnimatedPart RightDoor;
7272
AnimatedPart Mirrors;
73-
AnimatedPart LeftWindowFront;
74-
AnimatedPart RightWindowFront;
75-
AnimatedPart LeftWindowRear;
76-
AnimatedPart RightWindowRear;
73+
protected AnimatedPart LeftWindowFront;
74+
protected AnimatedPart RightWindowFront;
75+
protected AnimatedPart LeftWindowRear;
76+
protected AnimatedPart RightWindowRear;
7777
protected AnimatedPart Wipers;
7878
protected AnimatedPart Bell;
7979
protected AnimatedPart Item1Continuous;
@@ -736,6 +736,13 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
736736
foreach (ParticleEmitterViewer drawer in drawers)
737737
drawer.PrepareFrame(frame, elapsedTime);
738738

739+
if (!(car is MSTSLocomotive) && (LeftWindowFront.FrameCount > 0 || RightWindowFront.FrameCount > 0))
740+
{
741+
if (LeftWindowFront.FrameCount > 0)
742+
car.SoundHeardInternallyCorrection[MSTSWagon.LeftWindowFrontIndex] = LeftWindowFront.AnimationKeyFraction();
743+
if (RightWindowFront.FrameCount > 0)
744+
car.SoundHeardInternallyCorrection[MSTSWagon.RightWindowFrontIndex] = RightWindowFront.AnimationKeyFraction();
745+
}
739746
}
740747

741748

0 commit comments

Comments
 (0)