-
Notifications
You must be signed in to change notification settings - Fork 112
/
BDArmorySettings.cs
1639 lines (1360 loc) · 51 KB
/
BDArmorySettings.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
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
namespace BahaTurret
{
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class BDArmorySettings : MonoBehaviour
{
//=======configurable settings
public static bool INSTAKILL = false;
public static bool BULLET_HITS = true;
public static float PHYSICS_RANGE = 0;
public static bool EJECT_SHELLS = true;
public static bool SHELL_COLLISIONS = true;
public static bool INFINITE_AMMO = false;
public static bool DRAW_DEBUG_LINES = false;
public static bool DRAW_DEBUG_LABELS = false;
public static bool DRAW_AIMERS = true;
public static bool AIM_ASSIST = true;
public static bool REMOTE_SHOOTING = false;
public static bool BOMB_CLEARANCE_CHECK = true;
public static float DMG_MULTIPLIER = 6000;
public static float FLARE_CHANCE_FACTOR = 25;
public static bool SMART_GUARDS = true;
public static float MAX_BULLET_RANGE = 8000;
public static float TRIGGER_HOLD_TIME = 0.3f;
public static bool ALLOW_LEGACY_TARGETING = true;
public static float TARGET_CAM_RESOLUTION = 1024;
public static bool BW_TARGET_CAM = true;
public static float SMOKE_DEFLECTION_FACTOR = 10;
public static float FLARE_THERMAL = 1900;
public static float BDARMORY_UI_VOLUME = 0.35f;
public static float BDARMORY_WEAPONS_VOLUME = 0.32f;
public static float MAX_GUARD_VISUAL_RANGE = 3500;
public static float GLOBAL_LIFT_MULTIPLIER = 0.20f;
public static float GLOBAL_DRAG_MULTIPLIER = 4f;
public static float IVA_LOWPASS_FREQ = 2500;
public static bool PEACE_MODE = false;
//==================
//reflection field lists
FieldInfo[] iFs = null;
FieldInfo[] inputFields
{
get
{
if(iFs == null)
{
iFs = typeof(BDInputSettingsFields).GetFields();
}
return iFs;
}
}
//EVENTS
public delegate void VolumeChange();
public static event VolumeChange OnVolumeChange;
public delegate void SavedSettings();
public static event SavedSettings OnSavedSettings;
public delegate void PeaceEnabled();
public static event PeaceEnabled OnPeaceEnabled;
//particle optimization
public static int numberOfParticleEmitters = 0;
public static BDArmorySettings Instance;
public static bool GAME_UI_ENABLED = true;
//settings gui
public bool settingsGuiEnabled = false;
public string physicsRangeGui;
public string fireKeyGui;
//editor alignment
public static bool showWeaponAlignment = false;
//toolbar gui
public static bool hasAddedButton = false;
public static bool toolbarGuiEnabled = false;
float toolWindowWidth = 300;
float toolWindowHeight = 100;
public Rect toolbarWindowRect;
bool showWeaponList = false;
bool showGuardMenu = false;
bool showModules = false;
int numberOfModules = 0;
//gps window
public bool showingGPSWindow
{
get
{
return showGPSWindow;
}
}
bool showGPSWindow = false;
Rect gpsWindowRect;
float gpsEntryCount = 0;
float gpsEntryHeight = 24;
float gpsBorder = 5;
bool editingGPSName = false;
int editingGPSNameIndex = 0;
bool hasEnteredGPSName = false;
string newGPSName = string.Empty;
public MissileFire ActiveWeaponManager = null;
public bool missileWarning = false;
public float missileWarningTime = 0;
//load range stuff
VesselRanges combatVesselRanges = new VesselRanges();
float physRangeTimer;
public static List<CMFlare> Flares = new List<CMFlare>();
//gui styles
GUIStyle centerLabel;
GUIStyle centerLabelRed;
GUIStyle centerLabelOrange;
GUIStyle centerLabelBlue;
GUIStyle leftLabel;
GUIStyle leftLabelRed;
GUIStyle rightLabelRed;
GUIStyle leftLabelGray;
GUIStyle rippleSliderStyle;
GUIStyle rippleThumbStyle;
GUIStyle kspTitleLabel;
GUIStyle middleLeftLabel;
GUIStyle middleLeftLabelOrange;
GUIStyle targetModeStyle;
GUIStyle targetModeStyleSelected;
public enum BDATeams{A, B, None};
//common textures
public static string textureDir = "BDArmory/Textures/";
bool drawCursor = false;
Texture2D cursorTexture = GameDatabase.Instance.GetTexture(textureDir + "aimer", false);
private Texture2D dti;
public Texture2D directionTriangleIcon
{
get
{
return dti ? dti : dti = GameDatabase.Instance.GetTexture(textureDir + "directionIcon", false);
}
}
private Texture2D cgs;
public Texture2D crossedGreenSquare
{
get
{
return cgs ? cgs : cgs = GameDatabase.Instance.GetTexture(textureDir + "crossedGreenSquare", false);
}
}
private Texture2D dlgs;
public Texture2D dottedLargeGreenCircle
{
get
{
return dlgs ? dlgs : dlgs = GameDatabase.Instance.GetTexture (textureDir + "dottedLargeGreenCircle", false);
}
}
private Texture2D ogs;
public Texture2D openGreenSquare
{
get
{
return ogs ? ogs : ogs = GameDatabase.Instance.GetTexture(textureDir + "openGreenSquare", false);
}
}
private Texture2D gdott;
public Texture2D greenDotTexture
{
get
{
return gdott ? gdott : gdott = GameDatabase.Instance.GetTexture(textureDir + "greenDot", false);
}
}
private Texture2D gdt;
public Texture2D greenDiamondTexture
{
get
{
return gdt ? gdt : gdt = GameDatabase.Instance.GetTexture(textureDir + "greenDiamond", false);
}
}
private Texture2D lgct;
public Texture2D largeGreenCircleTexture
{
get
{
return lgct ? lgct : lgct = GameDatabase.Instance.GetTexture(textureDir + "greenCircle3", false);
}
}
private Texture2D gct;
public Texture2D greenCircleTexture
{
get
{
return gct ? gct : gct = GameDatabase.Instance.GetTexture(textureDir + "greenCircle2", false);
}
}
private Texture2D gpct;
public Texture2D greenPointCircleTexture
{
get
{
if(gpct == null)
{
gpct = GameDatabase.Instance.GetTexture(textureDir + "greenPointCircle", false);
}
return gpct;
}
}
private Texture2D gspct;
public Texture2D greenSpikedPointCircleTexture
{
get
{
return gspct ? gspct : gspct = GameDatabase.Instance.GetTexture(textureDir + "greenSpikedCircle", false);
}
}
private Texture2D wSqr;
public Texture2D whiteSquareTexture
{
get
{
return wSqr ? wSqr : wSqr = GameDatabase.Instance.GetTexture(textureDir + "whiteSquare", false);
}
}
private Texture2D oWSqr;
public Texture2D openWhiteSquareTexture
{
get
{
return oWSqr ? oWSqr : oWSqr = GameDatabase.Instance.GetTexture(textureDir + "openWhiteSquare", false);;
}
}
private Texture2D tDir;
public Texture2D targetDirectionTexture
{
get
{
return tDir ? tDir : tDir = GameDatabase.Instance.GetTexture(textureDir + "targetDirectionIndicator", false);
}
}
private Texture2D hInd;
public Texture2D horizonIndicatorTexture
{
get
{
return hInd ? hInd : hInd = GameDatabase.Instance.GetTexture(textureDir + "horizonIndicator", false);
}
}
private Texture2D si;
public Texture2D settingsIconTexture
{
get
{
return si ? si : si = GameDatabase.Instance.GetTexture(textureDir + "settingsIcon", false);
}
}
//end textures
public static bool GameIsPaused
{
get
{
return PauseMenu.isOpen || Time.timeScale == 0;
}
}
void Start()
{
Instance = this;
//settings
SetupSettingsSize();
LoadConfig();
//wmgr tolbar
toolbarWindowRect = new Rect(Screen.width-toolWindowWidth-4, 150, toolWindowWidth, toolWindowHeight);
physRangeTimer = Time.time;
GAME_UI_ENABLED = true;
fireKeyGui = BDInputSettingsFields.WEAP_FIRE_KEY.inputString;
//setup gui styles
centerLabel = new GUIStyle();
centerLabel.alignment = TextAnchor.UpperCenter;
centerLabel.normal.textColor = Color.white;
centerLabelRed = new GUIStyle();
centerLabelRed.alignment = TextAnchor.UpperCenter;
centerLabelRed.normal.textColor = Color.red;
centerLabelOrange = new GUIStyle();
centerLabelOrange.alignment = TextAnchor.UpperCenter;
centerLabelOrange.normal.textColor = XKCDColors.BloodOrange;
centerLabelBlue = new GUIStyle();
centerLabelBlue.alignment = TextAnchor.UpperCenter;
centerLabelBlue.normal.textColor = XKCDColors.AquaBlue;
leftLabel = new GUIStyle();
leftLabel.alignment = TextAnchor.UpperLeft;
leftLabel.normal.textColor = Color.white;
middleLeftLabel = new GUIStyle(leftLabel);
middleLeftLabel.alignment = TextAnchor.MiddleLeft;
middleLeftLabelOrange = new GUIStyle(middleLeftLabel);
middleLeftLabelOrange.normal.textColor = XKCDColors.BloodOrange;
targetModeStyle = new GUIStyle();
targetModeStyle.alignment = TextAnchor.MiddleRight;
targetModeStyle.fontSize = 9;
targetModeStyle.normal.textColor = Color.white;
targetModeStyleSelected = new GUIStyle(targetModeStyle);
targetModeStyleSelected.normal.textColor = XKCDColors.BloodOrange;
leftLabelRed = new GUIStyle();
leftLabelRed.alignment = TextAnchor.UpperLeft;
leftLabelRed.normal.textColor = Color.red;
rightLabelRed = new GUIStyle();
rightLabelRed.alignment = TextAnchor.UpperRight;
rightLabelRed.normal.textColor = Color.red;
leftLabelGray = new GUIStyle();
leftLabelGray.alignment = TextAnchor.UpperLeft;
leftLabelGray.normal.textColor = Color.gray;
rippleSliderStyle = new GUIStyle(HighLogic.Skin.horizontalSlider);
rippleThumbStyle = new GUIStyle(HighLogic.Skin.horizontalSliderThumb);
rippleSliderStyle.fixedHeight = rippleThumbStyle.fixedHeight = 0;
kspTitleLabel = new GUIStyle();
kspTitleLabel.normal.textColor = HighLogic.Skin.window.normal.textColor;
kspTitleLabel.font = HighLogic.Skin.window.font;
kspTitleLabel.fontSize = HighLogic.Skin.window.fontSize;
kspTitleLabel.fontStyle = HighLogic.Skin.window.fontStyle;
kspTitleLabel.alignment = TextAnchor.UpperCenter;
//
if(HighLogic.LoadedSceneIsFlight)
{
ApplyPhysRange();
SaveVolumeSettings();
GameEvents.onHideUI.Add(HideGameUI);
GameEvents.onShowUI.Add(ShowGameUI);
GameEvents.onVesselGoOffRails.Add(OnVesselGoOffRails);
GameEvents.OnGameSettingsApplied.Add(SaveVolumeSettings);
GameEvents.onVesselCreate.Add(ApplyNewVesselRanges);
/*
foreach(var cam in FlightCamera.fetch.cameras)
{
cam.gameObject.AddComponent<CameraBulletRenderer>();
}
*/
gpsWindowRect = new Rect(0, 0, toolbarWindowRect.width-10, 0);
GameEvents.onVesselChange.Add(VesselChange);
}
}
void Update()
{
if(HighLogic.LoadedSceneIsFlight)
{
if(missileWarning && Time.time - missileWarningTime > 1.5f)
{
missileWarning = false;
}
/*
if(Input.GetKeyDown(KeyCode.Keypad1))
{
VesselRanges vr = FlightGlobals.ActiveVessel.vesselRanges;
Debug.Log ("Flying: ");
Debug.Log ("load: " + vr.flying.load);
Debug.Log ("unload: " + vr.flying.unload);
Debug.Log ("pack: " + vr.flying.pack);
Debug.Log ("unpack" + vr.flying.unpack);
Debug.Log ("Landed: ");
Debug.Log ("load: " + vr.landed.load);
Debug.Log ("unload: " + vr.landed.unload);
Debug.Log ("pack: " + vr.landed.pack);
Debug.Log ("unpack" + vr.landed.unpack);
Debug.Log ("Splashed: ");
Debug.Log ("load: " + vr.splashed.load);
Debug.Log ("unload: " + vr.splashed.unload);
Debug.Log ("pack: " + vr.splashed.pack);
Debug.Log ("unpack" + vr.splashed.unpack);
}
*/
if(Input.GetKeyDown(KeyCode.KeypadMultiply))
{
toolbarGuiEnabled = !toolbarGuiEnabled;
}
}
else if(HighLogic.LoadedSceneIsEditor)
{
if(Input.GetKeyDown(KeyCode.F2))
{
showWeaponAlignment = !showWeaponAlignment;
}
}
if(Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
{
if(Input.GetKeyDown(KeyCode.B))
{
ToggleSettingsGUI();
}
}
}
void ToggleSettingsGUI()
{
if(HighLogic.LoadedScene == GameScenes.LOADING || HighLogic.LoadedScene == GameScenes.LOADINGBUFFER)
{
return;
}
settingsGuiEnabled = !settingsGuiEnabled;
if(settingsGuiEnabled)
{
physicsRangeGui = PHYSICS_RANGE.ToString();
LoadConfig();
}
else
{
SaveConfig();
}
}
void LateUpdate()
{
if(HighLogic.LoadedSceneIsFlight)
{
DrawAimerCursor();
}
}
void DrawAimerCursor()
{
if(ActiveWeaponManager == null)
{
Screen.showCursor = true;
return;
}
drawCursor = false;
if(!MapView.MapIsEnabled && !Misc.CheckMouseIsOnGui() && !PauseMenu.isOpen)
{
if(ActiveWeaponManager.weaponIndex > 0 && !ActiveWeaponManager.guardMode)
{
if(ActiveWeaponManager.selectedWeapon.GetWeaponClass() == WeaponClasses.Gun || ActiveWeaponManager.selectedWeapon.GetWeaponClass() == WeaponClasses.DefenseLaser)
{
ModuleWeapon mw = ActiveWeaponManager.selectedWeapon.GetPart().FindModuleImplementing<ModuleWeapon>();
if(mw.weaponState == ModuleWeapon.WeaponStates.Enabled && mw.maxPitch > 1 && !mw.slaved && !mw.aiControlled)
{
Screen.showCursor = false;
drawCursor = true;
return;
}
}
else if(ActiveWeaponManager.selectedWeapon.GetWeaponClass() == WeaponClasses.Rocket)
{
RocketLauncher rl = ActiveWeaponManager.selectedWeapon.GetPart().FindModuleImplementing<RocketLauncher>();
if(rl.readyToFire && rl.turret)
{
Screen.showCursor = false;
drawCursor = true;
return;
}
}
}
}
Screen.showCursor = true;
}
void VesselChange(Vessel v)
{
if(v.isActiveVessel)
{
GetWeaponManager();
}
}
void GetWeaponManager()
{
foreach(var mf in FlightGlobals.ActiveVessel.FindPartModulesImplementing<MissileFire>())
{
ActiveWeaponManager = mf;
return;
}
ActiveWeaponManager = null;
return;
}
public static void LoadConfig()
{
try
{
Debug.Log ("== BDArmory : Loading settings.cfg ==");
ConfigNode fileNode = ConfigNode.Load("GameData/BDArmory/settings.cfg");
if(!fileNode.HasNode("BDASettings"))
{
fileNode.AddNode("BDASettings");
}
ConfigNode cfg = fileNode.GetNode("BDASettings");
//if(cfg.HasValue("FireKey")) FIRE_KEY = cfg.GetValue("FireKey");
if(cfg.HasValue("INSTAKILL")) INSTAKILL = bool.Parse(cfg.GetValue("INSTAKILL"));
if(cfg.HasValue("BULLET_HITS")) BULLET_HITS = bool.Parse(cfg.GetValue("BULLET_HITS"));
if(cfg.HasValue("PHYSICS_RANGE")) PHYSICS_RANGE = float.Parse(cfg.GetValue("PHYSICS_RANGE"));
if(cfg.HasValue("EJECT_SHELLS")) EJECT_SHELLS = bool.Parse(cfg.GetValue("EJECT_SHELLS"));
if(cfg.HasValue("INFINITE_AMMO")) INFINITE_AMMO = bool.Parse(cfg.GetValue("INFINITE_AMMO"));
if(cfg.HasValue("DRAW_DEBUG_LINES")) DRAW_DEBUG_LINES = bool.Parse(cfg.GetValue("DRAW_DEBUG_LINES"));
if(cfg.HasValue("DRAW_AIMERS")) DRAW_AIMERS = bool.Parse(cfg.GetValue ("DRAW_AIMERS"));
if(cfg.HasValue("AIM_ASSIST")) AIM_ASSIST = bool.Parse(cfg.GetValue("AIM_ASSIST"));
if(cfg.HasValue("REMOTE_SHOOTING")) REMOTE_SHOOTING = bool.Parse(cfg.GetValue("REMOTE_SHOOTING"));
if(cfg.HasValue("DMG_MULTIPLIER")) DMG_MULTIPLIER = float.Parse(cfg.GetValue("DMG_MULTIPLIER"));
if(cfg.HasValue("FLARE_CHANCE_FACTOR")) FLARE_CHANCE_FACTOR = float.Parse(cfg.GetValue("FLARE_CHANCE_FACTOR"));
if(cfg.HasValue("BOMB_CLEARANCE_CHECK")) BOMB_CLEARANCE_CHECK = bool.Parse(cfg.GetValue("BOMB_CLEARANCE_CHECK"));
if(cfg.HasValue("SMART_GUARDS")) SMART_GUARDS = bool.Parse(cfg.GetValue("SMART_GUARDS"));
if(cfg.HasValue("MAX_BULLET_RANGE")) MAX_BULLET_RANGE = float.Parse(cfg.GetValue("MAX_BULLET_RANGE"));
if(cfg.HasValue("TRIGGER_HOLD_TIME")) TRIGGER_HOLD_TIME = float.Parse(cfg.GetValue("TRIGGER_HOLD_TIME"));
if(cfg.HasValue("ALLOW_LEGACY_TARGETING")) ALLOW_LEGACY_TARGETING = bool.Parse(cfg.GetValue("ALLOW_LEGACY_TARGETING"));
if(cfg.HasValue("TARGET_CAM_RESOLUTION")) TARGET_CAM_RESOLUTION = float.Parse(cfg.GetValue("TARGET_CAM_RESOLUTION"));
if(cfg.HasValue("BW_TARGET_CAM")) BW_TARGET_CAM = bool.Parse(cfg.GetValue("BW_TARGET_CAM"));
if(cfg.HasValue("SMOKE_DEFLECTION_FACTOR")) SMOKE_DEFLECTION_FACTOR = float.Parse(cfg.GetValue("SMOKE_DEFLECTION_FACTOR"));
if(cfg.HasValue("FLARE_THERMAL")) FLARE_THERMAL = float.Parse(cfg.GetValue("FLARE_THERMAL"));
if(cfg.HasValue("BDARMORY_UI_VOLUME")) BDARMORY_UI_VOLUME = float.Parse(cfg.GetValue("BDARMORY_UI_VOLUME"));
if(cfg.HasValue("BDARMORY_WEAPONS_VOLUME")) BDARMORY_WEAPONS_VOLUME = float.Parse(cfg.GetValue("BDARMORY_WEAPONS_VOLUME"));
if(cfg.HasValue("MAX_GUARD_VISUAL_RANGE")) MAX_GUARD_VISUAL_RANGE = float.Parse(cfg.GetValue("MAX_GUARD_VISUAL_RANGE"));
if(cfg.HasValue("GLOBAL_LIFT_MULTIPLIER")) GLOBAL_LIFT_MULTIPLIER = float.Parse(cfg.GetValue("GLOBAL_LIFT_MULTIPLIER"));
if(cfg.HasValue("GLOBAL_DRAG_MULTIPLIER")) GLOBAL_DRAG_MULTIPLIER = float.Parse(cfg.GetValue("GLOBAL_DRAG_MULTIPLIER"));
if(cfg.HasValue("IVA_LOWPASS_FREQ")) IVA_LOWPASS_FREQ = float.Parse(cfg.GetValue("IVA_LOWPASS_FREQ"));
if(cfg.HasValue("PEACE_MODE")) PEACE_MODE = bool.Parse(cfg.GetValue("PEACE_MODE"));
if(cfg.HasValue("SHELL_COLLISIONS")) SHELL_COLLISIONS = bool.Parse(cfg.GetValue("SHELL_COLLISIONS"));
BDInputSettingsFields.LoadSettings(fileNode);
}
catch(NullReferenceException)
{
Debug.Log ("== BDArmory : Failed to load settings config==");
}
}
public static void SaveConfig()
{
try
{
Debug.Log("== BDArmory : Saving settings.cfg == ");
ConfigNode fileNode = ConfigNode.Load("GameData/BDArmory/settings.cfg");
if(!fileNode.HasNode("BDASettings"))
{
fileNode.AddNode("BDASettings");
}
ConfigNode cfg = fileNode.GetNode("BDASettings");
//cfg.SetValue("FireKey", FIRE_KEY, true);
cfg.SetValue("INSTAKILL", INSTAKILL.ToString(), true);
cfg.SetValue("BULLET_HITS", BULLET_HITS.ToString(), true);
cfg.SetValue("PHYSICS_RANGE", PHYSICS_RANGE.ToString(), true);
cfg.SetValue("EJECT_SHELLS", EJECT_SHELLS.ToString(), true);
cfg.SetValue("INFINITE_AMMO", INFINITE_AMMO.ToString(), true);
cfg.SetValue("DRAW_DEBUG_LINES", DRAW_DEBUG_LINES.ToString(), true);
cfg.SetValue("DRAW_AIMERS", DRAW_AIMERS.ToString(), true);
cfg.SetValue("AIM_ASSIST", AIM_ASSIST.ToString(), true);
cfg.SetValue("REMOTE_SHOOTING", REMOTE_SHOOTING.ToString(), true);
cfg.SetValue("DMG_MULTIPLIER", DMG_MULTIPLIER.ToString(), true);
cfg.SetValue("FLARE_CHANCE_FACTOR", FLARE_CHANCE_FACTOR.ToString(), true);
cfg.SetValue("BOMB_CLEARANCE_CHECK", BOMB_CLEARANCE_CHECK.ToString(), true);
cfg.SetValue("SMART_GUARDS", SMART_GUARDS.ToString(), true);
cfg.SetValue("TRIGGER_HOLD_TIME", TRIGGER_HOLD_TIME.ToString(), true);
cfg.SetValue("ALLOW_LEGACY_TARGETING", ALLOW_LEGACY_TARGETING.ToString(), true);
cfg.SetValue("TARGET_CAM_RESOLUTION", TARGET_CAM_RESOLUTION.ToString(), true);
cfg.SetValue("BW_TARGET_CAM", BW_TARGET_CAM.ToString(), true);
cfg.SetValue("SMOKE_DEFLECTION_FACTOR", SMOKE_DEFLECTION_FACTOR.ToString(), true);
cfg.SetValue("FLARE_THERMAL", FLARE_THERMAL.ToString(), true);
cfg.SetValue("BDARMORY_UI_VOLUME", BDARMORY_UI_VOLUME.ToString(), true);
cfg.SetValue("BDARMORY_WEAPONS_VOLUME", BDARMORY_WEAPONS_VOLUME.ToString(), true);
cfg.SetValue("GLOBAL_LIFT_MULTIPLIER", GLOBAL_LIFT_MULTIPLIER.ToString(), true);
cfg.SetValue("GLOBAL_DRAG_MULTIPLIER", GLOBAL_DRAG_MULTIPLIER.ToString(), true);
cfg.SetValue("IVA_LOWPASS_FREQ", IVA_LOWPASS_FREQ.ToString(), true);
cfg.SetValue("MAX_BULLET_RANGE", MAX_BULLET_RANGE.ToString(), true);
cfg.SetValue("PEACE_MODE", PEACE_MODE.ToString(), true);
cfg.SetValue("MAX_GUARD_VISUAL_RANGE", MAX_GUARD_VISUAL_RANGE.ToString(), true);
cfg.SetValue("SHELL_COLLISIONS", SHELL_COLLISIONS.ToString(), true);
BDInputSettingsFields.SaveSettings(fileNode);
fileNode.Save ("GameData/BDArmory/settings.cfg");
if(OnSavedSettings!=null)
{
OnSavedSettings();
}
}
catch(NullReferenceException)
{
Debug.Log ("== BDArmory : Failed to save settings.cfg ==");
}
}
#region GUI
void OnGUI()
{
if(GAME_UI_ENABLED)
{
if(settingsGuiEnabled)
{
settingsRect = GUI.Window(129419, settingsRect, SettingsGUI, GUIContent.none);
}
if(drawCursor)
{
//mouse cursor
int origDepth = GUI.depth;
GUI.depth = -100;
float cursorSize = 40;
Vector3 cursorPos = Input.mousePosition;
Rect cursorRect = new Rect(cursorPos.x - (cursorSize/2), Screen.height - cursorPos.y - (cursorSize/2), cursorSize, cursorSize);
GUI.DrawTexture(cursorRect, cursorTexture);
GUI.depth = origDepth;
}
if(toolbarGuiEnabled && HighLogic.LoadedSceneIsFlight)
{
toolbarWindowRect = GUI.Window(321, toolbarWindowRect, ToolbarGUI, "BDA Weapon Manager", HighLogic.Skin.window);
BDGUIUtils.UseMouseEventInRect(toolbarWindowRect);
if(showGPSWindow && ActiveWeaponManager)
{
//gpsWindowRect = GUI.Window(424333, gpsWindowRect, GPSWindow, "", GUI.skin.box);
BDGUIUtils.UseMouseEventInRect(gpsWindowRect);
foreach(var coordinate in BDATargetManager.GPSTargets[BDATargetManager.BoolToTeam(ActiveWeaponManager.team)])
{
BDGUIUtils.DrawTextureOnWorldPos(coordinate.worldPos, BDArmorySettings.Instance.greenDotTexture, new Vector2(8,8), 0);
}
}
}
}
if(DRAW_DEBUG_LABELS && HighLogic.LoadedSceneIsFlight)
{
if(RadarUtils.radarRT)
{
GUI.DrawTexture(new Rect(20,20,128,128), RadarUtils.radarRT, ScaleMode.StretchToFill, true);
}
}
}
float rippleHeight = 0;
float weaponsHeight = 0;
float guardHeight = 0;
float modulesHeight = 0;
float gpsHeight = 0;
bool toolMinimized = false;
void ToolbarGUI(int windowID)
{
GUI.DragWindow(new Rect(30,0,toolWindowWidth-60, 30));
float line = 0;
float leftIndent = 10;
float contentWidth = (toolWindowWidth) - (2*leftIndent);
float contentTop = 10;
float entryHeight = 20;
//GUI.Label(new Rect(leftIndent, contentTop+(line*entryHeight), contentWidth, entryHeight*1.25f), , HighLogic.Skin.label);
/*
if(missileWarning)
{
GUI.Label(new Rect(leftIndent, contentTop+(line*entryHeight), contentWidth, entryHeight), "Missile", leftLabelRed);
GUI.Label(new Rect(leftIndent, contentTop+(line*entryHeight), contentWidth, entryHeight), "Lock", rightLabelRed);
}
*/
line += 1.25f;
line += 0.25f;
if(ActiveWeaponManager!=null)
{
//MINIMIZE BUTTON
toolMinimized = GUI.Toggle(new Rect(4, 4, 26, 26), toolMinimized, "_", toolMinimized ? HighLogic.Skin.box : HighLogic.Skin.button);
//SETTINGS BUTTON
if(!BDKeyBinder.current && GUI.Button(new Rect(toolWindowWidth - 30, 4, 26, 26), settingsIconTexture, HighLogic.Skin.button))
{
ToggleSettingsGUI();
}
GUIStyle armedLabelStyle;
Rect armedRect = new Rect(leftIndent, contentTop + (line * entryHeight), contentWidth / 2, entryHeight);
if(ActiveWeaponManager.guardMode)
{
if(GUI.Button(armedRect, "- Guard Mode -", HighLogic.Skin.box))
{
showGuardMenu = true;
}
}
else
{
string armedText = "Trigger is ";
if(ActiveWeaponManager.isArmed)
{
armedText += "ARMED.";
armedLabelStyle = HighLogic.Skin.box;
}
else
{
armedText += "disarmed.";
armedLabelStyle = HighLogic.Skin.button;
}
if(GUI.Button(armedRect, armedText, armedLabelStyle))
{
ActiveWeaponManager.ToggleArm();
}
}
GUIStyle teamButtonStyle;
string teamText = "Team: ";
if(ActiveWeaponManager.team)
{
teamButtonStyle = HighLogic.Skin.box;
teamText += "B";
}
else
{
teamButtonStyle = HighLogic.Skin.button;
teamText += "A";
}
if(GUI.Button(new Rect(leftIndent+(contentWidth/2), contentTop+(line*entryHeight), contentWidth/2, entryHeight), teamText, teamButtonStyle))
{
ActiveWeaponManager.ToggleTeam();
}
line++;
line += 0.25f;
string weaponName = ActiveWeaponManager.selectedWeaponString;// = ActiveWeaponManager.selectedWeapon == null ? "None" : ActiveWeaponManager.selectedWeapon.GetShortName();
string selectionText = "Weapon: "+weaponName;
GUI.Label(new Rect(leftIndent, contentTop+(line*entryHeight), contentWidth, entryHeight*1.25f), selectionText, HighLogic.Skin.box);
line += 1.25f;
line += 0.1f;
//if weapon can ripple, show option and slider.
if(ActiveWeaponManager.hasLoadedRippleData && ActiveWeaponManager.canRipple)
{
string rippleText = ActiveWeaponManager.rippleFire ? "Ripple: " + ActiveWeaponManager.rippleRPM.ToString("0") + " RPM" : "Ripple: OFF";
GUIStyle rippleStyle = ActiveWeaponManager.rippleFire ? HighLogic.Skin.box : HighLogic.Skin.button;
if(GUI.Button(new Rect(leftIndent, contentTop + (line * entryHeight), contentWidth / 2, entryHeight * 1.25f), rippleText, rippleStyle))
{
ActiveWeaponManager.ToggleRippleFire();
}
if(ActiveWeaponManager.rippleFire)
{
Rect sliderRect = new Rect(leftIndent + (contentWidth / 2) + 2, contentTop + (line * entryHeight) + 6.5f, (contentWidth / 2) - 2, 12);
ActiveWeaponManager.rippleRPM = GUI.HorizontalSlider(sliderRect, ActiveWeaponManager.rippleRPM, 100, 1600, rippleSliderStyle, rippleThumbStyle);
}
rippleHeight = Mathf.Lerp(rippleHeight, 1.25f, 0.15f);
}
else
{
rippleHeight = Mathf.Lerp(rippleHeight, 0, 0.15f);
}
//line += 1.25f;
line+=rippleHeight;
line += 0.1f;
if(!toolMinimized)
{
showWeaponList = GUI.Toggle(new Rect(leftIndent, contentTop + (line * entryHeight), contentWidth / 3, entryHeight), showWeaponList, "Weapons", showWeaponList ? HighLogic.Skin.box : HighLogic.Skin.button);
showGuardMenu = GUI.Toggle(new Rect(leftIndent + (contentWidth / 3), contentTop + (line * entryHeight), contentWidth / 3, entryHeight), showGuardMenu, "Guard Menu", showGuardMenu ? HighLogic.Skin.box : HighLogic.Skin.button);
showModules = GUI.Toggle(new Rect(leftIndent + (2 * contentWidth / 3), contentTop + (line * entryHeight), contentWidth / 3, entryHeight), showModules, "Modules", showModules ? HighLogic.Skin.box : HighLogic.Skin.button);
line++;
}
float weaponLines = 0;
if(showWeaponList && !toolMinimized)
{
line += 0.25f;
Rect weaponListGroupRect = new Rect(5, contentTop + (line * entryHeight), toolWindowWidth - 10, ((float)ActiveWeaponManager.weaponArray.Length+0.1f) * entryHeight);
GUI.BeginGroup(weaponListGroupRect, GUIContent.none, HighLogic.Skin.box); //darker box
weaponLines += 0.1f;
for(int i = 0; i < ActiveWeaponManager.weaponArray.Length; i++)
{
GUIStyle wpnListStyle;
GUIStyle tgtStyle;
if(i == ActiveWeaponManager.weaponIndex)
{
wpnListStyle = middleLeftLabelOrange;
tgtStyle = targetModeStyleSelected;
}
else
{
wpnListStyle = middleLeftLabel;
tgtStyle = targetModeStyle;
}
string label;
string subLabel;
if(ActiveWeaponManager.weaponArray[i] != null)
{
label = ActiveWeaponManager.weaponArray[i].GetShortName();
subLabel = ActiveWeaponManager.weaponArray[i].GetSubLabel();
}
else
{
label = "None";
subLabel = string.Empty;
}
Rect weaponButtonRect = new Rect(leftIndent, (weaponLines * entryHeight), weaponListGroupRect.width - (2*leftIndent), entryHeight);
GUI.Label(weaponButtonRect, subLabel, tgtStyle);
if(GUI.Button(weaponButtonRect, label, wpnListStyle))
{
ActiveWeaponManager.CycleWeapon(i);
}
if(i < ActiveWeaponManager.weaponArray.Length - 1)
{
BDGUIUtils.DrawRectangle(new Rect(weaponButtonRect.x, weaponButtonRect.y + weaponButtonRect.height, weaponButtonRect.width, 1), Color.white);
}
weaponLines++;
}
weaponLines += 0.1f;
GUI.EndGroup();
}
weaponsHeight = Mathf.Lerp(weaponsHeight, weaponLines, 0.15f);
line += weaponsHeight;
float guardLines = 0;
if(showGuardMenu && !toolMinimized)
{
line += 0.25f;
GUI.BeginGroup(new Rect(5, contentTop+(line*entryHeight), toolWindowWidth-10, 7.45f*entryHeight), GUIContent.none, HighLogic.Skin.box);
guardLines += 0.1f;
contentWidth -= 16;
leftIndent += 3;
string guardButtonLabel = "Guard Mode " + (ActiveWeaponManager.guardMode ? "ON" : "Off");
if(GUI.Button(new Rect(leftIndent, (guardLines * entryHeight), contentWidth, entryHeight), guardButtonLabel, ActiveWeaponManager.guardMode ? HighLogic.Skin.box : HighLogic.Skin.button))
{
ActiveWeaponManager.ToggleGuardMode();
}
guardLines += 1.25f;
string scanLabel = ALLOW_LEGACY_TARGETING ? "Scan Interval" : "Firing Interval";
GUI.Label(new Rect(leftIndent, (guardLines*entryHeight), 85, entryHeight), scanLabel, leftLabel);
ActiveWeaponManager.targetScanInterval = GUI.HorizontalSlider(new Rect(leftIndent+(90), (guardLines*entryHeight), contentWidth-90-38, entryHeight), ActiveWeaponManager.targetScanInterval, 1, 60);
ActiveWeaponManager.targetScanInterval = Mathf.Round(ActiveWeaponManager.targetScanInterval);
GUI.Label(new Rect(leftIndent+(contentWidth-35), (guardLines*entryHeight), 35, entryHeight), ActiveWeaponManager.targetScanInterval.ToString(), leftLabel);
guardLines++;
GUI.Label(new Rect(leftIndent, (guardLines*entryHeight), 85, entryHeight), "Field of View", leftLabel);
float guardAngle = ActiveWeaponManager.guardAngle;
guardAngle = GUI.HorizontalSlider(new Rect(leftIndent+90, (guardLines*entryHeight), contentWidth-90-38, entryHeight), guardAngle, 10, 360);
guardAngle = guardAngle/10;
guardAngle = Mathf.Round(guardAngle);
ActiveWeaponManager.guardAngle = guardAngle * 10;
GUI.Label(new Rect(leftIndent+(contentWidth-35), (guardLines*entryHeight), 35, entryHeight), ActiveWeaponManager.guardAngle.ToString(), leftLabel);
guardLines++;
string rangeLabel = ALLOW_LEGACY_TARGETING ? "Guard Range" : "Visual Range";
GUI.Label(new Rect(leftIndent, (guardLines*entryHeight), 85, entryHeight), rangeLabel, leftLabel);
float guardRange = ActiveWeaponManager.guardRange;
float maxVisRange = ALLOW_LEGACY_TARGETING ? Mathf.Clamp(PHYSICS_RANGE, 2500, 100000) : BDArmorySettings.MAX_GUARD_VISUAL_RANGE;
guardRange = GUI.HorizontalSlider(new Rect(leftIndent+90, (guardLines*entryHeight), contentWidth-90-38, entryHeight), guardRange, 100, maxVisRange);
guardRange = guardRange/100;
guardRange = Mathf.Round(guardRange);
ActiveWeaponManager.guardRange = guardRange * 100;
GUI.Label(new Rect(leftIndent+(contentWidth-35), (guardLines*entryHeight), 35, entryHeight), ActiveWeaponManager.guardRange.ToString(), leftLabel);
guardLines++;
GUI.Label(new Rect(leftIndent, (guardLines*entryHeight), 85, entryHeight), "Guns Range", leftLabel);
float gRange = ActiveWeaponManager.gunRange;
gRange = GUI.HorizontalSlider(new Rect(leftIndent+90, (guardLines*entryHeight), contentWidth-90-38, entryHeight), gRange, 0, 10000);
gRange /= 100f;
gRange = Mathf.Round(gRange);