Skip to content

Commit

Permalink
Some web server track monitor fixes by mbm_OR.
Browse files Browse the repository at this point in the history
  • Loading branch information
YoRyan committed Jul 23, 2020
1 parent 2ba1d2c commit 26983e9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
34 changes: 25 additions & 9 deletions Source/RunActivity/Viewer3D/WebServices/TrackMonitorDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private static class Sprites
public static readonly Rectangle LeftArrowSprite = new Rectangle(0, 168, 24, 24);
public static readonly Rectangle RightArrowSprite = new Rectangle(24, 168, 24, 24);
public static readonly Rectangle ReversalSprite = new Rectangle(0, 24, 24, 24);
public static readonly Rectangle WaitingPointSprite = new Rectangle(24, 24, 24, 24);
public static readonly Rectangle InvalidReversalSprite = new Rectangle(24, 144, 24, 24);
public static readonly Dictionary<TrainPosition, Rectangle> TrainPositionSprite = new Dictionary<TrainPosition, Rectangle>
{
Expand Down Expand Up @@ -380,6 +381,8 @@ void AddLabel(ListLabel label)
DrawAutoModeInfo(trackLabels, thisInfo, useMetric);
break;
case Train.TRAIN_CONTROL.TURNTABLE:
break;
default:
DrawManualModeInfo(trackLabels, thisInfo, useMetric);
break;
}
Expand Down Expand Up @@ -504,7 +507,7 @@ private static void DrawMPModeInfo(List<ListLabel> labels, Train.TrainInfo train
zeroObjectPointTop = zeroObjectPointMiddle + Positions.Train[1];
zeroObjectPointBottom = zeroObjectPointMiddle - Positions.Train[2];
}
float distanceFactor = (endObjectArea - startObjectArea - Positions.Train[4]) / MaximumDistanceM / trainInfo.direction == -1 ? 2 : 1;
float distanceFactor = (endObjectArea - startObjectArea - Positions.Train[4]) / MaximumDistanceM / (trainInfo.direction == -1 ? 2 : 1);

