Skip to content

Commit 005a1e8

Browse files
committed
Automatic merge of T1.5.1-957-g4fd63a327 and 16 pull requests
- Pull request #799 at dfc715e: Consolidated wind simulation - 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 3ca0eb1: Blueprint/train car operations UI window - Pull request #891 at 9a1d6b2: Auto save - 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 #900 at c27f32d: DMI updates - Pull request #903 at 7af1f91: Downloading route content (Github, zip) - Pull request #912 at 596a03a: New Triple Valve Features Vol. 2 - Pull request #919 at 26cc6a8: Added mouse wheel support for controls which can be moved by pressing t… - Pull request #922 at abe2e52: Autopilot for timetable mode - Pull request #923 at 4c27204: Add curve squeal to route - Pull request #929 at a406a69: Add support for common circuit breaker variants - Pull request #939 at 6c8095a: Add KM/HOUR/MIN to Cabview Units - Pull request #941 at 50378f6: AI Penalty Lights Fix
18 parents 2519e23 + 4fd63a3 + dfc715e + d00beb9 + f92de76 + 3ca0eb1 + 9a1d6b2 + 1f5ba4c + 5866028 + c27f32d + 7af1f91 + 596a03a + 26cc6a8 + abe2e52 + 4c27204 + a406a69 + 6c8095a + 50378f6 commit 005a1e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+845
-3104
lines changed

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

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

2626
using ORTS.Common;
27-
using ORTS.TrackViewer.UserInterface;
2827

