diff --git a/AGExt/CommonMethods.cs b/AGExt/CommonMethods.cs index f30c82a..33b701b 100644 --- a/AGExt/CommonMethods.cs +++ b/AGExt/CommonMethods.cs @@ -10,21 +10,47 @@ namespace ActionGroupsExtended { - public class AGXMethods : PartModule + + + + public class ModuleAGX : PartModule { + [KSPField(isPersistant = true, guiActive = false, guiActiveEditor = false)] + public string placeHolder = "Hello World"; //Config nodes can behave wierd when empty, a part with no actions on it will have no data besides this line + //config nodes get added/removed via OnLoad/OnSave here + public List agxActionsThisPart = new List(); + + public override void OnStart(StartState state) + { + if(agxActionsThisPart == null) + { + agxActionsThisPart = new List(); + } + } - - //public static void SettingsWindow(int WindowID) - //{ - // if(GUI.Button(new Rect(10, 25, 130, 40), "Show KeyCodes in\nFlight Window")) - // { - // AGXFlight.FlightWinShowKeycodes = !AGXFlight.FlightWinShowKeycodes; - // } - - - // GUI.DragWindow(); - //} - }//AGXMethods closing bracket + public override void OnSave(ConfigNode node) + { + if(agxActionsThisPart.Count > 0) + { + foreach (AGXAction agAct in agxActionsThisPart) + { + ConfigNode actionNode = new ConfigNode("ACTION"); + actionNode = AGextScenario.SaveAGXActionVer2(agAct); + node.AddNode(actionNode); + } + } + } + + public override void OnLoad(ConfigNode node) + { + ConfigNode[] actionsNodes = node.GetNodes("ACTION"); + foreach(ConfigNode actionNode in actionsNodes) + { + agxActionsThisPart.Add(AGextScenario.LoadAGXActionVer2(actionNode,this.part,false)); + } + } + + }//ModuleAGX diff --git a/AGExt/Editor.cs b/AGExt/Editor.cs index 44eec8a..e45a9fb 100644 --- a/AGExt/Editor.cs +++ b/AGExt/Editor.cs @@ -525,7 +525,8 @@ public void Start() PartPlus.LoadImage(importPartPlus); PartPlus.Apply(); //EditorLoadFromFile(); - if (HighLogic.LoadedScene == GameScenes.EDITOR) + //if (HighLogic.LoadedScene == GameScenes.EDITOR) + if(EditorDriver.editorFacility == EditorFacility.VAB) { inVAB = true; } @@ -621,6 +622,19 @@ public void PartAttaching(GameEvents.HostTargetAction host_target) AttachAGXPart(p); } DetachedPartReset.Start(); + + ModuleAGX agxMod = host_target.host.Modules.OfType().First(); + foreach(AGXAction agAct in agxMod.agxActionsThisPart) + { + if(!CurrentVesselActions.Contains(agAct)) + { + CurrentVesselActions.Add(agAct); + } + } + + + + } public void PartRemove(GameEvents.HostTargetAction host_target) @@ -634,6 +648,14 @@ public void PartRemove(GameEvents.HostTargetAction host_target) } DetachedPartReset.Stop(); //stop timer so it resets // //print("Detach"); + //start subassembly stuff + ModuleAGX agxMod = host_target.target.Modules.OfType().First(); + agxMod.agxActionsThisPart.AddRange(CurrentVesselActions.Where(p3 => p3.ba.listParent.part == host_target.target)); + foreach (Part p in host_target.target.FindChildParts(true)) //action only fires for part clicked on, have to parse all child parts this way + { + agxMod.agxActionsThisPart.AddRange(CurrentVesselActions.Where(p3 => p3.ba.listParent.part == p)); //add parts to list + } + } public void CheckExistingShips() @@ -3033,9 +3055,8 @@ public static void LoadGroupNames(string LoadNames) //v2 done // } //} - + public void Update() - { if (checkShipsExist) @@ -3053,54 +3074,54 @@ public void Update() } - + EditorLogic ELCur = new EditorLogic(); ELCur = EditorLogic.fetch;//get current editor logic instance - - + + if (AGXDoLock && ELCur.editorScreen != EditorScreen.Actions) { ELCur.Unlock("AGXLock"); AGXDoLock = false; } - else if(AGXDoLock && !TrapMouse) + else if (AGXDoLock && !TrapMouse) { ELCur.Unlock("AGXLock"); AGXDoLock = false; } else if (!AGXDoLock && TrapMouse && ELCur.editorScreen == EditorScreen.Actions) { - ELCur.Lock(false,false,false,"AGXLock"); + ELCur.Lock(false, false, false, "AGXLock"); AGXDoLock = true; } - - + + if (ELCur.editorScreen == EditorScreen.Actions) //only show mod if on actions editor screen { - + ShowSelectedWin = true; } else { - + ShowSelectedWin = false; - - - - + + + + AGEditorSelectedParts.Clear();//mod is hidden, clear list so parts don't get orphaned in it - + PartActionsList.Clear(); - + ActionsListDirty = true; } - - if (ShowSelectedWin) + + if (ShowSelectedWin) { - + if (EditorActionGroups.Instance.GetSelectedParts() != null) //on first run, list is null { @@ -3108,46 +3129,46 @@ public void Update() if (ActionsListDirty) { UpdateActionsListCheck(); - + } if (EditorActionGroups.Instance.GetSelectedParts().Count > 0) //are there parts selected? { - + if (PreviousSelectedPart != EditorActionGroups.Instance.GetSelectedParts().First()) //has selected part changed? { - - if(!AGEditorSelectedParts.Any(p => p.AGPart==EditorActionGroups.Instance.GetSelectedParts().First())) //make sure selected part is not already in AGEdSelParts + + if (!AGEditorSelectedParts.Any(p => p.AGPart == EditorActionGroups.Instance.GetSelectedParts().First())) //make sure selected part is not already in AGEdSelParts { if (AGEditorSelectedParts.Count == 0) //no items in Selected Parts list, so just add selection { - AGEditorSelectedParts.AddRange(AGXAddSelectedPart(EditorActionGroups.Instance.GetSelectedParts().First(),SelPartsIncSym)); - + AGEditorSelectedParts.AddRange(AGXAddSelectedPart(EditorActionGroups.Instance.GetSelectedParts().First(), SelPartsIncSym)); + } else if (AGEditorSelectedParts.First().AGPart.name == EditorActionGroups.Instance.GetSelectedParts().First().name) //selected part matches first part already in selected parts list, so just add selected part { - AGEditorSelectedParts.AddRange(AGXAddSelectedPart(EditorActionGroups.Instance.GetSelectedParts().First(),SelPartsIncSym)); - + AGEditorSelectedParts.AddRange(AGXAddSelectedPart(EditorActionGroups.Instance.GetSelectedParts().First(), SelPartsIncSym)); + } else //part does not match first part in list, clear list before adding part { - + AGEditorSelectedParts.Clear(); - AGEditorSelectedParts.AddRange(AGXAddSelectedPart(EditorActionGroups.Instance.GetSelectedParts().First(),SelPartsIncSym)); - + AGEditorSelectedParts.AddRange(AGXAddSelectedPart(EditorActionGroups.Instance.GetSelectedParts().First(), SelPartsIncSym)); + } } PreviousSelectedPart = EditorActionGroups.Instance.GetSelectedParts().First(); //remember selected part so logic does not run unitl another part selected } - + } } - + } @@ -3158,9 +3179,12 @@ public void Update() if (AGXRoot != EditorLogic.RootPart) { - // print("Root diff"); + // print("Root diff"); EditorLoadFromNode(); } + + // print("test " + FindObjectsOfType().Count()); + } //close Update() //if(needToAddStockButton) //{ // if (ApplicationLauncher.Ready) @@ -3184,7 +3208,7 @@ public void Update() //PrintSelectedPart(); //print("Keyset " + CurrentKeySet); - } + public void PrintSelectedPart() { diff --git a/AGExt/External.cs b/AGExt/External.cs index 5fb4387..dfa8407 100644 --- a/AGExt/External.cs +++ b/AGExt/External.cs @@ -280,14 +280,28 @@ public static bool AGXGroupState(int i) //is a group activated? } } - public class AGXAction : MonoBehaviour //basic data class for AGX mod, used everywhere + public class AGXAction : MonoBehaviour, IEquatable //basic data class for AGX mod, used everywhere { public Part prt; public BaseAction ba; public int group; public bool activated = false; + + public bool Equals(AGXAction obj) + { + if(this.prt == obj.prt && this.ba == obj.ba && this.group == obj.group) + { + return true; + } + else + { + return false; + } + } + +} - } + public class AGXDefaultCheck : MonoBehaviour //used in Editor to monitor default action groups { diff --git a/AGExt/Flight.cs b/AGExt/Flight.cs index d9bc346..b40ec41 100644 --- a/AGExt/Flight.cs +++ b/AGExt/Flight.cs @@ -4525,7 +4525,7 @@ public void Update() } //PrintPartActs(); - //print("Keyset " + CurrentKeySetFlight); + //print("landed " + FlightGlobals.ActiveVessel.landedAt); } catch(Exception e) { diff --git a/AGExt/Instantly.cs b/AGExt/Instantly.cs index 85c21f6..f878723 100644 --- a/AGExt/Instantly.cs +++ b/AGExt/Instantly.cs @@ -15,7 +15,7 @@ public class AGXMainMenu :PartModule public void Start() { - print("AGExt Ver. 1.26 loaded"); + print("AGExt Ver. 1.27 loaded"); //below no longer needed with InputLockManager //AGXguiKeys = new Dictionary(); //AGExtNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.cfg");