@@ -1468,7 +1468,7 @@ public CABViewControlTypes GetControlType()
1468
1468
/// Gets the requested Locomotive data and returns it as a fraction (from 0 to 1) of the range between Min and Max values.
1469
1469
/// </summary>
1470
1470
/// <returns>Data value as fraction (from 0 to 1) of the range between Min and Max values</returns>
1471
- public float GetRangeFraction ( )
1471
+ public float GetRangeFraction ( bool offsetFromZero = false )
1472
1472
{
1473
1473
var data = Locomotive . GetDataOf ( Control ) ;
1474
1474
if ( data < Control . MinValue )
@@ -1479,7 +1479,7 @@ public float GetRangeFraction()
1479
1479
if ( Control . MaxValue == Control . MinValue )
1480
1480
return 0 ;
1481
1481
1482
- return ( float ) ( ( data - Control . MinValue ) / ( Control . MaxValue - Control . MinValue ) ) ;
1482
+ return ( float ) ( ( data - ( offsetFromZero && Control . MinValue < 0 ? 0 : Control . MinValue ) ) / ( Control . MaxValue - Control . MinValue ) ) ;
1483
1483
}
1484
1484
1485
1485
public CABViewControlStyles GetStyle ( )
@@ -1630,7 +1630,8 @@ public CabViewGaugeRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCFirebox
1630
1630
1631
1631
public color GetColor ( out bool positive )
1632
1632
{
1633
- if ( Locomotive . GetDataOf ( Control ) < 0 ) { positive = false ; return Gauge . NegativeColor ; }
1633
+ if ( Locomotive . GetDataOf ( Control ) < 0 )
1634
+ { positive = false ; return Gauge . NegativeColor ; }
1634
1635
else { positive = true ; return Gauge . PositiveColor ; }
1635
1636
}
1636
1637
@@ -3251,45 +3252,46 @@ public void UpdateDigit()
3251
3252
3252
3253
Material UsedMaterial = FindMaterial ( ) ;
3253
3254
3254
- float length = CVFR . GetRangeFraction ( ) ;
3255
+ float length = CVFR . GetRangeFraction ( true ) ;
3255
3256
3256
3257
CVCGauge gauge = CVFR . GetGauge ( ) ;
3257
3258
3258
3259
var len = maxLen * length ;
3260
+ var absLen = Math . Abs ( len ) ;
3259
3261
Vertex v1 , v2 , v3 , v4 ;
3260
3262
3261
3263
//the left-bottom vertex if ori=0;dir=0, right-bottom if ori=0,dir=1; left-top if ori=1,dir=0; left-bottom if ori=1,dir=1;
3262
3264
v1 = new Vertex ( 0f , 0f , 0.002f , 0 , 0 , - 1 , 0f , 0f ) ;
3263
3265
3264
3266
if ( Orientation == 0 )
3265
3267
{
3266
- if ( Direction == 0 ) //moving right
3268
+ if ( Direction == 0 ^ len < 0 ) //moving right
3267
3269
{
3268
3270
//other vertices
3269
3271
v2 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3270
- v3 = new Vertex ( len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3271
- v4 = new Vertex ( len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3272
+ v3 = new Vertex ( absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3273
+ v4 = new Vertex ( absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3272
3274
}
3273
3275
else //moving left
3274
3276
{
3275
3277
v4 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3276
- v3 = new Vertex ( - len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3277
- v2 = new Vertex ( - len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3278
+ v3 = new Vertex ( - absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3279
+ v2 = new Vertex ( - absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3278
3280
}
3279
3281
}
3280
3282
else
3281
3283
{
3282
- if ( Direction == 1 ) //up
3284
+ if ( Direction == 1 ^ len < 0 ) //up
3283
3285
{
3284
3286
//other vertices
3285
- v2 = new Vertex ( 0f , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3286
- v3 = new Vertex ( width , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3287
+ v2 = new Vertex ( 0f , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3288
+ v3 = new Vertex ( width , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3287
3289
v4 = new Vertex ( width , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3288
3290
}
3289
3291
else //moving down
3290
3292
{
3291
- v4 = new Vertex ( 0f , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3292
- v3 = new Vertex ( width , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3293
+ v4 = new Vertex ( 0f , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3294
+ v3 = new Vertex ( width , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3293
3295
v2 = new Vertex ( width , 0 , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3294
3296
}
3295
3297
}
0 commit comments