-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBriefingForm.cs
3305 lines (3174 loc) · 116 KB
/
BriefingForm.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 (mjgaisser@gmail.com)
* Licensed under the MPL v2.0 or later
*
* VERSION: 1.16.0.5
*
* CHANGELOG
* v1.16.0.5, 241120
* [FIX #112] Exception adding events to blank briefing, and silently overwriting existing events.
* v1.16.0.2, 241017
* [FIX] Exception during XwaSetIcon and XwaMoveIcon event modifications
* v1.16, 241013
* [UPD] Updates due to Platform
* [UPD] Text tag, FG tag and mask colors defined at ctor instead of inline
* [NEW] TextTag and ShipTag structs to replace int[,] for _textTags and _fgTags
* [UPD] _events now EventCollection type
* v1.15.3, 231111
* [FIX #92] Event overflow due to XWA move
* v1.14, 230804
* [NEW] SkipMarker for TIE/XvT
* [UPD] Replaced Unk1 field with label
* [FIX] Moved page increment to CaptionText instead of PageBreak
* [FIX] Crash if a Caption/Title index was -1
* v1.13.6, 220619
* [NEW] Shift All checkbox on Events tab so timing can move together
* v1.11, 210801
* [UPD] Icons attempt to load from the platform directory to account for mods [JB]
* v1.9.2, 210328
* [FIX] Missing LST note in the title
* [FIX #53] Move map for XWA
* v1.8, 201004
* [FIX] Timers unregister Tick to prevent calls after Dispose [JB]
* v1.7, 200816
* [FIX] XWA MoveIcon selecting wrong icon
* [FIX] XvT craft icons [JB]
* v1.6.5, 200704
* [UPD] Icons now use BMPs instead of the DATs, importDats() renamed to importIcons()
* [UPD] If the craft index is OutOfRange, use the first one
* [FIX] XWA ShipInfo for X-wings work now
* v1.6.4, 200119
* [NEW #30] onModified callback to prevent mission from auto-dirty when opening
* v1.5, 180910
* [FIX] map performance [JB]
* [UPD] XvT map size tweaked [JB]
* [UPD] PostLoadInit tweaked [JB]
* [UPD] _Closed and _Closing changed to _FormClosed and _FormClosing, adjust the exit routine [JB]
* [FIX] _Load forces an update [JB]
* [ADD] redraw timer and supporting popup functions [JB]
* [FIX] limit to FF_Click [JB]
* [ADD] code moved to ProcessEvent() and ResetBriefing() [JB]
* [ADD] playback speed shown if not 1x [JB]
* [FIX] grid paint when at extreme coords [JB]
* [FIX] Y zoom when painting FG icons [JB]
* [NEW] lblCaption_Click [JB]
* [FIX] XWA tag names now use Icon # [JB]
* [UPD] control focus in updateParameters() [JB]
* [UPD] cmdNew now adds after current line [JB]
* [UPD] tweaked layout size
* v1.3, 170107
* [NEW] Multiple briefings capability, popup [JB]
* [NEW] BriefData.WaypointArr [JB]
* [FIX] crash fixes [JB]
* [NEW] support functions for event capacity and moving events [JB]
* v1.2.3, 141214
* [UPD] change to MPL
* v1.1.1, 120814
* - class renamed
* - ctors no longer ref
* - renamed a ton of stuff
* [NEW] txtNotes
* v1.1, 120715
* - using Platform
* - removed local EventType, use BaseBriefing.EventType
* - using BaseBriefing.EventParameterCount
* v1.0, 110921
* - Release
*/
using Idmr.Common;
using Idmr.Platform;
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;
namespace Idmr.Yogeme
{
/// <summary>The briefing forms for YOGEME, one form for TIE-XWA</summary>
public partial class BriefingForm : Form
{
#region Vars
BriefData[] _briefData;
BriefData _tempBD;
readonly Platform.Xvt.BriefingCollection _xvtBriefingCollection;
readonly Platform.Xwa.BriefingCollection _xwaBriefingCollection;
int _currentCollectionIndex;
readonly Platform.Tie.Briefing _tieBriefing;
Platform.Xvt.Briefing _xvtBriefing;
Platform.Xwa.Briefing _xwaBriefing;
bool _loading = false;
readonly Color _normalColor;
//readonly Color _highlightColor; // TODO: this is currently unused, maybe at some point work highlighting in
readonly Color _titleColor;
readonly BaseBriefing.EventCollection _events; // this will contain the event listing for use, raw data is in Briefing.Events[]
short _zoomX = 48;
short _zoomY;
short _mapX, _mapY; // mapX and mapY will be different, namely the grid coordinates of the center, like how TIE handles it
Bitmap _map;
readonly ShipTag[] _fgTags = new ShipTag[8];
TextTag[] _textTags = new TextTag[8];
TextTag[] _ttBackup;
readonly Color[] _tagColors;
readonly Color[] _iffColors;
readonly Color[] _iffBackColors;
readonly Color[] _maskColors;
readonly DataTable _tableTags = new DataTable("Tags");
readonly DataTable _tableStrings = new DataTable("Strings");
readonly int _timerInterval;
BaseBriefing.EventType _eventType = BaseBriefing.EventType.None;
short _tempX, _tempY;
readonly Settings.Platform _platform;
string[] _tags;
string[] _strings;
readonly int _maxEvents;
string _message = "";
int _regionDelay = -1;
int _page = 1;
short _icon = 0;
bool _popupPreviewActive = false; //[JB] The popup feature allows the user to move and zoom the map without changing any events, as well as see the coordinates of the mouse cursor. Designed to assist raw editing of the event list.
Point _popupPreviewZoom;
Point _popupPreviewMap;
bool _isMiddleDrag = false;
Point _popupMiddle;
bool _mapPaintScheduled = false;
int _previousTimeIndex = 0; //Tracks the previous time index of the briefing so we can detect when the user is manually scrolling through arbitrary times.
static int[] _xvtTagSizeCache = null;
#pragma warning disable IDE1006 // Naming Styles
EventHandler onModified = null;
#pragma warning restore IDE1006 // Naming Styles
#endregion
static public string[] SharedTeamNames = new string[10];
public BriefingForm(Platform.Tie.FlightGroupCollection fg, Platform.Tie.Briefing briefing, EventHandler onModifiedCallback)
{
_loading = true;
_platform = Settings.Platform.TIE;
_titleColor = Color.FromArgb(0xFC, 0xFC, 0x54);
_normalColor = Color.FromArgb(0xFC, 0xFC, 0xFC);
_tagColors = new Color[] {
Color.FromArgb(0, 0xAC, 0), // green
Color.FromArgb(0xAC, 0, 0), // red
Color.FromArgb(0xAC, 0, 0xAC), // purple
Color.FromArgb(0, 0x2C, 0xAC), // blue
Color.FromArgb(0xA8, 0, 0), // red2
Color.FromArgb(0xFC, 0x54, 0x54), // light red
Color.FromArgb(0x44, 0x44, 0x44), // gray
Color.FromArgb(0xCC, 0xCC, 0xCC) // white
};
_iffColors = new Color[] {
Color.FromArgb(0, 0xE0, 0), // green
Color.FromArgb(0xE0, 0, 0), // red
Color.FromArgb(0, 0x78, 0xE0), // blue
Color.FromArgb(0xE0, 0, 0xE0), // purple
Color.FromArgb(0xE0, 0, 0), // red2
Color.FromArgb(0xE0, 0, 0xE0) // purple2
};
_iffBackColors = new Color[] {
Color.FromArgb(0, 0x78, 0), // green
Color.FromArgb(0x78, 0, 0), // red
Color.FromArgb(0, 0x10, 0x78), // blue
Color.FromArgb(0x78, 0, 0x78), // purple
Color.FromArgb(0x78, 0, 0), // red2
Color.FromArgb(0x78, 0, 0x78) // purple2
};
//_highlightColor = Color.FromArgb(0x00, 0xA8, 0x00);
_zoomY = _zoomX; // in most cases, these will remain the same
_tieBriefing = briefing;
_maxEvents = Platform.Tie.Briefing.EventQuantityLimit;
_events = new BaseBriefing.EventCollection(MissionFile.Platform.TIE);
InitializeComponent();
Text = "YOGEME Briefing Editor - TIE";
#region layout edit
// final layout update, as in VS it's spread out
Height = 426;
Width = 760;
tabBrief.Width = 752;
cmdMarker.Top = 160;
Point loc = new Point(608, 188);
pnlShipTag.Location = loc;
pnlTextTag.Location = loc;
#endregion
Import(fg); // FGs are separate so they can be updated without running the BRF as well
importIcons(Application.StartupPath + "\\images\\TIE_BRF.bmp", 34);
_tags = _tieBriefing.BriefingTag;
_strings = _tieBriefing.BriefingString;
importStrings();
_timerInterval = Platform.Tie.Briefing.TicksPerSecond;
txtLength.Text = Convert.ToString(Math.Round((decimal)_tieBriefing.Length / _timerInterval, 2));
hsbTimer.Maximum = _tieBriefing.Length + 11;
_mapX = 0;
_mapY = 0;
lstEvents.Items.Clear();
importEvents(_tieBriefing.Events);
hsbTimer.Value = 0;
numTile.Value = _tieBriefing.Tile;
cboText.SelectedIndex = 0;
cboFGTag.SelectedIndex = 0;
cboTextTag.SelectedIndex = 0;
cboColorTag.SelectedIndex = 0;
labBriefIndex2.Visible = false;
cboBriefIndex2.Visible = false;
tabTeams.Enabled = false;
_loading = false;
onModified = onModifiedCallback;
postLoadInit();
}
public BriefingForm(Platform.Xvt.FlightGroupCollection fg, Platform.Xvt.BriefingCollection briefing, EventHandler onModifiedCallback)
{
_loading = true;
_platform = Settings.Platform.XvT;
_titleColor = Color.FromArgb(0xFC, 0xFC, 0x00);
_normalColor = Color.FromArgb(0xF8, 0xFC, 0xF8);
_tagColors = new Color[] {
Color.FromArgb(0, 0xAC, 0), // green
Color.FromArgb(0xA8, 0, 0), // red
Color.FromArgb(0xA8, 0xAC, 0), // yellow
Color.FromArgb(0, 0x2C, 0xA8), // blue
Color.FromArgb(0xA8, 0, 0xA8), // purple
Color.Black
};
_iffColors = new Color[] {
Color.FromArgb(0, 0xE0, 0), // green
Color.FromArgb(0xE0, 0, 0), // red
Color.FromArgb(0, 0, 0xE0), // blue
Color.FromArgb(0xE0, 0xE0, 0), // yellow
Color.FromArgb(0xE0, 0, 0), // red2
Color.FromArgb(0xE0, 0, 0xE0) // purple2
};
_iffBackColors = new Color[] {
Color.FromArgb(0, 0x78, 0), // green
Color.FromArgb(0x78, 0, 0), // red
Color.FromArgb(0, 0, 0x78), // blue
Color.FromArgb(0x78, 0x78, 0), // yellow
Color.FromArgb(0x78, 0, 0), // red2
Color.FromArgb(0x78, 0, 0x78) // purple2
};
_maskColors = new Color[] {
// green
Color.FromArgb(0x38, 0xD4, 0),
Color.FromArgb(0x18, 0xA8, 0),
Color.FromArgb(8, 0x7C, 0),
Color.FromArgb(0, 0x54, 0),
Color.Black,
Color.FromArgb(0, 1, 0),
// red
Color.FromArgb(0xF8, 0x24, 0),
Color.FromArgb(0xC0, 0x10, 0),
Color.FromArgb(0x80, 4, 0),
Color.FromArgb(0x48, 0, 0),
Color.Black,
Color.FromArgb(1, 0, 0),
// blue
Color.FromArgb(0x58, 0xDC, 0xF8),
Color.FromArgb(0x28, 0x84, 0xC0),
Color.FromArgb(8, 0x3C, 0x90),
Color.FromArgb(0, 8, 0x58),
Color.Black,
Color.FromArgb(0, 0, 1),
// yellow
Color.FromArgb(0xD8, 0xFC, 0),
Color.FromArgb(0xD0, 0xCC, 0),
Color.FromArgb(0xA8, 0x9C, 0),
Color.FromArgb(0x80, 0x74, 0),
Color.Black,
Color.FromArgb(1, 1, 0),
// red
Color.FromArgb(0xF8, 0x24, 0),
Color.FromArgb(0xC0, 0x10, 0),
Color.FromArgb(0x80, 4, 0),
Color.FromArgb(0x48, 0, 0),
Color.Black,
Color.FromArgb(1, 0, 0),
// purple
Color.FromArgb(0x90, 0x88, 0xF0),
Color.FromArgb(0x70, 0x5C, 0xB0),
Color.FromArgb(0x50, 0x30, 0x78),
Color.FromArgb(0x30, 8, 0x40),
Color.Black,
Color.FromArgb(1, 0, 1)
};
//_highlightColor = Color.FromArgb(0x40, 0xC4, 0x40);
_zoomY = _zoomX;
_xvtBriefingCollection = briefing;
_currentCollectionIndex = 0;
_xvtBriefing = briefing[0];
_maxEvents = Platform.Xvt.Briefing.EventQuantityLimit;
_events = new BaseBriefing.EventCollection(MissionFile.Platform.XvT);
InitializeComponent();
Text = "YOGEME Briefing Editor - XvT/BoP";
Import(fg);
#region XvT layout change
Height = 426;
Width = 760;
tabBrief.Width = 752;
Point loc = new Point(608, 188);
pnlShipTag.Location = loc;
pnlTextTag.Location = loc;
pctBrief.Size = new Size(360, 208); //[JB] //Was 214. The actual size in game appears to be 320x210, but I trimmed it down to 208 because it seemed to be rendering some extra pixels.
pctBrief.Left = 150;
lblCaption.BackColor = Color.FromArgb(0, 0, 0x78);
lblCaption.Font = new Font("Times New Roman", 8F, FontStyle.Regular, GraphicsUnit.Point, 0);
lblCaption.Size = new Size(360, 28);
lblCaption.Location = new Point(150, 254);
lblTitle.BackColor = Color.FromArgb(0x10, 0x10, 0x20);
lblTitle.Font = new Font("Times New Roman", 8F, FontStyle.Regular, GraphicsUnit.Point, 0);
lblTitle.Size = new Size(360, 16);
lblTitle.TextAlign = ContentAlignment.TopCenter;
lblTitle.ForeColor = _titleColor;
lblTitle.Text = "*Defined in .LST file*";
lblTitle.Location = new Point(150, 24);
cmdTitle.Enabled = false;
cboColorTag.Items.Clear();
cboColorTag.Items.Add("Green");
cboColorTag.Items.Add("Red");
cboColorTag.Items.Add("Yellow");
cboColorTag.Items.Add("Blue");
cboColorTag.Items.Add("Purple");
cboColorTag.Items.Add("Black");
cboColor.Items.Clear();
cboColor.Items.Add("Green");
cboColor.Items.Add("Red");
cboColor.Items.Add("Yellow");
cboColor.Items.Add("Blue");
cboColor.Items.Add("Purple");
cboColor.Items.Add("Black");
cmdMarker.Top = 160;
#endregion
importIcons(Application.StartupPath + "\\images\\XvT_BRF.bmp", 22);
_tags = _xvtBriefing.BriefingTag;
_strings = _xvtBriefing.BriefingString;
importStrings();
_timerInterval = Platform.Xvt.Briefing.TicksPerSecond;
txtLength.Text = Convert.ToString(Math.Round((decimal)_xvtBriefing.Length / _timerInterval, 2));
hsbTimer.Maximum = _xvtBriefing.Length + 11;
_mapX = 0;
_mapY = 0;
lstEvents.Items.Clear();
importEvents(_xvtBriefing.Events);
hsbTimer.Value = 0;
numTile.Value = _xvtBriefing.Tile;
cboText.SelectedIndex = 0;
cboFGTag.SelectedIndex = 0;
cboTextTag.SelectedIndex = 0;
cboColorTag.SelectedIndex = 0;
for (int i = 0; i < _xvtBriefingCollection.Count; i++)
{
string s = "Briefing " + (i + 1);
cboBriefIndex1.Items.Add(s);
cboBriefIndex2.Items.Add(s);
}
for (int i = 0; i < 10; i++) //XvT has 10 teams
lstTeams.Items.Add((i + 1) + ": " + SharedTeamNames[i]);
cboBriefIndex1.SelectedIndex = 0;
cboBriefIndex2.SelectedIndex = 0;
refreshTeamList();
updateTitle();
_loading = false;
onModified = onModifiedCallback;
postLoadInit();
}
public BriefingForm(Platform.Xwa.BriefingCollection briefing, EventHandler onModifiedCallback)
{
_loading = true;
_platform = Settings.Platform.XWA;
_titleColor = Color.FromArgb(0x63, 0x82, 0xFF);
_normalColor = Color.FromArgb(0xFF, 0xFF, 0xFF);
_tagColors = new Color[] {
Color.FromArgb(0, 0xE3, 0), // green
Color.FromArgb(0xE7, 0, 0), // red
Color.FromArgb(0xE7, 0xE3, 0), // yellow
Color.FromArgb(0x63, 0x61, 0xE7), // purple
Color.FromArgb(0xDE, 0, 0xDE), // pink
Color.FromArgb(0, 4, 0xA5) // blue
};
_iffColors = new Color[] {
Color.FromArgb(0, 0xE0, 0), // green
Color.FromArgb(0xE0, 0, 0), // red
Color.FromArgb(0x60, 0x60, 0xE0), // blue
Color.FromArgb(0xE0, 0xE0, 0), // yellow
Color.FromArgb(0xE0, 0, 0), // red2
Color.FromArgb(0xE0, 0, 0xE0) // purple
};
_iffBackColors = new Color[] {
Color.FromArgb(0, 0x78, 0), // green
Color.FromArgb(0x78, 0, 0), // red
Color.FromArgb(0x20, 0x20, 0x78), // blue
Color.FromArgb(0x78, 0x78, 0), // yellow
Color.FromArgb(0x78, 0, 0), // red2
Color.FromArgb(0x78, 0, 0x78) // purple
};
_maskColors = new Color[] {
Color.FromArgb(0x40, 0xBC, 0x20), // green
Color.FromArgb(0xF8, 0x54, 0x50), // red
Color.FromArgb(0x68, 0x8C, 0xF8), // blue
Color.FromArgb(0xE8, 0xD0, 0x40), // yellow
Color.FromArgb(0xF8, 0x54, 0x50), // red2
Color.FromArgb(0xF8, 0x80, 0xF8) // purple
};
//_highlightColor = _titleColor;
_zoomX = 32;
_zoomY = _zoomX;
_xwaBriefingCollection = briefing;
_currentCollectionIndex = 0;
_xwaBriefing = briefing[0];
_maxEvents = Platform.Xwa.Briefing.EventQuantityLimit;
_events = new BaseBriefing.EventCollection(MissionFile.Platform.XWA);
InitializeComponent();
Text = "YOGEME Briefing Editor - XWA";
#region XWA layout change
// TODO: view is off by a little bit, couple pixels
label7.Text = "Icon:";
Height = 484;
Width = 760;
tabBrief.Width = 752;
Point loc = new Point(608, 246);
pnlShipTag.Location = loc;
pnlTextTag.Location = loc;
pnlShipInfo.Location = loc;
pnlRotate.Location = loc;
pnlMove.Location = loc;
pnlNew.Location = loc;
pnlRegion.Location = loc;
cmdNewShip.Visible = true;
cmdMoveShip.Visible = true;
cmdRotate.Visible = true;
cmdShipInfo.Visible = true;
cmdRegion.Visible = true;
pctBrief.Size = new Size(510, 294);
pctBrief.Left += 36;
lblTitle.BackColor = Color.FromArgb(0x18, 0x18, 0x18);
lblTitle.Size = new Size(510, 28);
lblTitle.Left += 36;
lblTitle.Top -= 4;
lblTitle.TextAlign = ContentAlignment.TopCenter;
lblTitle.ForeColor = _titleColor;
lblTitle.Text = "*Defined in .LST file*";
lblTitle.Font = new Font("Arial", 10F, FontStyle.Bold, GraphicsUnit.Point, 0);
cmdTitle.Enabled = false;
cmdMarker.Visible = false;
lblCaption.BackColor = Color.FromArgb(0x20, 0x30, 0x88);
lblCaption.Font = new Font("Arial", 8F, FontStyle.Regular, GraphicsUnit.Point, 0);
lblCaption.Size = new Size(510, 40);
lblCaption.Top += 68;
lblCaption.Left += 36;
vsbBRF.Left -= 38;
vsbBRF.Height = 294;
tabBrief.Height += 58;
hsbBRF.Top += 70;
hsbBRF.Width = 510;
hsbBRF.Left += 36;
lblInstruction.Top += 58;
pnlBottomRight.Top += 58;
pnlBottomLeft.Top += 58;
dataT.Height += 58;
dataS.Height += 58;
lstEvents.Height += 58;
cboColorTag.Items.Clear();
cboColorTag.Items.Add("Green");
cboColorTag.Items.Add("Red");
cboColorTag.Items.Add("Yellow");
cboColorTag.Items.Add("Purple");
cboColorTag.Items.Add("Pink");
cboColorTag.Items.Add("Blue");
cboColor.Items.Clear();
cboColor.Items.Add("Green");
cboColor.Items.Add("Red");
cboColor.Items.Add("Yellow");
cboColor.Items.Add("Purple");
cboColor.Items.Add("Pink");
cboColor.Items.Add("Blue");
cboEvent.Items.RemoveAt(0); // Remove the "Skip Marker" event
cboEvent.Items.Add("New Icon");
cboEvent.Items.Add("Show Ship Data");
cboEvent.Items.Add("Move Icon");
cboEvent.Items.Add("Rotate Icon");
cboEvent.Items.Add("Switch to Region");
cboCraft.Items.AddRange(Platform.Xwa.Strings.CraftType);
cboNCraft.Items.AddRange(Platform.Xwa.Strings.CraftType);
#endregion
// Try loading directly from the installation. If it fails, load the default image strip.
if (!loadXwaIcons(56)) importIcons(Application.StartupPath + "\\images\\XWA_BRF.bmp", 56);
_tags = _xwaBriefing.BriefingTag;
_strings = _xwaBriefing.BriefingString;
importStrings();
_timerInterval = Platform.Xwa.Briefing.TicksPerSecond;
txtLength.Text = Convert.ToString(Math.Round((decimal)_xwaBriefing.Length / _timerInterval, 2));
hsbTimer.Maximum = _xwaBriefing.Length + 11;
_mapX = 0;
_mapY = 0;
lstEvents.Items.Clear();
_briefData = new BriefData[100]; // this way I don't have to deal with expanding the array
string[] names = new string[100];
for (int i = 0; i < _briefData.Length; i++) names[i] = "Icon #" + i;
cboFG.Items.AddRange(names);
cboFGTag.Items.AddRange(names);
cboInfoCraft.Items.AddRange(names);
cboRCraft.Items.AddRange(names);
cboMoveIcon.Items.AddRange(names);
cboNewIcon.Items.AddRange(names);
importEvents(_xwaBriefing.Events);
hsbTimer.Value = 0;
numTile.Value = _xwaBriefing.Tile;
txtNotes.Enabled = true;
txtNotes.Text = _xwaBriefing.BriefingStringsNotes[0];
cboText.SelectedIndex = 0;
cboFGTag.SelectedIndex = 0;
cboTextTag.SelectedIndex = 0;
cboColorTag.SelectedIndex = 0;
cboInfoCraft.SelectedIndex = 0;
cboRCraft.SelectedIndex = 0;
cboRotateAmount.SelectedIndex = 0;
cboMoveIcon.SelectedIndex = 0;
cboNewIcon.SelectedIndex = 0;
cboNCraft.SelectedIndex = 0;
cboIconIff.SelectedIndex = 0;
for (int i = 0; i < _xwaBriefingCollection.Count; i++)
{
string s = "Briefing " + (i + 1);
cboBriefIndex1.Items.Add(s);
cboBriefIndex2.Items.Add(s);
}
for (int i = 0; i < 10; i++) //XWA has 10 teams
lstTeams.Items.Add((i + 1) + ": " + SharedTeamNames[i]);
cboBriefIndex1.SelectedIndex = 0;
cboBriefIndex2.SelectedIndex = 0;
refreshTeamList();
updateTitle();
_loading = false;
onModified = onModifiedCallback;
postLoadInit();
}
/// <summary>Handles redundant code for each of the 3 platform modes.</summary>
void postLoadInit()
{
if (lstEvents.Items.Count > 0) lstEvents.SelectedIndex = 0;
else
{
cmdUp.Enabled = false;
cmdDown.Enabled = false;
}
}
void fillBriefData(int index, int craftType, BaseFlightGroup.Waypoint waypoint, BaseFlightGroup.Waypoint[] waypoints, byte iff, string name)
{
_briefData[index].Craft = craftType;
_briefData[index].Waypoint = (short[])waypoint;
_briefData[index].WaypointArr = waypoints;
_briefData[index].IFF = iff;
_briefData[index].Name = name;
cboFG.Items.Add(name);
cboFGTag.Items.Add(name);
}
/// <summary>Attempts to load XWA's briefing icons directly from the installation files.</summary>
bool loadXwaIcons(int size)
{
try
{
System.Collections.Generic.List<string> shiplist = new System.Collections.Generic.List<string>(232);
string line;
using (StreamReader sr = new StreamReader(CraftDataManager.GetInstance().GetInstallPath() + "\\SHIPLIST.TXT"))
{
while (!sr.EndOfStream)
{
line = sr.ReadLine();
if (line.StartsWith("!")) shiplist.Add(line);
}
}
Image bmp = Image.FromFile(CraftDataManager.GetInstance().GetInstallPath() + "\\FRONTRES\\MAPICONS\\LICON.BMP");
imgCraft.ImageSize = new Size(size, size);
for (int i = 0; i < shiplist.Count; i++)
{
Bitmap icon = new Bitmap(size, size);
using (Graphics g = Graphics.FromImage(icon))
{
string[] tokens = shiplist[i].Split(',');
int x1 = 0, x2 = 0, y1 = 0, y2 = 0, width = 0, height = 0;
if (tokens.Length >= 13) // Extraneous commas may exist.
{
int.TryParse(tokens[9].Trim(), out x1);
int.TryParse(tokens[10].Trim(), out y1);
int.TryParse(tokens[11].Trim(), out x2);
int.TryParse(tokens[12].Trim(), out y2);
width = x2 - x1;
height = y2 - y1;
}
Rectangle src = new Rectangle(x1, y1, width, height);
if (width > size) width = size;
if (height > size) height = size;
Rectangle dest = new Rectangle((size / 2) - (width / 2), (size / 2) - (height / 2), width, height);
g.DrawImage(bmp, dest, src, GraphicsUnit.Pixel);
}
imgCraft.Images.Add(icon);
}
}
catch { return false; }
return true;
}
void importIcons(string filename, int size)
{
try
{
imgCraft.ImageSize = new Size(size, size);
imgCraft.Images.AddStrip(Image.FromFile(filename));
}
catch (Exception x)
{
MessageBox.Show(x.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
}
void importEvents(BaseBriefing.EventCollection rawEvents)
{
for (int i = 0; i < _maxEvents; i++)
{
try
{
_events.Add(rawEvents[i].Clone());
if (_events[i].IsEndEvent) break;
if (_platform == Settings.Platform.XWA && _events[i].Type == BaseBriefing.EventType.XwaMoveIcon && _briefData[_events[i].Variables[0]].Waypoint != null && _briefData[_events[i].Variables[0]].Waypoint[0] == 0 && _briefData[_events[i].Variables[0]].Waypoint[1] == 0)
{ // this prevents Exception if Move instruction is before NewIcon, and only assigns initial position
_briefData[_events[i].Variables[0]].Waypoint[0] = _events[i].Variables[1];
_briefData[_events[i].Variables[0]].Waypoint[1] = _events[i].Variables[2];
}
}
catch (ArgumentOutOfRangeException) { break; } // if briefing is corrupted leading to an overflow, just kick out
lstEvents.Items.Add("");
updateList(i);
}
}
void importStrings()
{
if (_tableTags.Columns.Count == 0)
{
_tableTags.Columns.Add("tag");
_tableStrings.Columns.Add("string");
}
_tableTags.Clear();
_tableStrings.Clear();
for (int i = 0; i < _tags.Length; i++)
{
DataRow dr = _tableTags.NewRow();
dr[0] = _tags[i];
_tableTags.Rows.Add(dr);
dr = _tableStrings.NewRow();
dr[0] = _strings[i];
_tableStrings.Rows.Add(dr);
}
dataTags.Table = _tableTags;
dataStrings.Table = _tableStrings;
dataT.DataSource = dataTags;
dataS.DataSource = dataStrings;
_tableTags.RowChanged += new DataRowChangeEventHandler(tableTags_RowChanged);
_tableStrings.RowChanged += new DataRowChangeEventHandler(tableStrings_RowChanged);
loadTags();
loadStrings();
}
public void Import(Platform.Tie.FlightGroupCollection fg)
{
_briefData = new BriefData[fg.Count];
cboFG.Items.Clear();
cboFGTag.Items.Clear();
for (int i = 0; i < fg.Count; i++) fillBriefData(i, fg[i].CraftType, fg[i].Waypoints[14], null, fg[i].IFF, fg[i].Name);
}
public void Import(Platform.Xvt.FlightGroupCollection fg)
{
_briefData = new BriefData[fg.Count];
cboFG.Items.Clear();
cboFGTag.Items.Clear();
for (int i = 0; i < fg.Count; i++)
{
var wps = new BaseFlightGroup.Waypoint[8];
for (int k = 0; k < 8; k++) wps[k] = fg[i].Waypoints[14 + k];
fillBriefData(i, fg[i].CraftType, fg[i].Waypoints[14], wps, fg[i].IFF, fg[i].Name);
}
}
public void Save()
{
_baseBrf.Events.Clear();
for (int evnt = 0; evnt < _maxEvents; evnt++)
{
if (_events[evnt].IsEndEvent) break;
_baseBrf.Events.Add(_events[evnt].Clone());
}
_baseBrf.Tile = (short)numTile.Value;
onModified?.Invoke("Save", new EventArgs());
}
void tabBrief_SelectedIndexChanged(object sender, EventArgs e) => hsbTimer.Value = (tabBrief.SelectedIndex != 0 ? 1 : 0); // force refresh, since pct doesn't want to update when hidden
#region frmBrief
void frmBrief_Activated(object sender, EventArgs e) => MapPaint();
void frmBrief_FormClosed(object sender, FormClosedEventArgs e)
{
tabBrief.Focus();
_map.Dispose();
}
void frmBrief_FormClosing(object sender, FormClosingEventArgs e)
{
Save();
//Important! There's an issue where the event can trigger after the map is disposed, even after calling Stop(). The event must be unregistered.
tmrPopup.Stop();
tmrPopup.Tick -= tmrPopup_Tick;
tmrMapRedraw.Stop();
tmrMapRedraw.Tick -= tmrMapRedraw_Tick;
onModified = null;
}
void frmBrief_Load(object sender, EventArgs e)
{
for (int i = 0; i < 8; i++) _fgTags[i].Slot = -1;
for (int i = 0; i < 8; i++) _textTags[i].StringIndex = -1;
_map = new Bitmap(pctBrief.Width, pctBrief.Height, PixelFormat.Format24bppRgb);
hsbTimer.Value = 1;
hsbTimer.Value = 0;
}
#endregion frmBrief
#region tabDisplay
#region Timer related
void startTimer()
{
cmdPlay.Enabled = false;
cmdPlay.Visible = false;
cmdPause.Enabled = true;
cmdPause.Visible = true;
cmdPause.Focus();
tmrBrief.Start();
}
void stopTimer()
{
tmrBrief.Stop();
cmdPause.Enabled = false;
cmdPause.Visible = false;
cmdPlay.Enabled = true;
cmdPlay.Visible = true;
cmdPlay.Focus();
tmrBrief.Interval = 1000 / _timerInterval;
}
void cmdFF_Click(object sender, EventArgs e)
{
if (hsbTimer.Value == hsbTimer.Maximum - 11) return;
int newSpeed = tmrBrief.Interval / 2;
if (newSpeed < 125 / _timerInterval) newSpeed = 125 / _timerInterval; //Limit to 8x speed.
tmrBrief.Interval = newSpeed;
startTimer();
}
void cmdNext_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < _maxEvents; i++)
if (_events[i].Time > hsbTimer.Value && (_events[i].Type == BaseBriefing.EventType.SkipMarker || _events[i].Type == BaseBriefing.EventType.PageBreak)) break;
if (i == _maxEvents) hsbTimer.Value = hsbTimer.Maximum - 11; // tmr_Tick takes care of halting
else hsbTimer.Value = _events[i].Time;
}
void cmdPause_Click(object sender, EventArgs e) => stopTimer();
void cmdPlay_Click(object sender, EventArgs e)
{
if (hsbTimer.Value == hsbTimer.Maximum - 11) return;
tmrBrief.Interval = 1000 / _timerInterval;
startTimer();
}
void cmdStart_Click(object sender, EventArgs e)
{
for (int i = 0; i < 8; i++)
{
_fgTags[i].Slot = -1;
_fgTags[i].StartTime = 0;
_textTags[i].StringIndex = -1;
_textTags[i].X = 0;
_textTags[i].Y = 0;
_textTags[i].ColorIndex = 0;
}
_previousTimeIndex = 0;
hsbTimer.Value = 0;
}
void cmdStop_Click(object sender, EventArgs e)
{
stopTimer();
for (int i = 0; i < 8; i++)
{
_fgTags[i].Slot = -1;
_fgTags[i].StartTime = 0;
_textTags[i].StringIndex = -1;
_textTags[i].X = 0;
_textTags[i].Y = 0;
_textTags[i].ColorIndex = 0;
}
hsbTimer.Value = 0;
}
void hsbTimer_ValueChanged(object sender, EventArgs e)
{
bool paint = false;
if (hsbTimer.Value != 0 && ((hsbTimer.Value - _previousTimeIndex >= 2) || hsbTimer.Value <= _previousTimeIndex))
{
// A non-incremental or reverse change (if incremental the timer should be +1 to previous), the user most likely manually moved the scrollbar.
// Iterate through all past events and rebuild the briefing state.
resetBriefing();
stopTimer();
for (int i = 0; i < _maxEvents; i++)
{
if (_events[i].Time > hsbTimer.Value || _events[i].IsEndEvent) break;
paint |= processEvent(i, true);
}
}
_previousTimeIndex = hsbTimer.Value;
if (hsbTimer.Value == 0) resetBriefing();
if (_regionDelay != -1)
{
_message = "";
_regionDelay = -1;
lblCaption.Visible = true;
lblTitle.Visible = true;
}
for (int i = 0; i < _maxEvents; i++)
{
if (_events[i].Time < hsbTimer.Value) continue;
if (_events[i].Time > hsbTimer.Value || _events[i].IsEndEvent) break;
paint |= processEvent(i, false);
}
for (int h = 0; h < 8; h++) if (hsbTimer.Value - _fgTags[h].StartTime < 13) paint = true;
lblTime.Text = string.Format("{0:Time: 0.00}", (decimal)hsbTimer.Value / _timerInterval);
if (hsbTimer.Value == (hsbTimer.Maximum - 11) || hsbTimer.Value == 0) stopTimer();
if (paint) MapPaint();
if (tmrBrief.Interval != (1000 / _timerInterval)) lblTime.Text += " (" + (1000 / _timerInterval) / tmrBrief.Interval + "x)";
}
void tmrBrief_Tick(object sender, EventArgs e)
{
if (_regionDelay == -1) hsbTimer.Value++;
else if (_regionDelay == 0)
{
_message = "";
_regionDelay--;
lblCaption.Visible = true;
lblTitle.Visible = true;
}
else _regionDelay--;
}
void tmrPopup_Tick(object sender, EventArgs e)
{
if (_popupPreviewActive) return;
tmrPopup.Stop();
lblPopupInfo.Visible = false;
lblPopupInfo.Text = "";
}
void tmrMapRedraw_Tick(object sender, EventArgs e)
{
if (_mapPaintScheduled)
{
if (_platform == Settings.Platform.TIE) tiePaint();
else if (_platform == Settings.Platform.XvT) xvtPaint();
else if (_platform == Settings.Platform.XWA) xwaPaint();
_mapPaintScheduled = false;
}
tmrMapRedraw.Stop();
}
#endregion Timer related
public void MapPaint()
{
if (_mapPaintScheduled) return;
if (!tmrMapRedraw.Enabled) tmrMapRedraw.Start();
_mapPaintScheduled = true;
}
void drawGrid(int x, int y, Graphics g)
{
Pen pn = new Pen(Color.FromArgb(0x50, 0, 0)) { Width = 1 };
if (_platform == Settings.Platform.TIE)
{
pn.Color = Color.FromArgb(0x48, 0, 0);
pn.Width = 2;
}
int mod = (_platform == Settings.Platform.TIE ? 2 : 1);
int w = pctBrief.Width;
int h = pctBrief.Height;
//Calculate where the viewport is, then find the longest span to know how many lines to iterate through.
int x1 = (x - w) / (_zoomX * mod);
int y1 = (y - h) / (_zoomX * mod);
int x2 = (x + w) / (_zoomX * mod);
int y2 = (y + h) / (_zoomX * mod);
int min = x1, max = x2;
if (y1 < min) min = y1;
if (y2 > max) max = y2;
if (_zoomX >= 32)
{
for (int i = min; i < max; i++)
{
if (i % 4 == 0) continue; // don't draw where there'll be maj lines
g.DrawLine(pn, 0, _zoomY * i * mod + y - 1, w, _zoomY * i * mod + y - 1); //min lines, every zoom pixels
g.DrawLine(pn, 0, y - 1 - _zoomY * i * mod, w, y - 1 - _zoomY * i * mod);
g.DrawLine(pn, _zoomX * i * mod + x, 0, _zoomX * i * mod + x, h);
g.DrawLine(pn, x - _zoomX * i * mod, 0, x - _zoomX * i * mod, h);
}
}
else if (_zoomX >= 16)
{
for (int i = min; i < max; i++)
{
if (i % 2 == 0) continue;
g.DrawLine(pn, 0, _zoomY * 2 * i * mod + y - 1, w, _zoomY * 2 * i * mod + y - 1); //min lines, every zoomx2 pixels
g.DrawLine(pn, 0, y - 1 - _zoomY * 2 * i * mod, w, y - 1 - _zoomY * 2 * i * mod);
g.DrawLine(pn, _zoomX * 2 * i * mod + x, 0, _zoomX * 2 * i * mod + x, h);
g.DrawLine(pn, x - _zoomX * 2 * i * mod, 0, x - _zoomX * 2 * i * mod, h);
}
}
// else if (zoom < 16) just don't draw them
pn.Color = Color.FromArgb(0x90, 0, 0);
if (_platform == Settings.Platform.TIE) pn.Color = Color.FromArgb(0x78, 0, 0);
g.DrawLine(pn, 0, y - 1, w, y - 1); // origin lines
g.DrawLine(pn, x, 0, x, h);
for (int i = 0; i < 36; i++)
{
g.DrawLine(pn, 0, _zoomY * 4 * i * mod + y - 1, w, _zoomY * 4 * i * mod + y - 1); //maj lines, every zoomx4 pixels
g.DrawLine(pn, 0, y - 1 - _zoomY * 4 * i * mod, w, y - 1 - _zoomY * 4 * i * mod);
g.DrawLine(pn, _zoomX * 4 * i * mod + x, 0, _zoomX * 4 * i * mod + x, h);
g.DrawLine(pn, x - _zoomX * 4 * i * mod, 0, x - _zoomX * 4 * i * mod, h);
}
}
void enableOkCancel(bool state)
{
cmdOk.Enabled = state;
cmdCancel.Enabled = state;
cmdClear.Enabled = !state;
if (_platform == Settings.Platform.TIE) cmdTitle.Enabled = !state;
cmdCaption.Enabled = !state;
cmdFG.Enabled = !state;
cmdText.Enabled = !state;
cmdZoom.Enabled = !state;
cmdMove.Enabled = !state;
cmdBreak.Enabled = !state;
if (!state)
{
pnlShipInfo.Visible = false;
pnlShipTag.Visible = false;
pnlTextTag.Visible = false;
pnlRotate.Visible = false;
pnlMove.Visible = false;
pnlNew.Visible = false;
pnlRegion.Visible = false;
}
if (_platform == Settings.Platform.XWA)
{
cmdMoveShip.Enabled = !state;
cmdNewShip.Enabled = !state;
cmdRotate.Enabled = !state;
cmdShipInfo.Enabled = !state;
cmdRegion.Enabled = !state;
}
}
int findExisting(BaseBriefing.EventType eventType)
{
int i;
for (i = 0; i < _maxEvents; i++)
{
if (_events[i].Time < hsbTimer.Value) continue;
if (_events[i].Time > hsbTimer.Value) return (i + 10000); // did not find existing, return next available + marker
if (_events[i].Type == eventType) return i;
}
return i + 10000; // actually somehow got through the entire loop
}