Repository navigation
Expand file tree
/
Copy pathOptionsDialog.cs
More file actions
639 lines (582 loc) · 25.2 KB
/
Copy pathOptionsDialog.cs
File metadata and controls
639 lines (582 loc) · 25.2 KB
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
/*
* YOGEME.exe, All-in-one Mission Editor for the X-wing series, XW through XWA
* Copyright (C) 2007-2026 Michael Gaisser (mjgaisser@gmail.com)
* Licensed under the MPL v2.0 or later
*
* VERSION: 1.18
*
* CHANGELOG
* v1.18, 260711
* [NEW #137] FormScaler implemented
* v1.16, 241013
* [UPD] cleanup
* v1.15.6, 240311
* [UPD] Permanently enable SBD chk, even if not detected
* v1.13.12, 230116
* [NEW] RememberSelectedOrder
* v1.13.4, 220606
* [NEW] OneIndexedFGs
* v1.8, 201004
* [NEW] options for Map M-click actions [JB]
* [UPD] MapOptions no longer completely reset during OK, other flags are set on Map itself [JB]
* v1.7, 200816
* [NEW] new settings for Map wireframes [JB]
* v1.5, 180910
* [UPD] added callback [JB]
* [NEW] X-wing options [JB]
* [NEW] themeing options [JB]
* v1.4.1, 171118
* [NEW #13] Super Backdrops
* v1.3, 170107
* [NEW] RememberPlatformFolder and ConfirmFGDelete implementation [JB]
* v1.2.3, 141214
* [UPD] change to MPL
* v1.2, 121006
* [UPD] Test controls enabled
* v1.1.1, 120814
* - class renamed
* v1.1, 120715
* [NEW] Controls (Disabled) added for ConfirmTest, DeleteTestPilots and Verify Test
* v1.0, 110921
* - Release
*/
using Idmr.Yogeme.MapWireframe;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Idmr.Yogeme
{
/// <summary>Options dialog for YOGEME</summary>
public partial class OptionsDialog : Form
{
#pragma warning disable IDE1006 // Naming Styles
readonly CheckBox[] chkWP = new CheckBox[22];
#pragma warning restore IDE1006 // Naming Styles
readonly Settings _config = Settings.GetInstance();
readonly EventHandler _closeCallback;
readonly FormScaler _scaler = null;
/// <summary>Initialize and load the user's settings</summary>
/// <param name="config">The Settings config of the current user</param>
public OptionsDialog(EventHandler callback)
{
InitializeComponent();
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] = chkRND;
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;
switch (_config.Startup)
{
case Settings.StartupMode.Normal:
optStartNormal.Checked = true;
break;
case Settings.StartupMode.LastPlatform:
optStartPlat.Checked = true;
break;
case Settings.StartupMode.LastMission:
optStartMiss.Checked = true;
break;
default:
optStartNormal.Checked = true;
break;
}
chkRestrict.Checked = _config.RestrictPlatforms;
chkExit.Checked = _config.ConfirmExit;
chkSave.Checked = _config.ConfirmSave;
chkVerify.Checked = _config.Verify;
txtVerify.Text = _config.VerifyLocation;
chkXWInstall.Checked = _config.XwingInstalled;
txtXW.Text = _config.XwingPath;
txtXW.Enabled = chkXWInstall.Checked;
cboXWCraft.Items.AddRange(Platform.Xwing.Strings.CraftType);
cboXWCraft.SelectedIndex = _config.XwingCraft;
cboXWIFF.SelectedIndex = _config.XwingIff;
chkTIEInstall.Checked = _config.TieInstalled;
txtTIE.Text = _config.TiePath;
txtTIE.Enabled = chkTIEInstall.Checked;
cboTIECraft.Items.AddRange(Platform.Tie.Strings.CraftType);
cboTIECraft.SelectedIndex = _config.TieCraft;
cboTIEIFF.SelectedIndex = _config.TieIff;
chkXvTInstall.Checked = _config.XvtInstalled;
txtXvT.Text = _config.XvtPath;
txtXvT.Enabled = chkXvTInstall.Checked;
cboXvTCraft.Items.AddRange(Platform.Xvt.Strings.CraftType);
cboXvTCraft.SelectedIndex = _config.XvtCraft;
cboXvTIFF.SelectedIndex = _config.XvtIff;
chkBoPInstall.Checked = _config.BopInstalled;
txtBoP.Text = _config.BopPath;
txtBoP.Enabled = chkBoPInstall.Checked;
chkXWAInstall.Checked = _config.XwaInstalled;
txtXWA.Text = _config.XwaPath;
txtXWA.Enabled = chkXWAInstall.Checked;
cboXWACraft.Items.AddRange(Platform.Xwa.Strings.CraftType);
cboXWACraft.SelectedIndex = _config.XwaCraft;
cboXWAIFF.SelectedIndex = _config.XwaIff;
chkFG.Checked = Convert.ToBoolean(_config.MapOptions & Settings.MapOpts.FGTags);
chkTrace.Checked = Convert.ToBoolean(_config.MapOptions & Settings.MapOpts.Traces);
chkDeletePilot.Checked = _config.DeleteTestPilots;
chkRememberPlatformFolder.Checked = _config.RememberPlatformFolder; //[JB]
chkConfirmFGDelete.Checked = _config.ConfirmFGDelete; //[JB]
chkTest.Checked = _config.ConfirmTest;
chkVerifyTest.Checked = _config.VerifyTest;
chkVerifyTest.Enabled = !_config.Verify;
chkBackdrops.Checked = _config.InitializeUsingSuperBackdrops;
int t = _config.Waypoints;
for (int i = 0; i < 22; i++) chkWP[i].Checked = Convert.ToBoolean(t & (1 << i));
chkColorizeFG.Checked = _config.ColorizedDropDowns;
txtColorSelected.Text = (_config.ColorInteractSelected.ToArgb() & 0x00FFFFFF).ToString("X6"); //ARGB values include 0xFF for alpha, trim that out to just display RGB.
txtColorNonSelected.Text = (_config.ColorInteractNonSelected.ToArgb() & 0x00FFFFFF).ToString("X6");
txtColorBackground.Text = (_config.ColorInteractBackground.ToArgb() & 0x00FFFFFF).ToString("X6");
cboInteractiveTheme.SelectedIndex = (txtColorBackground.Text == "BC8F8F" ? 0 : txtColorBackground.Text == "BFBFFF" ? 1 : 0); //Select YOGEME or XvTED by looking at background color, otherwise default to YOGEME. What's selected here doesn't actually matter unless the user clicks it, so it's just a matter of display consistency.
refreshColors();
numMousewheelZoom.Value = Convert.ToDecimal(_config.MapMouseWheelZoomPercentage);
chkWireEnabled.Checked = _config.WireframeEnabled;
chkWireIconThreshold.Checked = _config.WireframeIconThresholdEnabled;
numWireIconThreshold.Value = _config.WireframeIconThresholdSize;
chkWireMeshIcon.Checked = _config.WireframeMeshIconEnabled;
numWireMeshIcon.Value = _config.WireframeMeshIconSize;
for (int i = 0; i < 32; i++) lstWireMeshTypes.SetSelected(i, (_config.WireframeMeshTypeVisibility & (1 << i)) != 0);
refreshAllMeshCollectionCheckbox();
chkXwingDetectMission.Checked = _config.XwingDetectMission;
chkTieDetectMission.Checked = _config.TieDetectMission;
chkXvtDetectMission.Checked = _config.XvtDetectMission;
chkXwaDetectMission.Checked = _config.XwaDetectMission;
chkXwingOverrideExternal.Checked = _config.XwingOverrideExternal;
chkTieOverrideExternal.Checked = _config.TieOverrideExternal;
chkXvtOverrideExternal.Checked = _config.XvtOverrideExternal;
chkXwaOverrideExternal.Checked = _config.XwaOverrideExternal;
chkXwaOverrideScan.Checked = _config.XwaOverrideScan;
chkXwaFlagRemappedCraft.Checked = _config.XwaFlagRemappedCraft;
bool exportInUse = _config.XwaOverrideExternal && CraftDataManager.GetInstance().XwaInstallSpecificExternalDataLoaded;
lblExportWarning.Visible = exportInUse;
cboMiddleClickActionSelected.SelectedIndex = (int)_config.MapMiddleClickActionSelected;
cboMiddleClickAction.SelectedIndex = (int)_config.MapMiddleClickActionNoneSelected;
chkOneIndexedFG.Checked = _config.OneIndexedFGs;
chkRememberOrder.Checked = _config.RememberSelectedOrder;
initFormScaleDropdown();
setFormScale(_config.FormScale);
_closeCallback = callback;
_scaler = new FormScaler(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value", Justification = "TryParse may not work")]
void refreshColors()
{
int sel = Color.Blue.ToArgb();
int nsel = Color.Black.ToArgb();
int background = Color.RosyBrown.ToArgb();
int.TryParse(txtColorSelected.Text, System.Globalization.NumberStyles.HexNumber, null, out sel);
int.TryParse(txtColorNonSelected.Text, System.Globalization.NumberStyles.HexNumber, null, out nsel);
int.TryParse(txtColorBackground.Text, System.Globalization.NumberStyles.HexNumber, null, out background);
sel += 0xFF << 24; //Add the alpha channel back in
nsel += 0xFF << 24;
background += 0xFF << 24;
lblInteractSelected.ForeColor = Color.FromArgb(sel);
lblInteractSelected.BackColor = Color.FromArgb(background);
lblInteractNonSelected.ForeColor = Color.FromArgb(nsel);
lblInteractNonSelected.BackColor = Color.FromArgb(background);
}
void selectPlatform(TextBox txt, CheckBox chk)
{
try { dirPlatform.SelectedPath = txt.Text; }
catch { /*do nothing*/ }
if (dirPlatform.ShowDialog() == DialogResult.OK)
{
txt.Text = dirPlatform.SelectedPath;
if (!chk.Checked) chk.Checked = true;
}
}
void OptionsDialog_FormClosed(object sender, FormClosedEventArgs e)
{
if (cboFormScale.Tag != null)
{
FontPreviewItem[] items = getPreviewItems();
for (int i = 0; i < items.Length; i++)
{
items[i].PreviewBitmap?.Dispose();
items[i].PreviewBitmap = null;
}
cboFormScale.Tag = null;
}
}
void cboInteractiveScheme_SelectedIndexChanged(object sender, EventArgs e)
{
if (ActiveControl != cboInteractiveTheme) return;
if (cboInteractiveTheme.SelectedIndex == 0)
{
txtColorSelected.Text = (Color.Blue.ToArgb() & 0x00FFFFFF).ToString("X6"); //ARGB values include 0xFF for alpha, trim that out before converting to a hexadecimal color code.
txtColorNonSelected.Text = (Color.Black.ToArgb() & 0x00FFFFFF).ToString("X6");
txtColorBackground.Text = (Color.RosyBrown.ToArgb() & 0x00FFFFFF).ToString("X6");
}
else
{
txtColorSelected.Text = "A90391";
txtColorNonSelected.Text = "000000";
txtColorBackground.Text = "BFBFFF";
}
refreshColors();
}
void chkColorizeFG_CheckedChanged(object sender, EventArgs e) => _config.ColorizedDropDowns = chkColorizeFG.Checked;
void chkXWInstall_CheckedChanged(object sender, EventArgs e) => txtXW.Enabled = chkXWInstall.Checked;
void chkTIEInstall_CheckedChanged(object sender, EventArgs e) => txtTIE.Enabled = chkTIEInstall.Checked;
void chkXvTInstall_CheckedChanged(object sender, EventArgs e) => txtXvT.Enabled = chkXvTInstall.Checked;
void chkBoPInstall_CheckedChanged(object sender, EventArgs e) => txtBoP.Enabled = chkBoPInstall.Checked;
void chkXWAInstall_CheckedChanged(object sender, EventArgs e) => txtXWA.Enabled = chkXWAInstall.Checked;
void chkVerify_CheckedChanged(object sender, EventArgs e) => chkVerifyTest.Enabled = chkVerify.Checked;
void cmdBop_Click(object sender, EventArgs e) => selectPlatform(txtBoP, chkBoPInstall);
void cmdCancel_Click(object sender, EventArgs e) => Close();
void cmdInteractSelect_Click(object sender, EventArgs e)
{
DialogResult dr = colorSelector.ShowDialog();
if (dr == DialogResult.OK)
{
txtColorSelected.Text = (colorSelector.Color.ToArgb() & 0x00FFFFFF).ToString("X6"); //ARGB values include 0xFF for alpha, trim that out before converting to a hexadecimal color code.
refreshColors();
}
}
void cmdInteractNonSelect_Click(object sender, EventArgs e)
{
DialogResult dr = colorSelector.ShowDialog();
if (dr == DialogResult.OK)
{
txtColorNonSelected.Text = (colorSelector.Color.ToArgb() & 0x00FFFFFF).ToString("X6");
refreshColors();
}
}
void cmdInteractBackground_Click(object sender, EventArgs e)
{
DialogResult dr = colorSelector.ShowDialog();
if (dr == DialogResult.OK)
{
txtColorBackground.Text = (colorSelector.Color.ToArgb() & 0x00FFFFFF).ToString("X6");
refreshColors();
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value", Justification = "TryParse")]
void cmdOK_Click(object sender, EventArgs e)
{
if (optStartNormal.Checked) _config.Startup = Settings.StartupMode.Normal;
else if (optStartPlat.Checked) _config.Startup = Settings.StartupMode.LastPlatform;
else _config.Startup = Settings.StartupMode.LastMission;
_config.RestrictPlatforms = chkRestrict.Checked;
_config.ConfirmExit = chkExit.Checked;
_config.ConfirmSave = chkSave.Checked;
_config.XwingInstalled = chkXWInstall.Checked;
_config.XwingPath = txtXW.Text;
_config.TieInstalled = chkTIEInstall.Checked;
_config.TiePath = txtTIE.Text;
_config.XvtInstalled = chkXvTInstall.Checked;
_config.XvtPath = txtXvT.Text;
_config.BopInstalled = chkBoPInstall.Checked;
_config.BopPath = txtBoP.Text;
_config.XwaInstalled = chkXWAInstall.Checked;
_config.XwaPath = txtXWA.Text;
_config.Verify = chkVerify.Checked;
_config.VerifyLocation = txtVerify.Text;
int temp = 0;
for (int i = 0; i < 22; i++) temp += (chkWP[i].Checked ? 1 << i : 0);
_config.Waypoints = temp;
_config.MapOptions = (_config.MapOptions ^ (_config.MapOptions & Settings.MapOpts.FGTags)) | (chkFG.Checked ? Settings.MapOpts.FGTags : Settings.MapOpts.None);
_config.MapOptions = (_config.MapOptions ^ (_config.MapOptions & Settings.MapOpts.Traces)) | (chkTrace.Checked ? Settings.MapOpts.Traces : Settings.MapOpts.None);
_config.XwingCraft = (byte)cboXWCraft.SelectedIndex;
_config.XwingIff = (byte)cboXWIFF.SelectedIndex;
_config.TieCraft = (byte)cboTIECraft.SelectedIndex;
_config.TieIff = (byte)cboTIEIFF.SelectedIndex;
_config.XvtCraft = (byte)cboXvTCraft.SelectedIndex;
_config.XvtIff = (byte)cboXvTIFF.SelectedIndex;
_config.XwaCraft = (byte)cboXWACraft.SelectedIndex;
_config.XwaIff = (byte)cboXWAIFF.SelectedIndex;
_config.ConfirmTest = chkTest.Checked;
_config.DeleteTestPilots = chkDeletePilot.Checked;
_config.RememberPlatformFolder = chkRememberPlatformFolder.Checked; //[JB]
_config.ConfirmFGDelete = chkConfirmFGDelete.Checked; //[JB]
_config.VerifyTest = chkVerifyTest.Checked;
_config.InitializeUsingSuperBackdrops = chkBackdrops.Checked;
int sel = Color.Blue.ToArgb();
int nsel = Color.Black.ToArgb();
int background = Color.RosyBrown.ToArgb();
int.TryParse(txtColorSelected.Text, System.Globalization.NumberStyles.HexNumber, null, out sel);
int.TryParse(txtColorNonSelected.Text, System.Globalization.NumberStyles.HexNumber, null, out nsel);
int.TryParse(txtColorBackground.Text, System.Globalization.NumberStyles.HexNumber, null, out background);
sel += 0xFF << 24; //Add the alpha channel back in
nsel += 0xFF << 24;
background += 0xFF << 24;
_config.ColorInteractSelected = Color.FromArgb(sel);
_config.ColorInteractNonSelected = Color.FromArgb(nsel);
_config.ColorInteractBackground = Color.FromArgb(background);
_config.MapMouseWheelZoomPercentage = Convert.ToDouble(numMousewheelZoom.Value);
_config.WireframeEnabled = chkWireEnabled.Checked;
_config.WireframeIconThresholdEnabled = chkWireIconThreshold.Checked;
_config.WireframeIconThresholdSize = Convert.ToInt32(numWireIconThreshold.Value);
_config.WireframeMeshIconEnabled = chkWireMeshIcon.Checked;
_config.WireframeMeshIconSize = Convert.ToInt32(numWireMeshIcon.Value);
int[] selectionArray = new int[lstWireMeshTypes.Items.Count];
lstWireMeshTypes.SelectedIndices.CopyTo(selectionArray, 0);
_config.WireframeMeshTypeVisibility = MeshTypeHelper.GetFlags(selectionArray);
_config.XwingDetectMission = chkXwingDetectMission.Checked;
_config.TieDetectMission = chkTieDetectMission.Checked;
_config.XvtDetectMission = chkXvtDetectMission.Checked;
_config.XwaDetectMission = chkXwaDetectMission.Checked;
_config.XwingOverrideExternal = chkXwingOverrideExternal.Checked;
_config.TieOverrideExternal = chkTieOverrideExternal.Checked;
_config.XvtOverrideExternal = chkXvtOverrideExternal.Checked;
_config.XwaOverrideExternal = chkXwaOverrideExternal.Checked;
_config.XwaOverrideScan = chkXwaOverrideScan.Checked;
_config.XwaFlagRemappedCraft = chkXwaFlagRemappedCraft.Checked;
_config.MapMiddleClickActionSelected = (MapForm.MiddleClickAction)cboMiddleClickActionSelected.SelectedIndex;
_config.MapMiddleClickActionNoneSelected = (MapForm.MiddleClickAction)cboMiddleClickAction.SelectedIndex;
_config.OneIndexedFGs = chkOneIndexedFG.Checked;
_config.RememberSelectedOrder = chkRememberOrder.Checked;
_closeCallback?.Invoke(0, new EventArgs());
Close();
}
void cmdXW_Click(object sender, EventArgs e) => selectPlatform(txtXW, chkXWInstall);
void cmdTie_Click(object sender, EventArgs e) => selectPlatform(txtTIE, chkTIEInstall);
void cmdVerify_Click(object sender, EventArgs e)
{
try { opnVerify.InitialDirectory = txtVerify.Text.Substring(0, txtVerify.Text.LastIndexOf("\\")); }
catch { opnVerify.InitialDirectory = Application.StartupPath; }
if (opnVerify.ShowDialog() == DialogResult.OK) txtVerify.Text = opnVerify.FileName;
}
void cmdXvt_Click(object sender, EventArgs e) => selectPlatform(txtXvT, chkXvTInstall);
void cmdXwa_Click(object sender, EventArgs e) => selectPlatform(txtXWA, chkXWAInstall);
void txtColorSelected_TextChanged(object sender, EventArgs e) => refreshColors();
void txtColorNonSelected_TextChanged(object sender, EventArgs e) => refreshColors();
void txtColorBackground_TextChanged(object sender, EventArgs e) => refreshColors();
/// <summary>Broadly sets or clears visibility states of an entire range of meshtypes.</summary>
void applyBatchVisibilityState(bool state, MeshType[] items)
{
foreach (var i in items)
{
int index = (int)i;
if (index >= 0 && index < lstWireMeshTypes.Items.Count) lstWireMeshTypes.SetSelected(index, state);
}
}
/// <summary>Refreshes the checked state of a single checkbox.</summary>
/// <remarks>Compares the specified list of meshtypes against the current visibility list. The checkbox will be grayed out in a partial match, otherwise fully on or off.</remarks>
void refreshMeshCollectionCheckbox(CheckBox chk, MeshType[] items)
{
int count = 0;
foreach (var i in items)
{
int index = (int)i;
if (index >= 0 && index < lstWireMeshTypes.Items.Count && lstWireMeshTypes.GetSelected(index)) count++;
}
chk.ThreeState = false;
if (count == items.Length) chk.CheckState = CheckState.Checked;
else if (count == 0) chk.CheckState = CheckState.Unchecked;
else
{
chk.ThreeState = true;
chk.CheckState = CheckState.Indeterminate;
}
}
/// <summary>Refreshes the checked state of all meshtype checkboxes.</summary>
void refreshAllMeshCollectionCheckbox()
{
refreshMeshCollectionCheckbox(chkWireToggleHull, MeshTypeHelper.HullMeshes);
refreshMeshCollectionCheckbox(chkWireToggleMisc, MeshTypeHelper.MiscMeshes);
refreshMeshCollectionCheckbox(chkWireToggleWeapon, MeshTypeHelper.WeaponMeshes);
refreshMeshCollectionCheckbox(chkWireToggleHangar, MeshTypeHelper.HangarMeshes);
}
void chkWireToggleHull_CheckedChanged(object sender, EventArgs e)
{
if (ActiveControl == chkWireToggleHull)
{
chkWireToggleHull.ThreeState = false;
applyBatchVisibilityState(chkWireToggleHull.Checked, MeshTypeHelper.HullMeshes);
}
}
void chkWireToggleMisc_CheckedChanged(object sender, EventArgs e)
{
if (ActiveControl == chkWireToggleMisc)
{
chkWireToggleMisc.ThreeState = false;
applyBatchVisibilityState(chkWireToggleMisc.Checked, MeshTypeHelper.MiscMeshes);
}
}
void chkWireToggleWeapon_CheckedChanged(object sender, EventArgs e)
{
if (ActiveControl == chkWireToggleWeapon)
{
chkWireToggleWeapon.ThreeState = false;
applyBatchVisibilityState(chkWireToggleWeapon.Checked, MeshTypeHelper.WeaponMeshes);
}
}
void chkWireToggleHangar_CheckedChanged(object sender, EventArgs e)
{
if (ActiveControl == chkWireToggleHangar)
{
chkWireToggleHangar.ThreeState = false;
applyBatchVisibilityState(chkWireToggleHangar.Checked, MeshTypeHelper.HangarMeshes);
}
}
void lstWireMeshTypes_SelectedIndexChanged(object sender, EventArgs e) { if (ActiveControl == lstWireMeshTypes) refreshAllMeshCollectionCheckbox(); }
void cmdWireMeshDefault_Click(object sender, EventArgs e)
{
lstWireMeshTypes.ClearSelected();
applyBatchVisibilityState(true, MeshTypeHelper.DefaultMeshes);
refreshAllMeshCollectionCheckbox();
}
void cmdExport_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog
{
FileName = "craft_data_xwa.txt",
Filter = "Text files (*.txt)|*.txt|All files|*.*"
};
string path = CraftDataManager.GetInstance().GetInstallPath();
if (path == "") path = Environment.CurrentDirectory;
dlg.InitialDirectory = path;
if (dlg.ShowDialog() == DialogResult.OK)
{
string result = CraftDataManager.GetInstance().SaveToFile(dlg.FileName);
if (result != "") MessageBox.Show(result, "Failed to save file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
struct FontPreviewItem
{
public float MultSize;
public float PointSize;
public Bitmap PreviewBitmap;
}
void initFormScaleDropdown()
{
if (cboFormScale.Tag != null) return;
// Assigning items will attempt to draw the control, but the data isn't ready yet.
cboFormScale.MeasureItem -= cboFormScale_MeasureItem;
cboFormScale.DrawItem -= cboFormScale_DrawItem;
string[] fontNames = new string[] { "100%", "125%", "150%", "175%", "200%", "225%", "250%" };
float[] fontSizes = new float[] { 1f, 1.25f, 1.50f, 1.75f, 2.0f, 2.25f, 2.50f };
int fontCount = fontSizes.Length;
FontPreviewItem[] previewItems = new FontPreviewItem[fontCount];
// Populate the list items.
cboFormScale.Items.Clear();
for (int i = 0; i < fontCount; i++)
{
string s = fontNames[i];
if (i == 0) s += " (default)";
cboFormScale.Items.Add(s);
}
cboFormScale.SelectedIndex = 0;
// Calculate the font point sizes and generate the bitmaps for the list item previews
// to illustrate their relative sizes.
Font orig = cboFormScale.Font;
Font[] fonts = new Font[fontCount];
using (Graphics textg = Graphics.FromHwnd(cboFormScale.Handle))
{
for (int i = 0; i < fontCount; i++)
{
float pointSize = orig.SizeInPoints * fontSizes[i];
fonts[i] = new Font(orig.FontFamily, pointSize);
previewItems[i].PointSize = pointSize;
previewItems[i].MultSize = fontSizes[i];
SizeF sz = textg.MeasureString(cboFormScale.Items[i].ToString(), fonts[i]);
int width = Math.Max(cboFormScale.Width, (int)Math.Ceiling(sz.Width));
int height = (int)Math.Ceiling(sz.Height);
Bitmap bmp = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(SystemColors.Control);
g.DrawString(cboFormScale.Items[i].ToString(), fonts[i], SystemBrushes.ControlText, 0, 0);
}
bmp.MakeTransparent(SystemColors.Control);
previewItems[i].PreviewBitmap = bmp;
}
}
// Cleanup and finish.
foreach (Font f in fonts)
f.Dispose();
cboFormScale.Tag = previewItems;
cboFormScale.MeasureItem += cboFormScale_MeasureItem;
cboFormScale.DrawItem += cboFormScale_DrawItem;
}
FontPreviewItem[] getPreviewItems() => (FontPreviewItem[])cboFormScale.Tag;
void setFormScale(float scale)
{
if (cboFormScale.Tag == null) return;
// Determines the closest value in the dropdown selection, in case the list items ever change.
FontPreviewItem[] preview = getPreviewItems();
float foundDiff = 100.0f;
int foundIndex = 0;
for (int i = 0; i < preview.Length; i++)
{
float diff = Math.Abs(scale - preview[i].MultSize);
if (diff < foundDiff)
{
foundDiff = diff;
foundIndex = i;
}
}
cboFormScale.SelectedIndex = foundIndex;
}
void cmdFormScale_Click(object sender, EventArgs e)
{
if (cboFormScale.Tag == null || cboFormScale.SelectedIndex < 0) return;
FontPreviewItem[] preview = getPreviewItems();
float scale = preview[cboFormScale.SelectedIndex].MultSize;
if (scale == _config.FormScale)
{
MessageBox.Show("Already using that scale amount.", "Notice");
return;
}
if (!_scaler.VerifyScale(scale))
{
DialogResult res = MessageBox.Show("Warning: a form reports that the scaled size may exceed the boundaries of the screen. If so, certain controls may be cropped and unreachable. Continue?", "Confirm selection", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if (res == DialogResult.No)
{
setFormScale(_config.FormScale); // Return to actual value
return;
}
}
_config.FormScale = scale;
cmdFormScale.Enabled = false;
// Scaling can bring other forms to the front, even though this form has modal focus.
// Make sure it stays in focus.
this.Focus();
}
void cboFormScale_SelectedIndexChanged(object sender, EventArgs e)
{
bool state = false;
if (cboFormScale.Tag != null && cboFormScale.SelectedIndex >= 0)
{
FontPreviewItem[] preview = getPreviewItems();
state = (preview[cboFormScale.SelectedIndex].MultSize != _config.FormScale);
}
cmdFormScale.Enabled = state;
}
void cboFormScale_DrawItem(object sender, DrawItemEventArgs e)
{
if (cboFormScale.Tag == null || e.Index < 0) return;
FontPreviewItem[] preview = getPreviewItems();
e.DrawBackground();
// Display the text only (if dropdown is collapsed) or draw the item contents.
if (e.State.HasFlag(DrawItemState.ComboBoxEdit))
e.Graphics.DrawString(cboFormScale.Items[e.Index].ToString(), cboFormScale.Font, SystemBrushes.ControlText, e.Bounds.Location);
else
e.Graphics.DrawImage(preview[e.Index].PreviewBitmap, e.Bounds.Location);
}
void cboFormScale_MeasureItem(object sender, MeasureItemEventArgs e)
{
if (cboFormScale.Tag == null || e.Index < 0) return;
FontPreviewItem[] preview = getPreviewItems();
e.ItemHeight = preview[e.Index].PreviewBitmap.Height;
}
}
}