/
Editor.cs
5349 lines (4828 loc) · 235 KB
/
Editor.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 System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Timers;
using UnityEngine;
using KSP.UI.Screens;
namespace ActionGroupsExtended
{
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
public class AGXEditor : PartModule
{
//bool agxWindowsShowing; //status bool, true if panels have been dismissed.
//bool forceShowDefaultEditor; //should be deleteable now
public static AGXEditor thisModule;
bool showCareerStockAGs = false; //support locking action groups in early career
bool showCareerCustomAGs = false;
bool showAGXRightClickMenu = false; //show stock toolbar right click menu?
ApplicationLauncherButton AGXAppEditorButton = null; //stock toolbar button instance
bool buttonCreated = false;
bool EditorShowToolbarPopout = false;
bool defaultShowingNonNumeric = false; //are we in non-numeric (abort/brakes/gear/list) mode?
List<BaseAction> defaultActionsListThisType; //list of default actions showing in group win when non-numeric
List<BaseAction> defaultActionsListAll; //list of all default actions on vessel, only used in non-numeric mode when going to other mode
KSPActionGroup defaultGroupToShow = KSPActionGroup.Abort; //which group is currently selected if showing non-numeric groups
List<AGXAction> ThisGroupActions;
//private Part AGXRootPart = null;
private string LastKeyCode = "";
public static Dictionary<int, bool> IsGroupToggle; //is group a toggle group?
public static bool[,] ShowGroupInFlight; //Show group in flight?
public static string[] ShowGroupInFlightNames;
public static int ShowGroupInFlightCurrent = 1;
private List<Part> SelectedWithSym; //selected parts from last frame for Default actions monitoring
private List<AGXDefaultCheck> SelectedWithSymActions; //monitor baseaction.actiongroups of selected parts
public static bool NeedToLoadActions = true;
public static bool LoadFinished = false;
//Selected Parts Window Variables
public static Rect SelPartsWin;
private static Vector2 ScrollPosSelParts;
public static Vector2 ScrollPosSelPartsActs;
public static Vector2 ScrollGroups;
public static Vector2 CurGroupsWin;
private static List<AGXPart> AGEditorSelectedParts;
private static bool AGEEditorSelectedPartsSame = false;
//private static GUIStyle AGXWinStyle = null;
private static int SelectedPartsCount = 0;
private static bool ShowSelectedWin = true;
private static Part PreviousSelectedPart = null;
private static bool SelPartsIncSym = true;
private static string BtnTxt;
private static bool AGXDoLock = false;
private static Rect TestWin;
private static Part AGXRoot;
public static List<AGXAction> DetachedPartActions;
public static Timer DetachedPartReset;
public static Timer DisablePartAttachingReset;
//private static bool NeedToSave = false;
private static int GroupsPage = 1;
private static string CurGroupDesc;
private static bool AutoHideGroupsWin = false;
private static bool TempShowGroupsWin = false;
private static Rect KeyCodeWin;
private static Rect CurActsWin;
private static bool ShowKeyCodeWin = false;
private static bool ShowJoySticks = false;
private static bool ShowKeySetWin = false;
private static int CurrentKeySet = 1;
private static string CurrentKeySetName;
private static Rect KeySetWin;
private static ConfigNode AGExtNode;
static string[] KeySetNames = new string[5];
private static bool TrapMouse = false;
//private static int LastPartCount = 0;
//public static List<AGXAction> CurrentVesselActions;
// private static bool MouseOverExitBtns = false;
private IButton AGXBtn;
public static Rect GroupsWin;
public static bool Trigger;
//private static bool Trigger2;
//private static int Value = 0;
public static string HexStr = "Load";
private static List<BaseAction> PartActionsList;
//public static ConfigNode AGXEditorNode;
Vector2 groupWinScroll = new Vector2();
bool highlightPartThisFrameGroupWin = false;
static Texture2D BtnTexRed = new Texture2D(1, 1);
static Texture2D BtnTexGrn = new Texture2D(1, 1);
public static Dictionary<int, string> AGXguiNames;
public static Dictionary<int, KeyCode> AGXguiKeys;
public static Dictionary<int, bool> AGXguiMod1Groups;
public static Dictionary<int, bool> AGXguiMod2Groups;
public static KeyCode AGXguiMod1Key = KeyCode.None;
public static KeyCode AGXguiMod2Key = KeyCode.None;
private bool AGXguiMod1KeySelecting = false;
private bool AGXguiMod2KeySelecting = false;
public static int AGXCurActGroup = 1;
static List<string> KeyCodeNames = new List<string>();
static List<string> JoyStickCodes = new List<string>();
private static bool ActionsListDirty = true; //is our actions requiring update?
private static bool ShowCurActsWin = true;
public static Dictionary<int, KSPActionGroup> KSPActs = new Dictionary<int, KSPActionGroup>();
public static Dictionary<int, bool> isDirectAction = new Dictionary<int, bool>();
private bool AGXShow = false;
private static GUISkin AGXSkin;
public static GUIStyle AGXWinStyle = null;
//private static GUIStyle TWR1WinStyle = null; //window style
private static GUIStyle AGXLblStyle = null; //window style
private static GUIStyle AGXBtnStyle = null; //window style
private static GUIStyle AGXFldStyle = null; //window style
static Texture2D ButtonTexture = new Texture2D(64, 64);
static Texture2D ButtonTextureRed = new Texture2D(64, 64);
static Texture2D ButtonTextureGreen = new Texture2D(64, 64);
//bool checkShipsExist = false; //flag to check existing ships on load window open
//int checkShipsExistDelay = 0;//delay timer to wait after opening load ship window
static bool inVAB = true; //true if in VAB, flase in SPH
bool highlightPartThisFrameSelWin = false;
bool highlightPartThisFrameActsWin = false;
Part partToHighlight = null;
Texture2D PartCenter = new Texture2D(41, 41);
Texture2D PartCross = new Texture2D(21, 21);
Texture2D PartPlus = new Texture2D(21, 21);
bool showAllPartsList = false; //show list of all parts in group window?
List<string> showAllPartsListTitles; //list of all parts with actions to show in group window
KSPActionGroup KSPDefaultLastActionGroup = KSPActionGroup.Custom01;
public static bool disablePartAttaching = true; //disable part attaching feature when loading so non-symmetric actions are not made symmetric
//static Part partLastHighlight = null;
////static Color partHighlighLastColor;
//static Part.HighlightType partHighlightLastType;
//static Material[] partHighlightLastMaterial;
public class SettingsWindowEditor : MonoBehaviour, IDrawable
{
public Rect SettingsWinEditor = new Rect(0, 0, 150, 85);
public Vector2 Draw(Vector2 position)
{
var oldSkin = GUI.skin;
GUI.skin = HighLogic.Skin;
SettingsWinEditor.x = position.x;
SettingsWinEditor.y = position.y;
GUI.Window(2233452, SettingsWinEditor, DrawSettingsWinEditor, "AGX Settings", AGXEditor.AGXWinStyle);
//RCSlaWin = GUILayout.Window(42334567, RCSlaWin, DrawWin, (string)null, GUI.skin.box);
//GUI.skin = oldSkin;
return new Vector2(SettingsWinEditor.width, SettingsWinEditor.height);
}
public void DrawSettingsWinEditor(int WindowID)
{
if (GUI.Button(new Rect(10, 25, 130, 25), "Reset Windows", AGXBtnStyle))
{
KeySetWin.x = 250;
KeySetWin.y = 250;
GroupsWin.x = 350;
GroupsWin.y = 350;
SelPartsWin.x = 200;
SelPartsWin.y = 200;
KeyCodeWin.x = 300;
KeyCodeWin.y = 300;
CurActsWin.x = 150;
CurActsWin.y = 150;
}
AGXBtnStyle.normal.background = AutoHideGroupsWin ? ButtonTextureRed : ButtonTexture;
AGXBtnStyle.hover.background = AutoHideGroupsWin ? ButtonTextureRed : ButtonTexture;
if (GUI.Button(new Rect(10, 50, 130, 25), "Auto-Hide Groups", AGXBtnStyle))
{
AutoHideGroupsWin = !AutoHideGroupsWin;
}
AGXBtnStyle.normal.background = ButtonTexture;
AGXBtnStyle.hover.background = ButtonTexture;
}
public void Update()
{
}
}
public void DrawSettingsWinEditor(int WindowID)
{
if (GUI.Button(new Rect(10, 25, 130, 25), "Reset Windows", AGXBtnStyle))
{
KeySetWin.x = 250;
KeySetWin.y = 250;
GroupsWin.x = 350;
GroupsWin.y = 350;
SelPartsWin.x = 200;
SelPartsWin.y = 200;
KeyCodeWin.x = 300;
KeyCodeWin.y = 300;
CurActsWin.x = 150;
CurActsWin.y = 150;
}
AGXBtnStyle.normal.background = AutoHideGroupsWin ? ButtonTextureRed : ButtonTexture;
AGXBtnStyle.hover.background = AutoHideGroupsWin ? ButtonTextureRed : ButtonTexture;
if (GUI.Button(new Rect(10, 50, 130, 25), "Auto-Hide Groups", AGXBtnStyle))
{
AutoHideGroupsWin = !AutoHideGroupsWin;
}
AGXBtnStyle.normal.background = ButtonTexture;
AGXBtnStyle.hover.background = ButtonTexture;
}
public void Start()
{
//Debug.Log("AGXEditorSTartSTart");
thisModule = this;
ShowKeyCodeWin = false;
ShowKeySetWin = false;
AGXguiMod1Groups = new Dictionary<int, bool>();
AGXguiMod2Groups = new Dictionary<int, bool>();
for (int i = 1; i <= 250; i++)
{
AGXguiMod1Groups[i] = false;
AGXguiMod2Groups[i] = false;
}
defaultActionsListThisType = new List<BaseAction>(); //initialize list
defaultActionsListAll = new List<BaseAction>(); //initialize list
//foreach (Part p in
string errLine = "1";
ThisGroupActions = new List<AGXAction>();
//var EdPnl = EditorPanels.Instance.actions;
//EditorActionGroups.Instance.groupActionsList.AddValueChangedDelegate(OnGroupActionsListChange);
try
{
errLine = "2";
KSPActs[1] = KSPActionGroup.Custom01;
KSPActs[2] = KSPActionGroup.Custom02;
KSPActs[3] = KSPActionGroup.Custom03;
KSPActs[4] = KSPActionGroup.Custom04;
KSPActs[5] = KSPActionGroup.Custom05;
KSPActs[6] = KSPActionGroup.Custom06;
KSPActs[7] = KSPActionGroup.Custom07;
KSPActs[8] = KSPActionGroup.Custom08;
KSPActs[9] = KSPActionGroup.Custom09;
KSPActs[10] = KSPActionGroup.Custom10;
TestWin = new Rect(600, 300, 100, 200);
//RenderingManager.AddToPostDrawQueue(0, AGXOnDraw);
AGEditorSelectedParts = new List<AGXPart>();
PartActionsList = new List<BaseAction>();
ScrollPosSelParts = Vector2.zero;
ScrollPosSelPartsActs = Vector2.zero;
ScrollGroups = Vector2.zero;
CurGroupsWin = Vector2.zero;
//AGXVsl = new AGXVessel();
AGXWinStyle = new GUIStyle(HighLogic.Skin.window);
BtnTexRed.SetPixel(0, 0, new Color(1, 0, 0, .5f));
BtnTexRed.Apply();
BtnTexGrn.SetPixel(0, 0, new Color(0, 1, 0, .5f));
BtnTexGrn.Apply();
AGXguiNames = new Dictionary<int, string>();
AGXguiKeys = new Dictionary<int, KeyCode>();
for (int i = 1; i <= 250; i = i + 1)
{
AGXguiNames[i] = "";
AGXguiKeys[i] = KeyCode.None;
}
errLine = "3";
KeyCodeNames = new List<String>();
KeyCodeNames.AddRange(Enum.GetNames(typeof(KeyCode)));
KeyCodeNames.Remove("None");
JoyStickCodes.AddRange(KeyCodeNames.Where(JoySticks));
KeyCodeNames.RemoveAll(JoySticks);
//AGExtNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.cfg");
AGExtNode = AGXStaticData.LoadBaseConfigNode();
errLine = "4";
if (AGExtNode.GetValue("EditShow") == "0")
{
AGXShow = false;
}
else
{
AGXShow = true;
}
errLine = "5";
CurrentKeySet = 1;
errLine = "6";
//LoadCurrentKeySet();
CurrentKeySetName = (string)AGExtNode.GetValue("KeySetName" + CurrentKeySet);
KeySetNames[0] = (string)AGExtNode.GetValue("KeySetName1");
KeySetNames[1] = (string)AGExtNode.GetValue("KeySetName2");
KeySetNames[2] = (string)AGExtNode.GetValue("KeySetName3");
KeySetNames[3] = (string)AGExtNode.GetValue("KeySetName4");
KeySetNames[4] = (string)AGExtNode.GetValue("KeySetName5");
errLine = "7";
//CurrentVesselActions = new List<AGXAction>();
errLine = "8";
AGXRoot = null;
errLine = "9";
StartLoadWindowPositions();
errLine = "14";
//print("a");
if (EditorDriver.editorFacility == EditorFacility.VAB)
{
inVAB = true;
}
else
{
inVAB = false;
}
if (AGExtNode.HasValue("OverrideCareer")) //are action groups unlocked?
{
//print("b");
if ((string)AGExtNode.GetValue("OverrideCareer") == "1")
{
//print("AGX 0");
showCareerCustomAGs = true;
showCareerStockAGs = true;
}
else
{
//print("d");
float facilityLevel = 0f;
if (EditorDriver.editorFacility == EditorFacility.SPH)
{
// print("e");
facilityLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar);
//print("AGX Career check SPH: " + facilityLevel);
}
else
{
//print("f");
facilityLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
//print("AGX Career check VAB: " + facilityLevel);
}
if (GameVariables.Instance.UnlockedActionGroupsCustom(facilityLevel, inVAB))
{
//print("AGX 1");
showCareerStockAGs = true;
showCareerCustomAGs = true;
}
else if (GameVariables.Instance.UnlockedActionGroupsStock(facilityLevel, inVAB))
{
//print("AGX 2");
showCareerStockAGs = true;
showCareerCustomAGs = false;
}
else
{
//print("AGX 3");
showCareerStockAGs = false;
showCareerCustomAGs = false;
}
}
}
else
{
// print("j");
float facilityLevel2 = 0f;
if (EditorDriver.editorFacility == EditorFacility.SPH)
{
// print("k");
facilityLevel2 = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar);
}
else
{
//print("l");
facilityLevel2 = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
}
if (GameVariables.Instance.UnlockedActionGroupsCustom(facilityLevel2, inVAB))
{
//print("m");
showCareerStockAGs = true;
showCareerCustomAGs = true;
}
else if (GameVariables.Instance.UnlockedActionGroupsStock(facilityLevel2,inVAB))
{
//print("n");
showCareerStockAGs = true;
showCareerCustomAGs = false;
}
else
{
//print("o");
showCareerStockAGs = false;
showCareerCustomAGs = false;
}
}
//print("startd " + showCareerCustomAGs);
//LoadCurrentKeyBindings();
errLine = "15";
if (ToolbarManager.ToolbarAvailable) //check if toolbar available, load if it is
{
AGXBtn = ToolbarManager.Instance.add("AGX", "AGXBtn");
AGXBtn.TexturePath = "Diazo/AGExt/icon_button";
AGXBtn.ToolTip = "Action Groups Extended";
AGXBtn.OnClick += (e) =>
{
//List<UnityEngine.Transform> UIPanelList = new List<UnityEngine.Transform>(); //setup list to find Editor Actions UI transform into a list. Could not figure out how to find just a transform
//UIPanelList.AddRange(FindObjectsOfType<UnityEngine.Transform>().Where(n => n.name == "PanelActionGroups")); //actual find command
if (e.MouseButton == 0)
{
onLeftButtonClick();
}
if (e.MouseButton == 1)
{
if (EditorLogic.fetch.editorScreen == EditorScreen.Actions)
{
if (EditorShowToolbarPopout)
{
AGXBtn.Drawable = null;
EditorShowToolbarPopout = false;
}
else
{
SettingsWindowEditor SettingsEditor = new SettingsWindowEditor();
AGXBtn.Drawable = SettingsEditor;
EditorShowToolbarPopout = true;
}
}
}
};
}
else
{
//AGXShow = true; //toolbar not installed, show AGX regardless
//now using stock toolbar as fallback
StartCoroutine("AddButtons");
//AGXAppEditorButton = ApplicationLauncher.Instance.AddModApplication(onStockToolbarClick, onStockToolbarClick, DummyVoid, DummyVoid, DummyVoid, DummyVoid, ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH, (Texture)GameDatabase.Instance.GetTexture("Diazo/AGExt/icon_button", false));
}
errLine = "16";
DetachedPartActions = new List<AGXAction>();
DetachedPartReset = new Timer();
DetachedPartReset.Interval = 500;
DetachedPartReset.Stop();
DetachedPartReset.AutoReset = true;
DetachedPartReset.Elapsed += new ElapsedEventHandler(ResetDetachedParts);
DisablePartAttachingReset = new Timer();
DisablePartAttachingReset.Interval = 1000;
DisablePartAttachingReset.Stop();
DisablePartAttachingReset.AutoReset = true;
DisablePartAttachingReset.Elapsed += new ElapsedEventHandler(ResetDisablePartAttaching);
SelectedWithSym = new List<Part>();
SelectedWithSymActions = new List<AGXDefaultCheck>();
errLine = "17";
//EditorPanels.Instance.actions.AddValueChangedDelegate(OnActionPanelsUIChanged); //hook buttons at top of screen for show/hide of action panel
//EditorLogic.fetch.partPanelBtn.AddValueChangedDelegate(OnPartButtonClick);
//EditorLogic.fetch.crewPanelBtn.AddValueChangedDelegate(OnCrewButtonClick);
//EditorLogic.fetch.actionPanelBtn.AddValueChangedDelegate(OnActionButtonClick);
//EditorLogic.fetch.loadBtn.AddValueChangedDelegate(OnLoadClick);
//EditorLogic.fetch.saveBtn.AddValueChangedDelegate(OnSaveButtonClick);
//EditorLogic.fetch.launchBtn.AddValueChangedDelegate(OnLaunchButtonClick);
//EditorLogic.fetch.exitBtn.AddValueChangedDelegate(OnExitButtonClick);
//EditorLogic.fetch.newBtn.AddValueChangedDelegate(OnNewButtonClick);
//EditorPanels.Instance.actions.AddValueChangedDelegate(OnUIChanged); //detect when EditorPanel moves. this ONLY detects editor panel, going from parts to crew will NOT trigger this
//EditorLogic.fetch.partPanelBtn.AddValueChangedDelegate(OnOtherButtonClick); //detect when Part button clicked at top of screen
//EditorLogic.fetch.crewPanelBtn.AddValueChangedDelegate(OnOtherButtonClick);
//EditorLogic.fetch.actionPanelBtn.AddValueChangedDelegate(OnActionButtonClick); //detect when Crew button clicked at top of screen
//EditorLogic.fetch.loadBtn.AddValueChangedDelegate(OnEditorResetButtonClick); //load button clicked to check for deleted ships
//EditorLogic.fetch.saveBtn.AddValueChangedDelegate(OnSaveButtonClick); //run save when save button clicked. auto-save from Scenario module only runs on leaving editor! not on clicking save button
//EditorLogic.fetch.launchBtn.AddValueChangedDelegate(OnSaveButtonClick);
//EditorLogic.fetch.exitBtn.AddValueChangedDelegate(OnSaveButtonClick);
//EditorLogic.fetch.newBtn.AddValueChangedDelegate(OnEditorResetButtonClick);
//GameEvents.onGameSceneLoadRequested.Add(LeavingEditor);
errLine = "18";
IsGroupToggle = new Dictionary<int, bool>();
ShowGroupInFlight = new bool[6, 251];
ShowGroupInFlightNames = new string[6];
ShowGroupInFlightNames[1] = "Group 1";
ShowGroupInFlightNames[2] = "Group 2";
ShowGroupInFlightNames[3] = "Group 3";
ShowGroupInFlightNames[4] = "Group 4";
ShowGroupInFlightNames[5] = "Group 5";
errLine = "19";
//Debug.Log("agx toggle dict set");
for (int i = 1; i <= 250; i++)
{
IsGroupToggle[i] = false;
for (int i2 = 1; i2 <= 5; i2++)
{
ShowGroupInFlight[i2, i] = true;
}
}
AGXSkin = (GUISkin)MonoBehaviour.Instantiate(HighLogic.Skin);
AGXWinStyle = new GUIStyle(AGXSkin.window);
AGXLblStyle = new GUIStyle(AGXSkin.label);
AGXFldStyle = new GUIStyle(AGXSkin.textField);
AGXFldStyle.fontStyle = FontStyle.Normal;
//AGXFldStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f, 1);
AGXFldStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f, 1f);
AGXLblStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f, 1f);
AGXLblStyle.wordWrap = false;
errLine = "20";
AGXBtnStyle = new GUIStyle(AGXSkin.button);
AGXBtnStyle.fontStyle = FontStyle.Normal;
AGXBtnStyle.alignment = TextAnchor.MiddleCenter;
AGXBtnStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f, 1f);
//AGXScrollStyle.normal.background = null;
//print("AGX " + AGXBtnStyle.normal.background);
byte[] importTxt = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTexture.png");
byte[] importTxtRed = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTextureRed.png");
byte[] importTxtGreen = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTextureGreen.png");
byte[] importPartCenter = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/PartLocationCross.png");
byte[] importPartCross = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/PartLocCross.png");
byte[] importPartPlus = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/PartLocPlus.png");
//byte[] testXport = AGXBtnStyle.normal.background.EncodeToPNG();
//File.WriteAllBytes(Application.dataPath + "/SavedScreen.png", testXport);
ButtonTexture.LoadImage(importTxt);
ButtonTexture.Apply();
ButtonTextureRed.LoadImage(importTxtRed);
ButtonTextureRed.Apply();
ButtonTextureGreen.LoadImage(importTxtGreen);
ButtonTextureGreen.Apply();
AGXBtnStyle.normal.background = ButtonTexture;
AGXBtnStyle.onNormal.background = ButtonTexture;
AGXBtnStyle.onActive.background = ButtonTexture;
AGXBtnStyle.onFocused.background = ButtonTexture;
AGXBtnStyle.onHover.background = ButtonTexture;
AGXBtnStyle.active.background = ButtonTexture;
AGXBtnStyle.focused.background = ButtonTexture;
AGXBtnStyle.hover.background = ButtonTexture;
AGXBtnStyle.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
AGXLblStyle.font = AGXBtnStyle.font;
AGXFldStyle.font = AGXBtnStyle.font;
PartCenter.LoadImage(importPartCenter);
PartCenter.Apply();
PartCross.LoadImage(importPartCross);
PartCross.Apply();
PartPlus.LoadImage(importPartPlus);
PartPlus.Apply();
//EditorLoadFromFile();
//if (HighLogic.LoadedScene == GameScenes.EDITOR)
GameEvents.onPartAttach.Add(PartAttaching);// this game event only fires for part removed, not child parts
GameEvents.onPartRemove.Add(PartRemove);
GameEvents.onEditorPartEvent.Add(OnPartEvent);
//GameEvents.onEditorShipModified.Add(VesselChanged);
GameEvents.onEditorLoad.Add(OnShipLoad);
//GameEvents.onGameStateSave.Add(OnSaveTest);
isDirectAction = new Dictionary<int, bool>();
StaticData.CurrentVesselActions.Clear();
//EditorLoadFromFile();
EditorLoadFromNode();
errLine = "21";
//print("Loading now");
//EditorActionGroups.Instance.groupActionsList.AddValueChangedDelegate(OnGroupActionsListChange);
LoadFinished = true;
//Debug.Log("AGX Editor Start Okay" + StaticData.CurrentVesselActions.Count());
//Debug.Log("AGXEditorSTartEnd");
}
catch (Exception e)
{
print("AGX Editor Start Fail " + errLine + " " + e);
print("AGX AGExt node dump: " + AGExtNode);
}
}
//public void OnSaveTest(ConfigNode node)
//{
// Debug.Log("AGX Game Save Event");
//}
//public void OnEditorResetButtonClick(IUIObject obj) //editor is resetting, fix action group UI panels
//{
// forceShowDefaultEditor = true;
// EditorLogic.fetch.Unlock("AGXLock");
// if (AGXShow && EditorLogic.fetch.editorScreen == EditorScreen.Actions)
// {
// EditorPanels.Instance.panelManager.BringIn(EditorPanels.Instance.actions);
// }
//}
public void OnShipLoad(ShipConstruct ship, CraftBrowserDialog.LoadType loadType)
{
//Debug.Log("AGX testing");
DetachedPartReset.Start(); //start timer so it fires even if no parts load
EditorPanels.Instance.panelManager.BringIn(EditorPanels.Instance.partsEditor);
//EditorLogic.fetch.editorScreen = EditorScreen.Actions;
if (loadType == CraftBrowserDialog.LoadType.Normal)
{
//Debug.Log("AGX part attaching disable");
disablePartAttaching = true; //disable symmetric action loading
DetachedPartActions.Clear(); //onPartAttach fires before this point, need to get rid of the actions that adds to this list.
StaticData.CurrentVesselActions.Clear();
//EditorLoadFromFile();
EditorLoadFromNode();
//Debug.Log("AGX Ship Load of type NORMAL detected");
}
else
{
//Debug.Log("AGX Ship Load of type MERGE detected");
//foreach (Part p in ship.parts)
//{
// ModuleAGX agxPM = p.Modules.OfType<ModuleAGX>().First();
// foreach (AGXAction agAct in agxPM.agxActionsThisPart)
// {
// if (!CurrentVesselActions.Contains(agAct))
// {
// CurrentVesselActions.Add(agAct);
// if (AGXguiNames[agAct.group].Length == 0)
// {
// AGXguiNames[agAct.group] = agAct.grpName;
// }
// }
// }
//}
}
}
//public void OnGroupActionsListChange(IUIObject obj)
//{
// print("List change " + obj.GetType());
// UIScrollList lst = (UIScrollList)obj;
// print(lst.
//}
public void StartLoadWindowPositions()
{
string errLine = "1";
try
{
int WinX;
int WinY;
if (Int32.TryParse((string)AGExtNode.GetValue("EdGroupsX"), out WinX) && Int32.TryParse((string)AGExtNode.GetValue("EdGroupsY"), out WinY))
{
GroupsWin = new Rect(WinX, WinY, 250, 530);
}
else
{
GroupsWin = new Rect(100, 100, 250, 530);
}
errLine = "10";
if (Int32.TryParse((string)AGExtNode.GetValue("EdSelPartsX"), out WinX) && Int32.TryParse((string)AGExtNode.GetValue("EdSelPartsY"), out WinY))
{
SelPartsWin = new Rect(WinX, WinY, 365, 270);
}
else
{
SelPartsWin = new Rect(100, 100, 365, 270);
}
errLine = "11";
if (Int32.TryParse((string)AGExtNode.GetValue("EdKeyCodeX"), out WinX) && Int32.TryParse((string)AGExtNode.GetValue("EdKeyCodeY"), out WinY))
{
KeyCodeWin = new Rect(WinX, WinY, 410, 730);
}
else
{
KeyCodeWin = new Rect(100, 100, 410, 730);
}
errLine = "12";
if (Int32.TryParse((string)AGExtNode.GetValue("EdKeySetX"), out WinX) && Int32.TryParse((string)AGExtNode.GetValue("EdKeySetY"), out WinY))
{
KeySetWin = new Rect(WinX, WinY, 185, 335);
}
else
{
KeySetWin = new Rect(100, 100, 185, 335);
}
errLine = "13";
if (Int32.TryParse((string)AGExtNode.GetValue("EdCurActsX"), out WinX) && Int32.TryParse((string)AGExtNode.GetValue("EdCurActsY"), out WinY))
{
CurActsWin = new Rect(WinX, WinY, 345, 140);
}
else
{
CurActsWin = new Rect(100, 100, 345, 140);
}
}
catch (Exception e)
{
print("AGX StartLoadWindowPostion Error, Recovered. " + errLine + " " + e);
GroupsWin = new Rect(100, 100, 250, 530);
SelPartsWin = new Rect(100, 100, 365, 270);
KeyCodeWin = new Rect(100, 100, 410, 730);
KeySetWin = new Rect(100, 100, 185, 335);
CurActsWin = new Rect(100, 100, 345, 140);
}
}
public void DummyVoid()
{
}
public void onStockToolbarClick() //void method, now done with the delegate method
{
//if (showCareerStockAGs)
//{
// //print("mouse " + Input.GetMouseButtonUp(1) + Input.GetMouseButtonDown(1));
// if (Input.GetMouseButtonUp(1))
// {
// onRightButtonStockClick();
// }
// else
// {
// onLeftButtonClick();
// }
//}
}
public Callback LeftClick = delegate
{
thisModule.onLeftButtonClick();
};
public Callback RightClick = delegate
{
thisModule.onRightButtonStockClick();
};
public void onRightButtonStockClick()
{
//forceShowDefaultEditor = false;
showAGXRightClickMenu = !showAGXRightClickMenu;
}
public void onLeftButtonClick()
{
//Debug.Log("AGX nods editor" + EditorLogic.fetch.editorScreen);
try
{
if (showCareerStockAGs)
{
if (EditorLogic.fetch.editorScreen != EditorScreen.Actions)
{
if (EditorLogic.SortedShipList.Count > 0)
{
EditorLogic.fetch.SelectPanelActions();
}
//Debug.Log("AGX no editor");
//if (EditorLogic.SortedShipList.Count > 0 && showCareerStockAGs)
//{
// EditorLogic.fetch.SelectPanelActions();
// StartCoroutine("DelayPanelsMovement");
//}
}
else
{
//Debug.Log("AGX iseditor");
if (AGXShow)
{
//UIPanelList.First().Translate(new Vector3(500f, 0, 0), UIPanelList.First().parent.transform); //hide UI panel
AGXShow = false;
AGExtNode.SetValue("EditShow", "0");
//EditorPanels.Instance.panelManager.BringIn(EditorPanels.Instance.actions);
//StartCoroutine("DelayPanelsMovement");
}
else
{
// UIPanelList.First().Translate(new Vector3(-500f, 0, 0), UIPanelList.First().parent.transform); //show UI panel
AGXShow = true;
AGExtNode.SetValue("EditShow", "1");
//EditorPanels.Instance.panelManager.Dismiss();
//StartCoroutine("DelayPanelsMovement");
}
AGXStaticData.SaveBaseConfigNode(AGExtNode);
}
}
else
{
ScreenMessages.PostScreenMessage("Action Groups Unavailable. Facility Upgrade Required.");
}
}
catch
{
//EdtiorLogic was null, do nothing so silent fail is okay
}
}
public void OnPartEvent(ConstructionEventType cType, Part p)
{
if(cType == ConstructionEventType.PartDeleted)
{
DisablePartAttachingReset.Start();
}
}
public void PartAttaching(GameEvents.HostTargetAction<Part, Part> host_target)
{
//Debug.Log("Part attache fire!"); //+ StaticData.CurrentVesselActions.Count() + "||" + EditorLogic.fetch.FSMStarted);
string ErrLine = "1";
try
{
ErrLine = "2";
//// print("Part attached! " + host_target.host.ConstructID + " " + host_target.target.ConstructID);
// //this.part, partAllActions, partAGActions);
// ErrLine = "3";
// foreach (Part p in host_target.host.FindChildParts<Part>(true)) //action only fires for part clicked on, have to parse all child parts this way
// {
// ErrLine = "4";
// // print("Part atached2! " + p.ConstructID);
// ErrLine = "5";
// }
ErrLine = "6";
//Debug.Log("AGX 1 " + host_target.host.name);
//Debug.Log("AGX 2 " + host_target.host.Modules.Count);
//foreach(PartModule pm in host_target.host.Modules)
//{
// Debug.Log("AGX 3 " + pm.moduleName);
//}
ErrLine = "7";
ModuleAGX agxMod = host_target.host.Modules.OfType<ModuleAGX>().First();
ErrLine = "8";
//Debug.Log("Part attache fire2!" + agxMod.agxActionsThisPart.Count);
foreach (AGXAction agAct in agxMod.agxActionsThisPart)
{
ErrLine = "9";
if (!StaticData.CurrentVesselActions.Contains(agAct))
{
//print("part attached detect");
//Debug.Log("part attached detect");
ErrLine = "10";
StaticData.CurrentVesselActions.Add(agAct);
//DetachedPartActions.Add(agAct);
ErrLine = "11";
ErrLine = "11b";
if (AGXguiNames[agAct.group].Length == 0)
{
ErrLine = "12";
AGXguiNames[agAct.group] = agAct.grpName;
ErrLine = "13";
}
ErrLine = "14";
}
else
{
//print("part attached not detect");
//Debug.Log("part attached not detect");
}
ErrLine = "15";
if (!disablePartAttaching)
{
DetachedPartActions.Add(agAct);
}
}
ErrLine = "16";
AttachAGXPart(host_target.host);
foreach (Part p in host_target.host.FindChildParts<Part>(true)) //action only fires for part clicked on, have to parse all child parts this way
{
ErrLine = "17";
agxMod = p.Modules.OfType<ModuleAGX>().First();
ErrLine = "18";
foreach (AGXAction agAct in agxMod.agxActionsThisPart)
{
ErrLine = "19";
if (!disablePartAttaching)
{
DetachedPartActions.Add(agAct);
}
if (!StaticData.CurrentVesselActions.Contains(agAct))
{
//print("adding action " + agAct.ba.guiName + agAct.group);
ErrLine = "20";
StaticData.CurrentVesselActions.Add(agAct);
ErrLine = "21";
if (AGXguiNames[agAct.group].Length == 0)
{
ErrLine = "22";
AGXguiNames[agAct.group] = agAct.grpName;
ErrLine = "23";
}
}
}
AttachAGXPart(p);
}
DetachedPartReset.Start();
//RefreshDefaultActionsList();
//Debug.Log("Part attache fire end!" + StaticData.CurrentVesselActions.Count());
}
catch (Exception e)
{
print("AGX Part Attaching Fail: " + ErrLine + " " + e);
}
}
public void PartRemove(GameEvents.HostTargetAction<Part, Part> host_target)
{
string errLine = "1";
try
{
//Debug.Log("AGX Part Remove Event Fire!");
disablePartAttaching = false;
//.Log("AGX Part Remove Fire " + StaticData.CurrentVesselActions.Count());
errLine = "2";
UpdateAGXActionGroupNames();
errLine = "3";
//print("Part detached! " + host_target.target.ConstructID);
DetachedPartActions.AddRange(StaticData.CurrentVesselActions.Where(p3 => p3.ba.listParent.part == host_target.target)); //add actiongroups on this part to List
errLine = "4";
foreach (Part p in host_target.target.FindChildParts<Part>(true)) //action only fires for part clicked on, have to parse all child parts this way
{
errLine = "5";
// print("Part detached2! " + p.ConstructID);
DetachedPartActions.AddRange(StaticData.CurrentVesselActions.Where(p3 => p3.ba.listParent.part == p)); //add parts to list
errLine = "6";
}
errLine = "7";
DetachedPartReset.Stop(); //stop timer so it resets
// //print("Detach");
//start subassembly stuff
errLine = "8";
ModuleAGX agxMod = host_target.target.Modules.OfType<ModuleAGX>().First();
errLine = "9";
agxMod.agxActionsThisPart.AddRange(StaticData.CurrentVesselActions.Where(p3 => p3.ba.listParent.part == host_target.target));
errLine = "10";
foreach (Part p in host_target.target.FindChildParts<Part>(true)) //action only fires for part clicked on, have to parse all child parts this way
{
errLine = "11";
agxMod = p.Modules.OfType<ModuleAGX>().First();
errLine = "12";
agxMod.agxActionsThisPart.AddRange(StaticData.CurrentVesselActions.Where(p3 => p3.ba.listParent.part == p)); //add parts to list
errLine = "13";
}
errLine = "14";
//Debug.Log("AGX Part Remove Fire " + StaticData.CurrentVesselActions.Count());
}
catch (Exception e)
{
print("AGX PartRemove FAIL " + errLine + " " + e);
}
}
public static void UpdateAGXActionGroupNames()
{
foreach (AGXAction agAct in StaticData.CurrentVesselActions)
{
try
{
agAct.grpName = AGXguiNames[agAct.group];
}
catch
{
//empty, silently fail
}
}
}
//public void CheckExistingShips()
//{
// List<string> existingShipsList = new List<string>();
// string fileDir = new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/Ships/VAB";
// int fileLen = fileDir.Length;
// string[] fileList = Directory.GetFiles(fileDir);
// //print("sc3 " + loadShipList.Length);