Skip to content

Commit df8c9cb

Browse files
committed
Automatic merge of T1.5.1-687-gd279e384a and 11 pull requests
- Pull request #570 at c59c788: 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 #865 at 67014b7: Dispatcher window improvements - Pull request #874 at f8dbeab: Dynamic brake controller refactoring - Pull request #875 at 43bf33e: Bug fix for https://bugs.launchpad.net/or/+bug/2036346 Player train switching doesn't work with 3D cabs - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #878 at 25f5e06: Implement Polach Adhesion - Pull request #882 at d8a1c4d: Blueprint/train car operations UI window - Pull request #883 at edcc2dd: SwitchPanel disconnect/connect handling - Pull request #885 at c81447b: feat: Add notifications to Menu - Pull request #886 at 44d1055: Scene viewer extension to TrackViewer
13 parents 343a09e + d279e38 + c59c788 + d00beb9 + 67014b7 + f8dbeab + 43bf33e + f92de76 + 25f5e06 + d8a1c4d + edcc2dd + c81447b + 44d1055 commit df8c9cb

29 files changed

+892
-135
lines changed

Source/Contrib/TrackViewer/Drawing/Labels/DrawLabels.cs

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Newtonsoft.Json;
2525

2626
using ORTS.Common;
27+
using ORTS.TrackViewer.UserInterface;
2728

