-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMapForm.cs
3084 lines (2900 loc) · 124 KB
/
MapForm.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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* YOGEME.exe, All-in-one Mission Editor for the X-wing series, XW through XWA
* Copyright (C) 2007-2025 Michael Gaisser (mjgaisser@gmail.com)
* Licensed under the MPL v2.0 or later
*
* VERSION: 1.17
*
* CHANGELOG
* v1.17, 250215
* [NEW] Cumulative WP time checkbox
* [NEW] XWA All Order traces checkbox
* [NEW #81] Move all WPs of selected craft
* [UPD] minor cleanup/reorg for my sanity
* v1.16, 241013
* [UPD] cleanup
* v1.15.5, 231222
* [FIX #94] WP1 on hyper orders being enabled even if disabled
* [FIX] bad offsets if hyper WP1 disabled
* v1.15.4, 231125
* [FIX #93] "From any" buoys detected
* v1.14, 230804
* [FIX] pct.MouseLeave will now clear shiftState
* [FIX] buoys also check Des2 [#83]
* [FIX] virtual exit points now only selectable when visible [#83]
* [FIX] virtual aim points now only selectable when visible [#83]
* v1.13.12, 230116
* [FIX] Can select disabled XWA SP1, since they're shown
* [FIX] Selection corners X location
* [FIX] Removed a leftover debug bypass from the 1.13.10 testing
* [FIX] XWA Enabled Order Waypoints are no longer displayed if the craft never visits that Region
* v1.13.11, 221030
* [FIX] XWA SP1 now always treated as Enabled
* v1.13.10, 221018
* [NEW] Correct display of hyper exit points
* [FIX] Wireframe roll
* v1.13.5, 220608
* [FIX] Removed a chunk that could've executed relating to not-yet-implemented changes
* v1.13.4, 220606
* [UPD] isVisibleInRegion now returns an enum to denote actually present versus other regions
* [UPD] moved chkWP[12+] checks in MapPaint to non-XWA block
* v1.13.3, 220402
* [FIX] pctMap_Enter stealing focus when window wasn't active
* v1.13.2, 220319
* [NEW] checkboxes to toggle wireframes and icon limit
* [UPD] increased minimum form width
* [UPD] fixed selection buttons to left side
* v1.13.1, 220208
* [UPD] XWA SP3 now labeled "RDV"
* v1.12, 220103
* [FIX] Cleared sortedMapDataList on reload to fix multi-delete [JB]
* [FIX] Listbox scrolling
* v1.11, 210801
* [UPD] FGs now also take into account Hyper orders for region visiblity [JB]
* v1.10, 210520
* [FIX #58] XWA wireframes when using rotations instead of Waypoints [JB]
* v1.8, 201004
* Lots of stuff here, may not list it all...
* [NEW] Selection expansion [JB]
* [NEW] New M-click actions [JB]
* [NEW] Traces can show ETA, speed, throttle. Also, options to control what's shown [JB]
* [NEW] Wireframes can be faded and hidden [JB]
* [UPD] Purple IFF now consistently MediumOrchid [JB]
* [NEW] Snap ability when moving [JB]
* [NEW] Keyboard commands for WP movement, selection [JB]
* [NEW] Ability to change WP's region for XWA [JB]
* [NEW] Ability to show/hide WPs based on Difficulty or IFF [JB]
* [NEW] Ability to zoom map to fit selected or fit all [JB]
* [UPD] Map Options save, don't need the Options dialog to change defaults [JB]
* v1.7, 200816
* [UPD] MapPaint now always persistent
* [NEW #12] Wireframe implementation [JB]
* [UPD] Max zoom and zoom speed adjusted [JB]
* [UPD] FgIndex added to MapData [JB]
* [FIX] Unregister Tick handler to prevent misfires after closing [JB]
* [UPD] form handlers renamed
* v1.6.5, 200704
* [NEW] if pulling from imgCraft trips an OutOfRange, default to img[0]
* v1.5, 180910
* [NEW] lots of variables for UI tracking [JB]
* [NEW] Xwing capability [JB]
* [NEW] Callbacks in ctors [JB]
* [UPD] Import moved to after Init [JB]
* [NEW] chkDistance, hide buttons, listboxes, help button [JB]
* [UPD] form closing events updated [JB]
* [UPD] paint bypass if !visible [JB]
* [NEW] GetIFFColor, GetDrawColor, SwapSelectedItems, UpdateFlightGroup, lots of new map functions [JB]
* [FIX] waypoint stuff [JB]
* [NEW] selection box [JB]
* [NEW] redraw timer [JB]
* [NEW] MapData.FullName, .Visible, .Selected, .Difficulty [JB]
* [UPD] keyboard/mouse controls reworked [JB]
* [NEW] added Deselect() to several controls [JB]
* [NEW] SelectionData [JB]
* v1.4, 171016
* [ADD #11] form is now resizable, can be maximized
* v1.2.3, 141214
* [UPD] change to MPL
* v1.2, 121006
* - Settings passed in
* v1.1.1, 120814
* [FIX] MapData.Waypoints now based on BaseFlightGroup.BaseWaypoint, now updates back and forth with parent Form
* - MapPaint() Orientation switch{} removed and condensed
* - class renamed
* v1.0, 110921
* - Release
*/
using Idmr.Common;
using Idmr.Platform;
using Idmr.Yogeme.MapWireframe;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Security.Cryptography;
using System.Windows.Forms;
namespace Idmr.Yogeme
{
/// <summary>graphical interface for craft waypoints</summary>
public partial class MapForm : Form
{
#region vars and stuff
int _zoom = 40; //Current zoom scale, in pixels per kilometer
#pragma warning disable IDE1006 // Naming Styles
int w, h, _mapX, _mapY, _mapZ; //The map vars store offset of the center of the game world (0,0,0) relative to the top left corner of the viewport, taking zoom into account.
#pragma warning restore IDE1006 // Naming Styles
public enum Orientation { XY, XZ, YZ };
Orientation _displayMode = Orientation.XY;
Bitmap _map;
MapData[] _mapData;
readonly List<SelectionData> _selectionList = new List<SelectionData>(); // List of all craft and waypoints that are currently selected and itemized in the list control.
readonly List<int> _sortedMapDataList = new List<int>(); // List of _mapData indices sorted for drawing order.
readonly List<SelectionData> _dragAllList = new List<SelectionData>(); // List to grab all enabled WPs based on selected craft
readonly int[] _dragIcon = new int[2]; // [0] = fg, [1] = wp
bool _isLoading = false;
#pragma warning disable IDE1006 // Naming Styles
readonly CheckBox[] chkWP = new CheckBox[22];
#pragma warning restore IDE1006 // Naming Styles
readonly Settings.Platform _platform;
bool _isDragged;
bool _leftButtonDown = false; // Left mouse button currently held down.
bool _rightButtonDown = false;
bool _dragSelectActive = false; // Indicates that a drag-select is in progress, and to draw the selection box.
bool _dragMoveActive = false; // A drag-move is in progress.
bool _dragMoveSnapReady = false; // The starting position for drag-move operation has been assigned, so that snapping can work correctly.
bool _dragAllActive = false; // A drag-move is in progress, for all WPs of the selected craft
Point _clickPixelDown = new Point(0, 0); //Form pixel coordinates of mouse click.
Point _clickPixelUp = new Point(0, 0);
Point _clickMapDown = new Point(0, 0); //Virtual map coordinates of mouse click
Point _clickMapUp = new Point(0, 0);
Point _dragMapPrevious = new Point(0, 0); //If dragging continuously, holds the last position so we know how much to update.
bool _mapFocus = false;
bool _shiftState = false;
bool _ignoreSelectionEvents = false; // Ignore control events if something is modifying the selection lists.
int _repeatSelectCount = 0; // Notifies the user if they keep trying to select a filtered item.
int[] _previousCraftSelection = null; // Maintains which craft items were previously selected, to detect which items were selected or unselected if selection was changed.
readonly Color _fadeColor = Color.FromArgb(52, 52, 52); // Icon and wireframe draw color for faded items.
int _lastSnapUnit = 0; // Used to detect if the user has changed the unit of measurement for movement snapping.
Keys _lastWaypointKeyCode = Keys.None; // These lastWaypoint values are used to detect keyboard double-taps for the purposes of selecting or creating waypoints via keypress.
Keys _lastWaypointKeyModifiers = Keys.None;
int _lastWaypointKeyTime = 0;
bool _mapPaintScheduled = false; //True if a paint is scheduled, that is a paint request is called while a paint is already in progress.
static WireframeManager _wireframeManager = null;
enum ExpandSelection { Craft, Iff, Size, Invert };
public enum MiddleClickAction { DoNothing, ResetToCenter, FitToWorld, FitToSelection, CenterOnSelection };
#pragma warning disable IDE1006 // Naming Styles
EventHandler onDataModified = null;
#pragma warning restore IDE1006 // Naming Styles
bool _isClosing = false; //Need a flag during form close to check whether external MapPaint() calls should be ignored.
readonly Settings _settings = Settings.GetInstance();
bool _hasFocus;
enum WaypointVisibility { Absent, Present, OtherRegion };
#endregion vars
#region ctors
/// <param name="fg">XwingFlights array</param>
public MapForm(Platform.Xwing.FlightGroupCollection fg, EventHandler dataModifiedCallback)
{
_platform = Settings.Platform.XWING;
InitializeComponent();
if (_settings.XwingOverrideExternal)
{
//Since the XW craft list is mapped to use TIE's list for the sake of the map, replace TIE's strings. Must be done prior to import.
Platform.Tie.Strings.OverrideShipList(null, null);
string[] xwType = Platform.Xwing.Strings.CraftType;
string[] xwAbbrev = Platform.Xwing.Strings.CraftAbbrv;
string[] newType = Platform.Tie.Strings.CraftType;
string[] newAbbrev = Platform.Tie.Strings.CraftAbbrv;
Platform.Xwing.FlightGroup temp = new Platform.Xwing.FlightGroup();
for (int i = 0; i < xwType.Length; i++)
{
temp.CraftType = (byte)i;
int remap = (i == xwType.Length - 1) ? 4 : temp.GetTIECraftType(); //B-wing is special case, last item in XW list. Replace directly.
if (remap >= 0 && remap < newType.Length)
{
newType[remap] = xwType[i];
newAbbrev[remap] = xwAbbrev[i];
}
}
Platform.Tie.Strings.OverrideShipList(newType, newAbbrev);
}
Import(fg);
try { imgCraft.Images.AddStrip(Image.FromFile(Application.StartupPath + "\\images\\craft_TIE.bmp")); }
catch (Exception x)
{
MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
onDataModified = dataModifiedCallback;
startup();
}
/// <param name="fg">TFlights array</param>
public MapForm(Platform.Tie.FlightGroupCollection fg, EventHandler dataModifiedCallback)
{
_platform = Settings.Platform.TIE;
InitializeComponent();
Import(fg);
try { imgCraft.Images.AddStrip(Image.FromFile(Application.StartupPath + "\\images\\craft_TIE.bmp")); }
catch (Exception x)
{
MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
onDataModified = dataModifiedCallback;
startup();
}
/// <param name="fg">XFlights array</param>
public MapForm(bool isBoP, Platform.Xvt.FlightGroupCollection fg, EventHandler dataModifiedCallback)
{
_platform = isBoP ? Settings.Platform.BoP : Settings.Platform.XvT;
InitializeComponent();
Import(fg);
try { imgCraft.Images.AddStrip(Image.FromFile(Application.StartupPath + "\\images\\craft_XvT.bmp")); }
catch (Exception x)
{
MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
onDataModified = dataModifiedCallback;
startup();
}
/// <param name="fg">WFlights array</param>
public MapForm(Platform.Xwa.FlightGroupCollection fg, EventHandler dataModifiedCallback)
{
_platform = Settings.Platform.XWA;
InitializeComponent();
Import(fg);
try { imgCraft.Images.AddStrip(Image.FromFile(Application.StartupPath + "\\images\\craft_XWA.bmp")); }
catch (Exception x)
{
MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
onDataModified = dataModifiedCallback;
startup();
}
#endregion ctors
#region private methods
/// <summary>Take the original image from the craft image strip and adds the RGB values from the craft IFF.</summary>
/// <param name="craftImage">The greyscale craft image.</param>
/// <param name="iff">The craft's IFF colors.</param>
/// <returns>Colorized craft image according to IFF.</returns>
static Bitmap applyIffMask(Bitmap craftImage, Color iff)
{
// craftImage comes in as 32bppRGB, but we force the image into 24bppRGB with LockBits
BitmapData bmData = GraphicsFunctions.GetBitmapData(craftImage, PixelFormat.Format24bppRgb);
byte[] pix = new byte[bmData.Stride * bmData.Height];
GraphicsFunctions.CopyImageToBytes(bmData, pix);
for (int y = 0; y < craftImage.Height; y++)
{
for (int x = 0, pos = bmData.Stride * y; x < craftImage.Width; x++)
{
// stupid thing returns BGR instead of RGB
// get intensity, apply to IFF mask
pix[pos + x * 3] = (byte)(pix[pos + x * 3] * iff.B / 255);
pix[pos + x * 3 + 1] = (byte)(pix[pos + x * 3 + 1] * iff.G / 255);
pix[pos + x * 3 + 2] = (byte)(pix[pos + x * 3 + 2] * iff.R / 255);
}
}
GraphicsFunctions.CopyBytesToImage(pix, bmData);
craftImage.UnlockBits(bmData);
craftImage.MakeTransparent(Color.Black);
return craftImage;
}
/// <summary>Comparison function that sorts MapData objects by visibility. Brings faded items up front so that they can be drawn first. Visible items will overlap them.</summary>
int compareDrawOrder(int leftIndex, int rightIndex)
{
if (_mapData[leftIndex].View > _mapData[rightIndex].View) return -1;
else if (_mapData[leftIndex].View < _mapData[rightIndex].View) return 1;
return 0;
}
/// <summary>Creates a waypoint for any selected craft whos waypoint is disabled. If no waypoints were created, then the existing waypoints are selected.</summary>
/// <remarks>The type of waypoint depends on which keys are pressed. Expects number row keys and modifiers. Resolves selected craft/waypoints to their parent craft.</remarks>
void createOrSelectWaypoint(KeyEventArgs e)
{
// Mouse position contains screen coordinates, so check their bounds and convert them relative to the map area.
Rectangle mapRect = pctMap.RectangleToScreen(pctMap.DisplayRectangle);
if (!mapRect.Contains(MousePosition)) return;
bool create = (e.KeyCode == _lastWaypointKeyCode && e.Modifiers == _lastWaypointKeyModifiers && (Environment.TickCount - _lastWaypointKeyTime <= SystemInformation.DoubleClickTime));
_lastWaypointKeyCode = e.KeyCode;
_lastWaypointKeyModifiers = e.Modifiers;
_lastWaypointKeyTime = Environment.TickCount;
Point mouse = new Point();
convertMousepointToWaypoint(MousePosition.X - mapRect.Left, MousePosition.Y - mapRect.Top, ref mouse);
int wp = -1;
int chk = -1; // Special case for XWA, since the checkbox array doesn't necessarily match the waypoint index.
int ord = (_platform == Settings.Platform.XWA ? (int)((numRegion.Value - 1) * 4 + numOrder.Value) : 0);
switch (_platform)
{
case Settings.Platform.XWING:
if (e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D3)
{
if (e.Shift && !e.Control) wp = e.KeyCode - Keys.D1; // SP1 to SP3
else if (!e.Shift && !e.Control) wp = 4 + e.KeyCode - Keys.D1; // WP1 to WP3
else if (!e.Shift && e.Control) wp = 14 + e.KeyCode - Keys.D1;
}
else if (e.KeyCode == Keys.D0) wp = 13; // HYP
break;
case Settings.Platform.TIE:
case Settings.Platform.XvT:
case Settings.Platform.BoP:
if (e.Shift && !e.Control && e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D4) wp = e.KeyCode - Keys.D1; // SP1 to SP4
else if (!e.Shift && !e.Control && e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D8) wp = 4 + e.KeyCode - Keys.D1; // WP1 to WP8
else if (!e.Shift && e.Control && e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D8) wp = 14 + (_platform == Settings.Platform.TIE ? 0 : e.KeyCode - Keys.D1); //BRF for TIE, BRF to BR8 for XvT
else if (e.KeyCode == Keys.D9) wp = 12; // RND
else if (e.KeyCode == Keys.D0) wp = 13; // HYP
break;
case Settings.Platform.XWA:
if (e.Shift && e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D3) { wp = e.KeyCode - Keys.D1; ord = 0; } // SP1 to SP3
else if (!e.Shift && e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D8) { wp = e.KeyCode - Keys.D1; chk = 4 + wp; } // WP1 to WP8
else if (e.KeyCode == Keys.D0) { wp = 3; ord = 0; } // HYP
break;
}
if (wp == -1) return; // Keys didn't resolve to a valid waypoint.
bool modified = false;
bool refreshRequired = false;
List<SelectionData> exist = new List<SelectionData>();
// Build a list of parent craft.
HashSet<int> parentSet = new HashSet<int>();
foreach (SelectionData dat in _selectionList) if (dat.Active) parentSet.Add(dat.MapDataIndex);
foreach (int i in parentSet)
{
if (wp < _mapData[i].WPs[ord].Length)
{
BaseFlightGroup.Waypoint baseWp = _mapData[i].WPs[ord][wp];
if (!baseWp.Enabled && create)
{
if (_platform == Settings.Platform.XWA)
{
((Platform.Xwa.FlightGroup.XwaWaypoint)baseWp).Region = Convert.ToByte(numRegion.Value - 1);
if (wp == 0 && ord == 0)
{
_mapData[i].Region = (int)numRegion.Value - 1;
refreshRequired = true;
}
}
modified = true;
baseWp.Enabled = true;
switch (_displayMode)
{
case Orientation.XY: baseWp.RawX = (short)mouse.X; baseWp.RawY = (short)mouse.Y; break;
case Orientation.XZ: baseWp.RawX = (short)mouse.X; baseWp.RawZ = (short)mouse.Y; break;
case Orientation.YZ: baseWp.RawY = (short)mouse.X; baseWp.RawZ = (short)mouse.Y; break;
}
}
else if (baseWp.Enabled && !create) exist.Add(new SelectionData(i, _mapData[i], ord, wp));
}
}
if (modified || exist.Count > 0)
{
if (chk == -1) chk = wp;
if (chk < chkWP.Length && !chkWP[chk].Checked) chkWP[chk].Checked = true;
}
if (modified)
{
onDataModified?.Invoke(0, new EventArgs());
if (refreshRequired) lstCraft.Refresh();
scheduleMapPaint();
}
else if (exist.Count > 0)
{
deselect();
foreach (SelectionData dat in exist) setSelectionState(dat.MapDataIndex, true, dat.WpOrder, dat.WpIndex);
updateSelectionListSize();
updatePreviousCraftSelection();
scheduleMapPaint();
}
}
void drawCraft(Graphics g, Bitmap bmp, MapData dat, int x, int y)
{
WireframeInstance model = _wireframeManager.GetOrCreateWireframeInstance(dat.Craft, dat.FgIndex);
if (!chkWireframe.Checked || model == null || model.ModelDef == null || (chkLimit.Checked && model.ModelDef.LongestSpanMeters < _settings.WireframeIconThresholdSize))
{
g.DrawImageUnscaled(bmp, x - 8, y - 8);
return;
}
//Simple bounds check to determine if it's definitely off screen.
double calcSpan = (double)model.ModelDef.LongestSpanRaw / 40960 * _zoom;
int viewSpan = (int)calcSpan;
if (x + viewSpan < 0 || x - viewSpan > w || y + viewSpan < 0 || y - viewSpan > h) return;
BaseFlightGroup.Waypoint dst;
int region = -1;
if (_platform == Settings.Platform.XWA)
{
region = (int)numRegion.Value - 1;
int ord = (int)(region * 4 + numOrder.Value);
dst = dat.WPs[ord][0];
if (!dat.WPs[ord][0].Enabled) // Default to first order if no waypoint defined, this keeps the orientation consistent if checking different orders and they're empty.
dst = dat.WPs[1][0];
}
else dst = dat.WPs[0][4];
int meshZoom = _zoom;
if (_settings.WireframeMeshIconEnabled && _settings.WireframeMeshIconSize > 0 && calcSpan < _settings.WireframeMeshIconSize)
{
if (calcSpan < 0.00001) calcSpan = 0.00001;
double scale = _settings.WireframeMeshIconSize / calcSpan;
meshZoom = (int)(_zoom * scale);
}
if (_platform == Settings.Platform.XWA && !dst.Enabled) model.UpdateSimple(meshZoom, _settings.WireframeMeshTypeVisibility, dat.Yaw, dat.Pitch, dat.Roll);
else if (_platform == Settings.Platform.XWA && dat.WPs[17][region].Enabled && ((Platform.Xwa.FlightGroup.XwaWaypoint)dat.WPs[0][0]).Region != region)
model.UpdateParams(dat.WPs[17][region], dat.WPs[18][region], meshZoom, _displayMode, _settings.WireframeMeshTypeVisibility, dat.Roll);
else model.UpdateParams(dat.WPs[0][0], dst, meshZoom, _displayMode, _settings.WireframeMeshTypeVisibility, dat.Roll);
Pen body = new Pen(dat.View == Visibility.Fade ? _fadeColor : getIFFColor(dat.IFF));
Pen hangar = new Pen(dat.View == Visibility.Fade ? _fadeColor : Color.White);
Pen dock = new Pen(dat.View == Visibility.Fade ? _fadeColor : Color.Yellow);
Pen p;
int x1, x2, y1, y2;
int lineDrawCount = 0;
foreach (MeshLayerInstance layer in model.LayerInstances)
{
if (layer.MatchMeshFilter(_settings.WireframeMeshTypeVisibility))
{
p = body;
MeshType mt = layer.MeshLayerDefinition.MeshType;
if (mt == MeshType.Hangar) p = hangar;
else if (mt == MeshType.DockingPlatform || mt == MeshType.LandingPlatform) p = dock;
lineDrawCount += layer.MeshLayerDefinition.Lines.Count;
if (_displayMode == Orientation.XY)
{
foreach (Line line in layer.MeshLayerDefinition.Lines)
{
x1 = x + (int)layer.Vertices[line.V1].X;
x2 = x + (int)layer.Vertices[line.V2].X;
y1 = y + (int)layer.Vertices[line.V1].Y;
y2 = y + (int)layer.Vertices[line.V2].Y;
g.DrawLine(p, x1, y1, x2, y2);
}
}
else if (_displayMode == Orientation.XZ)
{
foreach (Line line in layer.MeshLayerDefinition.Lines)
{
x1 = x + (int)layer.Vertices[line.V1].X;
x2 = x + (int)layer.Vertices[line.V2].X;
y1 = y + (int)layer.Vertices[line.V1].Z;
y2 = y + (int)layer.Vertices[line.V2].Z;
g.DrawLine(p, x1, y1, x2, y2);
}
}
else if (_displayMode == Orientation.YZ)
{
foreach (Line line in layer.MeshLayerDefinition.Lines)
{
x1 = x + (int)-layer.Vertices[line.V1].Y;
x2 = x + (int)-layer.Vertices[line.V2].Y;
y1 = y + (int)layer.Vertices[line.V1].Z;
y2 = y + (int)layer.Vertices[line.V2].Z;
g.DrawLine(p, x1, y1, x2, y2);
}
}
}
}
//If we didn't draw anything at all (empty model, or none matched the mesh filter) then our failsafe is a normal icon just so it's not invisible.
//For larger models that appear large enough on screen, draw a pip at the origin so the user knows where the selection point is.
if (lineDrawCount == 0) g.DrawImageUnscaled(bmp, x - 8, y - 8);
else if (model.ModelDef.LongestSpanMeters > 30 && viewSpan > 32) g.DrawEllipse(hangar, x - 1, y - 1, 2, 2);
}
/// <summary>Returns a value composed of a set of bit flags indicating which difficulties this FlightGroup arrives in.</summary>
int getDifficultyFlags(BaseFlightGroup.Difficulties fgDifficulty)
{
if (_platform == Settings.Platform.XWING) return 0b111;
// All, Easy, Medium, Hard, ...
int[] resultArray = { 0b111, 0b001, 0b010, 0b100, 0b110, 0b011, 0b000 };
return resultArray[(byte)fgDifficulty];
}
string getDistanceString(BaseFlightGroup.Waypoint wp1, BaseFlightGroup.Waypoint wp2)
{
double xlen = wp1.X - wp2.X;
double ylen = wp1.Y - wp2.Y;
double zlen = wp1.Z - wp2.Z;
double dist = Math.Sqrt((xlen * xlen) + (ylen * ylen) + (zlen * zlen));
return Math.Round(dist, 2).ToString() + " km";
}
string getTimeString(object fg, int orderIndex, BaseFlightGroup.Waypoint wp1, BaseFlightGroup.Waypoint wp2, int previousSeconds, out int seconds)
{
seconds = 0;
double xlen = wp1.X - wp2.X;
double ylen = wp1.Y - wp2.Y;
double zlen = wp1.Z - wp2.Z;
double dist = Math.Sqrt((xlen * xlen) + (ylen * ylen) + (zlen * zlen));
int command = 0;
int throttle = 0;
int speed = 0;
switch (_platform)
{
case Settings.Platform.XWING:
command = ((Platform.Xwing.FlightGroup)fg).Order;
throttle = ((Platform.Xwing.FlightGroup)fg).DockTimeThrottle;
if (throttle == 0) throttle = 100;
else if (throttle <= 9) throttle = (throttle + 1) * 10;
else throttle = 0;
if (command == 0 || command == 0xC || (command >= 0x1D && command <= 0x20)) // Hold Steady, Disabled, SS Await (Return, Launch, Boarding, Arrival)
throttle = 0;
break;
case Settings.Platform.TIE:
if (orderIndex > 2)
orderIndex = 2;
command = ((Platform.Tie.FlightGroup)fg).Orders[orderIndex].Command;
throttle = ((Platform.Tie.FlightGroup)fg).Orders[orderIndex].Throttle * 10;
break;
case Settings.Platform.XvT:
case Settings.Platform.BoP:
command = ((Platform.Xvt.FlightGroup)fg).Orders[orderIndex].Command;
throttle = ((Platform.Xvt.FlightGroup)fg).Orders[orderIndex].Throttle * 10;
speed = ((Platform.Xvt.FlightGroup)fg).Orders[orderIndex].Speed;
break;
case Settings.Platform.XWA:
command = ((Platform.Xwa.FlightGroup)fg).Orders[(int)numRegion.Value - 1, orderIndex].Command;
throttle = ((Platform.Xwa.FlightGroup)fg).Orders[(int)numRegion.Value - 1, orderIndex].Throttle * 10;
speed = ((Platform.Xwa.FlightGroup)fg).Orders[(int)numRegion.Value - 1, orderIndex].Speed;
break;
}
if (_platform != Settings.Platform.XWING)
{
var cmd = (Platform.Xwa.FlightGroup.Order.CommandList)command;
switch (cmd)
{
case Platform.Xwa.FlightGroup.Order.CommandList.HoldSteady:
case Platform.Xwa.FlightGroup.Order.CommandList.Disabled:
case Platform.Xwa.FlightGroup.Order.CommandList.AwaitBoarding:
case Platform.Xwa.FlightGroup.Order.CommandList.Wait:
case Platform.Xwa.FlightGroup.Order.CommandList.SSWait:
case Platform.Xwa.FlightGroup.Order.CommandList.SSAwaitReturn:
case Platform.Xwa.FlightGroup.Order.CommandList.SSLaunch:
case Platform.Xwa.FlightGroup.Order.CommandList.Hold1C:
case Platform.Xwa.FlightGroup.Order.CommandList.Hold1E:
case Platform.Xwa.FlightGroup.Order.CommandList.Hold21:
case Platform.Xwa.FlightGroup.Order.CommandList.Hold22:
case Platform.Xwa.FlightGroup.Order.CommandList.Hold23:
case Platform.Xwa.FlightGroup.Order.CommandList.SelfDestruct:
speed = 0;
throttle = 0;
break;
}
if (command >= 0x25 && _platform != Settings.Platform.XWA)
{
speed = 0;
throttle = 0;
}
}
if (speed > 0) // Using an explicit speed value instead of throttle.
{
speed = (int)(speed * 5 / 2.2235);
throttle = 0;
}
else
{
speed = CraftDataManager.GetInstance().GetCraftSpeed(((BaseFlightGroup)fg).CraftType);
speed = (int)(((double)throttle / 100) * speed);
}
if (speed == 0) return "stationary";
seconds = (int)(dist * 1000 / speed);
int totalSec = seconds + previousSeconds;
return $"{seconds / 60}:{((seconds % 60 < 10) ? "0" : "")}{seconds % 60} @ {(throttle != 0 ? throttle + "%" : speed + " mglt")}{(previousSeconds != 0 ? $" ({totalSec / 60}:{((totalSec % 60 < 10) ? "0" : "")}{totalSec % 60})" : "")}";
}
Brush getDrawColor(MapData dat)
{
if (!passFilter(dat)) return Brushes.DarkSlateGray;
Brush brText = SystemBrushes.ControlText;
switch (dat.IFF)
{
case 0:
brText = Brushes.Lime; //LimeGreen;
break;
case 1:
brText = Brushes.Red; //Crimson;
break;
case 2:
brText = Brushes.DodgerBlue; //RoyalBlue;
break;
case 3:
if (_platform == Settings.Platform.XWING) brText = Brushes.RoyalBlue;
else if (_platform == Settings.Platform.TIE) brText = Brushes.MediumOrchid; // FF9932CC
else brText = Brushes.Yellow;
break;
case 4:
brText = Brushes.OrangeRed; //Red;
break;
case 5:
brText = Brushes.MediumOrchid; //DarkOrchid;
break;
}
return brText;
}
Color getIFFColor(int IFF)
{
switch (IFF)
{
case 0: return Color.Lime; // FF00FF00 //[JB] Changed colors (was LimeGreen)
case 1: return Color.Red; // FFFF0000 (was Crimson)
case 2: return Color.DodgerBlue; // FF1E90FF (was Royal Blue)
case 3:
if (_platform == Settings.Platform.XWING) return Color.RoyalBlue; // FF4169E1
else if (_platform == Settings.Platform.TIE) return Color.MediumOrchid; // FFBA55D3 (was DarkOrchid)
else return Color.Yellow; // FFFFFF00
case 4: return Color.OrangeRed; // FFFF4500 (was Red)
case 5:
return Color.MediumOrchid; // FFBA55D3
}
return Color.White; //Nothing should return this color.
}
/// <summary>Returns a size rating of the map object, based off its wireframe.</summary>
/// <remarks>Wireframes must be enabled. NOTE: This should probably be replaced with craft categories, but that would require additional changes, and more information in the craft data files.</remarks>
int getModelSizeRating(int mapDataIndex)
{
if (!_settings.WireframeEnabled || (_platform == Settings.Platform.XWA && _mapData[mapDataIndex].Craft == 0x55)) return 0; // Hyper beacon
WireframeInstance wire = _wireframeManager.GetOrCreateWireframeInstance(_mapData[mapDataIndex].Craft, _mapData[mapDataIndex].FgIndex);
if (wire == null || wire.ModelDef == null) return 0;
int size = wire.ModelDef.LongestSpanMeters;
int limit1 = 40, limit2 = 100, limit3 = 450;
if (size > 1 && size < limit1) return 1;
else if (size >= limit1 && size < limit2) return 2;
else if (size >= limit2 && size < limit3) return 3;
else if (size >= limit3) return 4;
return 0;
}
/// <summary>Gets a waypoint along the vector defined by two points with the given raw offset from the starting point.</summary>
/// <param name="start">The origin Waypoint</param>
/// <param name="end">The end Waypoint to define length and direction of the vector.</param>
/// <param name="rawOffset">The distance in raw units from <paramref name="start"/>. Negative values are "behind" start.</param>
/// <returns>A Waypoint of the location.</returns>
BaseFlightGroup.Waypoint getOffsetWaypoint(BaseFlightGroup.Waypoint start, BaseFlightGroup.Waypoint end, int rawOffset)
{
int[] vector = new int[3];
for (int c = 0; c < 3; c++) vector[c] = end[c] - start[c];
double vectorLength = Math.Sqrt(Math.Pow(vector[0], 2) + Math.Pow(vector[1], 2) + Math.Pow(vector[2], 2));
if (vectorLength == 0)
{
vector[1] = 1;
vectorLength = 1;
}
var offsetWaypoint = new Platform.Xwa.FlightGroup.Waypoint();
for (int c = 0; c < 3; c++) offsetWaypoint[c] = (short)(start[c] + rawOffset * vector[c] / vectorLength);
return offsetWaypoint;
}
/// <summary>Retrieves the snap distance amount, in raw map units, as specified in the form control.</summary>
int getRawSnapAmount()
{
int snapAmount;
snapAmount = (cboSnapUnit.SelectedIndex == 0 ? (int)(numSnapAmount.Value * 160) : (int)numSnapAmount.Value); //km to Raw or already Raw
if (snapAmount < 1) snapAmount = 1;
return snapAmount;
}
/// <summary>Determines if the object is enabled and visible.</summary>
/// <remarks>For most platforms, checks the start point. For XWA, also checks for any hyper jump to the current region.</remarks>
WaypointVisibility isVisibleInRegion(int mapDataIndex, int waypoint)
{
if (_platform != Settings.Platform.XWA) return _mapData[mapDataIndex].WPs[0][waypoint].Enabled ? WaypointVisibility.Present : WaypointVisibility.Absent;
bool enabled = (waypoint == 0 || _mapData[mapDataIndex].WPs[0][waypoint].Enabled);
if (!enabled) return WaypointVisibility.Absent;
int region = (int)numRegion.Value - 1;
if (_mapData[mapDataIndex].WPs[0][waypoint][4] == (short)region) return WaypointVisibility.Present;
Platform.Xwa.FlightGroup xwaFg = (Platform.Xwa.FlightGroup)_mapData[mapDataIndex].FlightGroup;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
if (xwaFg.Orders[i, j].Command == 0x32 && xwaFg.Orders[i, j].Variable1 == region) return WaypointVisibility.OtherRegion; // Hyper to region
return WaypointVisibility.Absent;
}
/// <summary>Performs a middle click action depending on whether something is selected or not, based on user configuration.</summary>
void middleClick()
{
if (_selectionList.Count > 0) performMiddleClickAction(_settings.MapMiddleClickActionSelected);
else performMiddleClickAction(_settings.MapMiddleClickActionNoneSelected);
}
/// <summary>Aligns a control horizontally to the left of another control, or to the left of a fixed point if no control is specified.</summary>
void moveControlLeft(Control control, Control anchor, int value)
{
if (anchor != null) control.Left = anchor.Left - (control.Width + value + (control.Margin.Right >= anchor.Margin.Left ? control.Margin.Right : anchor.Margin.Left));
else control.Left = value - (control.Width + control.Margin.Right);
}
/// <summary>Aligns a control vertically above another control, or above a fixed point if no control is specified.</summary>
void moveControlAbove(Control control, Control anchor, int padding)
{
if (anchor != null) control.Top = anchor.Top - (control.Height + padding + (control.Margin.Bottom >= anchor.Margin.Top ? control.Margin.Bottom : anchor.Margin.Top));
else control.Top = padding - (control.Height + control.Margin.Bottom);
}
/// <summary>Converts points to become top-left (<paramref name="a"/>) and bottom-right (<paramref name="b"/>)</summary>
void normalizePoint(ref Point a, ref Point b)
{
if (b.X < a.X)
{
int t = a.X;
a.X = b.X;
b.X = t;
}
if (b.Y < a.Y)
{
int t = a.Y;
a.Y = b.Y;
b.Y = t;
}
}
/// <summary>Determines if the craft meets the filter settings for Difficulty and IFF.</summary>
/// <remarks>Although this is similar to hiding, and many contexts check both, there are some distinctions in the usage.</remarks>
bool passFilter(MapData dat)
{
bool passDiff = (cboViewDifficulty.SelectedIndex == 0 || _platform == Settings.Platform.XWING || Convert.ToBoolean(dat.Difficulty & (1 << cboViewDifficulty.SelectedIndex - 1)));
bool passIff = (cboViewIff.SelectedIndex == 0 || dat.IFF == cboViewIff.SelectedIndex - 1);
return (passDiff && passIff);
}
/// <summary>Performs a middle click action.</summary>
void performMiddleClickAction(MiddleClickAction action)
{
switch (action)
{
case MiddleClickAction.ResetToCenter: fitMapToObjects(null); break;
case MiddleClickAction.DoNothing: break;
case MiddleClickAction.FitToWorld: fitMapToWorld(); break;
case MiddleClickAction.FitToSelection: fitMapToObjects(_selectionList); break;
case MiddleClickAction.CenterOnSelection: centerMapOnSelection(); break;
default: fitMapToObjects(null); break;
}
}
void processHyperPoints()
{
int numCraft = _mapData.Length;
for (int i = 0; i < numCraft; i++)
{
var fg = (Platform.Xwa.FlightGroup)_mapData[i].FlightGroup;
for (int r = 0; r < 4; r++)
{
_mapData[i].WPs[17][r].Enabled = false;
_mapData[i].WPs[18][r].Enabled = false;
var exitBuoySP = new Platform.Xwa.FlightGroup.XwaWaypoint
{
RawZ = 621 // just using as a flag
};
for (int o = 0; o < 16; o++)
{
int reg = o / 4;
int ord = o % 4;
if (fg.Orders[reg, ord].Command == 50 && fg.Orders[reg, ord].Variable1 == r)
{
for (int b = 0; b < numCraft; b++)
{
var buoy = (Platform.Xwa.FlightGroup)_mapData[b].FlightGroup;
if (buoy.CraftType == 85 && buoy.Waypoints[0][4] == r && (buoy.Designation1 == reg + 12 || buoy.Designation2 == reg + 12 || buoy.Designation1 == 0x14 || buoy.Designation2 == 0x14)) // From are #12-15, 0x14 is "From any"
{
exitBuoySP = buoy.Waypoints[0];
System.Diagnostics.Debug.WriteLine(fg.ToString() + " enters Region " + (r + 1) + " from " + (reg + 1) + " via " + buoy.ToString());
break;
}
}
}
}
var o1w1 = _mapData[i].WPs[r * 4 + 1][0];
// if returning to the starting region, grab the first order after the Hyper order
if (exitBuoySP.RawZ != 621 && r == _mapData[i].WPs[0][0][4])
{
for (int o = 0; o < 3; o++)
{
if (fg.Orders[r, o].Command == 50)
{
o1w1 = _mapData[i].WPs[(r * 4 + 1) + (o + 1)][0];
System.Diagnostics.Debug.WriteLine("return o1w1 used: " + fg.ToString());
}
}
}
Platform.Xwa.FlightGroup.Order hyperOrder = null;
if (fg.PlayerNumber != 0)
{
// Player
for (int o = 0; o < 16; o++)
{
int reg = o / 4;
int ord = o % 4;
if (fg.Orders[reg, ord].Command == 50 && fg.Orders[reg, ord].Variable1 == r)
{
var exitPoint = getOffsetWaypoint(exitBuoySP, o1w1, -100); // .625 km
for (int c = 0; c < 3; c++) _mapData[i].WPs[17][r][c] = exitPoint[c];
_mapData[i].WPs[17][r].Enabled = true;
for (int c = 0; c < 3; c++) _mapData[i].WPs[18][r][c] = o1w1[c];
_mapData[i].WPs[18][r].Enabled = true;
}
}
}
else
{
// AI
var hyperEntry = new Platform.Xwa.FlightGroup.XwaWaypoint();
for (int o = 0; o < 16; o++)
{
int reg = o / 4;
int ord = o % 4;
if (fg.Orders[reg, ord].Command == (byte)Platform.Xwa.FlightGroup.Order.CommandList.HyperToRegion && fg.Orders[reg, ord].Variable1 == r)
{
hyperOrder = fg.Orders[reg, ord];
for (int w = 1; w < 8; w++)
{
if (!fg.Orders[reg, ord].Waypoints[w].Enabled)
{
for (int c = 0; c < 3; c++) hyperEntry[c] = fg.Orders[reg, ord].Waypoints[w - 1][c];
hyperEntry.Region = (byte)reg;
hyperEntry.Enabled = true;
break;
}
}
}
}
if (!hyperEntry.Enabled) continue; // this is the "not found"/"doesn't hyper" check
var enterBuoy = new Platform.Xwa.FlightGroup.XwaWaypoint();
for (int b = 0; b < numCraft; b++)
{
var buoy = (Platform.Xwa.FlightGroup)_mapData[b].FlightGroup;
if (buoy.CraftType == 85 && buoy.Waypoints[0][4] == hyperEntry.Region && (buoy.Designation1 == r + 16 || buoy.Designation2 == r + 16)) // To are #16-19
{
enterBuoy = buoy.Waypoints[0];
System.Diagnostics.Debug.WriteLine(fg.ToString() + " leaves Region " + (hyperEntry.Region + 1) + " to " + (r + 1) + " via " + buoy.ToString());
break;
}
}
int[] offset = new int[3];
if (hyperOrder.Waypoints[0].Enabled) // don't calc an offset if WP1 disabled, use the buoy itself
for (int c = 0; c < 3; c++) offset[c] = hyperEntry[c] - enterBuoy[c];
for (int c = 0; c < 3; c++) _mapData[i].WPs[17][r][c] = (short)(exitBuoySP[c] + offset[c]);
_mapData[i].WPs[17][r].Enabled = true;
for (int c = 0; c < 3; c++) _mapData[i].WPs[18][r][c] = (short)(o1w1[c] + offset[c]);
_mapData[i].WPs[18][r].Enabled = true;
}
}
}
}
/// <summary>Re-counts how many objects are faded or hidden, updates controls providing this information, and re-sorts the draw order.</summary>
void refreshVisibility()
{
int[] count = new int[3];
for (int i = 0; i < _mapData.Length; i++) count[(int)_mapData[i].View]++;
lblFade.Text = "Faded: " + count[1] + " craft";
lblHide.Text = "Hidden: " + count[2] + " craft";
lblFade.ForeColor = (count[1] > 0 ? Color.Red : SystemColors.WindowText);
lblHide.ForeColor = (count[2] > 0 ? Color.Red : SystemColors.WindowText);
scheduleMapPaint();
lstCraft.Refresh();
_sortedMapDataList.Sort(compareDrawOrder);
}
/// <summary>Assigns which measurement units are used when snapping object movement.</summary>
/// <remarks>If the unit is changed, converts the existing amount and updates the form controls with the new limits.</remarks>
void setSnapUnit(int selectedIndex)
{
cboSnapUnit.SelectedIndex = selectedIndex;
if (_lastSnapUnit == selectedIndex) return;
decimal value = numSnapAmount.Value;
if (selectedIndex == 0) // KM
{
numSnapAmount.Minimum = (decimal)0.01;
numSnapAmount.Maximum = (decimal)0.50;
numSnapAmount.Increment = (decimal)0.01;
numSnapAmount.DecimalPlaces = 2;
}
else // Raw
{
numSnapAmount.Minimum = 1;
numSnapAmount.Maximum = 80;
numSnapAmount.Increment = 1;
numSnapAmount.DecimalPlaces = 0;
}
if (selectedIndex == 0) value = (decimal)((double)value / 160); // Raw to KM
else value = (decimal)Math.Round((double)value * 160, 0); // KM to Raw, round to whole units
if (value < numSnapAmount.Minimum) value = numSnapAmount.Minimum;
else if (value > numSnapAmount.Maximum) value = numSnapAmount.Maximum;
numSnapAmount.Value = value;
_lastSnapUnit = selectedIndex;
}
/// <summary>Intialization routine, loads settings and config per platform</summary>
void startup()
{
if (_wireframeManager == null) _wireframeManager = new WireframeManager();
_wireframeManager.SetPlatform(_platform);
#region checkbox array
chkWP[0] = chkSP1;
chkWP[1] = chkSP2;
chkWP[2] = chkSP3;
chkWP[3] = chkSP4;
chkWP[4] = chkWP1;
chkWP[5] = chkWP2;
chkWP[6] = chkWP3;
chkWP[7] = chkWP4;
chkWP[8] = chkWP5;
chkWP[9] = chkWP6;
chkWP[10] = chkWP7;
chkWP[11] = chkWP8;
chkWP[12] = chkRDV;
chkWP[13] = chkHYP;
chkWP[14] = chkBRF;
chkWP[15] = chkBRF2;
chkWP[16] = chkBRF3;
chkWP[17] = chkBRF4;
chkWP[18] = chkBRF5;
chkWP[19] = chkBRF6;
chkWP[20] = chkBRF7;
chkWP[21] = chkBRF8;
for (int i = 0; i < 22; i++)
{
chkWP[i].CheckedChanged += new EventHandler(chkWPArr_CheckedChanged);
chkWP[i].Tag = i;
}
#endregion
updateLayout();
_mapX = w / 2;
_mapY = h / 2;
_mapZ = h / 2;
_dragIcon[0] = -1;
_isLoading = true;
chkTags.Checked = Convert.ToBoolean(_settings.MapOptions & Settings.MapOpts.FGTags);
chkTrace.Checked = Convert.ToBoolean(_settings.MapOptions & Settings.MapOpts.Traces);
chkDistance.Checked = Convert.ToBoolean(_settings.MapOptions & Settings.MapOpts.TraceDistance);
chkTime.Checked = Convert.ToBoolean(_settings.MapOptions & Settings.MapOpts.TraceTime);
chkTraceHideFade.Checked = Convert.ToBoolean(_settings.MapOptions & Settings.MapOpts.TraceHideFade);
chkTraceSelected.Checked = Convert.ToBoolean(_settings.MapOptions & Settings.MapOpts.TraceSelected);
chkWireframe.Checked = _settings.WireframeEnabled;
chkLimit.Checked = _settings.WireframeIconThresholdEnabled;
chkLimit.Text = "Only above " + _settings.WireframeIconThresholdSize + "m";
chkDistance.Enabled = chkTrace.Checked;
chkTime.Enabled = chkTrace.Checked;
chkTraceHideFade.Enabled = chkTrace.Checked;
chkTraceSelected.Enabled = chkTrace.Checked;
int t = _settings.Waypoints;
if (_platform == Settings.Platform.XWING)
{
for (int i = 0; i < 3; i++) chkWP[i].Checked = Convert.ToBoolean(t & (1 << i));
chkWP[3].Enabled = false;
for (int i = 4; i < 7; i++) chkWP[i].Checked = Convert.ToBoolean(t & (1 << i));
for (int i = 7; i < 13; i++) chkWP[i].Enabled = false;
//[13] = hyper point
//[14,15,16] CS points, replacing HYP points.
for (int i = 17; i < 22; i++) chkWP[i].Enabled = false;
chkBRF.Text = "CS2";
chkBRF2.Text = "CS3";
chkBRF3.Text = "CS4";
}
else if (_platform == Settings.Platform.TIE)
{
for (int i = 0; i < 15; i++) chkWP[i].Checked = Convert.ToBoolean(t & (1 << i));