Skip to content

Commit a82c1f4

Browse files
committed
Automatic merge of T1.5.1-870-ge0bf062eb and 17 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 9c456aa: 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 #903 at 9bead33: 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 #911 at 6834af0: docs: Add refactoring as a special type of PR - Pull request #912 at d595703: New Triple Valve Features Vol. 2 - Pull request #914 at 2ffadd6: Adjustments to Duplex steam - Pull request #915 at 6d911d7: Correct calculation error with curve friction - Pull request #917 at 3bbf66e: Lighting Configuration Enhancements - Pull request #919 at a3c907f: Added mouse wheel support for controls which can be moved by pressing t…
19 parents a583419 + e0bf062 + 3539862 + d00beb9 + f92de76 + 9c456aa + 8f94333 + 6c0785b + 1f5ba4c + 5866028 + 42f1dd9 + 9bead33 + 9b0b04f + 6834af0 + d595703 + 2ffadd6 + 6d911d7 + 3bbf66e + a3c907f commit a82c1f4

File tree

6 files changed

+179
-5
lines changed

6 files changed

+179
-5
lines changed

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
namespace ORTS.Common.Input
1+
// COPYRIGHT 2024 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
19+
namespace ORTS.Common.Input
220
{
321
/// <summary>
422
/// Specifies game commands.
@@ -50,6 +68,7 @@ public enum UserCommand
5068
[GetString("Display Compass Window")] DisplayCompassWindow,
5169
[GetString("Display Train List Window")] DisplayTrainListWindow,
5270
[GetString("Display EOT List Window")] DisplayEOTListWindow,
71+
[GetString("Display Control Rectangles")] DisplayControlRectangle,
5372

5473
[GetString("Debug Speed Up")] DebugSpeedUp,
5574
[GetString("Debug Speed Down")] DebugSpeedDown,

Source/ORTS.Settings/InputSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ static void InitializeCommands(UserCommandInput[] Commands)
516516
Commands[(int)UserCommand.DisplayTrainOperationsWindow] = new UserCommandKeyInput(0x43);
517517
Commands[(int)UserCommand.DisplayTrainDpuWindow] = new UserCommandKeyInput(0x43, KeyModifiers.Shift);
518518
Commands[(int)UserCommand.DisplayEOTListWindow] = new UserCommandKeyInput(0x43, KeyModifiers.Control);
519+
Commands[(int)UserCommand.DisplayControlRectangle] = new UserCommandKeyInput(0x3F, KeyModifiers.Control);
519520

520521
Commands[(int)UserCommand.GameAutopilotMode] = new UserCommandKeyInput(0x1E, KeyModifiers.Alt);
521522
Commands[(int)UserCommand.GameChangeCab] = new UserCommandKeyInput(0x12, KeyModifiers.Control);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// COPYRIGHT 2024 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System;
19+
using Microsoft.Xna.Framework;
20+
using Microsoft.Xna.Framework.Graphics;
21+
using Orts.Viewer3D.RollingStock;
22+
23+
namespace Orts.Viewer3D.Popups
24+
{
25+
public class ControlRectangle : Window
26+
{
27+
private readonly Texture2D Line;
28+
private readonly int Thickness = 3;
29+
private readonly Color Color = Color.Yellow;
30+
private readonly Viewer Viewer;
31+
32+
public ControlRectangle(WindowManager owner, Viewer viewer) : base(owner)
33+
{
34+
Line = new Texture2D(Owner.Viewer.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
35+
Line.SetData(new[] { Color });
36+
Viewer = viewer;
37+
}
38+
39+
public override void Draw(SpriteBatch spriteBatch)
40+
{
41+
if (Viewer.Camera is CabCamera && (Viewer.PlayerLocomotiveViewer as MSTSLocomotiveViewer)._hasCabRenderer)
42+
{
43+
var cabRenderer = (Viewer.PlayerLocomotiveViewer as MSTSLocomotiveViewer)._CabRenderer;
44+
foreach (var controlRenderer in cabRenderer.ControlMap.Values)
45+
{
46+
if ((Viewer.Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer)
47+
{
48+
if (mouseRenderer.isMouseControl())
49+
{
50+
Rectangle rectangle = mouseRenderer.DestinationRectangleGet();
51+
52+
int width = rectangle.Width;
53+
int height = rectangle.Height;
54+
55+
if (width > 0)
56+
{
57+
// do not know why rectangles with width and height = 0 are there
58+
59+
// top line
60+
DrawLine(spriteBatch, rectangle.X, rectangle.Y, width, Thickness, 0);
61+
62+
// bottom line
63+
DrawLine(spriteBatch, rectangle.X, rectangle.Y + height - Thickness, width, Thickness, 0);
64+
65+
// left line
66+
DrawLine(spriteBatch, rectangle.X + Thickness, rectangle.Y, height, Thickness, 90);
67+
68+
// right line
69+
DrawLine(spriteBatch, rectangle.X + width, rectangle.Y, height, Thickness, 90);
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+
77+
private void DrawLine(SpriteBatch spriteBatch, int X, int Y, int width, int height, int degrees)
78+
{
79+
spriteBatch.Draw(
80+
Line,
81+
new Rectangle(X, Y, width, height),
82+
null,
83+
Color,
84+
ConvertToRadiansFromDegrees(degrees),
85+
new Vector2(0, 0),
86+
SpriteEffects.None, 0);
87+
}
88+
89+
private float ConvertToRadiansFromDegrees(int angle)
90+
{
91+
return (float)((System.Math.PI / 180) * angle);
92+
}
93+
}
94+
}

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,8 @@ public interface ICabViewMouseControlRenderer
16991699
void HandleUserInput();
17001700
string GetControlName();
17011701
string ControlLabel { get; }
1702+
Rectangle DestinationRectangleGet();
1703+
bool isMouseControl();
17021704
}
17031705

17041706
/// <summary>
@@ -2033,11 +2035,32 @@ public CabViewDiscreteRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCWith
20332035
ChangedValue = (value) =>
20342036
{
20352037
IntermediateValue %= 0.5f;
2038+
if (UserInput.IsMouseLeftButtonDown)
2039+
{
20362040
IntermediateValue += NormalizedMouseMovement();
2041+
}
2042+
else
2043+
{
2044+
// mousewheel
2045+
IntermediateValue += (float)UserInput.MouseWheelChange / 700;
2046+
}
20372047
return IntermediateValue > 0.5f ? 1 : IntermediateValue < -0.5f ? -1 : 0;
20382048
};
20392049
break;
2040-
default: ChangedValue = (value) => value + NormalizedMouseMovement(); break;
2050+
default:
2051+
ChangedValue = (value) =>
2052+
{
2053+
if (UserInput.IsMouseLeftButtonDown)
2054+
{
2055+
return value + NormalizedMouseMovement();
2056+
}
2057+
else
2058+
{
2059+
// mousewheel
2060+
return value + (float)UserInput.MouseWheelChange / 1500;
2061+
}
2062+
};
2063+
break;
20412064
}
20422065
}
20432066

@@ -2341,11 +2364,22 @@ public virtual int GetDrawIndex()
23412364
/// </summary>
23422365
float NormalizedMouseMovement()
23432366
{
2367+
if (UserInput.IsMouseLeftButtonDown)
2368+
{
23442369
return (ControlDiscrete.Orientation > 0
23452370
? (float)UserInput.MouseMoveY / (float)Control.Height
23462371
: (float)UserInput.MouseMoveX / (float)Control.Width)
23472372
* (ControlDiscrete.Direction > 0 ? -1 : 1);
23482373
}
2374+
else
2375+
{
2376+
// mousewheel
2377+
return (ControlDiscrete.Orientation > 0
2378+
? (float)UserInput.MouseWheelChange / (float)Control.Height
2379+
: (float)UserInput.MouseWheelChange / (float)Control.Width)
2380+
* (ControlDiscrete.Direction > 0 ? -1 : 1);
2381+
}
2382+
}
23492383

23502384
public bool IsMouseWithin()
23512385
{
@@ -2851,6 +2885,16 @@ protected int PercentToIndex(float percent)
28512885

28522886
return index;
28532887
}
2888+
2889+
public Rectangle DestinationRectangleGet()
2890+
{
2891+
return DestinationRectangle;
2892+
}
2893+
2894+
public bool isMouseControl()
2895+
{
2896+
return ControlDiscrete.MouseControl;
2897+
}
28542898
}
28552899

28562900
/// <summary>

Source/RunActivity/Viewer3D/RollingStock/SubSystems/ETCS/DriverMachineInterface.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,5 +863,14 @@ public override void Draw(GraphicsDevice graphicsDevice)
863863
ControlView.SpriteBatch.End();
864864
ControlView.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.Default, null, Shader);
865865
}
866+
867+
public Rectangle DestinationRectangleGet()
868+
{
869+
return DrawPosition;
870+
}
871+
public bool isMouseControl()
872+
{
873+
return true;
874+
}
866875
}
867876
}

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public class Viewer
107107
public TrainListWindow TrainListWindow { get; private set; } // for switching driven train
108108
public TTDetachWindow TTDetachWindow { get; private set; } // for detaching player train in timetable mode
109109
public EOTListWindow EOTListWindow { get; private set; } // to select EOT
110+
public ControlRectangle ControlRectangle { get; private set; } // to display the control rectangles
111+
110112
private OutOfFocusWindow OutOfFocusWindow; // to show colored rectangle around the main window when not in focus
111113
public EditorShapes EditorShapes { get; set; }
112114

@@ -526,6 +528,7 @@ internal void Initialize()
526528
TrainListWindow = new TrainListWindow(WindowManager);
527529
TTDetachWindow = new TTDetachWindow(WindowManager);
528530
EOTListWindow = new EOTListWindow(WindowManager);
531+
ControlRectangle = new ControlRectangle(WindowManager, this);
529532
if (Settings.SuppressConfirmations < (int)ConfirmLevel.Error)
530533
// confirm level Error might be set to suppressed when taking a movie
531534
// do not show the out of focus red square in that case
@@ -1043,6 +1046,7 @@ void HandleUserInput(ElapsedTime elapsedTime)
10431046
if (UserInput.IsPressed(UserCommand.DebugSignalling)) if (UserInput.IsDown(UserCommand.DisplayNextWindowTab)) SignallingDebugWindow.TabAction(); else SignallingDebugWindow.Visible = !SignallingDebugWindow.Visible;
10441047
if (UserInput.IsPressed(UserCommand.DisplayTrainListWindow)) TrainListWindow.Visible = !TrainListWindow.Visible;
10451048
if (UserInput.IsPressed(UserCommand.DisplayEOTListWindow)) EOTListWindow.Visible = !EOTListWindow.Visible;
1049+
if (UserInput.IsPressed(UserCommand.DisplayControlRectangle)) ControlRectangle.Visible = !ControlRectangle.Visible;
10461050

10471051

10481052
if (UserInput.IsPressed(UserCommand.GameChangeCab))
@@ -1408,12 +1412,14 @@ void HandleUserInput(ElapsedTime elapsedTime)
14081412

14091413
if (Camera is CabCamera && (PlayerLocomotiveViewer as MSTSLocomotiveViewer)._hasCabRenderer)
14101414
{
1411-
if (UserInput.IsMouseLeftButtonPressed)
1415+
if (UserInput.IsMouseLeftButtonPressed || UserInput.IsMouseWheelChanged)
14121416
{
14131417
var cabRenderer = (PlayerLocomotiveViewer as MSTSLocomotiveViewer)._CabRenderer;
14141418
foreach (var controlRenderer in cabRenderer.ControlMap.Values)
14151419
{
1416-
if ((Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer && mouseRenderer.IsMouseWithin())
1420+
if ((Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer)
1421+
{
1422+
if (mouseRenderer.IsMouseWithin())
14171423
{
14181424
if ((controlRenderer.Control.Screens == null || controlRenderer.Control.Screens[0] == "all"))
14191425
{
@@ -1435,11 +1441,12 @@ void HandleUserInput(ElapsedTime elapsedTime)
14351441
}
14361442
}
14371443
}
1444+
}
14381445

14391446
if (MouseChangingControl != null)
14401447
{
14411448
MouseChangingControl.HandleUserInput();
1442-
if (UserInput.IsMouseLeftButtonReleased)
1449+
if (UserInput.IsMouseLeftButtonReleased || UserInput.IsMouseWheelChanged)
14431450
{
14441451
MouseChangingControl = null;
14451452
UserInput.Handled();

0 commit comments

Comments
 (0)