-
Notifications
You must be signed in to change notification settings - Fork 9
/
XwingForm.cs
2328 lines (2238 loc) · 86 KB
/
XwingForm.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-2024 Michael Gaisser ([email protected])
* This file authored by "JB" (Random Starfighter) ([email protected])
* Licensed under the MPL v2.0 or later
*
* VERSION: 1.16.0.3
*
* CHANGELOG
* v1.16.0.3, 241027
* [FIX #110] FG library callback cast exception
* v1.16, 241013
* [FIX] SaveAs behavior
* [UPD] Events changes
* [UPD] lblODesc actually used now
* v1.14.2, 230901
* [FIX #86] FG.CraftType when changing to B-wing
* v1.13.11, 221030
* [FIX] Open dialog not following current directory after switching paltforms via "Open Recent"
* v1.13.7, 220730
* [FIX] crash when copying a WP value via Ctrl+C and no text is selected
* v1.13.6, 220619
* [UPD] Confirm save now only asks if modified
* v1.13.4, 220606
* [UPD] OneIndexedFGs implementation
* v1.13.3, 220402
* [FIX] ComboBox stutter for colorized cbo's due to OwnerDrawVariable
* v1.13.2, 220319
* [FIX] Remove focus during save to trigger any Leave events
* v1.13.1, 220208
* [NEW] menuCut [JB]
* [FIX] multi-select refresh issues [JB]
* [FIX] craftStart issues during Paste and arrival changes [JB]
* v1.13, 220130
* [NEW] Multi-select [JB]
* v1.12, 220103
* [NEW] Tour Editor
* [FIX] Listbox scrolling
* v1.11.2, 2101005
* [UPD] Copy/paste now uses system clipboard, can more easily paste external text
* [NEW] Copy/paste now works for Waypoints
* v1.10, 210520
* [UPD #56] Replaced try/catch with TyrParse [JB]
* v1.9, 210108
* [FIX] Clipboard path in some locations
* v1.8.1, 201213
* [FIX] Removed RunVerify() call
* [UPD] menuTest moved under Tools, changed to &Test
* v1.8, 201004
* [FIX] Deactivate added to force focus fix [JB]
* [UPD] newFG now returns bool
* [NEW] FlightGroupLibrary [JB]
* v1.7, 200816
* [UPD #14] Nothing specific, but closing that issue
* [FIX] recalculateEditorCraftNumbering() handles _activeFG now [JB]
* [UPD] shiplist and Map calls updated for Wireframe implementation [JB]
* [FIX] Starting ships set to 1 [JB]
* [UPD] Unk1 now RandomSeed [JB]
* [UPD] MaxCraft increased to 255 [JB]
* [UPD] Yaw/Pitch/Roll tweaks, save fixed [JB]
* [UPD] form handlers renamed
* [FIX] re-init if load fails
* v1.6.5, 200704
* [NEW] Custom shiplist
* [FIX #32] bin path now explicitly uses Startup Path to prevent implicit from defaulting to sys32
* v1.6.4, 200119
* [NEW #30] Briefing callback
* v1.5, 180910
* [NEW] Release [JB]
* [NEW] Added SaveAsXwing
* [FIX] colorized cbo uses black BG, "None" is black with white text
*/
using System;
using System.Data; // DataView and DataTable
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;
using Idmr.Platform.Xwing;
namespace Idmr.Yogeme
{
/// <summary>XWING95 Mission Editor GUI</summary>
public partial class XwingForm : Form
{
#region vars and stuff
readonly Settings _config = Settings.GetInstance();
Mission _mission;
bool _applicationExit; //for frmTIE_Closing, confirms application exit vs switching platforms
int _activeFG = 0; //counter to keep track of current FG being displayed
int _startingShips = 1; //counter for craft in play at start <30s, warning above 28
int _startingObjects = 0;
bool _loading; //alerts certain functions to disable during the loading process
bool _noRefresh = false;
enum EditorMode
{
XWI,
BRF
}
EditorMode _mode = EditorMode.XWI; //Which FG selection we're currently viewing and editing (0=XWI, 1=BRF)
Color _original_lstFG_BackColor;
private readonly int[] _waypointMapping = new int[10] { //The raw waypoint data is not in a convenient order (Start1,Waypt1,Waypt2,Waypt3,Start2,Start3,Hyper) so assists in providing an intuitive datagrid, mapping the display row (array index) to the actual FG waypoint index (element value).
0, 4, 5, //Start1, Start2, Start3
1, 2, 3, //Waypt1, Waypt2, Waypt3
6, //Hyper
7, 8, 9 //BRF coordinate sets, listed here as virtual waypoints for ease of editing.
};
readonly DataTable _table = new DataTable("Waypoints");
readonly DataTable _tableRaw = new DataTable("Waypoints_Raw");
MapForm _fMap;
BriefingFormXwing _fBrief;
FlightGroupLibraryForm _fLibrary;
TourForm _fTour;
#endregion
#region Control Arrays
#pragma warning disable IDE1006 // Naming Styles
readonly TextBox[] txtEoM = new TextBox[3];
readonly CheckBox[] chkWP = new CheckBox[7];
readonly CheckBox[] chkGunPlatform = new CheckBox[6];
readonly MenuItem[] menuRecentMissions = new MenuItem[6];
readonly Dictionary<ComboBox, ComboBox> ColorizedFGList = new Dictionary<ComboBox, ComboBox>(); //[JB] Maps a control that should have a colorized FG list with a control that determines whether the list actually contains a FG list.
#pragma warning restore IDE1006 // Naming Styles
#endregion
public XwingForm()
{
InitializeComponent();
_loading = true;
initializeMission();
startup();
lstFG.SelectedIndex = 0;
_loading = false;
}
public XwingForm(string path)
{ //this is the command line and "Open..." support
InitializeComponent();
_loading = true;
initializeMission();
startup();
if (!loadMission(path)) return;
lstFG.SelectedIndex = 0;
_loading = false;
}
#region methods
void closeForms()
{
try { _fMap.Close(); }
catch { /* do nothing */ }
try { _fBrief.Close(); }
catch { /* do nothing */ }
try { _fLibrary.Close(); }
catch { /* do nothing */ }
try { _fTour.Close(); }
catch { /* do nothing */ }
}
void comboLoadIndex(ComboBox cbo, int index, bool nullable)
{
bool btemp = _loading;
_loading = true;
try
{
if (nullable) index++;
cbo.SelectedIndex = index;
}
catch { cbo.SelectedIndex = 0; }
_loading = btemp;
}
void comboRefreshFGList(ComboBox cbo, bool nullable)
{
_loading = true;
int index = cbo.SelectedIndex;
cbo.Items.Clear();
if (nullable == false)
cbo.Items.AddRange(_mission.FlightGroups.GetList());
else
cbo.Items.AddRange(getNullableFGList());
if (index >= cbo.Items.Count) //Changing missions could cause existing selected indexes to become invalid
index = 0;
cbo.SelectedIndex = index;
_loading = false;
}
static void comboReset(ComboBox cbo, string[] items, int index)
{
cbo.Items.Clear();
cbo.Items.AddRange(items);
cbo.SelectedIndex = index;
}
void recalculateStart()
{
_startingShips = 0;
_startingObjects = 0;
for (int i = 0; i < _mission.FlightGroups.Count; i++)
craftStart(_mission.FlightGroups[i], true);
}
void craftStart(FlightGroup fg, bool add)
{
if (fg.IsFlightGroup() && fg.ArrivalEvent != 0) return;
if (!fg.ArrivesIn30Seconds) return;
if (fg.IsFlightGroup())
{
if (add) _startingShips += fg.NumberOfCraft;
else _startingShips -= fg.NumberOfCraft;
}
else
{
int count = fg.NumberOfCraft;
if (fg.ObjectType >= 18 && fg.ObjectType <= 21)
count *= fg.NumberOfCraft; //Square minefield.
if (fg.IsTrainingPlatform()) //Training Platform 1 uses the NumberOfCraft field for minutes on the clock. Other platforms use it to activate guns.
count = 1;
if (add) _startingObjects += count;
else _startingObjects -= count;
}
lblStarting.Text = _startingShips.ToString() + " Craft at 30 seconds" + Environment.NewLine + _startingObjects.ToString() + " Object" + (_startingObjects != 1 ? "s" : "");
if (_startingShips > Mission.CraftLimit) lblStarting.ForeColor = Color.Red;
else lblStarting.ForeColor = SystemColors.ControlText;
}
Brush getFlightGroupDrawColor(int fgIndex)
{
Brush brText = Brushes.White;
if (fgIndex < 0 || fgIndex >= _mission.FlightGroups.Count) return brText;
if (_mission.FlightGroups[fgIndex].IsFlightGroup())
{
switch (_mission.FlightGroups[fgIndex].GetActualIFF())
{
case 0: //Default IFF will be translated in GetActualIFF().
brText = Brushes.DodgerBlue;
break;
case 1:
brText = Brushes.Lime; //Brushes.LimeGreen;
break;
case 2:
brText = Brushes.Red; //Brushes.Crimson;
break;
case 3:
brText = Brushes.DodgerBlue;
break;
case 4:
brText = Brushes.RoyalBlue;
break;
}
}
return brText;
}
void initializeMission()
{
tabMain.Focus(); // Exit focus from any form controls. Fixes some issues that might arise from Leave() events trying to access modified lists.
lstFG.Items.Clear(); // Clearing FGs here prevents issues with ComboBoxes further down.
_mission = new Mission();
_config.LastMission = "";
_activeFG = 0;
_mission.FlightGroups[0].CraftType = 1;
_mission.FlightGroups[0].ObjectType = 0;
_mission.FlightGroups[0].IFF = 1;
_startingShips = 0;
_startingObjects = 0;
craftStart(_mission.FlightGroups[0], true);
//string[] fgList = _mission.FlightGroups.GetList();
comboRefreshFGList(cboMothership, true);
comboRefreshFGList(cboArrFG, true);
comboRefreshFGList(cboOrderPrimary, true);
comboRefreshFGList(cboOrderSecondary, true);
lstFG.Items.Add(_mission.FlightGroups[_activeFG].ToString(true));
tabMain.SelectedIndex = 0;
tabFGMinor.SelectedIndex = 0;
cboIFF.Items.Clear();
cboIFF.Items.AddRange(Strings.IFF);
_mission.MissionPath = "\\NewMission.xwi";
Text = "Ye Olde Galactic Empire Mission Editor - X-wing - NewMission.xwi";
}
void loadCraftData(string fileMission)
{
Strings.OverrideShipList(null, null); //Restore defaults.
try
{
CraftDataManager.GetInstance().LoadPlatform(Settings.Platform.XWING, Strings.CraftType, Strings.CraftAbbrv, fileMission);
Strings.OverrideShipList(CraftDataManager.GetInstance().GetLongNames(), CraftDataManager.GetInstance().GetShortNames());
}
catch (Exception x) { MessageBox.Show("Error processing custom XW ship list, using defaults.\n\n" + x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
cboCraft.Items.Clear();
cboCraft.Items.AddRange(Strings.CraftType);
}
/*string replaceTargetText(string text)
{
while (text.Contains("FG:"))
{
int index = text.IndexOf("FG:") + 3;
int length = text.IndexOfAny(new char[] { ' ', ',', '\0' }, index) - index;
int fg;
if (length > 0) fg = int.Parse(text.Substring(index, length));
else fg = int.Parse(text.Substring(index));
text = text.Replace("FG:" + fg, _mission.FlightGroups[fg].ToString());
}
return text;
}*/
bool loadMission(string fileMission)
{
/* return true if successful, returns false if aborted or failed
* code is fairly straight-forward. read the crap and save it */
switchTo(EditorMode.XWI);
closeForms();
try
{
FileStream fs = File.OpenRead(fileMission);
try
{
#region determine platform
switch (Platform.MissionFile.GetPlatform(fs))
{
case Platform.MissionFile.Platform.Xwing: //[JB] Added support for X-wing
initializeMission();
break;
case Platform.MissionFile.Platform.TIE:
_applicationExit = false;
new TieForm(fileMission).Show();
Close();
fs.Close(); //[JB] Files were being left open, which could cause access violations. Need to close stream before returning.
return false;
case Platform.MissionFile.Platform.XvT:
_applicationExit = false;
new XvtForm(fileMission).Show();
Close();
fs.Close();
return false;
case Platform.MissionFile.Platform.BoP:
_applicationExit = false;
new XvtForm(fileMission).Show();
Close();
fs.Close();
return false;
case Platform.MissionFile.Platform.XWA:
_applicationExit = false;
new XwaForm(fileMission).Show();
Close();
fs.Close();
return false;
default:
throw new Exception("File is not a valid mission file for any platform, please select an appropriate *.tie or *.xwi file.");
}
#endregion
_mission.LoadFromStream(fs);
fs.Close();
//Unlike other platforms, need to load a second file to get the briefing.
string brf = fileMission.ToLower().Replace(".xwi", ".brf");
if (File.Exists(brf))
{
fs = File.OpenRead(brf);
_mission.LoadBriefingFromStream(fs);
fs.Close();
}
}
catch (Exception x)
{
fs.Close();
throw x;
}
}
catch (Exception x)
{
MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
menuNewXwing_Click(0, new EventArgs());
return false;
}
loadCraftData(fileMission);
lstFG.Items.Clear();
_startingShips = 0;
for (int i = 0; i < _mission.FlightGroups.Count; i++)
{
lstFG.Items.Add(_mission.FlightGroups[i].ToString(true));
if (_mission.FlightGroups[i].ArrivesIn30Seconds) craftStart(_mission.FlightGroups[i], true);
}
updateFGList();
updateMissionTabs();
Text = "Ye Olde Galactic Empire Mission Editor - X-wing - " + _mission.MissionFileName;
_config.LastMission = fileMission;
refreshRecent();
return true;
}
void promptSave()
{
_config.SaveSettings();
if (_config.ConfirmSave && (Text.IndexOf("*") != -1))
{
DialogResult res = MessageBox.Show("Mission has been edited without saving, would you like to save?", "Confirm", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
if (_mission.MissionPath == "\\NewMission.xwi") savXW.ShowDialog();
else saveMission(_mission.MissionPath);
}
}
}
void refreshRecent()
{
for (int i = 1; i < 6; i++)
{
menuRecentMissions[i].Text = "&" + i + ": " + _config.RecentMissions[i] + " (" + _config.RecentPlatforms[i].ToString() + ")";
menuRecentMissions[i].Visible = (_config.RecentMissions[i] != "");
}
menuRecentMissions[0].Enabled = menuRecentMissions[1].Visible;
}
void registerColorizedFGList(ComboBox Variable, ComboBox VariableType)
{
if (!_config.ColorizedDropDowns) return;
if (Variable == null)
return;
ColorizedFGList[Variable] = VariableType;
Variable.DrawMode = DrawMode.OwnerDrawFixed;
Variable.DrawItem += colorizedComboBox_DrawItem;
}
void registerFgMultiEdit(Control control, string propertyName, MultiEditRefreshType refreshType)
{
Common.AddControlChangedHandler(control, flightgroupMultiEditHandler);
control.Tag = new MultiEditProperty(propertyName, refreshType);
}
void saveMission(string fileMission)
{
tabMain.Focus();
switchTo(EditorMode.XWI);
try { _fBrief.Save(); }
catch { /* do nothing */ }
if (Text.IndexOf("*") == -1) return; // don't save if unmodified
try { _mission.Save(fileMission); }
catch (Exception x) { MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
Text = "Ye Olde Galactic Empire Mission Editor - X-wing - " + _mission.MissionFileName;
_config.LastMission = fileMission;
refreshRecent(); //[JB] Setting _config.LastMission modifies the Recent list. Need to refresh the menu to match.
//Verify the mission after it's been saved
//if (_config.Verify) Common.RunVerify(_mission.MissionPath, _config);
}
void startup()
{
loadCraftData("");
switchTo(EditorMode.XWI);
//initializes cbo's, IFFs, resets bAppExit
_config.LastMission = "";
_config.LastPlatform = Settings.Platform.XWING;
opnXW.InitialDirectory = _config.GetWorkingPath(); //[JB] Updated for MRU access. Defaults to installation and mission folder if not enabled.
savXW.InitialDirectory = _config.GetWorkingPath();
_applicationExit = true; //becomes false if selecting "New Mission" from menu
#region Menu
menuTest.Enabled = _config.XwingInstalled;
if (_config.RestrictPlatforms)
{
menuNewXwing.Enabled = _config.XwingInstalled;
menuNewXvT.Enabled = _config.XvtInstalled;
menuNewBoP.Enabled = _config.BopInstalled;
menuNewXWA.Enabled = _config.XwaInstalled;
}
menuRecentMissions[0] = menuRecent;
menuRecentMissions[1] = menuRec1;
menuRecentMissions[2] = menuRec2;
menuRecentMissions[3] = menuRec3;
menuRecentMissions[4] = menuRec4;
menuRecentMissions[5] = menuRec5;
for (int i = 1; i < 6; i++)
{
menuRecentMissions[i].Click += new EventHandler(menuRecentMissions_Click);
menuRecentMissions[i].Tag = i;
}
refreshRecent();
#endregion
#region Craft
bool btemp = _loading;
_loading = true;
cboCraft.SelectedIndex = _mission.FlightGroups[0].CraftType; // already loaded in loadCraftData
cboObject.Items.AddRange(Strings.ObjectType); cboObject.SelectedIndex = _mission.FlightGroups[0].ObjectType;
_loading = btemp;
cboIFF.SelectedIndex = _mission.FlightGroups[0].IFF; // already loaded default IFFs at start of function through txtIFF#.Text
cboAI.Items.AddRange(Strings.Rating); cboAI.SelectedIndex = 3;
cboMarkings.Items.AddRange(Strings.Color); cboMarkings.SelectedIndex = 0;
cboPlayer.SelectedIndex = 0;
cboFormation.Items.AddRange(Strings.Formation); cboFormation.SelectedIndex = 0;
cboStatus.Items.AddRange(Strings.Status); cboStatus.SelectedIndex = 0;
#endregion
#region Arr/Dep
comboReset(cboArrCondition, Strings.Trigger, 0);
comboReset(cboOrder, Strings.Orders, 0);
cboOrderValue.Items.AddRange(Strings.OrderValue);
for (int i = cboOrderValue.Items.Count; i <= 20; i++)
cboOrderValue.Items.Add(i.ToString());
#endregion
#region Waypoints
_table.Columns.Add("X"); _table.Columns.Add("Y"); _table.Columns.Add("Z");
_tableRaw.Columns.Add("X"); _tableRaw.Columns.Add("Y"); _tableRaw.Columns.Add("Z");
for (int i = 0; i < 10; i++) //initialize WPs
{
DataRow dr = _table.NewRow();
int j;
for (j = 0; j < 3; j++) dr[j] = 0; //set X Y Z to zero
_table.Rows.Add(dr);
dr = _tableRaw.NewRow();
for (j = 0; j < 3; j++) dr[j] = 0; //mirror in raw table
_tableRaw.Rows.Add(dr);
}
dataWaypoints.Table = _table;
dataWaypointsRaw.Table = _tableRaw;
dataWP.DataSource = dataWaypoints;
dataWP_Raw.DataSource = dataWaypointsRaw;
this._table.RowChanged += new DataRowChangeEventHandler(table_RowChanged);
this._tableRaw.RowChanged += new DataRowChangeEventHandler(tableRaw_RowChanged);
chkWP[0] = chkSP1;
chkWP[1] = chkSP2;
chkWP[2] = chkSP3;
chkWP[3] = chkWP1;
chkWP[4] = chkWP2;
chkWP[5] = chkWP3;
chkWP[6] = chkWPHyp;
for (int i = 0; i < 7; i++)
{
chkWP[i].CheckedChanged += new EventHandler(chkWPArr_CheckedChanged);
chkWP[i].Tag = i;
}
#endregion
#region FG Goals
cboPrimGoalT.Items.AddRange(Strings.Objective);
cboPrimGoalT.SelectedIndex = 0;
#endregion
#region Mission
cboEndEvent.Items.AddRange(Strings.EndEvents);
cboMissionLocation.Items.AddRange(Strings.MissionLocation);
txtEoM[0] = txtPrimComp1;
txtEoM[1] = txtPrimComp2;
txtEoM[2] = txtPrimComp3;
for (int i = 0; i < 3; i++)
{
txtEoM[i].Leave += new EventHandler(txtEoMArr_Leave);
txtEoM[i].Tag = i;
}
#endregion
chkGunPlatform[0] = chkGun1;
chkGunPlatform[1] = chkGun2;
chkGunPlatform[2] = chkGun3;
chkGunPlatform[3] = chkGun4;
chkGunPlatform[4] = chkGun5;
chkGunPlatform[5] = chkGun6;
for (int i = 0; i < 6; i++)
chkGunPlatform[i].CheckedChanged += new EventHandler(chkGunArr_CheckedChanged);
updateMissionTabs();
#region ControlRegistration
registerColorizedFGList(cboMothership, null);
registerColorizedFGList(cboArrFG, null);
registerColorizedFGList(cboOrderPrimary, null);
registerColorizedFGList(cboOrderSecondary, null);
registerFgMultiEdit(txtName, "Name", MultiEditRefreshType.ItemText | MultiEditRefreshType.CraftName);
registerFgMultiEdit(numCraft, "NumberOfCraft", MultiEditRefreshType.ItemText | MultiEditRefreshType.CraftName | MultiEditRefreshType.CraftCount);
registerFgMultiEdit(numWaves, "NumberOfWaves", MultiEditRefreshType.ItemText);
registerFgMultiEdit(txtCargo, "Cargo", 0);
registerFgMultiEdit(txtSpecCargo, "SpecialCargo", 0);
registerFgMultiEdit(numSC, "SpecialCargoCraft", 0);
// Craft and object types have special logic, not handled here.
registerFgMultiEdit(cboIFF, "IFF", MultiEditRefreshType.ItemText | MultiEditRefreshType.CraftName);
registerFgMultiEdit(cboAI, "AI", 0);
registerFgMultiEdit(cboMarkings, "Markings", 0);
registerFgMultiEdit(cboPlayer, "PlayerCraft", MultiEditRefreshType.ItemText);
registerFgMultiEdit(cboFormation, "Formation", 0);
registerFgMultiEdit(numObjectValue, "PlatformValue", 0);
registerFgMultiEdit(numSeconds, "PlatformSeconds", 0);
registerFgMultiEdit(cboStatus, "Status", 0);
registerFgMultiEdit(optArrHyp, "ArriveViaHyper", 0);
registerFgMultiEdit(optArrMS, "ArriveViaMothership", 0);
registerFgMultiEdit(optDepHyp, "DepartViaHyper", 0);
registerFgMultiEdit(optDepMS, "DepartViaMothership", 0);
registerFgMultiEdit(cboMothership, "Mothership", 0);
registerFgMultiEdit(cboArrFG, "ArrivalTrigFlightgroup", 0);
registerFgMultiEdit(cboArrCondition, "ArrivalTrigCondition", MultiEditRefreshType.CraftCount);
registerFgMultiEdit(numArrMin, "ArrivalDelayMin", MultiEditRefreshType.CraftCount);
registerFgMultiEdit(numArrSec, "ArrivalDelaySec", MultiEditRefreshType.CraftCount);
registerFgMultiEdit(cboPrimGoalT, "Goal", 0);
registerFgMultiEdit(numPitch, "Pitch", 0);
registerFgMultiEdit(numYaw, "Yaw", 0);
registerFgMultiEdit(numRoll, "Roll", 0);
registerFgMultiEdit(cboOrder, "OrderCommand", 0);
registerFgMultiEdit(cboOrderPrimary, "OrderPrimary", 0);
registerFgMultiEdit(cboOrderSecondary, "OrderSecondary", 0);
registerFgMultiEdit(cboOrderValue, "OrderValue", 0);
#endregion ControlRegistration
_original_lstFG_BackColor = lstFG.BackColor;
lblBRFNotice.Visible = (_mode == EditorMode.BRF);
cmdImportXWI.Visible = (_mode == EditorMode.BRF);
}
void switchTo(EditorMode mode)
{
if (mode == _mode)
return;
closeForms();
bool btemp = _loading;
_loading = true;
FlightGroupCollection temp = _mission.FlightGroups;
_mission.FlightGroups = _mission.FlightGroupsBriefing;
_mission.FlightGroupsBriefing = temp;
_activeFG = 0; //Prevent index bounds if selected index is higher in one mode than available FGs in another.
_mode = mode;
lstFG.Items.Clear();
lstFG.Items.AddRange(_mission.FlightGroups.GetList());
listRefreshAll();
updateFGList(); //Need to refresh all the comboboxes since the list may change.
lstFG.SelectedIndex = 0;
tabMain.SelectedIndex = 0;
tabArrDep.Enabled = (_mode == EditorMode.XWI);
tabGoals.Enabled = (_mode == EditorMode.XWI);
tabOrders.Enabled = (_mode == EditorMode.XWI);
lblArrDepNote.Visible = (_mode == EditorMode.BRF);
lblGoalNote.Visible = (_mode == EditorMode.BRF);
lblOrderNote.Visible = (_mode == EditorMode.BRF);
lblArrDepNote.Enabled = (_mode == EditorMode.BRF);
lblGoalNote.Enabled = (_mode == EditorMode.BRF);
lblOrderNote.Enabled = (_mode == EditorMode.BRF);
lstFG.BackColor = (_mode == EditorMode.XWI) ? _original_lstFG_BackColor : Color.MidnightBlue; ;
cmdSwitchFG.Text = "Switch to " + ((_mode == EditorMode.XWI) ? "BRF" : "XWI");
lblBRFNotice.Visible = (_mode == EditorMode.BRF);
cmdImportXWI.Visible = (_mode == EditorMode.BRF);
lblStarting.Visible = (_mode == EditorMode.XWI);
recalculateStart();
_loading = btemp;
}
void updateMissionTabs()
{
for (int i = 0; i < 3; i++) txtEoM[i].Text = _mission.EndOfMissionMessages[i];
numMissionTime.Value = _mission.TimeLimitMinutes;
cboEndEvent.SelectedIndex = _mission.EndEvent;
numRndSeed.Value = _mission.RndSeed;
cboMissionLocation.SelectedIndex = _mission.Location;
//Check if this is a training course.
lblMissionTimeNote.Visible = false;
foreach (var fg in _mission.FlightGroups)
{
if (fg.IsTrainingPlatform())
{
lblMissionTimeNote.Visible = true;
break;
}
}
}
#endregion methods
#region event handlers
void briefingModifiedCallback(object sender, EventArgs e)
{
Common.MarkDirty(this, _loading);
}
void colorizedComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
//X-wing does not use VariableType like the other platforms do
ComboBox variable = (ComboBox)sender;
bool colorize = true;
if (e.Index == -1 || e.Index >= _mission.FlightGroups.Count + 1) colorize = false; //+1 because of None
//else if(e.Index == 0) colorize = false; //The first entry is always "None"
if (variable.BackColor == Color.Black || variable.BackColor == SystemColors.Window)
variable.BackColor = (colorize == true) ? Color.Black : SystemColors.Window;
e.DrawBackground();
Brush brText = SystemBrushes.ControlText;
if (colorize == true) brText = getFlightGroupDrawColor(e.Index - 1);
e.Graphics.DrawString(e.Index >= 0 ? variable.Items[e.Index].ToString() : "", e.Font, brText, e.Bounds, StringFormat.GenericDefault);
}
void form_Activated(object sender, EventArgs e)
{
// Force control refresh for current FG without losing multi-select.
lstFG_SelectedIndexChanged(0, new EventArgs());
}
void form_Deactivate(object sender, EventArgs e)
{
// Exit focus from any form controls. This submits changes to the map (if it's open), and can prevent issues if coming back in.
lstFG.Focus();
}
void form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
promptSave();
if (_config.ConfirmExit && _applicationExit && Text.IndexOf("*") != -1)
{
DialogResult res = MessageBox.Show("There are unsaved changes, are you sure you wish to exit?", "Confirm", MessageBoxButtons.YesNo);
if (res == DialogResult.No) { e.Cancel = true; return; }
}
closeForms();
if (_applicationExit) Application.Exit();
}
void form_KeyDown(object sender, KeyEventArgs e)
{
//Instead of using a global shortcut for Delete in designer.cs
// this.menuDelete.Shortcut = System.Windows.Forms.Shortcut.Del;
//We trap and process the key here. This allows the Delete key to remain function when editing other controls like text boxes.
if (e.KeyCode == Keys.Delete)
{
if (lstFG.Focused)
{
menuDelete_Click(0, new EventArgs());
e.Handled = true;
}
}
else if (Common.KeyDown(ActiveControl, e))
{
e.Handled = true;
e.SuppressKeyPress = true; // Stop the Windows UI beeping
}
}
void flightgroupMultiEditHandler(object sender, EventArgs e)
{
if (_loading) return;
MultiEditProperty prop = (MultiEditProperty)((Control)sender).Tag;
if (prop.Name != "")
{
setFlightgroupProperty(prop.RefreshType, prop.Name, Common.GetControlValue(sender));
Common.MarkDirty(this); // Since we're not loading, any change marks as dirty.
}
if (prop.RefreshType.HasFlag(MultiEditRefreshType.ItemText)) listRefreshSelectedItems();
if (prop.RefreshType.HasFlag(MultiEditRefreshType.CraftName)) updateFGList();
if (prop.RefreshType.HasFlag(MultiEditRefreshType.Map)) refreshMap(-1);
}
void opnXW_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
_loading = true;
if (loadMission(opnXW.FileName))
{
tabMain.SelectedIndex = 0;
tabFGMinor.SelectedIndex = 0;
_activeFG = 0;
lstFG.SelectedIndex = 0;
}
_loading = false;
}
void savXW_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
saveMission(savXW.FileName);
}
void tabMain_SelectedIndexChanged(object sender, EventArgs e)
{
switch (tabMain.SelectedIndex)
{
case 0:
toolNewItem.ToolTipText = "New FlightGroup";
toolNewItem.Enabled = true;
toolDeleteItem.ToolTipText = "Delete FlightGroup";
toolDeleteItem.Enabled = true;
toolCopy.ToolTipText = "Copy FlightGroup";
toolPaste.ToolTipText = "Paste FlightGroup";
break;
case 1:
updateMissionTabs();
break;
default:
toolNewItem.Enabled = false;
toolDeleteItem.Enabled = false;
toolNewItem.ToolTipText = "";
toolDeleteItem.ToolTipText = "";
toolCopy.ToolTipText = "Copy Item";
toolPaste.ToolTipText = "Paste Item";
break;
}
}
void toolXwing_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
toolXwing.Focus();
switch (toolXwing.Buttons.IndexOf(e.Button))
{
case 0: //New Mission
menuNewXwing_Click("toolbar", new EventArgs());
_loading = false;
break;
case 1: //Open Mission
menuOpen_Click("toolbar", new EventArgs());
_loading = false;
break;
case 2: //Save Mission
menuSave_Click("toolbar", new EventArgs());
break;
case 3: //Save As
menuSaveAsXwing_Click("toolbar", new EventArgs());
break;
case 5: //New Item
if (tabMain.SelectedIndex == 0) newFG(true);
break;
case 6: //Delete Item
menuDelete_Click("toolbar", new EventArgs());
break;
case 7: //Copy Item
menuCopy_Click("toolbar", new EventArgs());
break;
case 8: //Paste Item
menuPaste_Click("toolbar", new EventArgs());
break;
case 10: //Map
menuMap_Click("toolbat", new EventArgs());
break;
case 11: //Briefing
menuBriefing_Click("toolbar", new EventArgs());
break;
case 12: //Verify
menuVerify_Click("toolbar", new EventArgs());
break;
case 14: //Options
menuOptions_Click("toolbar", new EventArgs());
break;
case 15: //Help
menuHelpInfo_Click("toolbar", new EventArgs());
break;
}
}
#endregion event handlers
#region Menu
void menuAbout_Click(object sender, EventArgs e)
{
new AboutDialog().ShowDialog();
}
void menuBriefing_Click(object sender, EventArgs e)
{
try { _fBrief.Close(); }
catch { /* do nothing */ }
if (_mode == EditorMode.XWI)
_fBrief = new BriefingFormXwing(_mission.FlightGroupsBriefing, _mission.Briefing, briefingModifiedCallback);
else
_fBrief = new BriefingFormXwing(_mission.FlightGroups, _mission.Briefing, briefingModifiedCallback);
_fBrief.Show();
}
//[JB] Added function for menu item and modified for extra safety checks to prevent deleting when the list controls don't have focus.
void menuDelete_Click(object sender, EventArgs e)
{
//Ensure controls have focus, otherwise editing various text controls will trigger deletions.
if (tabMain.SelectedIndex == 0)
{
if ((sender.ToString() == "toolbar") || (lstFG.Focused)) deleteFG();
}
}
void menuCopy_Click(object sender, EventArgs e)
{
System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Stream stream = new MemoryStream();
DataObject data = new DataObject();
if (sender.ToString() == "AD")
{
formatter.Serialize(stream, _mission.FlightGroups[_activeFG]);
data.SetText(Strings.Trigger[_mission.FlightGroups[_activeFG].ArrivalEvent]);
}
else if (sender.ToString() == "Order")
{
formatter.Serialize(stream, _mission.FlightGroups[_activeFG]);
data.SetText(Strings.Orders[_mission.FlightGroups[_activeFG].Order]);
}
else if (ActiveControl.GetType().ToString() == "System.Windows.Forms.TextBox")
{
TextBox txt = (TextBox)ActiveControl;
if (txt.SelectedText != "")
{
formatter.Serialize(stream, txt.SelectedText);
data.SetText(txt.SelectedText);
}
}
else if (ActiveControl.GetType().ToString() == "System.Windows.Forms.NumericUpDown") //[JB] Added copy/paste for this
{
NumericUpDown num = (NumericUpDown)ActiveControl;
formatter.Serialize(stream, num.Value);
data.SetText(num.Value.ToString());
}
else if (ActiveControl.GetType().ToString() == "System.Windows.Forms.DataGridTextBox")
{
DataGridTextBox dgt = (DataGridTextBox)ActiveControl;
if (dgt.Text != "")
{
formatter.Serialize(stream, dgt.Text);
data.SetText(dgt.Text);
}
}
switch (tabMain.SelectedIndex)
{
case 0:
formatter.Serialize(stream, _mission.FlightGroups[_activeFG]);
data.SetText(_mission.FlightGroups[_activeFG].ToString());
break;
}
data.SetData("yogeme", false, stream);
Clipboard.SetDataObject(data, true);
}
void menuCut_Click(object sender, EventArgs e)
{
if(Common.Cut(ActiveControl))
Common.MarkDirty(this);
}
void menuER_Click(object sender, EventArgs e)
{
Common.LaunchER();
}
void menuExit_Click(object sender, EventArgs e)
{
Close();
}
void menuGoalSummary_Click(object sender, EventArgs e)
{
string dsGoal = "";
if (_mission.Location == 1) //Death Star surface
{
if (_mission.EndEvent == 1) dsGoal = "Death Star Surface: Clear Laser Towers";
else if (_mission.EndEvent == 5) dsGoal = "Death Star Surface: Hit Exhaust Port";
if (dsGoal.Length > 0) dsGoal += "\r\n\r\n";
}
new GoalSummaryDialog(dsGoal + generateGoalSummary()).Show();
}
void menuLibrary_Click(object sender, EventArgs e)
{
_fLibrary?.Close();
_fLibrary = new FlightGroupLibraryForm(Settings.Platform.XWING, _mission.FlightGroups, flightGroupLibraryCallback);
}
void flightGroupLibraryCallback(object sender, EventArgs e)
{
foreach (object obj in (object[])sender)
{
FlightGroup fg = (FlightGroup)obj;
if (fg == null || !newFG(fg.IsFlightGroup())) break;
_mission.FlightGroups[_activeFG] = fg;
updateFGList();
listRefreshItem(_activeFG);
_startingShips--;
craftStart(fg, true);
}
}
void menuHelpInfo_Click(object sender, EventArgs e)
{
Common.LaunchHelp();
}
void menuIDMR_Click(object sender, EventArgs e)
{
Common.LaunchGithub();
}
void menuMap_Click(object sender, EventArgs e)
{
try { _fMap.Close(); }
catch { /* do nothing */ }
_fMap = new MapForm(_mission.FlightGroups, mapForm_DataChangedCallback);
_fMap.Show();
}
void mapForm_DataChangedCallback(object sender, EventArgs e)
{
Common.MarkDirty(this);
if (tabFGMinor.SelectedIndex == 3) //Update waypoints tab.
refreshWaypointTab();
}
void menuNewXwing_Click(object sender, EventArgs e)
{
switchTo(EditorMode.XWI);
promptSave();
closeForms();
_loading = true;
initializeMission();
lstFG.SelectedIndex = 0;
_startingShips = 1;
lblStarting.Text = "1 Craft at 30 seconds";
updateMissionTabs();
_loading = false;
if (Text.EndsWith("*")) Text = Text.Substring(0, Text.Length - 1);
}
void menuNewBoP_Click(object sender, EventArgs e)
{
menuNewXvT_Click("BoP", new EventArgs());
}
void menuNewTIE_Click(object sender, EventArgs e)
{
promptSave();
closeForms();
_applicationExit = false;
new TieForm().Show();
Close();
}
void menuNewXvT_Click(object sender, EventArgs e)
{
promptSave();
closeForms();
_applicationExit = false;
new XvtForm(sender.ToString() == "BoP").Show();
Close();
}
void menuNewXWA_Click(object sender, EventArgs e)
{
promptSave();
closeForms();