-
Notifications
You must be signed in to change notification settings - Fork 52
/
ProgramR.cs
792 lines (752 loc) · 25 KB
/
ProgramR.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
// ╔═════════════════════════════════════════════════════════════╗
// ║ Program.cs for the Route Viewer ║
// ╠═════════════════════════════════════════════════════════════╣
// ║ This file cannot be used in the openBVE main program. ║
// ║ The file from the openBVE main program cannot be used here. ║
// ╚═════════════════════════════════════════════════════════════╝
using LibRender2.Cameras;
using OpenBveApi;
using OpenBveApi.FileSystem;
using OpenBveApi.Interface;
using OpenBveApi.Routes;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
using RouteManager2;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using System.Runtime;
using System.Text;
using System.Windows.Forms;
using LibRender2.Overlays;
using OpenBveApi.Colors;
using OpenBveApi.Hosts;
using OpenBveApi.Objects;
using ButtonState = OpenTK.Input.ButtonState;
using Vector3 = OpenBveApi.Math.Vector3;
namespace RouteViewer
{
internal static class Program {
// system
internal static FileSystem FileSystem = null;
internal static string CurrentRouteFile = null;
internal static bool CurrentlyLoading = false;
internal static bool JumpToPositionEnabled = false;
internal static string JumpToPositionValue = "";
internal static double MinimumJumpToPositionValue = 0;
internal static bool processCommandLineArgs;
// keys
private static bool ShiftPressed = false;
private static bool ControlPressed = false;
private static bool AltPressed = false;
internal static GameWindow currentGameWindow;
internal static GraphicsMode currentGraphicsMode;
// mouse
private static int MouseButton;
/// <summary>The host API used by this program.</summary>
internal static Host CurrentHost = null;
internal static NewRenderer Renderer;
internal static CurrentRoute CurrentRoute;
internal static Sounds Sounds;
internal static TrainManager TrainManager;
internal static formRailPaths pathForm;
// main
[STAThread]
internal static void Main(string[] args)
{
CurrentHost = new Host();
// file system
FileSystem = FileSystem.FromCommandLineArgs(args, CurrentHost);
FileSystem.CreateFileSystem();
Sounds = new Sounds();
Options.LoadOptions();
Renderer = new NewRenderer(CurrentHost, Interface.CurrentOptions, FileSystem);
CurrentRoute = new CurrentRoute(CurrentHost, Renderer);
TrainManager = new TrainManager(CurrentHost, Renderer, Interface.CurrentOptions, FileSystem);
string error;
if (!CurrentHost.LoadPlugins(FileSystem, Interface.CurrentOptions, out error, TrainManager, Renderer))
{
MessageBox.Show(error, @"OpenBVE", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// command line arguments
string objectsToLoad = string.Empty;
if (args.Length != 0)
{
for (int i = 0; i < args.Length; i++)
{
if (args[i] != null)
{
if (System.IO.File.Exists(args[i]))
{
for (int j = 0; j < CurrentHost.Plugins.Length; j++)
{
if (CurrentHost.Plugins[j].Object != null && CurrentHost.Plugins[j].Object.CanLoadObject(args[i]))
{
objectsToLoad += args[i] + " ";
continue;
}
if (CurrentHost.Plugins[j].Route != null && CurrentHost.Plugins[j].Route.CanLoadRoute(args[i]))
{
if (string.IsNullOrEmpty(CurrentRouteFile))
{
CurrentRouteFile = args[i];
processCommandLineArgs = true;
}
}
}
}
else if (args[i].ToLowerInvariant() == "/enablehacks")
{
//Deliberately undocumented option for debugging use
Interface.CurrentOptions.EnableBveTsHacks = true;
for (int j = 0; j < CurrentHost.Plugins.Length; j++)
{
if (CurrentHost.Plugins[j].Object != null)
{
CompatabilityHacks enabledHacks = new CompatabilityHacks
{
BveTsHacks = true,
CylinderHack = false,
BlackTransparency = true
};
CurrentHost.Plugins[j].Object.SetCompatibilityHacks(enabledHacks);
}
}
}
}
}
}
if (objectsToLoad.Length != 0)
{
string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe");
if (System.IO.File.Exists(File))
{
System.Diagnostics.Process.Start(File, objectsToLoad.ToString());
if (string.IsNullOrEmpty(CurrentRouteFile))
{
//We only supplied objects, so launch Object Viewer instead
Environment.Exit(0);
}
}
}
var options = new ToolkitOptions();
options.Backend = PlatformBackend.PreferX11;
Toolkit.Init(options);
string folder = Program.FileSystem.GetDataFolder("Languages");
Translations.LoadLanguageFiles(folder);
Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000;
Interface.CurrentOptions.ObjectOptimizationFullThreshold = 250;
// application
currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel);
if (Renderer.Screen.Width == 0 || Renderer.Screen.Height == 0)
{
//Duff values saved, so reset to something sensible else we crash
Renderer.Screen.Width = 1024;
Renderer.Screen.Height = 768;
}
Renderer.CameraTrackFollower = new TrackFollower(Program.CurrentHost);
currentGameWindow = new RouteViewer(Renderer.Screen.Width, Renderer.Screen.Height, currentGraphicsMode, "Route Viewer", GameWindowFlags.Default);
currentGameWindow.Visible = true;
currentGameWindow.TargetUpdateFrequency = 0;
currentGameWindow.TargetRenderFrequency = 0;
currentGameWindow.Title = "Route Viewer";
processCommandLineArgs = true;
currentGameWindow.Run();
//Unload
Sounds.Deinitialize();
}
// load route
internal static bool LoadRoute(Bitmap bitmap = null) {
if (string.IsNullOrEmpty(CurrentRouteFile))
{
return false;
}
Renderer.UpdateViewport();
bool result;
try
{
Encoding encoding = TextEncoding.GetSystemEncodingFromFile(CurrentRouteFile);
Loading.Load(CurrentRouteFile, encoding, bitmap);
result = true;
} catch (Exception ex) {
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
Game.Reset();
result = false;
CurrentRouteFile = null;
}
if (Loading.Cancel)
{
result = false;
CurrentRouteFile = null;
}
Renderer.Lighting.Initialize();
Renderer.InitializeVisibility();
for (int i = 0; i < CurrentRoute.Tracks.Count; i++)
{
int key = Program.CurrentRoute.Tracks.ElementAt(i).Key;
if (!Renderer.trackColors.ContainsKey(key))
{
if (key == 0)
{
Renderer.trackColors.Add(key, new RailPath(CurrentHost, Renderer, key, Program.CurrentRoute.BlockLength, Color24.Red));
Renderer.usedTrackColors.Add(5);
}
else
{
var randomGenerator = new Random();
int colorIdx = 5; // known value already in list to make our while loop easy
while (Renderer.usedTrackColors.Contains(colorIdx))
{
colorIdx = randomGenerator.Next(0, 255);
}
Renderer.usedTrackColors.Add(colorIdx);
Renderer.trackColors.Add(key, new RailPath(Program.CurrentHost, Renderer, key, Program.CurrentRoute.BlockLength, ColorPalettes.Windows256ColorPalette[colorIdx])); //use the 256 color Windows pallette for a decent set of contrasting colors
}
}
Renderer.trackColors[key].Render();
}
return result;
}
// jump to station
private static void JumpToStation(int Direction) {
if (Direction < 0) {
for (int i = CurrentRoute.Stations.Length - 1; i >= 0; i--) {
if (CurrentRoute.Stations[i].Stops.Length != 0) {
double p = CurrentRoute.Stations[i].Stops[CurrentRoute.Stations[i].Stops.Length - 1].TrackPosition;
if (p < Program.Renderer.CameraTrackFollower.TrackPosition - 0.1) {
Program.Renderer.CameraTrackFollower.UpdateAbsolute(p, true, false);
Renderer.Camera.Alignment.TrackPosition = p;
Renderer.Camera.Reset();
break;
}
}
}
} else if (Direction > 0) {
for (int i = 0; i < CurrentRoute.Stations.Length; i++) {
if (CurrentRoute.Stations[i].Stops.Length != 0) {
double p = CurrentRoute.Stations[i].Stops[CurrentRoute.Stations[i].Stops.Length - 1].TrackPosition;
if (p > Program.Renderer.CameraTrackFollower.TrackPosition + 0.1) {
Program.Renderer.CameraTrackFollower.UpdateAbsolute(p, true, false);
Renderer.Camera.Alignment.TrackPosition = p;
Renderer.Camera.Reset();
break;
}
}
}
}
}
internal static void UpdateGraphicsSettings()
{
if (CurrentRouteFile != null)
{
Program.CurrentlyLoading = true;
Renderer.RenderScene(0.0);
Program.currentGameWindow.SwapBuffers();
CameraAlignment a = Renderer.Camera.Alignment;
if (Program.LoadRoute())
{
Renderer.Camera.Alignment = a;
Program.Renderer.CameraTrackFollower.UpdateAbsolute(-1.0, true, false);
Program.Renderer.CameraTrackFollower.UpdateAbsolute(a.TrackPosition, true, false);
Renderer.Camera.AlignmentDirection = new CameraAlignment();
Renderer.Camera.AlignmentSpeed = new CameraAlignment();
Renderer.UpdateVisibility(a.TrackPosition, true);
ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
}
Program.CurrentlyLoading = false;
}
}
internal static void MouseEvent(object sender, MouseButtonEventArgs e)
{
if (e.Button == OpenTK.Input.MouseButton.Left)
{
MouseButton = e.Mouse.LeftButton == ButtonState.Pressed ? 1 : 0;
}
if (e.Button == OpenTK.Input.MouseButton.Right)
{
MouseButton = e.Mouse.RightButton == ButtonState.Pressed ? 2 : 0;
}
if (e.Button == OpenTK.Input.MouseButton.Middle)
{
MouseButton = e.Mouse.RightButton == ButtonState.Pressed ? 3 : 0;
}
previousMouseState = Mouse.GetState();
if (MouseButton == 0)
{
Renderer.Camera.AlignmentDirection.Yaw = 0.0;
Renderer.Camera.AlignmentDirection.Pitch = 0.0;
Renderer.Camera.AlignmentDirection.Position.X = 0.0;
Renderer.Camera.AlignmentDirection.Position.Y = 0.0;
}
}
internal static MouseState currentMouseState;
internal static MouseState previousMouseState;
internal static void MouseMovement()
{
if (MouseButton == 0)
{
return;
}
currentMouseState = Mouse.GetState();
if (currentMouseState != previousMouseState)
{
Renderer.Camera.AlignmentDirection.Yaw = 0.0;
Renderer.Camera.AlignmentDirection.Pitch = 0.0;
Renderer.Camera.AlignmentDirection.Position.X = 0.0;
Renderer.Camera.AlignmentDirection.Position.Y = 0.0;
if (MouseButton == 1)
{
Renderer.Camera.AlignmentDirection.Yaw = 0.025 * (double) (previousMouseState.X - currentMouseState.X);
Renderer.Camera.AlignmentDirection.Pitch = 0.025 * (double)(previousMouseState.Y - currentMouseState.Y);
}
else if (MouseButton == 2)
{
Renderer.Camera.AlignmentDirection.Position.X = 0.1 * (double)(previousMouseState.X - currentMouseState.X);
Renderer.Camera.AlignmentDirection.Position.Y = 0.1 * (double)(previousMouseState.Y - currentMouseState.Y);
}
}
}
internal static void FileDrop(object sender, FileDropEventArgs e)
{
//Seem to need to flush the WM queue after dropping a file, else it crashes nastily after load on Mono
Application.DoEvents();
CurrentlyLoading = true;
CurrentRouteFile = e.FileName;
LoadRoute();
ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
CurrentlyLoading = false;
Renderer.Camera.Reset();
UpdateCaption();
}
internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e)
{
double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0);
switch (e.Key)
{
case Key.ShiftLeft:
case Key.ShiftRight:
ShiftPressed = true;
break;
case Key.ControlLeft:
case Key.ControlRight:
ControlPressed = true;
break;
case Key.LAlt:
case Key.RAlt:
AltPressed = true;
break;
case Key.F5:
if (CurrentlyLoading)
{
return;
}
if (CurrentRouteFile != null && CurrentlyLoading == false)
{
Bitmap bitmap = null;
CurrentlyLoading = true;
Renderer.OptionInterface = false;
if (!Interface.CurrentOptions.LoadingBackground)
{
Renderer.RenderScene(0.0);
currentGameWindow.SwapBuffers();
bitmap = new Bitmap(Renderer.Screen.Width, Renderer.Screen.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
BitmapData bData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
GL.ReadPixels(0, 0, Renderer.Screen.Width, Renderer.Screen.Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bData.Scan0);
bitmap.UnlockBits(bData);
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
}
Renderer.Reset();
CameraAlignment a = Renderer.Camera.Alignment;
if (LoadRoute(bitmap))
{
Renderer.Camera.Alignment = a;
Program.Renderer.CameraTrackFollower.UpdateAbsolute(-1.0, true, false);
Program.Renderer.CameraTrackFollower.UpdateAbsolute(a.TrackPosition, true, false);
Renderer.UpdateVisibility(a.TrackPosition, true);
ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
}
else
{
Renderer.Camera.Reset();
Renderer.UpdateViewport();
World.UpdateAbsoluteCamera(0.0);
Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
}
CurrentlyLoading = false;
Renderer.OptionInterface = true;
if (bitmap != null)
{
bitmap.Dispose();
}
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
}
break;
case Key.F7:
if (CurrentlyLoading == true)
{
break;
}
OpenFileDialog Dialog = new OpenFileDialog();
Dialog.CheckFileExists = true;
Dialog.Filter = @"All Supported Routes|*.csv;*.rw;*.dat|CSV/RW files|*.csv;*.rw|Mechanik Routes|*.dat|All files|*";
if (Dialog.ShowDialog() == DialogResult.OK)
{
Application.DoEvents();
CurrentlyLoading = true;
CurrentRouteFile = Dialog.FileName;
bool canLoad = false;
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
{
if (Program.CurrentHost.Plugins[i].Route != null && Program.CurrentHost.Plugins[i].Route.CanLoadRoute(CurrentRouteFile))
{
canLoad = true;
break;
}
}
if (canLoad && LoadRoute())
{
ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
Renderer.Camera.Reset();
Renderer.UpdateViewport();
World.UpdateAbsoluteCamera(0.0);
Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
}
else
{
bool isObject = false;
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
{
if (Program.CurrentHost.Plugins[i].Object != null && Program.CurrentHost.Plugins[i].Object.CanLoadObject(CurrentRouteFile))
{
isObject = true;
break;
}
}
if (isObject)
{
// oops, that's actually an object- Let's show Object Viewer
string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe");
if (System.IO.File.Exists(File))
{
System.Diagnostics.Process.Start(File, CurrentRouteFile);
}
}
else
{
MessageBox.Show("No plugins found capable of loading routefile: " +Environment.NewLine + CurrentRouteFile);
}
Renderer.Camera.Reset();
Renderer.UpdateViewport();
World.UpdateAbsoluteCamera(0.0);
CurrentRouteFile = null;
Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
}
CurrentlyLoading = false;
UpdateCaption();
}
else
{
if (Program.CurrentHost.MonoRuntime)
{
//HACK: Dialog doesn't close properly when pressing the ESC key under Mono
//Avoid calling Application.DoEvents() unless absolutely necessary though!
Application.DoEvents();
}
}
Dialog.Dispose();
break;
case Key.F8:
if (Program.CurrentlyLoading == true)
{
//Don't allow the user to update the settings during loading, bad idea..
break;
}
if (formOptions.ShowOptions() == DialogResult.OK)
{
UpdateGraphicsSettings();
}
Application.DoEvents();
Renderer.Camera.AlignmentDirection.TrackPosition = 0;
Renderer.Camera.AlignmentDirection.Position.X = 0;
Renderer.Camera.AlignmentDirection.Position.Y = 0;
break;
case Key.F9:
if (Interface.LogMessages.Count != 0)
{
formMessages.ShowMessages();
Application.DoEvents();
Renderer.Camera.AlignmentDirection.TrackPosition = 0;
Renderer.Camera.AlignmentDirection.Position.X = 0;
Renderer.Camera.AlignmentDirection.Position.Y = 0;
}
break;
case Key.F10:
Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay;
break;
case Key.A:
case Key.Keypad4:
Renderer.Camera.AlignmentDirection.Position.X = -CameraProperties.ExteriorTopSpeed * speedModified;
break;
case Key.D:
case Key.Keypad6:
Renderer.Camera.AlignmentDirection.Position.X = CameraProperties.ExteriorTopSpeed * speedModified;
break;
case Key.Keypad2:
Renderer.Camera.AlignmentDirection.Position.Y = -CameraProperties.ExteriorTopSpeed * speedModified;
break;
case Key.Keypad8:
Renderer.Camera.AlignmentDirection.Position.Y = CameraProperties.ExteriorTopSpeed * speedModified;
break;
case Key.W:
case Key.Keypad9:
Renderer.Camera.AlignmentDirection.TrackPosition = CameraProperties.ExteriorTopSpeed * speedModified;
break;
case Key.S:
case Key.Keypad3:
Renderer.Camera.AlignmentDirection.TrackPosition = -CameraProperties.ExteriorTopSpeed * speedModified;
break;
case Key.Left:
Renderer.Camera.AlignmentDirection.Yaw = -CameraProperties.ExteriorTopAngularSpeed * speedModified;
break;
case Key.Right:
Renderer.Camera.AlignmentDirection.Yaw = CameraProperties.ExteriorTopAngularSpeed * speedModified;
break;
case Key.Up:
Renderer.Camera.AlignmentDirection.Pitch = CameraProperties.ExteriorTopAngularSpeed * speedModified;
break;
case Key.Down:
Renderer.Camera.AlignmentDirection.Pitch = -CameraProperties.ExteriorTopAngularSpeed * speedModified;
break;
case Key.KeypadDivide:
Renderer.Camera.AlignmentDirection.Roll = -CameraProperties.ExteriorTopAngularSpeed * speedModified;
break;
case Key.KeypadMultiply:
Renderer.Camera.AlignmentDirection.Roll = CameraProperties.ExteriorTopAngularSpeed * speedModified;
break;
case Key.Keypad0:
Renderer.Camera.AlignmentDirection.Zoom = CameraProperties.ZoomTopSpeed * speedModified;
break;
case Key.KeypadPeriod:
Renderer.Camera.AlignmentDirection.Zoom = -CameraProperties.ZoomTopSpeed * speedModified;
break;
case Key.Keypad1:
Game.ApplyPointOfInterest(-1, true);
break;
case Key.Keypad7:
Game.ApplyPointOfInterest(1, true);
break;
case Key.PageUp:
JumpToStation(1);
break;
case Key.PageDown:
JumpToStation(-1);
break;
case Key.Keypad5:
Renderer.Camera.Reset();
Renderer.UpdateViewport();
World.UpdateAbsoluteCamera(0.0);
Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
break;
case Key.F:
Renderer.OptionWireFrame = !Renderer.OptionWireFrame;
break;
case Key.N:
Renderer.OptionNormals = !Renderer.OptionNormals;
break;
case Key.E:
Renderer.OptionEvents = !Renderer.OptionEvents;
break;
case Key.I:
Renderer.OptionInterface = !Renderer.OptionInterface;
break;
case Key.M:
//SoundManager.Mute = !SoundManager.Mute;
break;
case Key.Plus:
case Key.KeypadPlus:
if (!JumpToPositionEnabled)
{
JumpToPositionEnabled = true;
JumpToPositionValue = "+";
}
break;
case Key.Minus:
case Key.KeypadMinus:
if (!JumpToPositionEnabled)
{
JumpToPositionEnabled = true;
JumpToPositionValue = "-";
}
break;
case Key.Number0:
case Key.Number1:
case Key.Number2:
case Key.Number3:
case Key.Number4:
case Key.Number5:
case Key.Number6:
case Key.Number7:
case Key.Number8:
case Key.Number9:
if (!JumpToPositionEnabled)
{
JumpToPositionEnabled = true;
JumpToPositionValue = string.Empty;
}
JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0);
break;
case Key.Period:
if (!JumpToPositionEnabled)
{
JumpToPositionEnabled = true;
JumpToPositionValue = "0.";
}
else if (JumpToPositionValue.IndexOf('.') == -1)
{
JumpToPositionValue += ".";
}
break;
case Key.BackSpace:
if (JumpToPositionEnabled && JumpToPositionValue.Length != 0)
{
JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1);
}
break;
case Key.Enter:
if (JumpToPositionEnabled)
{
if (JumpToPositionValue.Length != 0)
{
int direction;
if (JumpToPositionValue[0] == '-')
{
JumpToPositionValue = JumpToPositionValue.Substring(1);
direction = -1;
}
else if (JumpToPositionValue[0] == '+')
{
JumpToPositionValue = JumpToPositionValue.Substring(1);
direction = 1;
}
else
{
direction = 0;
}
double value;
if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture,out value))
{
if (value < CurrentRoute.Tracks[0].Elements[CurrentRoute.Tracks[0].Elements.Length - 1].StartingTrackPosition + 100 && value > MinimumJumpToPositionValue - 100)
{
if (direction != 0)
{
value = Program.Renderer.CameraTrackFollower.TrackPosition + (double)direction * value;
}
Program.Renderer.CameraTrackFollower.UpdateAbsolute(value, true, false);
Renderer.Camera.Alignment.TrackPosition = value;
Renderer.Camera.Reset();
World.UpdateAbsoluteCamera(0.0);
Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
}
}
}
}
JumpToPositionEnabled = false;
break;
case Key.Escape:
JumpToPositionEnabled = false;
break;
case Key.R:
Renderer.SwitchOpenGLVersion();
break;
case Key.P:
if (CurrentRouteFile != null && CurrentlyLoading == false)
{
if (pathForm == null || pathForm.IsDisposed)
{
pathForm = new formRailPaths();
}
// Must be shown as a dialog box on Linux for paint events to work....
if (CurrentHost.Platform == HostPlatform.MicrosoftWindows)
{
if (!pathForm.Visible)
{
pathForm.Show();
}
}
else
{
pathForm.ShowDialog();
Application.DoEvents();
}
}
//pathForm.ShowDialog();
break;
}
}
internal static void keyUpEvent(object sender, KeyboardKeyEventArgs e)
{
switch (e.Key)
{
case Key.LShift:
case Key.RShift:
ShiftPressed = false;
break;
case Key.LControl:
case Key.RControl:
ControlPressed = false;
break;
case Key.LAlt:
case Key.RAlt:
AltPressed = false;
break;
case Key.A:
case Key.Keypad4:
case Key.D:
case Key.Keypad6:
Renderer.Camera.AlignmentDirection.Position.X = 0.0;
break;
case Key.Keypad2:
case Key.Keypad8:
Renderer.Camera.AlignmentDirection.Position.Y = 0.0;
break;
case Key.W:
case Key.Keypad9:
case Key.S:
case Key.Keypad3:
Renderer.Camera.AlignmentDirection.TrackPosition = 0.0;
break;
case Key.Left:
case Key.Right:
Renderer.Camera.AlignmentDirection.Yaw = 0.0;
break;
case Key.Up:
case Key.Down:
Renderer.Camera.AlignmentDirection.Pitch = 0.0;
break;
case Key.KeypadDivide:
case Key.KeypadMultiply:
Renderer.Camera.AlignmentDirection.Roll = 0.0;
break;
case Key.Keypad0:
case Key.KeypadPeriod:
Renderer.Camera.AlignmentDirection.Zoom = 0.0;
break;
}
}
// update caption
internal static void UpdateCaption() {
if (CurrentRouteFile != null) {
currentGameWindow.Title = System.IO.Path.GetFileName(CurrentRouteFile) + " - " + Application.ProductName;
} else
{
currentGameWindow.Title = Application.ProductName;
}
}
}
}