// Draw direction arrow
if (trainInfo.direction == 0)
Expand All @@ -523,7 +526,7 @@ private static void DrawMPModeInfo(List<ListLabel> labels, Train.TrainInfo train
if (trainInfo.direction !=0)
{
// Draw fixed distance indications
float markerIntervalM = DrawDistanceMarkers(labels, distanceFactor, zeroObjectPointBottom, numberOfMarkers: 3, direction: TrainDirection.Backward, useMetric);
float markerIntervalM = DrawDistanceMarkers(labels, distanceFactor, zeroObjectPointBottom, numberOfMarkers: 4, direction: TrainDirection.Backward, useMetric);

// Draw backward items
DrawTrackItems(labels, trainInfo.ObjectInfoBackward, zeroObjectPointBottom, distanceFactor, markerIntervalM, direction: TrainDirection.Backward, useMetric);
Expand Down Expand Up @@ -596,7 +599,7 @@ private static void DrawManualModeInfo(List<ListLabel> labels, Train.TrainInfo t
int zeroObjectPointMiddle = startObjectArea + (endObjectArea - startObjectArea) / 2;
int zeroObjectPointTop = zeroObjectPointMiddle + Positions.Train[1];
int zeroObjectPointBottom = zeroObjectPointMiddle - Positions.Train[2];
float distanceFactor = (endObjectArea - startObjectArea) / MaximumDistanceM;
float distanceFactor = (zeroObjectPointTop - startObjectArea) / MaximumDistanceM;

// Draw train position line
ListLabel DarkGraySeparator(ListLabel _) => new ListLabel
Expand Down Expand Up @@ -678,7 +681,7 @@ private static float DrawDistanceMarkers(List<ListLabel> labels, float distanceF
foreach (int ipos in imarkers)
{
float actDistanceM = markerIntervalM * ipos;
int itemOffset = (int)(actDistanceM * distanceFactor);
int itemOffset = Convert.ToInt32(actDistanceM * distanceFactor);
int itemLocationWS = ItemLocationToRow(zeroPoint, zeroPoint + itemOffset * (direction == TrainDirection.Forward ? -1 : 1));
ChangeLabelAt(labels, itemLocationWS, (ListLabel dataCol) =>
{
Expand Down Expand Up @@ -719,7 +722,8 @@ TrackItem MakeTrackItem(Train.TrainObjectItem item)
var trackItems = new List<TrackItem>(itemList
.Select(MakeTrackItem)
.Where((TrackItem item) => item.Render)
.Where((TrackItem item) => item.Item.DistanceToTrainM < MaximumDistanceM - TextSpacing / distanceFactor));
.Where((TrackItem item) => (item.Item.DistanceToTrainM < MaximumDistanceM - TextSpacing / distanceFactor)
|| (item.Item.ItemType == TRAINOBJECTTYPE.SIGNAL && item.Item.DistanceToTrainM > markerIntervalM && item.Item.SignalState != TrackMonitorSignalAspect.Stop)));
// Keep a pointer to the next available row. If a track item conflicts with a previously placed one, bump it to the next row.
var nextLocations = new Dictionary<TrackItemColumn, int>();
foreach (TrackItem trackItem in trackItems)
Expand All @@ -736,11 +740,20 @@ TrackItem MakeTrackItem(Train.TrainObjectItem item)
if (direction == TrainDirection.Forward)
{
itemLocationWS = Math.Min(nextLocationWS, ItemLocationToRow(zeroPoint, zeroPoint - itemOffset));
// Signal at top
if (trackItem.Item.ItemType == TRAINOBJECTTYPE.SIGNAL && trackItem.Item.SignalState != TrackMonitorSignalAspect.Stop && trackItem.Item.DistanceToTrainM > MaximumDistanceM)
{
ChangeLabelAt(labels, itemLocationWS, (ListLabel dataCol) =>
{
dataCol.DistCol = FormatStrings.FormatDistance(trackItem.Item.DistanceToTrainM, useMetric);
return dataCol;
});
}
nextLocationWS = itemLocationWS - 1;
}
else
{
itemLocationWS = Math.Max(nextLocationWS, ItemLocationToRow(zeroPoint, zeroPoint + itemOffset));
itemLocationWS = ItemLocationToRow(zeroPoint, Math.Max(nextLocationWS, zeroPoint + itemOffset));
nextLocationWS = itemLocationWS + 1;
}
nextLocations[column] = nextLocationWS;
Expand Down Expand Up @@ -949,6 +962,7 @@ public override ListLabel TransformLabel(ListLabel dataCol)
{
Color color = Item.Enabled ? Color.Yellow : Color.OrangeRed;
dataCol.TrackCol = $"{Symbols.WaitingPointWS}{ColorCode[color]}";
dataCol.TrackColItem = Sprites.WaitingPointSprite;
return dataCol;
}
}
Expand Down Expand Up @@ -1059,13 +1073,15 @@ private static int ItemLocationToRow(int zeroPoint, int itemLocation)
return Round(MathHelper.Clamp(itemLocation * (11f / 200f), 0, 11));
case 224: // Auto mode track + train zone
return Round(MathHelper.Clamp(itemLocation * (12f / 200f), 0, 12));
case 320: // forwardsY
case 240: // forwardsY
case 0: // backwardsY
return Round(MathHelper.Clamp(itemLocation * (16f / 240f), 0, 16));
case 108: // Manual mode upper zone
return Round(MathHelper.Clamp(itemLocation * (6f / 93f), 0, 6));
case 132: // Manual mode lower zone
return Round(MathHelper.Clamp(itemLocation * (16f / 232f), 10, 16));
return (int)MathHelper.Clamp(itemLocation * (6f / 93f), 0, 6);
case 132:// lower zone
return Orts.MultiPlayer.MPManager.IsMultiPlayer() ? Round(MathHelper.Clamp(itemLocation * (16.0f / 266.0f), 9, 16))// MultiPlayer mode
: Round(MathHelper.Clamp(itemLocation * (16f / 232f), 10, 16));// Manual mode
default:
return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions Source/RunActivity/Viewer3D/WebServices/Web/TrackMonitor/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ table td{
margin: 4px 2px;
}

/* Allows to apply image color */
img[ColorCode= "%%$"]{/*lightgreen*/
filter: brightness(0.5) sepia(1) hue-rotate(50deg) saturate(1000%);
}
img[ColorCode= "!!?"]{/*orange*/
filter: brightness(0.8) sepia(1) hue-rotate(300deg) saturate(1000%);
}
img[ColorCode= "!!?"]{/*orangered*/
filter: brightness(0.5) sepia(1) hue-rotate(0deg) saturate(10000%);
}
img[ColorCode= "!!?"]{/*yellow*/
filter: brightness(0.8) sepia(1) hue-rotate(0deg) saturate(1000%);
}

/* Allows to apply text color */
td[ColorCode= "???"]{
background-color:black;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<link rel="stylesheet" type="text/css" href="index.css">

</head>

<body id="body" onload="setInterval (ApiTrackMonitor, 500)">
<p id="demo"></p>
<div id=menu><a href="/">Back to Menu</a></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ async function ApiTrackMonitor() {
}
else {
// first col = FirstCol data
Str += DisplayItem(row > 25 ? 'center' : 'left', 1, firstColor, stringColorFirst, firstColor ? newDataFirst : data.FirstCol, row > 25 ? true : false);
Str += DisplayItem(row > 25 && controlMode.indexOf("AUTO") != -1? 'center' : 'left', 1, firstColor, stringColorFirst, firstColor ? newDataFirst : data.FirstCol, row > 25 && controlMode.indexOf("AUTO") != -1? true : false);

// second col = TrackColLeft data
Str += DisplayItem('right', 1, trackColorLeft, stringColorTrackLeft, trackColorLeft ? newDataTrackLeft : data.TrackColLeft, false);

// third col = TrackCol data
if (row > 12 && data.TrackCol.indexOf("││") == -1) {
let size = 24;
Str += `<td><img src='${await DrawPng(trackMonitorImages, data.TrackColItem)}' width ='${size}' height ='${size}' style='background-color:black' /></td>`;
Str += `<td><img src='${await DrawPng(trackMonitorImages, data.TrackColItem)}' width ='${size}' height ='${size}' ColorCode='${`` + (data.TrackCol.indexOf("↶")!= -1 || data.TrackCol.indexOf("✋")!= -1? stringColorTrack :'') + ``}' style='background-color: black' /></td>`;
Str += "<td></td>";
}
else {
Expand Down

0 comments on commit 26983e9

Please sign in to comment.