public void MonitorDefaultActions() { //print("2a"); if (EditorActionGroups.Instance.GetSelectedParts() != null) //is a part selected? { if (EditorActionGroups.Instance.GetSelectedParts().Count > 0) //list can exist with no parts in it if you selected then unselect one { if(SelectedWithSym.Count == 0 || SelectedWithSym.First() != EditorActionGroups.Instance.GetSelectedParts().First()) //check if there is a previously selected part, if so check if its changed { //print("2b"); //parts are different SelectedWithSym.Clear(); //reset lastpart list SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts()); SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts); SelectedWithSymActions.Clear(); //reset actions list //print("2c"); foreach (Part prt in SelectedWithSym) { // print("2d"); foreach (BaseAction bap in prt.Actions) //get part actions { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare } foreach (PartModule pm in prt.Modules) //add actions from all partmodules { foreach (BaseAction bapm in pm.Actions) { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup }); } } } // print("2e"); } else //selected part is the same a previously selected part { // print("2f"); List<Part> PartsThisFrame = new List<Part>(); //get list of parts this update frame PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts()); PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts); // print("2g"); List<BaseAction> ThisFrameActions = new List<BaseAction>(); //get actions fresh again this update frame foreach (Part prt in PartsThisFrame) { // print("2h"); foreach (BaseAction bap in prt.Actions) { ThisFrameActions.Add(bap); } foreach (PartModule pm in prt.Modules) { foreach (BaseAction bapm in pm.Actions) { ThisFrameActions.Add(bapm); } } } //print("2i"); foreach (BaseAction ba2 in ThisFrameActions) //check each action's actiongroup enum against last update frames actiongroup enum { //print("2j"); AGXDefaultCheck ActionLastFrame = new AGXDefaultCheck(); //print("2j1"); ActionLastFrame = SelectedWithSymActions.Find(a => a.ba == ba2); // print("2j2"); if (ActionLastFrame.agrp != ba2.actionGroup) //actiongroup enum is different { // print("2j3"); int NewGroup = 0; //which actiongroup changed? if (KSPActionGroup.Custom01 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 1; } else if (KSPActionGroup.Custom02 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 2; } else if (KSPActionGroup.Custom03 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 3; } else if (KSPActionGroup.Custom04 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 4; } else if (KSPActionGroup.Custom05 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 5; } else if (KSPActionGroup.Custom06 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 6; } else if (KSPActionGroup.Custom07 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 7; } else if (KSPActionGroup.Custom08 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 8; } else if (KSPActionGroup.Custom09 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 9; } else if (KSPActionGroup.Custom10 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 10; } // print("2k"); if (NewGroup != 0) //if one of the other actiongroups (gear, lights) has changed, ignore it. newgroup will be the actiongroup if I want to process it. { AGXAction ToAdd = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false }; List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(CurrentVesselActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { CurrentVesselActions.Add(ToAdd); //SaveCurrentVesselActions(); } } ActionLastFrame.agrp = KSPActionGroup.None; ActionLastFrame.agrp = ActionLastFrame.agrp | ba2.actionGroup; // print("2l"); } } SelectedWithSymActions.Clear(); //reset actions list as one of the enums changed. // print("2k"); foreach (Part prt in SelectedWithSym) { foreach (BaseAction bap in prt.Actions) //get part actions { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare } foreach (PartModule pm in prt.Modules) //add actions from all partmodules { foreach (BaseAction bapm in pm.Actions) { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup }); } } } } } } // print("2l"); }
public static void EditorLoadFromFile() { //print("EDITORLoadFromFile called"); string errLine = "1"; CurrentVesselActions.Clear(); try { //ConfigNode AGXBaseNode = ConfigNode.Load(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg"); errLine = "2"; //if (File.Exists(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt.cfg")) //{ // errLine = "3"; // AGXBaseNode = ConfigNode.Load(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt.cfg"); // print("AGX ConfigNode Load Okay! (Loading)"); //} //else //{ // errLine = "4"; // print("AGX ConfigNode not found, creating..... (Loading)"); // errLine = "5"; // AGXBaseNode.AddValue("name", "Action Groups Extended save file"); // AGXBaseNode.AddNode("FLIGHT"); // errLine = "6"; // AGXBaseNode.AddNode("EDITOR"); // errLine = "7"; // AGXBaseNode.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt.cfg"); // errLine = "8"; //} //print("Load 1"); errLine = "9"; ConfigNode AGXEditorNode = new ConfigNode("EDITOR"); AGXEditorNode.AddValue("name", "editor"); //print("Load 2"); errLine = "9a"; if (File.Exists(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg")) { //print("Load 3"); errLine = "9b"; AGXEditorNode = ConfigNode.Load(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg"); //print("Load 4"); } else { errLine = "9c"; AGXEditorNode = new ConfigNode("EDITOR"); } errLine = "10"; string hashedShipName = AGextScenario.EditorHashShipName(EditorLogic.fetch.shipNameField.Text,inVAB); ConfigNode thisVsl = new ConfigNode(); if (AGXEditorNode.HasNode(hashedShipName)) { errLine = "11"; thisVsl = AGXEditorNode.GetNode(hashedShipName); } errLine = "12"; if (thisVsl.HasValue("currentKeyset")) { CurrentKeySet = Convert.ToInt32(thisVsl.GetValue("currenKeyset")); } else { CurrentKeySet = 1; } if (CurrentKeySet < 1 || CurrentKeySet > 5) { CurrentKeySet = 1; } errLine = "13"; if (thisVsl.HasValue("groupNames")) { LoadGroupNames(thisVsl.GetValue("groupNames")); } else { LoadGroupNames(""); } errLine = "14"; if (thisVsl.HasValue("groupVisibility")) { LoadGroupVisibility(thisVsl.GetValue("groupVisibility")); } else { LoadGroupVisibility(""); } errLine = "15"; if (thisVsl.HasValue("groupVisibilityNames")) { LoadGroupVisibilityNames(thisVsl.GetValue("groupVisibilityNames")); } else { LoadGroupVisibilityNames("Group1" + '\u2023' + "Group2" + '\u2023' + "Group3" + '\u2023' + "Group4" + '\u2023' + "Group5"); } foreach (ConfigNode prtNode in thisVsl.nodes) { Vector3 partLoc = new Vector3((float)Convert.ToDouble( prtNode.GetValue("relLocX")), (float)Convert.ToDouble( prtNode.GetValue("relLocY")), (float)Convert.ToDouble( prtNode.GetValue("relLocZ"))); float partDist = 100f; Part gamePart = new Part(); foreach (Part p in EditorLogic.SortedShipList) //do a distance compare check, floats do not guarantee perfect decimal accuray so use part with least distance, should be zero distance in most cases { float thisPartDist = Vector3.Distance(partLoc, p.transform.position - EditorLogic.startPod.transform.position); if (thisPartDist < partDist) { gamePart = p; partDist = thisPartDist; } } foreach (ConfigNode actNode in prtNode.nodes) { AGXAction actToAdd = AGextScenario.LoadAGXActionVer2(actNode, gamePart); if (actToAdd.ba != null) { CurrentVesselActions.Add(actToAdd); } } } List<KSPActionGroup> CustomActions = new List<KSPActionGroup>(); CustomActions.Add(KSPActionGroup.Custom01); //how do you add a range from enum? CustomActions.Add(KSPActionGroup.Custom02); CustomActions.Add(KSPActionGroup.Custom03); CustomActions.Add(KSPActionGroup.Custom04); CustomActions.Add(KSPActionGroup.Custom05); CustomActions.Add(KSPActionGroup.Custom06); CustomActions.Add(KSPActionGroup.Custom07); CustomActions.Add(KSPActionGroup.Custom08); CustomActions.Add(KSPActionGroup.Custom09); CustomActions.Add(KSPActionGroup.Custom10); errLine = "16"; // string AddGroup = ""; List<BaseAction> partAllActions = new List<BaseAction>(); //is all vessel actions, copy pasting code foreach (Part p in EditorLogic.SortedShipList) { partAllActions.AddRange(p.Actions); foreach(PartModule pm in p.Modules) { partAllActions.AddRange(pm.Actions); } } foreach (BaseAction baLoad in partAllActions) { foreach (KSPActionGroup agrp in CustomActions) { if ((baLoad.actionGroup & agrp) == agrp) { errLine = "17"; ////AddGroup = AddGroup + '\u2023' + (CustomActions.IndexOf(agrp) + 1).ToString("000") + baLoad.guiName; //partAGActions2.Add(new AGXAction() { group = CustomActions.IndexOf(agrp) + 1, prt = this.part, ba = baLoad, activated = false }); AGXAction ToAdd = new AGXAction() { prt = baLoad.listParent.part, ba = baLoad, group = CustomActions.IndexOf(agrp) + 1, activated = false }; List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(CurrentVesselActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { CurrentVesselActions.Add(ToAdd); } } } errLine = "18"; } } catch (Exception e) { print("AGXEd EditorLoadFromFile Fail " + errLine + " " + e); } }
public static ConfigNode SaveAGXActionVer2(AGXAction agxAct) { //print("Save called"); string errLine ="1"; try { ConfigNode actionNode = new ConfigNode("ACTION"); errLine ="2"; actionNode.AddValue("group", agxAct.group); errLine = "2a"; actionNode.AddValue("groupName", agxAct.grpName); errLine ="3"; actionNode.AddValue("activated",(agxAct.activated) ? "1":"0"); errLine ="4"; actionNode.AddValue("partModule", agxAct.ba.listParent.module.moduleName); errLine ="5"; actionNode.AddValue("actionGuiName", agxAct.ba.guiName); errLine ="6"; actionNode.AddValue("actionName", agxAct.ba.name); errLine ="7"; if (agxAct.ba.listParent.module.moduleName == "ModuleEnviroSensor") //add this to the agxactions list somehow and add to save.load serialze { errLine = "8"; ModuleEnviroSensor MSE = (ModuleEnviroSensor)agxAct.ba.listParent.module; errLine = "9"; actionNode.AddValue("custom1", MSE.sensorType); //u2020 is envirosensor errLine = "10"; } else if (agxAct.ba.listParent.module.moduleName == "ModuleScienceExperiment") //add this to the agxactions list somehow and add to save.load serialze { errLine = "11"; ModuleScienceExperiment MSE = (ModuleScienceExperiment)agxAct.ba.listParent.module; //all other modules use guiname errLine = "12"; actionNode.AddValue("custom1", MSE.experimentID); //u2021 is sciencemodule errLine = "13"; } else if (agxAct.ba.listParent.module.moduleName == "ModuleAnimateGeneric") //add this to the agxactions list somehow and add to save.load serialze { errLine = "14"; ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agxAct.ba.listParent.module; //all other modules use guiname errLine = "15"; actionNode.AddValue("custom1", MAnim.animationName); //u2021 is sciencemodule errLine = "16"; //print(MAnim.animationName); } else if (agxAct.ba.listParent.module.moduleName == "FSanimateGeneric") //add this to the agxactions list somehow and add to save.load serialze { errLine = "14"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agxAct.ba.listParent.module; //all other modules use guiname errLine = "15"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("animationName")); //u2021 is sciencemodule errLine = "16"; //print(MAnim.animationName); } else if (agxAct.ba.listParent.module.moduleName == "DMModuleScienceAnimate") //DMagic orbital science mod { errLine = "17"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "18"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("startEventGUIName")); //u2021 is sciencemodule errLine = "19"; } else if (agxAct.ba.listParent.module.moduleName == "DMSolarCollector") //DMagic orbital science mod { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("startEventGUIName")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "BTSMModuleCrewReport" || agxAct.ba.listParent.module.moduleName == "BTSMModuleScienceExperiment" || agxAct.ba.listParent.module.moduleName == "BTSMModuleScienceExperimentWithTime") //DMagic orbital science mod { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("experimentActionName")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "BTSMModuleResourceActionToggle") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("resourceName")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "SCANsat") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("scanName")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "ModuleEnginesFX") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("engineID")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "RealChuteModule") // { //RealChute needs no extra data saved, just add this for tracking so I know it is saving as exception. errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; //actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("engineID")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "REGO_ModuleAnimationGroup") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", (string)agxAct.ba.listParent.module.Fields.GetValue("deployAnimationName") + (string)agxAct.ba.listParent.module.Fields.GetValue("activeAnimationName")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "REGO_ModuleResourceHarvester") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", (string)agxAct.ba.listParent.module.Fields.GetValue("RecipeInputs") + (string)agxAct.ba.listParent.module.Fields.GetValue("ResourceName")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "REGO_ModuleResourceConverter") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", (string)agxAct.ba.listParent.module.Fields.GetValue("RecipeInputs") + (string)agxAct.ba.listParent.module.Fields.GetValue("RecipeOutputs")); //u2021 is sciencemodule errLine = "22"; } else if (agxAct.ba.listParent.module.moduleName == "REGO_ModuleAsteroidDrill") // { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", (string)agxAct.ba.listParent.module.Fields.GetValue("ImpactTransform")); //u2021 is sciencemodule errLine = "22"; } //BTSMModuleReactionWheel does not need custom save, just load else //if (agAct.ba.listParent.module.moduleName == "ModuleScienceExperiment") //add this to the agxactions list somehow and add to save.load serialze { errLine = "23"; //ModuleScienceExperiment MSE = (ModuleScienceExperiment)agAct.ba.listParent.module; //all other modules use guiname actionNode.AddValue("custom1","NA"); //u2021 is sciencemodule errLine = "24"; } return actionNode; } catch(Exception e) { print("AGX SaveAGXAction2 FAIL " + errLine+ " " + agxAct.prt.partName+" " + agxAct.ba.name+ " " + e); return new ConfigNode(); } }
public void SelParts(int WindowID) { HighLogic.Skin.scrollView.normal.background = null; SelectedPartsCount = AGEditorSelectedParts.Count; int SelPartsLeft = new int(); SelPartsLeft = -10; //GUI.DrawTexture(new Rect(25, 30, 80, PartsScrollHeight), TexBlk, ScaleMode.StretchToFill, false); //AGXPart FirstPart = new AGXPart(); // FirstPart = AGEditorSelectedParts.First().AGPart.name; GUI.Box(new Rect(SelPartsLeft + 20, 25, 200, 110), ""); highlightPartThisFrameSelWin = false; if (AGEditorSelectedParts != null && AGEditorSelectedParts.Count > 0) { int ButtonCount = new int(); ButtonCount = 1; ScrollPosSelParts = GUI.BeginScrollView(new Rect(SelPartsLeft + 20, 30, 220, 110), ScrollPosSelParts, new Rect(0, 0, 200, (20 * Math.Max(5, SelectedPartsCount)) + 10)); //GUI.Box(new Rect(SelPartsLeft, 25, 200, (20 * Math.Max(5, SelectedPartsCount)) + 10), ""); while (ButtonCount <= SelectedPartsCount) { //Rect buttonRect = new Rect(5, 0 + ((ButtonCount - 1) * 20), 190, 20); //need this rectangle twice if (Mouse.screenPos.y >= SelPartsWin.y + 30 && Mouse.screenPos.y <= SelPartsWin.y + 140 && new Rect(SelPartsWin.x + SelPartsLeft + 25, (SelPartsWin.y + 30 + ((ButtonCount - 1) * 20)) - ScrollPosSelParts.y, 190, 20).Contains(Mouse.screenPos)) { highlightPartThisFrameSelWin = true; //print("part found to highlight " + AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.ConstructID); partToHighlight = AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart; } if (GUI.Button(new Rect(5, 0 + ((ButtonCount - 1) * 20), 190, 20), AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.partInfo.title, AGXBtnStyle)) { AGEditorSelectedParts.RemoveAt(ButtonCount - 1); if (AGEditorSelectedParts.Count == 0) { AGEEditorSelectedPartsSame = false; } return; } ButtonCount = ButtonCount + 1; } GUI.EndScrollView(); } else //no parts selected, show list all parts button? { if (GUI.Button(new Rect(SelPartsLeft + 50, 45, 140, 70), "Show list of\nall parts?", AGXBtnStyle)) //button itself { showAllPartsListTitles = new List<string>(); //generate list of all parts showAllPartsListTitles.Clear(); //this probably isn't needed, but it works as is, not messing with it foreach (Part p in EditorLogic.SortedShipList) //cycle all parts { List<BaseAction> actCheck = new List<BaseAction>(); //start check to see if p has any actions actCheck.AddRange(p.Actions); //add actions on part foreach(PartModule pm in p.Modules) //add actions from each partModule on part { actCheck.AddRange(pm.Actions); } if(actCheck.Count >0) //only add part to showAllPartsListTitles if part has actions on it { if (!showAllPartsListTitles.Contains(p.partInfo.title)) { showAllPartsListTitles.Add(p.partInfo.title); } } } showAllPartsListTitles.Sort(); //sort alphabetically //ScrollGroups = Vector2.zero; showAllPartsList = true; //change groups win to all parts list TempShowGroupsWin = true; // if autohide enabled, show group win } } if (SelPartsIncSym) { //GUI.DrawTexture(new Rect(SelPartsLeft + 246, 26, 108, 23), BtnTexGrn, ScaleMode.StretchToFill, false); AGXBtnStyle.normal.background = ButtonTextureGreen; BtnTxt = "Symmetry? Yes"; } else { //GUI.DrawTexture(new Rect(SelPartsLeft + 246, 26, 108, 23), BtnTexRed, ScaleMode.StretchToFill, false); AGXBtnStyle.normal.background = ButtonTextureRed; BtnTxt = "Symmetry? No"; } if (GUI.Button(new Rect(SelPartsLeft + 245, 25, 110, 25), BtnTxt, AGXBtnStyle)) { SelPartsIncSym = !SelPartsIncSym; } AGXBtnStyle.normal.background = ButtonTexture; if (GUI.Button(new Rect(SelPartsLeft + 245, 55, 110, 25), "Clear List", AGXBtnStyle)) { AGEditorSelectedParts.Clear(); PartActionsList.Clear(); AGEEditorSelectedPartsSame = false; } GUI.Box(new Rect(SelPartsLeft + 20, 150, 200, 110), ""); if (AGEEditorSelectedPartsSame) { if (PartActionsList.Count > 0) { int ActionsCount = new int(); int ActionsCountTotal = new int(); ActionsCount = 1; ActionsCountTotal = PartActionsList.Count; ScrollPosSelPartsActs = GUI.BeginScrollView(new Rect(SelPartsLeft + 20, 155, 220, 110), ScrollPosSelPartsActs, new Rect(0, 0, 200, (20 * Math.Max(5, ActionsCountTotal)) + 10)); while (ActionsCount <= ActionsCountTotal) { if (GUI.Button(new Rect(5, 0 + ((ActionsCount - 1) * 20), 190, 20), PartActionsList.ElementAt(ActionsCount - 1).guiName, AGXBtnStyle)) { int PrtCnt = new int(); PrtCnt = 0; foreach (AGXPart agPrt in AGEditorSelectedParts) { List<BaseAction> ThisPartActionsList = new List<BaseAction>(); ThisPartActionsList.AddRange(agPrt.AGPart.Actions); foreach (PartModule pm3 in agPrt.AGPart.Modules) { ThisPartActionsList.AddRange(pm3.Actions); } AGXAction ToAdd = new AGXAction(); if (ThisPartActionsList.ElementAt(ActionsCount - 1).guiName == PartActionsList.ElementAt(ActionsCount - 1).guiName) { ToAdd = new AGXAction() { prt = agPrt.AGPart, ba = ThisPartActionsList.ElementAt(ActionsCount - 1), group = AGXCurActGroup, activated = false }; } else { ToAdd = new AGXAction() { prt = agPrt.AGPart, ba = PartActionsList.ElementAt(ActionsCount - 1), group = AGXCurActGroup, activated = false }; } List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(CurrentVesselActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { CurrentVesselActions.Add(ToAdd); //SaveCurrentVesselActions(); } PrtCnt = PrtCnt + 1; if (ToAdd.group < 11) { SetDefaultAction(ToAdd.ba, ToAdd.group); } } } ActionsCount = ActionsCount + 1; } GUI.EndScrollView(); } else { if (AGEditorSelectedParts.Count >= 1) { if (GUI.Button(new Rect(SelPartsLeft + 30, 190, 185, 40), "No actions found.\r\nRefresh?", AGXBtnStyle)) { PartActionsList.Clear(); PartActionsList.AddRange(AGEditorSelectedParts.First().AGPart.Actions); foreach (PartModule pm in AGEditorSelectedParts.First().AGPart.Modules) { PartActionsList.AddRange(pm.Actions); } print("AGX Actions refresh found actions: " + PartActionsList.Count); } } } // } else { TextAnchor TxtAnch = new TextAnchor(); TxtAnch = GUI.skin.label.alignment; //GUI.skin.label.alignment = TextAnchor.MiddleCenter; AGXLblStyle.alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(SelPartsLeft + 20, 180, 190, 40), "Select parts of\nthe same type",AGXLblStyle); AGXLblStyle.alignment = TextAnchor.MiddleLeft; //GUI.skin.label.alignment = TxtAnch; } TextAnchor TxtAnch2 = new TextAnchor(); TxtAnch2 = GUI.skin.button.alignment; //GUI.skin.button.alignment = TextAnchor.MiddleLeft; AGXBtnStyle.alignment = TextAnchor.MiddleLeft; if (GUI.Button(new Rect(SelPartsLeft + 245, 85, 120, 30), AGXCurActGroup + ": " + AGXguiNames[AGXCurActGroup], AGXBtnStyle)) { TempShowGroupsWin = true; } //GUI.skin.button.alignment = TxtAnch2; AGXBtnStyle.alignment = TextAnchor.MiddleCenter; if (IsGroupToggle[AGXCurActGroup]) { Color TxtClr = GUI.contentColor; GUI.contentColor = Color.green; if (GUI.Button(new Rect(SelPartsLeft + 245, 160, 110, 22), "Toggle Grp: Yes", AGXBtnStyle)) { IsGroupToggle[AGXCurActGroup] = false; } GUI.contentColor = TxtClr; } else { if (GUI.Button(new Rect(SelPartsLeft + 245, 160, 110, 22), "Toggle Grp: No", AGXBtnStyle)) { IsGroupToggle[AGXCurActGroup] = true; } } GUI.Label(new Rect(SelPartsLeft + 231, 183, 110, 22), "Show:",AGXLblStyle); Color TxtClr2 = GUI.contentColor; if (ShowGroupInFlight[1, AGXCurActGroup]) { GUI.contentColor = Color.green; } else { GUI.contentColor = Color.red; } if (GUI.Button(new Rect(SelPartsLeft + 271, 183, 20, 22), "1", AGXBtnStyle)) { ShowGroupInFlight[1, AGXCurActGroup] = !ShowGroupInFlight[1, AGXCurActGroup]; } if (ShowGroupInFlight[2, AGXCurActGroup]) { GUI.contentColor = Color.green; } else { GUI.contentColor = Color.red; } if (GUI.Button(new Rect(SelPartsLeft + 291, 183, 20, 22), "2", AGXBtnStyle)) { ShowGroupInFlight[2, AGXCurActGroup] = !ShowGroupInFlight[2, AGXCurActGroup]; //CalculateActionsToShow(); } if (ShowGroupInFlight[3, AGXCurActGroup]) { GUI.contentColor = Color.green; } else { GUI.contentColor = Color.red; } if (GUI.Button(new Rect(SelPartsLeft + 311, 183, 20, 22), "3", AGXBtnStyle)) { ShowGroupInFlight[3, AGXCurActGroup] = !ShowGroupInFlight[3, AGXCurActGroup]; //CalculateActionsToShow(); } if (ShowGroupInFlight[4, AGXCurActGroup]) { GUI.contentColor = Color.green; } else { GUI.contentColor = Color.red; } if (GUI.Button(new Rect(SelPartsLeft + 331, 183, 20, 22), "4", AGXBtnStyle)) { ShowGroupInFlight[4, AGXCurActGroup] = !ShowGroupInFlight[4, AGXCurActGroup]; // CalculateActionsToShow(); } if (ShowGroupInFlight[5, AGXCurActGroup]) { GUI.contentColor = Color.green; } else { GUI.contentColor = Color.red; } if (GUI.Button(new Rect(SelPartsLeft + 351, 183, 20, 22), "5", AGXBtnStyle)) { ShowGroupInFlight[5, AGXCurActGroup] = !ShowGroupInFlight[5, AGXCurActGroup]; // CalculateActionsToShow(); } GUI.contentColor = TxtClr2; GUI.Label(new Rect(SelPartsLeft + 245, 115, 110, 20), "Description:",AGXLblStyle); CurGroupDesc = AGXguiNames[AGXCurActGroup]; CurGroupDesc = GUI.TextField(new Rect(SelPartsLeft + 245, 135, 120, 22), CurGroupDesc,AGXFldStyle); AGXguiNames[AGXCurActGroup] = CurGroupDesc; GUI.Label(new Rect(SelPartsLeft + 245, 203, 110, 25), "Keybinding:",AGXLblStyle); if (GUI.Button(new Rect(SelPartsLeft + 245, 222, 120, 20), AGXguiKeys[AGXCurActGroup].ToString(),AGXBtnStyle)) { ShowKeyCodeWin = true; } if (GUI.Button(new Rect(SelPartsLeft + 245, 244, 120, 20),CurrentKeySetName,AGXBtnStyle)) { //print("1a"); SaveCurrentKeyBindings(); //print("2a"); KeySetNames[0] = AGExtNode.GetValue("KeySetName1"); //print("3a"); KeySetNames[1] = AGExtNode.GetValue("KeySetName2"); KeySetNames[2] = AGExtNode.GetValue("KeySetName3"); KeySetNames[3] = AGExtNode.GetValue("KeySetName4"); KeySetNames[4] = AGExtNode.GetValue("KeySetName5"); //print("4a"); //print("cure key " + CurrentKeySet); KeySetNames[CurrentKeySet - 1] = CurrentKeySetName; //print("5a"); ShowKeySetWin = true; //print("6a"); } GUI.DragWindow(); }
public static ConfigNode SaveAGXActionVer2(AGXAction agxAct) { string errLine ="1"; try { ConfigNode actionNode = new ConfigNode("ACTION"); errLine ="2"; actionNode.AddValue("group", agxAct.group); errLine ="3"; actionNode.AddValue("activated",(agxAct.activated) ? "1":"0"); errLine ="4"; actionNode.AddValue("partModule", agxAct.ba.listParent.module.moduleName); errLine ="5"; actionNode.AddValue("actionGuiName", agxAct.ba.guiName); errLine ="6"; actionNode.AddValue("actionName", agxAct.ba.name); errLine ="7"; if (agxAct.ba.listParent.module.moduleName == "ModuleEnviroSensor") //add this to the agxactions list somehow and add to save.load serialze { errLine = "8"; ModuleEnviroSensor MSE = (ModuleEnviroSensor)agxAct.ba.listParent.module; errLine = "9"; actionNode.AddValue("custom1", MSE.sensorType); //u2020 is envirosensor errLine = "10"; } else if (agxAct.ba.listParent.module.moduleName == "ModuleScienceExperiment") //add this to the agxactions list somehow and add to save.load serialze { errLine = "11"; ModuleScienceExperiment MSE = (ModuleScienceExperiment)agxAct.ba.listParent.module; //all other modules use guiname errLine = "12"; actionNode.AddValue("custom1", MSE.experimentID); //u2021 is sciencemodule errLine = "13"; } else if (agxAct.ba.listParent.module.moduleName == "ModuleAnimateGeneric") //add this to the agxactions list somehow and add to save.load serialze { errLine = "14"; ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agxAct.ba.listParent.module; //all other modules use guiname errLine = "15"; actionNode.AddValue("custom1", MAnim.animationName); //u2021 is sciencemodule errLine = "16"; //print(MAnim.animationName); } else if (agxAct.ba.listParent.module.moduleName == "DMModuleScienceAnimate") //DMagic orbital science mod { errLine = "17"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "18"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("startEventGUIName")); //u2021 is sciencemodule errLine = "19"; } else if (agxAct.ba.listParent.module.moduleName == "DMSolarCollector") //DMagic orbital science mod { errLine = "20"; //ModuleAnimateGeneric MAnim = (ModuleAnimateGeneric)agAct.ba.listParent.module; //all other modules use guiname errLine = "21"; actionNode.AddValue("custom1", agxAct.ba.listParent.module.Fields.GetValue("startEventGUIName")); //u2021 is sciencemodule errLine = "22"; } else //if (agAct.ba.listParent.module.moduleName == "ModuleScienceExperiment") //add this to the agxactions list somehow and add to save.load serialze { errLine = "23"; //ModuleScienceExperiment MSE = (ModuleScienceExperiment)agAct.ba.listParent.module; //all other modules use guiname actionNode.AddValue("custom1","NA"); //u2021 is sciencemodule errLine = "24"; } return actionNode; } catch(Exception e) { print("AGX SaveAGXAction2 FAIL " + errLine+ " " + agxAct.prt.partName+" " + agxAct.ba.name+ " " + e); return new ConfigNode(); } }
public static AGXAction LoadAGXActionVer2(ConfigNode actNode, Part actPart, bool showAmbiguousMessage) { string errLine ="1"; //print("load action " + actPart.partName + " " + actNode); try { errLine = "2"; AGXAction ActionToLoad = new AGXAction(); //create action we are loading errLine = "2aa"; ActionToLoad.prt = actPart; //assign part errLine = "2bb"; ActionToLoad.group = Convert.ToInt32(actNode.GetValue("group")); //assign group errLine = "2cc"; if (actNode.HasValue("groupName")) { ActionToLoad.grpName = actNode.GetValue("groupName"); //assign group } errLine = "2a"; if (actNode.GetValue("activated") == "1") //assign activated { ActionToLoad.activated = true; } else { ActionToLoad.activated = false; } errLine = "2b"; string pmName = actNode.GetValue("partModule");//get partModule name List<BaseAction> actsToCompare = new List<BaseAction>(); //create list of actions we will compare to errLine = "2c"; if (pmName == "ModuleEnviroSensor") { string sensorType = actNode.GetValue("custom1"); foreach (PartModule pmSensor in actPart.Modules.OfType<ModuleEnviroSensor>()) { ModuleEnviroSensor mesSensor = (ModuleEnviroSensor)pmSensor; if (mesSensor.sensorType == sensorType) { actsToCompare.AddRange(mesSensor.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "ModuleScienceExperiment") { string expID = actNode.GetValue("custom1"); foreach (PartModule pmSensor in actPart.Modules.OfType<ModuleScienceExperiment>()) { ModuleScienceExperiment mesExp = (ModuleScienceExperiment)pmSensor; if (mesExp.experimentID == expID) { actsToCompare.AddRange(mesExp.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); // actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "ModuleAnimateGeneric") { string animName = actNode.GetValue("custom1"); foreach (PartModule pmSensor in actPart.Modules.OfType <ModuleAnimateGeneric>()) { ModuleAnimateGeneric mesExp = (ModuleAnimateGeneric)pmSensor; if (mesExp.animationName == animName) { actsToCompare.AddRange(mesExp.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "FSanimateGeneric") { //print("load it"); string animName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { //ModuleAnimateGeneric mesExp = (ModuleAnimateGeneric)pmSensor; if (pm.moduleName == pmName) { if ((string)pm.Fields.GetValue("animationName") == animName) { actsToCompare.AddRange(pm.Actions); } } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "DMModuleScienceAnimate") { string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); actsToCompare.RemoveAll(b3 => (string)b3.listParent.module.Fields.GetValue("startEventGUIName") != (string)startEventName); } else if (pmName == "DMSolarCollector") { string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); actsToCompare.RemoveAll(b3 => (string)b3.listParent.module.Fields.GetValue("startEventGUIName") != (string)startEventName); } else if (pmName == "BTSMModuleReactionWheel") { //string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); //actsToCompare.RemoveAll(b3 => b3.listParent.module.Fields.GetValue("startEventGUIName") != startEventName); } else if (pmName == "BTSMModuleCrewReport" || pmName == "BTSMModuleScienceExperiment" || pmName == "BTSMModuleScienceExperimentWithTime") { string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); actsToCompare.RemoveAll(b3 => (string)b3.listParent.module.Fields.GetValue("experimentActionName") != (string)startEventName); } else if (pmName == "BTSMModuleResourceActionToggle") { string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); // print("Batest " + actNode.GetValue("actionName") + " " + pm.Fields.GetValue("resourceName") + " " + startEventName); } } //foreach (BaseAction ba6 in actsToCompare) //{ // print("1 " + ba6.name + " " + ba6.listParent.module.Fields.GetValue("resourceName")); //} actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //foreach (BaseAction ba6 in actsToCompare) //{ // print("2 " + ba6.name + " " + ba6.listParent.module.Fields.GetValue("resourceName")); //} //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); //print("2a " + startEventName); actsToCompare.RemoveAll(b3 => (string)b3.listParent.module.Fields.GetValue("resourceName") != (string)startEventName); //foreach (BaseAction ba6 in actsToCompare) //{ // print("3 " + ba6.name + " " + ba6.listParent.module.Fields.GetValue("resourceName")); //} } else if (pmName == "Capacitor" || pmName == "DischargeCapacitor") //NearFutureElectrical { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == "Capacitor" || pm.moduleName == "DischargeCapacitor") { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "FissionReprocessor" || pmName == "Nuclear Fuel Reprocessor") //NearFutureElectrical { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == "FissionReprocessor" || pm.moduleName == "Nuclear Fuel Reprocessor") { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "FissionGenerator" || pmName == "Fission Reactor") //NearFutureElectrical { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == "FissionGenerator" || pm.moduleName == "Fission Reactor") { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "ModuleCurvedSolarPanel" || pmName == "Curved Solar Panel") //NearFutureSolar { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == "ModuleCurvedSolarPanel" || pm.moduleName == "Curved Solar Panel") { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "VariableISPEngine" || pmName == "Variable ISP Engine") //NearFutureSolar { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == "VariableISPEngine" || pm.moduleName == "Variable ISP Engine") { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "ModuleRTAntenna") //Remotetech { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); // actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "SCANsat") //Remotetech { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => (string)b2.listParent.module.Fields.GetValue("scanName") != (string)actNode.GetValue("custom1")); } } else if (pmName == "ModuleEnginesFX") { foreach (ModuleEnginesFX pm in actPart.Modules.OfType<ModuleEnginesFX>()) //add actions to compare { //print("Fields " + (string)pm.Fields.GetValue("engineID") + "||" + (string)actNode.GetValue("custom1")); if ((string)pm.Fields.GetValue("engineID") == (string)actNode.GetValue("custom1")) { actsToCompare.AddRange(pm.Actions); //print("Acts to compare " + actsToCompare.Count + " " + pm.Actions.Count + pm.name + pm.moduleName); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => (string)b2.listParent.module.Fields.GetValue("scanName") != (string)actNode.GetValue("custom1")); } } else if (pmName == "RealChuteModule") { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } else if (pmName == "REGO_ModuleAnimationGroup") { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => (string)b2.listParent.module.Fields.GetValue("deployAnimationName") + (string)b2.listParent.module.Fields.GetValue("activeAnimationName") != (string)actNode.GetValue("custom1")); } } else if (pmName == "REGO_ModuleResourceHarvester") { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => (string)b2.listParent.module.Fields.GetValue("RecipeInputs") + (string)b2.listParent.module.Fields.GetValue("ResourceName") != (string)actNode.GetValue("custom1")); } } else if (pmName == "REGO_ModuleResourceConverter") { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => (string)b2.listParent.module.Fields.GetValue("RecipeInputs") + (string)b2.listParent.module.Fields.GetValue("RecipeOutputs") != (string)actNode.GetValue("custom1")); } } else if (pmName == "REGO_ModuleAsteroidDrill") { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => (string)b2.listParent.module.Fields.GetValue("ImpactTransform") != (string)actNode.GetValue("custom1")); } } else if (pmName == "ModuleModActions") //guiName is player editable so can't be used. { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); } } else { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != (string)actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != (string)actNode.GetValue("actionGuiName")); } } errLine = "3"; //print("ActsCount " + actsToCompare.Count); if (actsToCompare.Count != 1) { errLine = "4"; print("AGX actsToCompare.count != 1 "+actsToCompare.Count + " Part: " + actPart.name + " Module: " + actNode.GetValue("partModule") + " " + actNode.GetValue("actionName")); //if (showAmbiguousMessage) //{ // ScreenMessages.PostScreenMessage("AGX Load Action ambiguous. Count: " + actsToCompare.Count, 10F, ScreenMessageStyle.UPPER_CENTER); //} } errLine = "5"; if (actsToCompare.Count > 0) { // print("ActsCounta"); errLine = "6"; ActionToLoad.ba = actsToCompare.First(); //action to load assign action, ready to return } else { errLine = "7"; // print("ActsCountb"); ActionToLoad.ba = null; } errLine = "8"; //print("load action2 " + ActionToLoad.ba.name + " " + ActionToLoad.group); //print("agx check " + actsToCompare.Count + " " + ActionToLoad.group + ActionToLoad.ba.name); //print("actual act " + ActionToLoad + " " + ActionToLoad.ba.name); //print("BA load " + ActionToLoad.ba.name + " " + ActionToLoad.ba.listParent.part.ConstructID + " " + ActionToLoad.prt.ConstructID); return ActionToLoad; } catch (Exception e) { print("AGXLoadAGXAction2 FAIL " + errLine + " " + e); AGXAction rtnAgx = new AGXAction(); rtnAgx.ba = null; return rtnAgx; } }
public static AGXAction LoadAGXActionVer2(ConfigNode actNode, Part actPart) { string errLine ="1"; //print("load action " + actPart.partName + " " + actNode); try { errLine = "2"; AGXAction ActionToLoad = new AGXAction(); //create action we are loading ActionToLoad.prt = actPart; //assign part ActionToLoad.group = Convert.ToInt32(actNode.GetValue("group")); //assign group errLine = "2a"; if (actNode.GetValue("activated") == "1") //assign activated { ActionToLoad.activated = true; } else { ActionToLoad.activated = false; } errLine = "2b"; string pmName = actNode.GetValue("partModule");//get partModule name List<BaseAction> actsToCompare = new List<BaseAction>(); //create list of actions we will compare to errLine = "2c"; if (pmName == "ModuleEnviroSensor") { string sensorType = actNode.GetValue("custom1"); foreach (PartModule pmSensor in actPart.Modules.OfType<ModuleEnviroSensor>()) { ModuleEnviroSensor mesSensor = (ModuleEnviroSensor)pmSensor; if (mesSensor.sensorType == sensorType) { actsToCompare.AddRange(mesSensor.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "ModuleScienceExperiment") { string expID = actNode.GetValue("custom1"); foreach (PartModule pmSensor in actPart.Modules.OfType<ModuleScienceExperiment>()) { ModuleScienceExperiment mesExp = (ModuleScienceExperiment)pmSensor; if (mesExp.experimentID == expID) { actsToCompare.AddRange(mesExp.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "ModuleAnimateGeneric") { string animName = actNode.GetValue("custom1"); foreach (PartModule pmSensor in actPart.Modules.OfType <ModuleAnimateGeneric>()) { ModuleAnimateGeneric mesExp = (ModuleAnimateGeneric)pmSensor; if (mesExp.animationName == animName) { actsToCompare.AddRange(mesExp.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } else if (pmName == "DMModuleScienceAnimate") { string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); actsToCompare.RemoveAll(b3 => b3.listParent.module.Fields.GetValue("startEventGUIName") != startEventName); } else if (pmName == "DMSolarCollector") { string startEventName = actNode.GetValue("custom1"); foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); //actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); actsToCompare.RemoveAll(b3 => b3.listParent.module.Fields.GetValue("startEventGUIName") != startEventName); } else { foreach (PartModule pm in actPart.Modules) //add actions to compare { if (pm.moduleName == pmName) { actsToCompare.AddRange(pm.Actions); } actsToCompare.RemoveAll(b => b.name != actNode.GetValue("actionName")); actsToCompare.RemoveAll(b2 => b2.guiName != actNode.GetValue("actionGuiName")); } } errLine = "3"; //print("ActsCount " + actsToCompare.Count); if (actsToCompare.Count != 1) { errLine = "4"; print("AGX actsToCompare.count != 1 "+actsToCompare.Count); } errLine = "5"; if (actsToCompare.Count > 0) { // print("ActsCounta"); errLine = "6"; ActionToLoad.ba = actsToCompare.First(); //action to load assign action, ready to return } else { errLine = "7"; // print("ActsCountb"); ActionToLoad.ba = null; } errLine = "8"; //print("load action2 " + ActionToLoad.ba.name + " " + ActionToLoad.group); //print("agx check " + actsToCompare.Count + " " + ActionToLoad.group + ActionToLoad.ba.name); //print("actual act " + ActionToLoad + " " + ActionToLoad.ba.name); return ActionToLoad; } catch (Exception e) { print("AGXLoadAGXAction2 FAIL " + errLine + " " + e); AGXAction rtnAgx = new AGXAction(); rtnAgx.ba = null; return rtnAgx; } }
public void Update() { //Debug.Log("Start update!");//print("lock " + InputLockManager.IsLocked(ControlTypes.ALL_SHIP_CONTROLS)); //if ((ControlTypes.ALL_SHIP_CONTROLS & (ControlTypes)InputLockManager.lockMask) == 0) //{ // print("not Locked"); //} //else //{ // print("locked"); //} //print("AGXLock state " + AGXLockSet); string errLine = "1"; try { bool RootPartExists = new bool(); errLine = "2"; try { errLine = "3"; if (FlightGlobals.ActiveVessel.parts.Count > 0) //we are actually checking null here on teh try-catch block, the if statement is a dummy { errLine = "4"; } errLine = "5"; RootPartExists = true; } catch { errLine = "6"; RootPartExists = false; } errLine = "7"; if (flightNodeIsLoaded) { if (RootPartExists) { errLine = "8"; if (AGXRoot != FlightGlobals.ActiveVessel.rootPart) //root part change, refresh stuff { // print("AGX Root change"); bool isDocking = false; bool isUndocking = false; try { if (FlightGlobals.ActiveVessel.parts.Contains(AGXRoot)) { isDocking = true; // print("AGX: Is a dock ");// + AGXRoot.ConstructID + " " + FlightGlobals.ActiveVessel.rootPart.ConstructID); } else if (oldShipParts.Contains(FlightGlobals.ActiveVessel.rootPart)) { isUndocking = true; //print("AGX: is an undock"); //only clear actions if not a docking event } else { //print("AGX: vessel switch"); //CurrentVesselActions.Clear(); } } catch { //print("AGX: something was null in docking check"); } errLine = "8a"; //print("Root part changed, AGX reloading"); //print("Root prt ch"); //if(!overrideRootChange) //no longer using DockingEvent //{ errLine = "8b"; //print("Root part changed, AGX reloading B"); //loadFinished = false; //CurrentVesselActions.Clear(); //we have saved old ship so clear actions //if (!isDocking && !isUndocking) //{ // CurrentVesselActions.Clear(); //} errLine = "24"; if (isDocking) //is a docking maneuver { DockingEvent(); RefreshCurrentActions(); } if (isUndocking) { CheckListForMultipleVessels(); //RefreshCurrentActions(); } //else //not a docking or undocking, load single node //this else closed at line 3792 //{ if (!isUndocking && !isDocking) { ConfigNode oldVsl = new ConfigNode(); errLine = "8c"; if (AGXRoot != null) { errLine = "9"; // print("Root part changed, AGX reloadinga"); oldVsl = new ConfigNode(AGXRoot.vessel.rootPart.flightID.ToString()); if (AGXFlightNode.HasNode(AGXRoot.vessel.rootPart.flightID.ToString())) { errLine = "10"; //print("Root part changed, AGX reloadingb"); oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.rootPart.flightID.ToString()); AGXFlightNode.RemoveNode(AGXRoot.vessel.rootPart.flightID.ToString()); } else if (AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString())) { errLine = "10"; //print("Root part changed, AGX reloadingb"); oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString()); AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString()); } errLine = "11"; //print("Root part changed, AGX reloadingc"); if (oldVsl.HasValue("name")) { oldVsl.RemoveValue("name"); } oldVsl.AddValue("name", AGXRoot.vessel.vesselName); errLine = "12"; // errLine = "13"; if (oldVsl.HasValue("currentKeyset")) { oldVsl.RemoveValue("currentKeyset"); } oldVsl.AddValue("currentKeyset", CurrentKeySetFlight.ToString()); errLine = "13"; //errLine = "14"; if (oldVsl.HasValue("groupNames")) { oldVsl.RemoveValue("groupNames"); } oldVsl.AddValue("groupNames", SaveGroupNames("")); errLine = "14"; //errLine = "15"; if (oldVsl.HasValue("groupVisibility")) { oldVsl.RemoveValue("groupVisibility"); } oldVsl.AddValue("groupVisibility", SaveGroupVisibility("")); errLine = "15"; //errLine = "16"; if (oldVsl.HasValue("groupVisibilityNames")) { errLine = "15b"; oldVsl.RemoveValue("groupVisibilityNames"); errLine = "15c"; } errLine = "15d"; oldVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames("")); errLine = "16"; if (oldVsl.HasValue("DirectActionState")) { errLine = "16b"; oldVsl.RemoveValue("DirectActionState"); errLine = "16c"; } errLine = "16d"; oldVsl.AddValue("DirectActionState", SaveDirectActionState("")); oldVsl.RemoveNodes("PART"); foreach (Part p in AGXRoot.vessel.Parts) { errLine = "17"; List<AGXAction> thisPartsActions = new List<AGXAction>(); errLine = "18 "; //print("part 18a" + p.ConstructID + " " + CurrentVesselActions); thisPartsActions.AddRange(StaticData.CurrentVesselActions.FindAll(p2 => p2.ba.listParent.part == p)); errLine = "18a"; //errLine = "18"; if (thisPartsActions.Count > 0) { errLine = "18b"; ConfigNode partTemp = new ConfigNode("PART"); errLine = "19"; partTemp.AddValue("name", p.vessel.vesselName); partTemp.AddValue("vesselID", p.vessel.id); //partTemp.AddValue("relLocX", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).x); //partTemp.AddValue("relLocY", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).y); //partTemp.AddValue("relLocZ", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).z); partTemp.AddValue("flightID", p.flightID.ToString()); errLine = "20"; foreach (AGXAction agxAct in thisPartsActions) { errLine = "21"; partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct)); } errLine = "22"; oldVsl.AddNode(partTemp); errLine = "23"; } errLine = "24"; } //print("AGX Save old vessel "+ oldVsl); AGXFlightNode.AddNode(oldVsl); //print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames")); } errLine = "24a"; StaticData.CurrentVesselActions.Clear(); errLine = "24b"; } errLine = "24c"; if (!isDocking) { errLine = "24d"; bool checkIsVab = true; ConfigNode vslNode = new ConfigNode(); try { if (FlightGlobals.ActiveVessel.landedAt == "Runway") { //print("Runway found"); checkIsVab = false; } else { //print("runway not found"); checkIsVab = true; } } catch { //print("runway iffy"); checkIsVab = true; } errLine = "24e"; if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString())) { //print("AGX flight node found"); vslNode = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.id.ToString()); } else if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString())) { // print("AGX flightID found"); vslNode = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()); } //else if(RootParts.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()) && AGXRoot != null) //replace with previously docked ship check, in other parts of code //{ // print("AGX root part found"); // vslNode = oldVsl; // ConfigNode FoundRootPart = RootParts.GetNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()); // vslNode.RemoveValue("currentKeyset"); // vslNode.AddValue("currentKeyset", FoundRootPart.GetValue("currentKeyset")); // vslNode.RemoveValue("groupVisibility"); // vslNode.AddValue("groupVisibility", FoundRootPart.GetValue("groupVisibility")); // vslNode.RemoveValue("groupVisibilityNames"); // vslNode.AddValue("groupVisibilityNames", FoundRootPart.GetValue("groupVisibilityNames")); // ShowAmbiguousMessage = false; //} else if (AGXEditorNodeFlight.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, checkIsVab))) { // print("AGX VAB1 ");// + FlightGlobals.ActiveVessel.vesselName + " " + FlightGlobals.ActiveVessel.rootPart.ConstructID); vslNode = AGXEditorNodeFlight.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, checkIsVab)); vslNode.name = FlightGlobals.ActiveVessel.rootPart.flightID.ToString(); AGXFlightNode.AddNode(vslNode); // print("node check " + vslNode.ToString()); } else if (AGXEditorNodeFlight.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab))) { //print("AGX vab2"); vslNode = AGXEditorNodeFlight.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab)); vslNode.name = FlightGlobals.ActiveVessel.rootPart.flightID.ToString(); AGXFlightNode.AddNode(vslNode); } else { //print("AGX notfound"); vslNode = new ConfigNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()); vslNode.AddValue("name", FlightGlobals.ActiveVessel.vesselName); vslNode.AddValue("currentKeyset", "1"); vslNode.AddValue("groupNames", ""); vslNode.AddValue("groupVisibility", "1011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111"); vslNode.AddValue("groupVisibilityNames", "Group 1‣Group 2‣Group 3‣Group 4‣Group 5"); vslNode.AddValue("DirectActionState", ""); AGXFlightNode.AddNode(vslNode); } errLine = "24f"; CurrentKeySetFlight = Convert.ToInt32((string)vslNode.GetValue("currentKeyset")); //LoadCurrentKeyBindings(); try { if (CurrentKeySetFlight < 1 || CurrentKeySetFlight > 5) { CurrentKeySetFlight = 1; } } catch { CurrentKeySetFlight = 1; } CurrentKeySetNameFlight = KeySetNamesFlight[CurrentKeySetFlight - 1]; LoadGroupNames(vslNode.GetValue("groupNames")); LoadGroupVisibility(vslNode.GetValue("groupVisibility")); LoadGroupVisibilityNames(vslNode.GetValue("groupVisibilityNames")); //Debug.Log(vslNode); if (vslNode.HasValue("DirectActionState")) { //Debug.Log("has state"); LoadDirectActionState(vslNode.GetValue("DirectActionState")); } else { //Debug.Log("no state"); LoadDirectActionState(""); } errLine = "24fg"; foreach (ConfigNode prtNode in vslNode.nodes) { float partDist = 100f; Part gamePart = new Part(); if (prtNode.HasValue("flightID")) { errLine = "24h"; try { uint flightIDFromFile = Convert.ToUInt32(prtNode.GetValue("flightID")); gamePart = FlightGlobals.ActiveVessel.parts.First(prt => prt.flightID == flightIDFromFile); partDist = 0f; } catch { continue; //bad FLightID in file, skip this action } } else { errLine = "24i"; foreach (Part p in FlightGlobals.ActiveVessel.parts) //do a distance compare check, floats do not guarantee perfect decimal accuray so use part with least distance, should be zero distance in most cases { Vector3 partLoc = new Vector3((float)Convert.ToDouble(prtNode.GetValue("relLocX")), (float)Convert.ToDouble(prtNode.GetValue("relLocY")), (float)Convert.ToDouble(prtNode.GetValue("relLocZ"))); float thisPartDist = Vector3.Distance(partLoc, FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position)); if (thisPartDist < partDist) { gamePart = p; partDist = thisPartDist; } } } bool ShowAmbiguousMessage2 = true; //show actions ambiguous message? errLine = "24j"; //if (ShowAmbiguousMessage && partDist < 0.3f) if (partDist < 0.3f)//do not show it if part found is more then 0.3meters off { ShowAmbiguousMessage2 = true; } else { ShowAmbiguousMessage2 = false; } errLine = "24k"; //print("gamepart " + gamePart.ConstructID + " " + partDist); foreach (ConfigNode actNode in prtNode.nodes) { //print("node " + actNode + " " + gamePart.ConstructID); AGXAction actToAdd = AGextScenario.LoadAGXActionVer2(actNode, gamePart, ShowAmbiguousMessage2); //print("act to add " + actToAdd.ba); if (actToAdd.ba != null && !StaticData.CurrentVesselActions.Contains(actToAdd)) { StaticData.CurrentVesselActions.Add(actToAdd); } } } errLine = "24l"; List<KSPActionGroup> CustomActions = new List<KSPActionGroup>(); CustomActions.Add(KSPActionGroup.Custom01); //how do you add a range from enum? CustomActions.Add(KSPActionGroup.Custom02); CustomActions.Add(KSPActionGroup.Custom03); CustomActions.Add(KSPActionGroup.Custom04); CustomActions.Add(KSPActionGroup.Custom05); CustomActions.Add(KSPActionGroup.Custom06); CustomActions.Add(KSPActionGroup.Custom07); CustomActions.Add(KSPActionGroup.Custom08); CustomActions.Add(KSPActionGroup.Custom09); CustomActions.Add(KSPActionGroup.Custom10); //errLine = "16"; // string AddGroup = ""; List<BaseAction> partAllActions = new List<BaseAction>(); //is all vessel actions, copy pasting code foreach (Part p in FlightGlobals.ActiveVessel.parts) { partAllActions.AddRange(p.Actions); foreach (PartModule pm in p.Modules) { partAllActions.AddRange(pm.Actions); } //foreach (BaseAction ba in partAllActions) //{ // print(ba.listParent.part + " " + ba.listParent.module.moduleName + " " + ba.name + " " + ba.guiName); //} // print("part orgpos " + p.ConstructID+ " " + p.orgPos + " " + p.orgRot); } errLine = "24m"; foreach (BaseAction baLoad in partAllActions) { foreach (KSPActionGroup agrp in CustomActions) { if ((baLoad.actionGroup & agrp) == agrp) { // errLine = "17"; ////AddGroup = AddGroup + '\u2023' + (CustomActions.IndexOf(agrp) + 1).ToString("000") + baLoad.guiName; //partAGActions2.Add(new AGXAction() { group = CustomActions.IndexOf(agrp) + 1, prt = this.part, ba = baLoad, activated = false }); AGXAction ToAdd = new AGXAction() { prt = baLoad.listParent.part, ba = baLoad, group = CustomActions.IndexOf(agrp) + 1, activated = false }; List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(StaticData.CurrentVesselActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { StaticData.CurrentVesselActions.Add(ToAdd); } } } // errLine = "18"; } } //} //close backet on else statment that this is not dock/undock errLine = "32"; AGXRoot = FlightGlobals.ActiveVessel.rootPart; oldShipParts = new List<Part>(FlightGlobals.ActiveVessel.parts); errLine = "32a"; overrideRootChange = false; LastPartCount = FlightGlobals.ActiveVessel.parts.Count; AGEditorSelectedParts.Clear(); PartActionsList.Clear(); RefreshCurrentActions(); loadFinished = true; //print("sit " + FlightGlobals.ActiveVessel.situation.ToString()); errLine = "33"; CurrentKeySetNameFlight = KeySetNamesFlight[CurrentKeySetFlight - 1]; LoadCurrentKeyBindings(); errLine = "33a"; FlightSaveToFile(AGXFlightNode);//add save current vessel here errLine = "33b"; } } errLine = "34"; if (LastPartCount != FlightGlobals.ActiveVessel.parts.Count) //parts count changed, remove any actions assigned to parts that have disconnected/been destroyed { print("Part count change, reload AGX"); if (FlightGlobals.ActiveVessel.parts.Count > LastPartCount) { DockingEvent(); } else if (LastPartCount > FlightGlobals.ActiveVessel.parts.Count) //new count is larger was a docking op, see the dock gameevent to handle that //chaged again { CheckListForMultipleVessels(); } AGEditorSelectedParts.Clear(); PartActionsList.Clear(); //LoadActionGroups(); RefreshCurrentActions(); LastPartCount = FlightGlobals.ActiveVessel.parts.Count; oldShipParts = new List<Part>(FlightGlobals.ActiveVessel.parts); errLine = "35"; } } errLine = "36"; if (InputLockManager.GetControlLock("kOSTerminal") == ControlTypes.None && (ControlTypes.KSC_ALL & (ControlTypes)InputLockManager.lockMask) == 0)// && InputLockManager.IsLocked(ControlTypes.All))//&& !InputLockManager.IsLocked(ControlTypes.All)) { foreach (KeyCode KC in ActiveKeys) { errLine = "37"; if (Input.GetKeyDown(KC)) { //print("keydown " + KC); for (int i = 1; i <= 250; i = i + 1) { if (AGXguiKeys[i] == KC) { //print("Key act for some reason " + i); ActivateActionGroupCheckModKeys(i); } } } } foreach (KeyValuePair<int, KeyCode> kcPair in ActiveKeysDirect) { if (Input.GetKey(kcPair.Value) && !DirectKeysState[kcPair.Key]) { ActivateActionGroupCheckModKeys(kcPair.Key, true, true); DirectKeysState[kcPair.Key] = true; //Debug.Log("turn on"); } else if (!Input.GetKey(kcPair.Value) && DirectKeysState[kcPair.Key]) { ActivateActionGroupCheckModKeys(kcPair.Key, true, false); DirectKeysState[kcPair.Key] = false; //Debug.Log("turn off"); } } foreach (KeyValuePair<int, KeyCode> kcPair2 in DefaultTen) //toggle groups if no actions are assigned { if (Input.GetKeyDown(kcPair2.Value)) { if (AGXguiMod1Groups[kcPair2.Key] == Input.GetKey(AGXguiMod1Key) && AGXguiMod2Groups[kcPair2.Key] == Input.GetKey(AGXguiMod2Key)) { if (kcPair2.Key <= 10) { Dictionary<int, KSPActionGroup> CustomActions = new Dictionary<int, KSPActionGroup>(); CustomActions.Add(1, KSPActionGroup.Custom01); //how do you add a range from enum? CustomActions.Add(2, KSPActionGroup.Custom02); CustomActions.Add(3, KSPActionGroup.Custom03); CustomActions.Add(4, KSPActionGroup.Custom04); CustomActions.Add(5, KSPActionGroup.Custom05); CustomActions.Add(6, KSPActionGroup.Custom06); CustomActions.Add(7, KSPActionGroup.Custom07); CustomActions.Add(8, KSPActionGroup.Custom08); CustomActions.Add(9, KSPActionGroup.Custom09); CustomActions.Add(10, KSPActionGroup.Custom10); FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(CustomActions[kcPair2.Key]); groupActivatedState[kcPair2.Key] = FlightGlobals.ActiveVessel.ActionGroups[CustomActions[kcPair2.Key]]; } else { groupActivatedState[kcPair2.Key] = !groupActivatedState[kcPair2.Key]; } } } } } errLine = "38"; //if (!ActiveActionsCalculated) //{ // CalculateActiveActions(); // Debug.Log("AGX update middel A"); //} if (Input.GetKeyDown(KeyCode.Mouse0) && ShowSelectedWin) { errLine = "39"; Part selPart = new Part(); selPart = SelectPartUnderMouse(); if (selPart != null) { AddSelectedPart(selPart); } errLine = "40"; } //Debug.Log("AGX update middel b"); errLine = "41"; if (RightClickDelay < 3) { errLine = "42"; if (RightClickDelay == 2) { errLine = "43"; UIPartActionWindow UIPartsListThing = new UIPartActionWindow(); UIPartsListThing = (UIPartActionWindow)FindObjectOfType(typeof(UIPartActionWindow)); //UnityEngine.Object[] TempObj = FindObjectsOfType(typeof(UIPartActionWindow)); //print(TempObj.Length); try { if (UIPartsListThing != null) { AddSelectedPart(UIPartsListThing.part); } // print(UIPartsListThing.part.name); //finds part right-clicked on RightLickPartAdded = true; } catch { // print("nope!"); RightLickPartAdded = true; } } RightClickDelay = RightClickDelay + 1; errLine = "44"; } //Debug.Log("AGX update middel c"); errLine = "45"; if (Input.GetKeyUp(KeyCode.Mouse1) && ShowSelectedWin && RightLickPartAdded == true) { RightClickDelay = 0; RightLickPartAdded = false; } errLine = "46"; // Debug.Log("AGX update middel d"); //foreach (Part p in FlightGlobals.ActiveVessel.Parts) //{ // foreach (PartModule pm in p.Modules) // { // foreach (BaseAction ba in pm.Actions) // { // print(p.partName + " " + pm.moduleName + " " + ba.name + " " + ba.guiName); // } // } //} if (ShowAGXMod) { if (actionsCheckFrameCount >= 15) //this increments in the FixedUpdate frame now { CheckActionsActive(); //PartVesselChangeCheck(); actionsCheckFrameCount = 0; } } //else //{ // actionsCheckFrameCount = actionsCheckFrameCount + (int)(Time.deltaTime * 1000f); //} //print("delta time " + actionsCheckFrameCount); errLine = "47"; //Debug.Log("AGX update middel e2"); //count down action cool downs groupCooldowns.RemoveAll(cd => cd.delayLeft > activationCoolDown); //remove actions from list that are finished cooldown, cooldown is in Update frame passes, pulled from .cfg foreach (AGXCooldown agCD in groupCooldowns) { agCD.delayLeft = agCD.delayLeft + 1; } //Debug.Log("AGX update middel e"); errLine = "48"; if (RTFound) { CheckRTQueue(); } //Debug.Log("AGX update middel f"); errLine = "49"; //PrintPartActs(); //print("landed " + FlightGlobals.ActiveVessel.landedAt); //if (test == null) //{ // Debug.Log("NULL"); //} //else //{ // Debug.Log("found " + test.nodes.Count + " " + test.values.Count); //} //Debug.Log("btn font " + HighLogic.Skin.font +);// AGXBtnStyle.font + AGXBtnStyle.fontSize + AGXBtnStyle.fontStyle); //Debug.Log("End update!"); } catch (Exception e) { print("AGX Update error: " + errLine + " " + e); } }
public void MonitorDefaultActions() { //print("AGX Monitor default start " + StaticData.CurrentVesselActions.Count()); KSPActionGroup KSPDefaultActionGroupThisFrame = KSPActionGroup.Custom01; try //find which action group is selected in default ksp editor this pass { string grpText = "None"; for (int i = 0; i < EditorActionGroups.Instance.actionGroupList.Count; i++) { IUIListObject lObj = EditorActionGroups.Instance.actionGroupList.GetItem(i); UIListItem LstItem = (UIListItem)lObj; if (LstItem.controlState == UIButton.CONTROL_STATE.ACTIVE) { grpText = LstItem.Text; } } KSPDefaultActionGroupThisFrame = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), grpText); //print("Selected group " + KSPDefaultLastActionGroup); } catch { print("AGX Monitor default list fail"); } string errLine = "1"; try { errLine = "2"; if (EditorActionGroups.Instance.GetSelectedParts() != null) //is a part selected? { errLine = "3"; if (EditorActionGroups.Instance.GetSelectedParts().Count > 0) //list can exist with no parts in it if you selected then unselect one { errLine = "4"; if (SelectedWithSym.Count == 0 || SelectedWithSym.First() != EditorActionGroups.Instance.GetSelectedParts().First() || KSPDefaultActionGroupThisFrame != KSPDefaultLastActionGroup) //check if there is a previously selected part, if so check if its changed { errLine = "5"; //print("2b"); //parts are different SelectedWithSym.Clear(); //reset lastpart list SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts()); SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts); SelectedWithSymActions.Clear(); //reset actions list //print("2c"); errLine = "6"; foreach (Part prt in SelectedWithSym) { // print("2d"); errLine = "7"; foreach (BaseAction bap in prt.Actions) //get part actions { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare } errLine = "8"; foreach (PartModule pm in prt.Modules) //add actions from all partmodules { errLine = "9"; foreach (BaseAction bapm in pm.Actions) { errLine = "10"; SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup }); } } } errLine = "11"; int groupToAdd = 1; switch (KSPDefaultActionGroupThisFrame) { case KSPActionGroup.Custom01: groupToAdd = 1; break; case KSPActionGroup.Custom02: groupToAdd = 2; break; case KSPActionGroup.Custom03: groupToAdd = 3; break; case KSPActionGroup.Custom04: groupToAdd = 4; break; case KSPActionGroup.Custom05: groupToAdd = 5; break; case KSPActionGroup.Custom06: groupToAdd = 6; break; case KSPActionGroup.Custom07: groupToAdd = 7; break; case KSPActionGroup.Custom08: groupToAdd = 8; break; case KSPActionGroup.Custom09: groupToAdd = 9; break; case KSPActionGroup.Custom10: groupToAdd = 10; break; } errLine = "12"; foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd)) { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = agact2.ba, agrp = agact2.ba.actionGroup }); } errLine = "13"; KSPDefaultLastActionGroup = KSPDefaultActionGroupThisFrame; //foreach (AGXDefaultCheck dC in SelectedWithSymActions) //{ // print("Acts " + dC.ba.name); //} // print("2e"); } else //selected part is the same a previously selected part { errLine = "14"; //print("2f"); List<Part> PartsThisFrame = new List<Part>(); //get list of parts this update frame PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts()); PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts); // print("2g"); List<BaseAction> ThisFrameActions = new List<BaseAction>(); //get actions fresh again this update frame foreach (Part prt in PartsThisFrame) { errLine = "15"; // print("2h"); foreach (BaseAction bap in prt.Actions) { ThisFrameActions.Add(bap); } errLine = "16"; foreach (PartModule pm in prt.Modules) { foreach (BaseAction bapm in pm.Actions) { ThisFrameActions.Add(bapm); } } } errLine = "17"; int groupToAdd = 1; switch (KSPDefaultActionGroupThisFrame) { case KSPActionGroup.Custom01: groupToAdd = 1; break; case KSPActionGroup.Custom02: groupToAdd = 2; break; case KSPActionGroup.Custom03: groupToAdd = 3; break; case KSPActionGroup.Custom04: groupToAdd = 4; break; case KSPActionGroup.Custom05: groupToAdd = 5; break; case KSPActionGroup.Custom06: groupToAdd = 6; break; case KSPActionGroup.Custom07: groupToAdd = 7; break; case KSPActionGroup.Custom08: groupToAdd = 8; break; case KSPActionGroup.Custom09: groupToAdd = 9; break; case KSPActionGroup.Custom10: groupToAdd = 10; break; } foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd)) { ThisFrameActions.Add(agact2.ba); } errLine = "18"; //print("2i"); foreach (BaseAction ba2 in ThisFrameActions) //check each action's actiongroup enum against last update frames actiongroup enum, this adds/removes a group to default KSP when added/removed in agx { //print("2j"); errLine = "19"; AGXDefaultCheck ActionLastFrame = new AGXDefaultCheck(); //print("2j1"); ActionLastFrame = SelectedWithSymActions.Find(a => a.ba == ba2); // print("2j2"); errLine = "20"; if (ActionLastFrame.agrp != ba2.actionGroup) //actiongroup enum is different { // print("2j3"); int NewGroup = 0; //which actiongroup changed? if (KSPActionGroup.Custom01 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 1; } else if (KSPActionGroup.Custom02 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 2; } else if (KSPActionGroup.Custom03 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 3; } else if (KSPActionGroup.Custom04 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 4; } else if (KSPActionGroup.Custom05 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 5; } else if (KSPActionGroup.Custom06 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 6; } else if (KSPActionGroup.Custom07 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 7; } else if (KSPActionGroup.Custom08 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 8; } else if (KSPActionGroup.Custom09 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 9; } else if (KSPActionGroup.Custom10 == (ActionLastFrame.agrp ^ ba2.actionGroup)) { NewGroup = 10; } // print("2k"); errLine = "21"; if (NewGroup != 0) //if one of the other actiongroups (gear, lights) has changed, ignore it. newgroup will be the actiongroup if I want to process it. { // print("Newgroup called on " + NewGroup); errLine = "22"; if (Mouse.screenPos.x >= 130 && Mouse.screenPos.x <= 280) { //print("remove actions"); //AGXAction ToRemove = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false }; StaticData.CurrentVesselActions.RemoveAll(ag3 => ag3.ba == ba2 && ag3.group == NewGroup); } else { errLine = "23"; //print("add actions"); AGXAction ToAdd = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false }; List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(StaticData.CurrentVesselActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { StaticData.CurrentVesselActions.Add(ToAdd); //SaveCurrentVesselActions(); } } } errLine = "24"; ActionLastFrame.agrp = KSPActionGroup.None; ActionLastFrame.agrp = ActionLastFrame.agrp | ba2.actionGroup; //print("2l"); } } SelectedWithSymActions.Clear(); //reset actions list as one of the enums changed. //print("2k"); errLine = "25"; foreach (Part prt in SelectedWithSym) { errLine = "26"; foreach (BaseAction bap in prt.Actions) //get part actions { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare } errLine = "27"; foreach (PartModule pm in prt.Modules) //add actions from all partmodules { foreach (BaseAction bapm in pm.Actions) { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup }); } } } errLine = "28"; foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd)) { SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = agact2.ba, agrp = agact2.ba.actionGroup }); } errLine = "29"; } } } //print("AGX Monitor default end " + StaticData.CurrentVesselActions.Count()); } catch (Exception e) { Debug.Log("AGX Monitor Default Actions Error " + errLine + " " + e); } //print("2l " + Mouse.screenPos); }
public static void EditorLoadFromNode() { //print("LoadFromNode Called" + StaticData.CurrentVesselActions.Count()); string errLine = "1"; try { errLine = "10"; string hashedShipName = AGextScenario.EditorHashShipName(EditorLogic.fetch.shipNameField.Text, inVAB); errLine = "10a"; //print(hashedShipName); ConfigNode thisVsl = new ConfigNode(); errLine = "10b"; // print(AGXEditorNode); if (AGXEditorNode == null) { EditorLoadFromFile(); print("AGX EditorNode is Null, recovering...."); } errLine = "10bc"; if (AGXEditorNode.HasNode(hashedShipName)) { errLine = "11"; thisVsl = AGXEditorNode.GetNode(hashedShipName); } errLine = "12"; if (thisVsl.HasValue("currentKeyset")) { CurrentKeySet = Convert.ToInt32((string)thisVsl.GetValue("currentKeyset")); //print("curkey a " + CurrentKeySet + " " + thisVsl.GetValue("currentKeyset")); } else { CurrentKeySet = 1; //print("curkey b " + CurrentKeySet); } if (CurrentKeySet < 1 || CurrentKeySet > 5) { //print("curkey c " + CurrentKeySet); CurrentKeySet = 1; } LoadCurrentKeyBindings(); CurrentKeySetName = KeySetNames[CurrentKeySet - 1]; errLine = "13"; if (thisVsl.HasValue("groupNames")) { LoadGroupNames(thisVsl.GetValue("groupNames")); } else { LoadGroupNames(""); } errLine = "14"; if (thisVsl.HasValue("groupVisibility")) { LoadGroupVisibility(thisVsl.GetValue("groupVisibility")); } else { LoadGroupVisibility(""); } errLine = "15"; if (thisVsl.HasValue("groupVisibilityNames")) { LoadGroupVisibilityNames(thisVsl.GetValue("groupVisibilityNames")); } else { LoadGroupVisibilityNames("Group1" + '\u2023' + "Group2" + '\u2023' + "Group3" + '\u2023' + "Group4" + '\u2023' + "Group5"); } if (thisVsl.HasValue("DirectActionState")) { LoadDirectActionState(thisVsl.GetValue("DirectActionState")); } else { LoadDirectActionState(""); } errLine = "15a"; //print("adfg " + thisVsl.CountNodes); foreach (ConfigNode prtNode in thisVsl.nodes) { Vector3 partLoc = new Vector3((float)Convert.ToDouble(prtNode.GetValue("relLocX")), (float)Convert.ToDouble(prtNode.GetValue("relLocY")), (float)Convert.ToDouble(prtNode.GetValue("relLocZ"))); float partDist = 100f; Part gamePart = new Part(); try { foreach (Part p in EditorLogic.SortedShipList) //do a distance compare check, floats do not guarantee perfect decimal accuray so use part with least distance, should be zero distance in most cases { float thisPartDist = Vector3.Distance(partLoc, EditorLogic.RootPart.transform.InverseTransformPoint(p.transform.position)); if (thisPartDist < partDist) { gamePart = p; partDist = thisPartDist; } } bool ShowAmbiguousMessage = true; if (partDist < 0.3f) //do not show it if part found is more then 0.3meters off { ShowAmbiguousMessage = true; } else { ShowAmbiguousMessage = false; } foreach (ConfigNode actNode in prtNode.nodes) { AGXAction actToAdd = AGextScenario.LoadAGXActionVer2(actNode, gamePart, ShowAmbiguousMessage); if (actToAdd.ba != null && !StaticData.CurrentVesselActions.Contains(actToAdd)) { StaticData.CurrentVesselActions.Add(actToAdd); } } } catch { //Silently fail, if we hit this it is because EditorLogic.sorted ship list is not valid } } errLine = "15b"; List<KSPActionGroup> CustomActions = new List<KSPActionGroup>(); CustomActions.Add(KSPActionGroup.Custom01); //how do you add a range from enum? CustomActions.Add(KSPActionGroup.Custom02); CustomActions.Add(KSPActionGroup.Custom03); CustomActions.Add(KSPActionGroup.Custom04); CustomActions.Add(KSPActionGroup.Custom05); CustomActions.Add(KSPActionGroup.Custom06); CustomActions.Add(KSPActionGroup.Custom07); CustomActions.Add(KSPActionGroup.Custom08); CustomActions.Add(KSPActionGroup.Custom09); CustomActions.Add(KSPActionGroup.Custom10); errLine = "16"; // string AddGroup = ""; List<BaseAction> partAllActions = new List<BaseAction>(); //is all vessel actions, copy pasting code try { foreach (Part p in EditorLogic.SortedShipList) { partAllActions.AddRange(p.Actions); foreach (PartModule pm in p.Modules) { partAllActions.AddRange(pm.Actions); } } foreach (BaseAction baLoad in partAllActions) { foreach (KSPActionGroup agrp in CustomActions) { if ((baLoad.actionGroup & agrp) == agrp) { errLine = "17"; ////AddGroup = AddGroup + '\u2023' + (CustomActions.IndexOf(agrp) + 1).ToString("000") + baLoad.guiName; //partAGActions2.Add(new AGXAction() { group = CustomActions.IndexOf(agrp) + 1, prt = this.part, ba = baLoad, activated = false }); AGXAction ToAdd = new AGXAction() { prt = baLoad.listParent.part, ba = baLoad, group = CustomActions.IndexOf(agrp) + 1, activated = false }; List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(StaticData.CurrentVesselActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { StaticData.CurrentVesselActions.Add(ToAdd); } } } errLine = "18"; } } catch { //silently fail, if we hit this EditorLogic.sortedShipList is not valid } AGXRoot = EditorLogic.RootPart; //print("LoadFromNode Called End" + StaticData.CurrentVesselActions.Count()); } catch (Exception e) { print("AGX EditorLoadFromNode Fail " + errLine + " " + e); } }
public void VesselOffRails(Vessel vsl) //load vessels here { print("Vessel off rails! " + vsl.vesselName); ConfigNode vslNode = new ConfigNode(); bool checkIsVab = true; try { if (vsl.landedAt == "Runway") { //print("Runway found"); checkIsVab = false; } else { //print("runway not found"); checkIsVab = true; } } catch { //print("runway iffy"); checkIsVab = true; } if (AGXFlightNode.HasNode(vsl.id.ToString())) { //print("Vessel off rails! case 1 " + vsl.vesselName); vslNode = AGXFlightNode.GetNode(vsl.id.ToString()); } else if(AGXEditorNode.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName,checkIsVab))) { //print("Vessel off rails! case2 " + vsl.vesselName); vslNode = AGXEditorNode.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName,checkIsVab)); vslNode.name = vsl.id.ToString(); AGXFlightNode.AddNode(vslNode); } else if (AGXEditorNode.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab))) { //print("Vessel off rails! case3 " + vsl.vesselName); vslNode = AGXEditorNode.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName,!checkIsVab)); vslNode.name = vsl.id.ToString(); AGXFlightNode.AddNode(vslNode); } else { // print("Vessel off rails! case4 " + vsl.vesselName); vslNode = new ConfigNode(vsl.id.ToString()); vslNode.AddValue("name", vsl.vesselName); vslNode.AddValue("currentKeyset", "1"); vslNode.AddValue("groupNames", ""); vslNode.AddValue("groupVisibility", "1011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111"); vslNode.AddValue("groupVisibilityNames", "Group 1‣Group 2‣Group 3‣Group 4‣Group 5"); AGXFlightNode.AddNode(vslNode); } foreach (ConfigNode prtNode in vslNode.nodes) { Vector3 partLoc = new Vector3((float)Convert.ToDouble(prtNode.GetValue("relLocX")), (float)Convert.ToDouble(prtNode.GetValue("relLocY")), (float)Convert.ToDouble(prtNode.GetValue("relLocZ"))); float partDist = 100f; Part gamePart = new Part(); foreach (Part p in vsl.parts) //do a distance compare check, floats do not guarantee perfect decimal accuray so use part with least distance, should be zero distance in most cases { float thisPartDist = Vector3.Distance(partLoc, p.orgPos); if (thisPartDist < partDist) { gamePart = p; partDist = thisPartDist; } } foreach (ConfigNode actNode in prtNode.nodes) { //print("node " + actNode + " " + gamePart.ConstructID); AGXAction actToAdd = AGextScenario.LoadAGXActionVer2(actNode, gamePart); //print("act to add " + actToAdd.ba); if (actToAdd.ba != null) { AllVesselsActions.Add(actToAdd); } } } List<KSPActionGroup> CustomActions = new List<KSPActionGroup>(); CustomActions.Add(KSPActionGroup.Custom01); //how do you add a range from enum? CustomActions.Add(KSPActionGroup.Custom02); CustomActions.Add(KSPActionGroup.Custom03); CustomActions.Add(KSPActionGroup.Custom04); CustomActions.Add(KSPActionGroup.Custom05); CustomActions.Add(KSPActionGroup.Custom06); CustomActions.Add(KSPActionGroup.Custom07); CustomActions.Add(KSPActionGroup.Custom08); CustomActions.Add(KSPActionGroup.Custom09); CustomActions.Add(KSPActionGroup.Custom10); //errLine = "16"; // string AddGroup = ""; List<BaseAction> partAllActions = new List<BaseAction>(); //is all vessel actions, copy pasting code foreach (Part p in vsl.parts) { partAllActions.AddRange(p.Actions); foreach (PartModule pm in p.Modules) { partAllActions.AddRange(pm.Actions); } // print("part orgpos " + p.ConstructID+ " " + p.orgPos + " " + p.orgRot); } foreach (BaseAction baLoad in partAllActions) { foreach (KSPActionGroup agrp in CustomActions) { if ((baLoad.actionGroup & agrp) == agrp) { // errLine = "17"; ////AddGroup = AddGroup + '\u2023' + (CustomActions.IndexOf(agrp) + 1).ToString("000") + baLoad.guiName; //partAGActions2.Add(new AGXAction() { group = CustomActions.IndexOf(agrp) + 1, prt = this.part, ba = baLoad, activated = false }); AGXAction ToAdd = new AGXAction() { prt = baLoad.listParent.part, ba = baLoad, group = CustomActions.IndexOf(agrp) + 1, activated = false }; List<AGXAction> Checking = new List<AGXAction>(); Checking.AddRange(AllVesselsActions); Checking.RemoveAll(p => p.group != ToAdd.group); Checking.RemoveAll(p => p.prt != ToAdd.prt); Checking.RemoveAll(p => p.ba != ToAdd.ba); if (Checking.Count == 0) { AllVesselsActions.Add(ToAdd); } } } // errLine = "18"; } if (vsl == FlightGlobals.ActiveVessel) { CurrentKeySet = Convert.ToInt32(vslNode.GetValue("currentKeyset")); LoadCurrentKeyBindings(); LoadGroupNames(vslNode.GetValue("groupNames")); LoadGroupVisibility(vslNode.GetValue("groupVisibility")); LoadGroupVisibilityNames(vslNode.GetValue("groupVisibilityNames")); loadFinished = true; } RefreshCurrentActions(); foreach (Part p in vsl.Parts) //add parts to checking list to see if the vessel cahnges (undock, break, etc.) { partOldVessel.Add(new AGXPartVesselCheck() { prt = p, pVsl = vsl }); } loadedVessels.Add(vsl); //add this vessel to loaded vessels list }