2928
namespace ORTS.TrackViewer.Drawing.Labels
3029
{
@@ -35,7 +34,7 @@ namespace ORTS.TrackViewer.Drawing.Labels
3534
/// The list of labels can be saved or loaded to .json. This will not be done automatically.
3635
/// The labels can be modified either w.r.t. to their location (dragging) or w.r.t. their text.
3736
/// </summary>
38-
public class DrawLabels
37+
class DrawLabels
3938
{
4039
#region private fields
4140
/// <summary>This is the list of labels that we need to draw and possibly modify </summary>
@@ -57,15 +56,6 @@ public class DrawLabels
5756
private WorldLocation draggingStartLocation;
5857
/// <summary>Are we currently dragging?</summary>
5958
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-
6959
#endregion
7060

7161
#region Constructor
@@ -74,12 +64,9 @@ public class DrawLabels
7464
/// Constructor
7565
/// </summary>
7666
/// <param name="fontHeight">The height of the font so we can correct during drawing</param>
77-
public DrawLabels(TrackViewer trackViewer, int fontHeight)
67+
public DrawLabels(int fontHeight)
7868
{
7969
this.fontHeight = fontHeight;
80-
TrackViewer = trackViewer;
81-
82-
CreateContextMenu();
8370
}
8471
#endregion
8572

@@ -101,7 +88,7 @@ public void Draw(DrawArea drawArea)
10188
DrawLabel(label);
10289
}
10390
float distanceSquared = WorldLocation.GetDistanceSquared2D(label.WorldLocation, drawArea.MouseLocation);
104-
if (distanceSquared < closestDistanceSquared)
91+
if (distanceSquared < closestDistanceSquared )
10592
{
10693
closestDistanceSquared = distanceSquared;
10794
closestToMouseLabel = label;
@@ -120,7 +107,7 @@ public void Draw(DrawArea drawArea)
120107
/// <param name="label">The lable to draw</param>
121108
private void DrawLabel(StorableLabel label)
122109
{
123-
drawArea.DrawExpandingString(label.WorldLocation, label.LabelText, 0, -fontHeight / 2);
110+
drawArea.DrawExpandingString(label.WorldLocation, label.LabelText, 0, -fontHeight/2);
124111
}
125112

126113
#endregion
@@ -133,58 +120,36 @@ private void DrawLabel(StorableLabel label)
133120
/// <param name="mouseY">Current Y-location of the mouse to determine popu location</param>
134121
internal void AddLabel(int mouseX, int mouseY)
135122
{
136-
var labelInputPopup = new EditLabel("<label>", mouseX, mouseY,
123+
var labelInputPopup = new EditLabel("<label>", mouseX, mouseY,
137124
(newLabelText) => labels.Add(drawArea.MouseLocation, newLabelText),
138125
allowDelete: false);
139126
TrackViewer.Localize(labelInputPopup);
140127
labelInputPopup.ShowDialog();
141128
}
142129

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.Icon = TrackViewer.menuControl.ThreeDSceneIcon;
159-
SetLocationMenuItem.Click += new RoutedEventHandler((sender, e) => TrackViewer.menuControl.MenuSceneWindow_Click(sender, e));
160-
SetLocationMenuItem.Click += new RoutedEventHandler(async (sender, e) => await TrackViewer.SceneView?.SetCameraLocation(
161-
SetLocationMenuItem.CommandParameter as WorldLocation? ?? new WorldLocation()));
162-
ContextMenu.Items.Add(SetLocationMenuItem);
163-
}
164-
165130
/// <summary>
166131
/// Popup a context menu that allows you to edit the text of a label
167132
/// </summary>
168133
/// <param name="mouseX">Current X-location of the mouse to determine popup location</param>
169-
/// <param name="mouseY">Current Y-location of the mouse to determine popup location</param>
170-
internal void PopupContextMenu(int mouseX, int mouseY, WorldLocation mouseLocation)
134+
/// <param name="mouseY">Current Y-location of the mouse to determine popu location</param>
135+
internal void PopupContextMenu(int mouseX, int mouseY)
171136
{
172-
if (!Properties.Settings.Default.showLabels || labels.Labels.Count() == 0)
173-
EditLabelMenuItem.Visibility = Visibility.Collapsed;
174-
else
175-
EditLabelMenuItem.Visibility = Visibility.Visible;
176-
177-
SetLocationMenuItem.CommandParameter = mouseLocation;
137+
if (!Properties.Settings.Default.showLabels) return;
138+
if (labels.Labels.Count() == 0) return;
139+
var editingLabel = closestToMouseLabel;
178140

179-
var visible = false;
180-
foreach (MenuItem item in ContextMenu.Items)
181-
visible |= item.Visibility == Visibility.Visible;
141+
var contextMenu = new ContextMenu();
182142

183-
if (visible)
143+
var editLabelMenuItem = new MenuItem
184144
{
185-
ContextMenu.PlacementRectangle = new Rect((double)mouseX, (double)mouseY, 20, 20);
186-
ContextMenu.IsOpen = true;
187-
}
145+
Header = "Edit label",
146+
IsCheckable = false
147+
};
148+
editLabelMenuItem.Click += new RoutedEventHandler((sender, e) => ModifyLabel(closestToMouseLabel, mouseX, mouseY));
149+
150+
contextMenu.Items.Add(editLabelMenuItem);
151+
contextMenu.PlacementRectangle = new Rect((double)mouseX, (double)mouseY, 20, 20);
152+
contextMenu.IsOpen = true;
188153
}
189154

190155
/// <summary>
@@ -301,7 +266,7 @@ private void LoadJson(string fileName)
301266
MessageBox.Show(TrackViewer.catalog.GetString("The .json file could not be read properly."));
302267
return;
303268
}
304-
269+
305270
bool itemsWereRemoved = labelsNew.Sanitize();
306271
int itemsLeft = labelsNew.Labels.Count();
307272
string message = string.Empty;
@@ -355,8 +320,8 @@ internal void OnLeftMouseMoved()
355320
//The new location is then 'original' + 'current' - 'start'.
356321
draggingStartLocation.NormalizeTo(drawArea.MouseLocation.TileX, drawArea.MouseLocation.TileZ);
357322
WorldLocation shiftedLocation = new WorldLocation(
358-
draggingLabelToReplace.WorldLocation.TileX + drawArea.MouseLocation.TileX - draggingStartLocation.TileX,
359-
draggingLabelToReplace.WorldLocation.TileZ + drawArea.MouseLocation.TileZ - draggingStartLocation.TileZ,
323+
draggingLabelToReplace.WorldLocation.TileX + drawArea.MouseLocation.TileX - draggingStartLocation.TileX,
324+
draggingLabelToReplace.WorldLocation.TileZ + drawArea.MouseLocation.TileZ - draggingStartLocation.TileZ,
360325
draggingLabelToReplace.WorldLocation.Location.X + drawArea.MouseLocation.Location.X - draggingStartLocation.Location.X,
361326
0,
362327
draggingLabelToReplace.WorldLocation.Location.Z + drawArea.MouseLocation.Location.Z - draggingStartLocation.Location.Z

0 commit comments

Comments
 (0)