Skip to content

Commit de02783

Browse files
committed
Automatic merge of T1.5.1-913-g91804456c and 16 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 1a5693d: Blueprint/train car operations UI window - 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 #903 at f588e31: Downloading route content (Github, zip) - Pull request #910 at 97d4569: Allow building code using .NET 6 (Windows) - Pull request #911 at 6834af0: docs: Add refactoring as a special type of PR - Pull request #912 at f7b85e4: New Triple Valve Features Vol. 2 - Pull request #919 at 5040910: Added mouse wheel support for controls which can be moved by pressing t… - Pull request #920 at a94e403: Update RailDriver in Manual - Pull request #923 at e0f3c55: Add curve squeal to route - Pull request #924 at 6c2c3cd: Default Asset Improvements - Pull request #925 at e3b1688: Fix brakeshoe force bug
18 parents 50aa3d6 + 9180445 + 3539862 + d00beb9 + f92de76 + 1a5693d + 6c0785b + 1f5ba4c + 5866028 + f588e31 + 97d4569 + 6834af0 + f7b85e4 + 5040910 + a94e403 + e0f3c55 + 6c2c3cd + e3b1688 commit de02783

File tree

1 file changed

+56
-17
lines changed

1 file changed

+56
-17
lines changed

Source/RunActivity/Viewer3D/Popups/ControlRectangle.cs

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,73 +15,112 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18+
using System.Collections.Generic;
1819
using System.Linq;
1920
using Microsoft.Xna.Framework;
2021
using Microsoft.Xna.Framework.Graphics;
2122
using Orts.Simulation.RollingStocks;
2223
using Orts.Viewer3D.RollingStock;
24+
using SpriteBatch = Microsoft.Xna.Framework.Graphics.SpriteBatch;
2325

2426
namespace Orts.Viewer3D.Popups
2527
{
2628
public class ControlRectangle : Window
2729
{
2830
private readonly Texture2D Line;
29-
private readonly int Thickness = 3;
31+
private int Thickness = 1;
3032
private readonly Color Color = Color.Yellow;
3133
private readonly Viewer Viewer;
34+
private bool CabViewFront;
35+
private bool IsOverRectangle = false;
36+
private class ListRect
37+
{
38+
public bool Front;
39+
public Rectangle CabRectangle;
40+
public string Name;
41+
}
42+
private List<ListRect> ListRectangles = new List<ListRect>();
43+
private ListRect ListRects;
3244

3345
public ControlRectangle(WindowManager owner, Viewer viewer) : base(owner)
3446
{
3547
Line = new Texture2D(Owner.Viewer.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
3648
Line.SetData(new[] { Color });
3749
Viewer = viewer;
3850
}
39-
4051
public override void Draw(SpriteBatch spriteBatch)
4152
{
4253
if (Viewer.Camera is CabCamera && (Viewer.PlayerLocomotiveViewer as MSTSLocomotiveViewer)._hasCabRenderer)
4354
{
4455
var cabRenderer = (Viewer.PlayerLocomotiveViewer as MSTSLocomotiveViewer)._CabRenderer;
4556

4657
var loco = Viewer.PlayerLocomotive as MSTSLocomotive;
47-
var cabViewFrontRear = loco.UsingRearCab ? 1 : 0;
58+
CabViewFront = !loco.UsingRearCab;
59+
4860
var itemsFrontCount = loco.CabViewList[(int)CabViewType.Front].CVFFile.CabViewControls.Count();
4961
var itemsRearCount = loco.CabViewList.Count > 1 ? loco.CabViewList[(int)CabViewType.Rear].CVFFile.CabViewControls.Count() : 0;
50-
51-
foreach (var controlRenderer in cabRenderer.ControlMap.Values.Skip(cabViewFrontRear == 0 ? 0 : itemsFrontCount).Take(cabViewFrontRear == 0 ? itemsFrontCount : itemsRearCount))
62+
63+
foreach (var controlRenderer in cabRenderer.ControlMap.Values.Skip(CabViewFront ? 0 : itemsFrontCount).Take(CabViewFront ? itemsFrontCount : itemsRearCount))
5264
{
5365
if ((Viewer.Camera as CabCamera).SideLocation == controlRenderer.Control.CabViewpoint && controlRenderer is ICabViewMouseControlRenderer mouseRenderer)
54-
{
66+
{
5567
if (mouseRenderer.isMouseControl())
5668
{
5769
Rectangle rectangle = mouseRenderer.DestinationRectangleGet();
58-
5970
int width = rectangle.Width;
6071
int height = rectangle.Height;
6172

6273
if (width > 0)
6374
{
6475
// do not know why rectangles with width and height = 0 are there
76+
ListRects = ListRectangles.FirstOrDefault(c => c.Name == mouseRenderer.GetControlName() && c.Front == CabViewFront);
77+
if (ListRects == null)
78+
{
79+
ListRectangles.Add(new ListRect
80+
{
81+
CabRectangle = rectangle,
82+
Front = CabViewFront,
83+
Name = mouseRenderer.GetControlName(),
84+
});
85+
}
86+
else
87+
{
88+
ListRects.CabRectangle = rectangle;
89+
}
6590

66-
// top line
67-
DrawLine(spriteBatch, rectangle.X, rectangle.Y, width, Thickness, 0);
68-
69-
// bottom line
70-
DrawLine(spriteBatch, rectangle.X, rectangle.Y + height - Thickness, width, Thickness, 0);
91+
Thickness = 1; // default
92+
if (mouseRenderer.IsMouseWithin())
93+
{
94+
ListRects = ListRectangles.FirstOrDefault(c => c.CabRectangle == rectangle && c.Front == CabViewFront);
7195

72-
// left line
73-
DrawLine(spriteBatch, rectangle.X + Thickness, rectangle.Y, height, Thickness, 90);
96+
if (ListRects != null && rectangle.Intersects(ListRects.CabRectangle) && ListRects.Name == mouseRenderer.GetControlName() && !IsOverRectangle)
97+
{
98+
Thickness = 3; // Highlights the currently selected rectangle
99+
IsOverRectangle = true;
100+
}
101+
}
74102

75-
// right line
76-
DrawLine(spriteBatch, rectangle.X + width, rectangle.Y, height, Thickness, 90);
103+
DrawRectangle(spriteBatch, rectangle.X, rectangle.Y, width, height, Thickness, Color);
77104
}
78105
}
79106
}
80107
}
108+
IsOverRectangle = false;
81109
}
82110
}
83111

84-
private void DrawLine(SpriteBatch spriteBatch, int X, int Y, int width, int height, int degrees)
112+
private void DrawRectangle(SpriteBatch spriteBatch, int newX, int newY, int width, int height, int Thickness, Color Color)
113+
{ // top line
114+
DrawLine(spriteBatch, newX, newY, width, Thickness, 0, Color);
115+
// bottom line
116+
DrawLine(spriteBatch, newX, newY + height - Thickness, width, Thickness, 0, Color);
117+
// left line
118+
DrawLine(spriteBatch, newX + Thickness, newY, height, Thickness, 90, Color);
119+
// right line
120+
DrawLine(spriteBatch, newX + width, newY, height, Thickness, 90, Color);
121+
}
122+
123+
private void DrawLine(SpriteBatch spriteBatch, int X, int Y, int width, int height, int degrees, Color Color)
85124
{
86125
spriteBatch.Draw(
87126
Line,

0 commit comments

Comments
 (0)