2829
namespace ORTS.TrackViewer.Drawing.Labels
2930
{
@@ -34,7 +35,7 @@ namespace ORTS.TrackViewer.Drawing.Labels
3435
/// The list of labels can be saved or loaded to .json. This will not be done automatically.
3536
/// The labels can be modified either w.r.t. to their location (dragging) or w.r.t. their text.
3637
/// </summary>
37-
class DrawLabels
38+
public class DrawLabels
3839
{
3940
#region private fields
4041
/// <summary>This is the list of labels that we need to draw and possibly modify </summary>
@@ -56,6 +57,15 @@ class DrawLabels
5657
private WorldLocation draggingStartLocation;
5758
/// <summary>Are we currently dragging?</summary>
5859
private bool dragging = false; // draggingLabelToReplace is not nullable, so we cannot use that
60+
61+
private TrackViewer TrackViewer;
62+
63+
private ContextMenu ContextMenu;
64+
65+
private MenuItem EditLabelMenuItem;
66+
67+
public MenuItem SetLocationMenuItem;
68+
5969
#endregion
6070

6171
#region Constructor
@@ -64,9 +74,12 @@ class DrawLabels
6474
/// Constructor
6575
/// </summary>
6676
/// <param name="fontHeight">The height of the font so we can correct during drawing</param>
67-
public DrawLabels(int fontHeight)
77+
public DrawLabels(TrackViewer trackViewer, int fontHeight)
6878
{
6979
this.fontHeight = fontHeight;
80+
TrackViewer = trackViewer;
81+
82+
CreateContextMenu();
7083
}
7184
#endregion
7285

@@ -88,7 +101,7 @@ public void Draw(DrawArea drawArea)
88101
DrawLabel(label);
89102
}
90103
float distanceSquared = WorldLocation.GetDistanceSquared2D(label.WorldLocation, drawArea.MouseLocation);
91-
if (distanceSquared < closestDistanceSquared )
104+
if (distanceSquared < closestDistanceSquared)
92105
{
93106
closestDistanceSquared = distanceSquared;
94107
closestToMouseLabel = label;
@@ -107,7 +120,7 @@ public void Draw(DrawArea drawArea)
107120
/// <param name="label">The lable to draw</param>
108121
private void DrawLabel(StorableLabel label)
109122
{
110-
drawArea.DrawExpandingString(label.WorldLocation, label.LabelText, 0, -fontHeight/2);
123+
drawArea.DrawExpandingString(label.WorldLocation, label.LabelText, 0, -fontHeight / 2);
111124
}
112125

113126
#endregion
@@ -120,36 +133,56 @@ private void DrawLabel(StorableLabel label)
120133
/// <param name="mouseY">Current Y-location of the mouse to determine popu location</param>
121134
internal void AddLabel(int mouseX, int mouseY)
122135
{
123-
var labelInputPopup = new EditLabel("<label>", mouseX, mouseY,
136+
var labelInputPopup = new EditLabel("<label>", mouseX, mouseY,
124137
(newLabelText) => labels.Add(drawArea.MouseLocation, newLabelText),
125138
allowDelete: false);
126139
TrackViewer.Localize(labelInputPopup);
127140
labelInputPopup.ShowDialog();
128141
}
129142

143+
private void CreateContextMenu()
144+
{
145+
ContextMenu = new ContextMenu();
146+
EditLabelMenuItem = new MenuItem
147+
{
148+
Header = "Edit label",
149+
IsCheckable = false
150+
};
151+
EditLabelMenuItem.Click += new RoutedEventHandler((sender, e) => ModifyLabel(closestToMouseLabel,
152+
TrackViewer.Window.ClientBounds.Left + TVUserInput.MouseLocationX,
153+
TrackViewer.Window.ClientBounds.Left + TVUserInput.MouseLocationY));
154+
155+
ContextMenu.Items.Add(EditLabelMenuItem);
156+
157+
SetLocationMenuItem = new MenuItem() { Header = "View scene here" };
158+
SetLocationMenuItem.Click += new RoutedEventHandler((sender, e) => TrackViewer.menuControl.MenuSceneWindow_Click(sender, e));
159+
SetLocationMenuItem.Click += new RoutedEventHandler(async (sender, e) => await TrackViewer.SceneViewer?.SetCameraLocation());
160+
ContextMenu.Items.Add(SetLocationMenuItem);
161+
}
162+
130163
/// <summary>
131164
/// Popup a context menu that allows you to edit the text of a label
132165
/// </summary>
133166
/// <param name="mouseX">Current X-location of the mouse to determine popup location</param>
134-
/// <param name="mouseY">Current Y-location of the mouse to determine popu location</param>
135-
internal void PopupContextMenu(int mouseX, int mouseY)
167+
/// <param name="mouseY">Current Y-location of the mouse to determine popup location</param>
168+
internal void PopupContextMenu(int mouseX, int mouseY, WorldLocation mouseLocation)
136169
{
137-
if (!Properties.Settings.Default.showLabels) return;
138-
if (labels.Labels.Count() == 0) return;
139-
var editingLabel = closestToMouseLabel;
170+
if (!Properties.Settings.Default.showLabels || labels.Labels.Count() == 0)
171+
EditLabelMenuItem.Visibility = Visibility.Collapsed;
172+
else
173+
EditLabelMenuItem.Visibility = Visibility.Visible;
140174

141-
var contextMenu = new ContextMenu();
175+
SetLocationMenuItem.CommandParameter = mouseLocation;
142176

143-
var editLabelMenuItem = new MenuItem
144-
{
145-
Header = "Edit label",
146-
IsCheckable = false
147-
};
148-
editLabelMenuItem.Click += new RoutedEventHandler((sender, e) => ModifyLabel(closestToMouseLabel, mouseX, mouseY));
177+
var visible = false;
178+
foreach (MenuItem item in ContextMenu.Items)
179+
visible |= item.Visibility == Visibility.Visible;
149180

150-
contextMenu.Items.Add(editLabelMenuItem);
151-
contextMenu.PlacementRectangle = new Rect((double)mouseX, (double)mouseY, 20, 20);
152-
contextMenu.IsOpen = true;
181+
if (visible)
182+
{
183+
ContextMenu.PlacementRectangle = new Rect((double)mouseX, (double)mouseY, 20, 20);
184+
ContextMenu.IsOpen = true;
185+
}
153186
}
154187

155188
/// <summary>
@@ -266,7 +299,7 @@ private void LoadJson(string fileName)
266299
MessageBox.Show(TrackViewer.catalog.GetString("The .json file could not be read properly."));
267300
return;
268301
}
269-
302+
270303
bool itemsWereRemoved = labelsNew.Sanitize();
271304
int itemsLeft = labelsNew.Labels.Count();
272305
string message = string.Empty;
@@ -320,8 +353,8 @@ internal void OnLeftMouseMoved()
320353
//The new location is then 'original' + 'current' - 'start'.
321354
draggingStartLocation.NormalizeTo(drawArea.MouseLocation.TileX, drawArea.MouseLocation.TileZ);
322355
WorldLocation shiftedLocation = new WorldLocation(
323-
draggingLabelToReplace.WorldLocation.TileX + drawArea.MouseLocation.TileX - draggingStartLocation.TileX,
324-
draggingLabelToReplace.WorldLocation.TileZ + drawArea.MouseLocation.TileZ - draggingStartLocation.TileZ,
356+
draggingLabelToReplace.WorldLocation.TileX + drawArea.MouseLocation.TileX - draggingStartLocation.TileX,
357+
draggingLabelToReplace.WorldLocation.TileZ + drawArea.MouseLocation.TileZ - draggingStartLocation.TileZ,
325358
draggingLabelToReplace.WorldLocation.Location.X + drawArea.MouseLocation.Location.X - draggingStartLocation.Location.X,
326359
0,
327360
draggingLabelToReplace.WorldLocation.Location.Z + drawArea.MouseLocation.Location.Z - draggingStartLocation.Location.Z
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This is the controlling file of the Microsoft.Windows.CsWin32 package's
2+
// source code generator, telling that what native functions to generate.
3+
// Check the result in the project/Dependencies/Analyzers/Microsoft.Windows.CsWin32
4+
// in the Visual Studio Solution Explorer.
5+
6+
SetParent
7+
SetWindowLong
8+
WINDOW_STYLE

0 commit comments

Comments
 (0)