Skip to content

Commit a89e599

Browse files
committed
Automatic merge of T1.5.1-799-gb02a6e5d3 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 f9f6804: 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 #897 at 42f1dd9: feat: Improved system information collection - Pull request #899 at b227eec: Duplex steam engines - Booster Engine addition - Pull request #903 at 0d6d045: Downloading route content (Github, zip) - Pull request #907 at 9b0b04f: Bug fix for https://bugs.launchpad.net/or/+bug/2047300 Dynamic tracks disappear after long tunnel - Pull request #908 at 4b4afe3: feat: supports switching adhesion precisions - Pull request #911 at 6834af0: docs: Add refactoring as a special type of PR
16 parents f15a477 + b02a6e5 + 3539862 + d00beb9 + f92de76 + f9f6804 + 8f94333 + 6c0785b + 1f5ba4c + 5866028 + 42f1dd9 + b227eec + 0d6d045 + 9b0b04f + 4b4afe3 + 6834af0 commit a89e599

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ public class Label3DMaterial : SpriteBatchMaterial
16181618
{
16191619
public readonly Texture2D Texture;
16201620
public readonly WindowTextFont Font;
1621+
public readonly WindowTextFont BigFont;
16211622

16221623
readonly List<Rectangle> TextBoxes = new List<Rectangle>();
16231624

@@ -1627,6 +1628,7 @@ public Label3DMaterial(Viewer viewer)
16271628
Texture = new Texture2D(SpriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
16281629
Texture.SetData(new[] { Color.White });
16291630
Font = Viewer.WindowManager.TextManager.GetScaled("Arial", 12, System.Drawing.FontStyle.Bold, 1);
1631+
BigFont = Viewer.WindowManager.TextManager.GetScaled("Arial", 24, System.Drawing.FontStyle.Bold, 2);
16301632
}
16311633

16321634
public override void SetState(GraphicsDevice graphicsDevice, Material previousMaterial)

Source/RunActivity/Viewer3D/Popups/LabelPrimitive.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LabelPrimitive : RenderPrimitive
3434

3535
readonly Viewer Viewer;
3636
readonly float OffsetY;
37-
37+
public bool InsideBox { set; get; }
3838
public LabelPrimitive(Label3DMaterial material, Color color, Color outline, float offsetY)
3939
{
4040
Material = material;
@@ -43,6 +43,15 @@ public LabelPrimitive(Label3DMaterial material, Color color, Color outline, floa
4343
Outline = outline;
4444
OffsetY = offsetY;
4545
}
46+
public LabelPrimitive(Label3DMaterial material, Color color, Color outline, float offsetY, bool insideBox)
47+
{
48+
Material = material;
49+
Viewer = material.Viewer;
50+
Color = color;
51+
Outline = outline;
52+
OffsetY = offsetY;
53+
InsideBox = insideBox;
54+
}
4655

4756
public override void Draw(GraphicsDevice graphicsDevice)
4857
{
@@ -55,13 +64,17 @@ public override void Draw(GraphicsDevice graphicsDevice)
5564
if (lineLocation2DStart.Z > 1 || lineLocation2DStart.Z < 0)
5665
return; // Out of range or behind the camera
5766

58-
lineLocation3D.Y += 10;
67+
lineLocation3D.Y += InsideBox ? 0 : 10;
5968
var lineLocation2DEndY = Viewer.GraphicsDevice.Viewport.Project(lineLocation3D, Viewer.Camera.XnaProjection, Viewer.Camera.XnaView, Matrix.Identity).Y;
6069

6170
var labelLocation2D = Material.GetTextLocation((int)lineLocation2DStart.X, (int)lineLocation2DEndY - Material.Font.Height, Text);
6271
lineLocation2DEndY = labelLocation2D.Y + Material.Font.Height;
6372

64-
Material.Font.Draw(Material.SpriteBatch, labelLocation2D, Text, Color, Outline);
73+
if (InsideBox)
74+
Material.BigFont.Draw(Material.SpriteBatch, labelLocation2D, Text, Color, Outline);
75+
else
76+
Material.Font.Draw(Material.SpriteBatch, labelLocation2D, Text, Color, Outline);
77+
6578
Material.SpriteBatch.Draw(Material.Texture, new Vector2(lineLocation2DStart.X - 1, lineLocation2DEndY), null, Outline, 0, Vector2.Zero, new Vector2(4, lineLocation2DStart.Y - lineLocation2DEndY), SpriteEffects.None, lineLocation2DStart.Z);
6679
Material.SpriteBatch.Draw(Material.Texture, new Vector2(lineLocation2DStart.X, lineLocation2DEndY), null, Color, 0, Vector2.Zero, new Vector2(2, lineLocation2DStart.Y - lineLocation2DEndY), SpriteEffects.None, lineLocation2DStart.Z);
6780
}

Source/RunActivity/Viewer3D/Popups/OSDCars.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ public int CarPosition
9191
set;
9292
get;
9393
}
94-
public int NewCarPosition
94+
public string CurrentCarID
95+
{
96+
set;
97+
get;
98+
}
99+
public int NewCarPosition
95100
{
96101
set;
97102
get;
@@ -270,6 +275,7 @@ protected override ControlLayout Layout(ControlLayout layout)
270275
: $" {Viewer.Catalog.GetString(wagon.WagonType.ToString())}";
271276

272277
Vbox.Add(buttonClose = new Label(Vbox.RemainingWidth, Owner.TextFontDefault.Height, $"{Viewer.Catalog.GetString("Car ID")} {(CarPosition >= PlayerTrain.Cars.Count ? " " : PlayerTrain.Cars[CarPosition].CarID + wagonType)}", LabelAlignment.Center));
278+
CurrentCarID = CarPosition >= PlayerTrain.Cars.Count ? " " : PlayerTrain.Cars[CarPosition].CarID;
273279
buttonClose.Click += new Action<Control, Point>(buttonClose_Click);
274280
buttonClose.Color = Owner.Viewer.TrainCarOperationsWindow.WarningCarPosition.Find(x => x == true) ? Color.Cyan : Color.White;
275281
Vbox.AddHorizontalSeparator();

Source/RunActivity/Viewer3D/WebServices/TrainCarOperationsWebpage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public OperationsStatus(int amountOfCars)
8282

8383
public bool TrainCarSelected;
8484
public int TrainCarSelectedPosition;
85+
public string CurrentCarID { get; set; }
8586

8687
public int Connections = 0;
8788

@@ -352,6 +353,8 @@ private string getCarId(TrainCar trainCar, int carPosition)
352353
var isElectric = trainCar is MSTSElectricLocomotive;
353354
var isSteam = trainCar is MSTSSteamLocomotive;
354355
var isEngine = isDiesel || isElectric || isSteam;
356+
// Required by OSDCar.cs
357+
CurrentCarID = Viewer.PlayerTrain.Cars[TrainCarSelectedPosition].CarID;
355358
var wagonType = isEngine ?
356359
$" {Viewer.Catalog.GetString(locomotive.WagonType.ToString())}" + $":{Viewer.Catalog.GetString(locomotive.EngineType.ToString())}" :
357360
$" {Viewer.Catalog.GetString(trainCar.WagonType.ToString())}";

0 commit comments

Comments
 (0)