@@ -78,32 +78,54 @@ public override void PrepareFrame(RenderFrame frame, ORTS.Common.ElapsedTime ela
7878 var newLabels = new Dictionary < TrainCar , LabelPrimitive > ( labels . Count ) ;
7979 var cars = Owner . Viewer . World . Trains . Cars ;
8080 var cameraLocation = Owner . Viewer . Camera . CameraWorldLocation ;
81+ var carID = Owner . Viewer . TrainCarOperationsViewerWindow . CurrentCarID ;
82+ //data from Webpage
83+ var trainCarWebpage = Owner . Viewer . TrainCarOperationsWebpage ;
84+ var carIDWebpage = trainCarWebpage != null && trainCarWebpage . Connections > 0 ? trainCarWebpage . CurrentCarID : "" ;
85+ bool isVisibleTrainCarViewerOrWebpage = Owner . Viewer . TrainCarOperationsViewerWindow . Visible || ( trainCarWebpage != null && trainCarWebpage . Connections > 0 && Owner . Viewer . TrainCarOperationsWebpage . TrainCarSelected ) ;
8186 foreach ( var car in cars . Keys )
8287 {
8388 // Calculates distance between camera and platform label.
8489 var distance = WorldLocation . GetDistance ( car . WorldPosition . WorldLocation , cameraLocation ) . Length ( ) ;
85- if ( distance <= MaximumDistance )
90+ var carBodyLength = car . CarBodyLengthM < 21 ? 21 : car . CarBodyLengthM ;
91+ if ( ( ! isVisibleTrainCarViewerOrWebpage || ! car . IsPlayerTrain ) && distance <= MaximumDistance )
8692 {
8793 if ( ( State == DisplayState . Cars ) || ( State == DisplayState . Trains && ( car . Train == null || car . Train . FirstCar == car ) ) )
8894 {
8995 if ( labels . ContainsKey ( car ) )
9096 newLabels [ car ] = labels [ car ] ;
9197 else
92- newLabels [ car ] = new LabelPrimitive ( Owner . Label3DMaterial , Color . Blue , Color . White , car . CarHeightM ) { Position = car . WorldPosition } ;
98+ newLabels [ car ] = new LabelPrimitive ( Owner . Label3DMaterial , Color . Blue , Color . White , car . CarHeightM , false ) { Position = car . WorldPosition } ;
9399
100+ newLabels [ car ] . InsideBox = false ;
94101 newLabels [ car ] . Text = State == DisplayState . Cars || car . Train == null ? car . CarID : car . Train . Name ;
95102
96103 // Change color with distance.
97104 var ratio = ( MathHelper . Clamp ( distance , MinimumDistance , MaximumDistance ) - MinimumDistance ) / ( MaximumDistance - MinimumDistance ) ;
98105 newLabels [ car ] . Color . A = newLabels [ car ] . Outline . A = ( byte ) MathHelper . Lerp ( 255 , 0 , ratio ) ;
99106 }
100107 }
108+ else if ( car . IsPlayerTrain && isVisibleTrainCarViewerOrWebpage && ( car . CarID == carID || car . CarID == carIDWebpage ) && distance <= carBodyLength )
109+ {
110+ if ( ( State == DisplayState . Cars ) || ( State == DisplayState . Trains && ( car . Train == null || car . Train . FirstCar == car ) ) )
111+ {
112+ if ( labels . ContainsKey ( car ) )
113+ newLabels [ car ] = labels [ car ] ;
114+ else
115+ newLabels [ car ] = new LabelPrimitive ( Owner . Label3DMaterial , Color . Blue , Color . White , car . CarHeightM , true ) { Position = car . WorldPosition } ;
116+
117+ newLabels [ car ] . InsideBox = true ;
118+ newLabels [ car ] . Text = State == DisplayState . Cars || car . Train == null ? car . CarID : car . Train . Name ;
119+ }
120+ }
101121 }
102122 Labels = newLabels ;
103123 }
104124
105125 foreach ( var primitive in Labels . Values )
126+ {
106127 frame . AddPrimitive ( Owner . Label3DMaterial , primitive , RenderPrimitiveGroup . Labels , ref Identity ) ;
128+ }
107129 }
108130
109131 public DisplayState CurrentDisplayState
0 commit comments