Skip to content

Commit

Permalink
Automatic merge of T1.5.1-870-ge0bf062eb and 17 pull requests
Browse files Browse the repository at this point in the history
- 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…
  • Loading branch information
openrails-bot committed Feb 23, 2024
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 5 deletions.
21 changes: 20 additions & 1 deletion Source/ORTS.Common/Input/UserCommand.cs
@@ -1,4 +1,22 @@
namespace ORTS.Common.Input
// COPYRIGHT 2024 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
//

namespace ORTS.Common.Input
{
/// <summary>
/// Specifies game commands.
Expand Down Expand Up @@ -50,6 +68,7 @@ public enum UserCommand
[GetString("Display Compass Window")] DisplayCompassWindow,
[GetString("Display Train List Window")] DisplayTrainListWindow,
[GetString("Display EOT List Window")] DisplayEOTListWindow,
[GetString("Display Control Rectangles")] DisplayControlRectangle,

[GetString("Debug Speed Up")] DebugSpeedUp,
[GetString("Debug Speed Down")] DebugSpeedDown,
Expand Down
1 change: 1 addition & 0 deletions Source/ORTS.Settings/InputSettings.cs
Expand Up @@ -516,6 +516,7 @@ static void InitializeCommands(UserCommandInput[] Commands)
Commands[(int)UserCommand.DisplayTrainOperationsWindow] = new UserCommandKeyInput(0x43);
Commands[(int)UserCommand.DisplayTrainDpuWindow] = new UserCommandKeyInput(0x43, KeyModifiers.Shift);
Commands[(int)UserCommand.DisplayEOTListWindow] = new UserCommandKeyInput(0x43, KeyModifiers.Control);
Commands[(int)UserCommand.DisplayControlRectangle] = new UserCommandKeyInput(0x3F, KeyModifiers.Control);

Commands[(int)UserCommand.GameAutopilotMode] = new UserCommandKeyInput(0x1E, KeyModifiers.Alt);
Commands[(int)UserCommand.GameChangeCab] = new UserCommandKeyInput(0x12, KeyModifiers.Control);
Expand Down
94 changes: 94 additions & 0 deletions Source/RunActivity/Viewer3D/Popups/ControlRectangle.cs
@@ -0,0 +1,94 @@
// COPYRIGHT 2024 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Orts.Viewer3D.RollingStock;

namespace Orts.Viewer3D.Popups
{
public class ControlRectangle : Window
{
private readonly Texture2D Line;
private readonly int Thickness = 3;
private readonly Color Color = Color.Yellow;
private readonly Viewer Viewer;

public ControlRectangle(WindowManager owner, Viewer viewer) : base(owner)
{
Line = new Texture2D(Owner.Viewer.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
Line.SetData(new[] { Color });
Viewer = viewer;
}

public override void Draw(SpriteBatch spriteBatch)
{
if (Viewer.Camera is CabCamera && (Viewer.PlayerLocomotiveViewer as MSTSLocomotiveViewer)._hasCabRenderer)
{
var cabRenderer = (Viewer.PlayerLocomotiveViewer as MSTSLocomotiveViewer)._CabRenderer;
foreach (var controlRenderer in cabRenderer.ControlMap.Values)
{
if ((Viewer.Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer)
{
if (mouseRenderer.isMouseControl())
{
Rectangle rectangle = mouseRenderer.DestinationRectangleGet();

int width = rectangle.Width;
int height = rectangle.Height;

if (width > 0)
{
// do not know why rectangles with width and height = 0 are there

// top line
DrawLine(spriteBatch, rectangle.X, rectangle.Y, width, Thickness, 0);

// bottom line
DrawLine(spriteBatch, rectangle.X, rectangle.Y + height - Thickness, width, Thickness, 0);

// left line
DrawLine(spriteBatch, rectangle.X + Thickness, rectangle.Y, height, Thickness, 90);

// right line
DrawLine(spriteBatch, rectangle.X + width, rectangle.Y, height, Thickness, 90);
}
}
}
}
}
}

private void DrawLine(SpriteBatch spriteBatch, int X, int Y, int width, int height, int degrees)
{
spriteBatch.Draw(
Line,
new Rectangle(X, Y, width, height),
null,
Color,
ConvertToRadiansFromDegrees(degrees),
new Vector2(0, 0),
SpriteEffects.None, 0);
}

private float ConvertToRadiansFromDegrees(int angle)
{
return (float)((System.Math.PI / 180) * angle);
}
}
}
46 changes: 45 additions & 1 deletion Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs
Expand Up @@ -1699,6 +1699,8 @@ public interface ICabViewMouseControlRenderer
void HandleUserInput();
string GetControlName();
string ControlLabel { get; }
Rectangle DestinationRectangleGet();
bool isMouseControl();
}

/// <summary>
Expand Down Expand Up @@ -2033,11 +2035,32 @@ public CabViewDiscreteRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCWith
ChangedValue = (value) =>
{
IntermediateValue %= 0.5f;
if (UserInput.IsMouseLeftButtonDown)
{
IntermediateValue += NormalizedMouseMovement();
}
else
{
// mousewheel
IntermediateValue += (float)UserInput.MouseWheelChange / 700;
}
return IntermediateValue > 0.5f ? 1 : IntermediateValue < -0.5f ? -1 : 0;
};
break;
default: ChangedValue = (value) => value + NormalizedMouseMovement(); break;
default:
ChangedValue = (value) =>
{
if (UserInput.IsMouseLeftButtonDown)
{
return value + NormalizedMouseMovement();
}
else
{
// mousewheel
return value + (float)UserInput.MouseWheelChange / 1500;
}
};
break;
}
}

Expand Down Expand Up @@ -2341,11 +2364,22 @@ public virtual int GetDrawIndex()
/// </summary>
float NormalizedMouseMovement()
{
if (UserInput.IsMouseLeftButtonDown)
{
return (ControlDiscrete.Orientation > 0
? (float)UserInput.MouseMoveY / (float)Control.Height
: (float)UserInput.MouseMoveX / (float)Control.Width)
* (ControlDiscrete.Direction > 0 ? -1 : 1);
}
else
{
// mousewheel
return (ControlDiscrete.Orientation > 0
? (float)UserInput.MouseWheelChange / (float)Control.Height
: (float)UserInput.MouseWheelChange / (float)Control.Width)
* (ControlDiscrete.Direction > 0 ? -1 : 1);
}
}

public bool IsMouseWithin()
{
Expand Down Expand Up @@ -2851,6 +2885,16 @@ protected int PercentToIndex(float percent)

return index;
}

public Rectangle DestinationRectangleGet()
{
return DestinationRectangle;
}

public bool isMouseControl()
{
return ControlDiscrete.MouseControl;
}
}

/// <summary>
Expand Down
Expand Up @@ -863,5 +863,14 @@ public override void Draw(GraphicsDevice graphicsDevice)
ControlView.SpriteBatch.End();
ControlView.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.Default, null, Shader);
}

public Rectangle DestinationRectangleGet()
{
return DrawPosition;
}
public bool isMouseControl()
{
return true;
}
}
}
13 changes: 10 additions & 3 deletions Source/RunActivity/Viewer3D/Viewer.cs
Expand Up @@ -107,6 +107,8 @@ public class Viewer
public TrainListWindow TrainListWindow { get; private set; } // for switching driven train
public TTDetachWindow TTDetachWindow { get; private set; } // for detaching player train in timetable mode
public EOTListWindow EOTListWindow { get; private set; } // to select EOT
public ControlRectangle ControlRectangle { get; private set; } // to display the control rectangles

private OutOfFocusWindow OutOfFocusWindow; // to show colored rectangle around the main window when not in focus
public EditorShapes EditorShapes { get; set; }

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


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

if (Camera is CabCamera && (PlayerLocomotiveViewer as MSTSLocomotiveViewer)._hasCabRenderer)
{
if (UserInput.IsMouseLeftButtonPressed)
if (UserInput.IsMouseLeftButtonPressed || UserInput.IsMouseWheelChanged)
{
var cabRenderer = (PlayerLocomotiveViewer as MSTSLocomotiveViewer)._CabRenderer;
foreach (var controlRenderer in cabRenderer.ControlMap.Values)
{
if ((Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer && mouseRenderer.IsMouseWithin())
if ((Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer)
{
if (mouseRenderer.IsMouseWithin())
{
if ((controlRenderer.Control.Screens == null || controlRenderer.Control.Screens[0] == "all"))
{
Expand All @@ -1435,11 +1441,12 @@ void HandleUserInput(ElapsedTime elapsedTime)
}
}
}
}

if (MouseChangingControl != null)
{
MouseChangingControl.HandleUserInput();
if (UserInput.IsMouseLeftButtonReleased)
if (UserInput.IsMouseLeftButtonReleased || UserInput.IsMouseWheelChanged)
{
MouseChangingControl = null;
UserInput.Handled();
Expand Down

0 comments on commit a82c1f4

Please sign in to comment.