From e9954de6591a802e79a59da95d852740ab6b8131 Mon Sep 17 00:00:00 2001 From: SirDiazo Date: Thu, 24 Dec 2015 16:06:56 -0700 Subject: [PATCH] 1.34d New external interface methods --- AGExt/CommonMethods.cs | 2 +- AGExt/External.cs | 104 +++++++++++++++++++++++++++++++++++------ AGExt/Flight.cs | 26 +++++++++++ AGExt/Instantly.cs | 2 +- 4 files changed, 119 insertions(+), 15 deletions(-) diff --git a/AGExt/CommonMethods.cs b/AGExt/CommonMethods.cs index dea1d12..4078a63 100644 --- a/AGExt/CommonMethods.cs +++ b/AGExt/CommonMethods.cs @@ -559,7 +559,7 @@ public override void OnLoad(ConfigNode node) { private uint flightID; // private bool vesselInstanceOK = false; //is this vessel loadable? if this is false, run nothing - private List actionsList; + public List actionsList; private Vessel thisVsl; private Dictionary guiNames; diff --git a/AGExt/External.cs b/AGExt/External.cs index 0f41d07..3ba3194 100644 --- a/AGExt/External.cs +++ b/AGExt/External.cs @@ -90,7 +90,7 @@ public static List AGX2VslGroupActions(uint FlightID, int group) //wo } else if (HighLogic.LoadedSceneIsEditor) { - return StaticData.CurrentVesselActions.FindAll(ag => ag.group == group); + return StaticData.CurrentVesselActions.FindAll(ag => ag.group == group); } else { @@ -161,9 +161,9 @@ public static string AGX2VslGroupNameSingle(uint FlightID, int group) //return n } } - public static Dictionary AGXGroupNamesAll() //return dictionary of group names, returns dictionary of 250 items, only groups with defined names will have strings + public static Dictionary AGXGroupNamesAll() //return dictionary of group names, returns dictionary of 250 items, only groups with defined names will have strings { - if(HighLogic.LoadedSceneIsFlight) + if (HighLogic.LoadedSceneIsFlight) { return AGXFlight.AGXguiNames; } @@ -175,13 +175,13 @@ public static Dictionary AGXGroupNamesAll() //return dictionary of g { return new Dictionary(); } - } - - public static Dictionary AGX2VslGroupNamesAll(uint FlightID) //return dictionary of group names + } + + public static Dictionary AGX2VslGroupNamesAll(uint FlightID) //return dictionary of group names { - if(HighLogic.LoadedSceneIsFlight) + if (HighLogic.LoadedSceneIsFlight) { - if(FlightID == FlightGlobals.ActiveVessel.rootPart.flightID) + if (FlightID == FlightGlobals.ActiveVessel.rootPart.flightID) { return AGXFlight.AGXguiNames; } @@ -191,9 +191,9 @@ public static Dictionary AGX2VslGroupNamesAll(uint FlightID) //retur return otherVsl.GetGroupNamesAll(); } } - else if(HighLogic.LoadedSceneIsEditor) + else if (HighLogic.LoadedSceneIsEditor) { - if(FlightID == EditorLogic.RootPart.flightID) + if (FlightID == EditorLogic.RootPart.flightID) { return AGXEditor.AGXguiNames; } @@ -207,7 +207,7 @@ public static Dictionary AGX2VslGroupNamesAll(uint FlightID) //retur return new Dictionary(); } } - + public static bool AGX2VslToggleGroup(uint FlightID, int group) //other vessel direct toggle activate { print("AGX Call: toggle action " + group + " for vessel " + FlightID); @@ -801,6 +801,84 @@ public static List AGXListOfPartsInGroup(int i) } } + public static Dictionary AGXListOfAssignedGroups() + { + print("AGX Call: list of groups with assigned actions"); + if (HighLogic.LoadedSceneIsFlight) + { + Dictionary grpList = new Dictionary(); + foreach (AGXAction agAct in StaticData.CurrentVesselActions) + { + if(!grpList.ContainsKey(agAct.group)) + //if (!grpList.Concat(agAct.group)) + { + grpList.Add(agAct.group,AGXFlight.AGXguiNames[agAct.group]); + } + } + //dictionary isn't sortable, you sort the results when you access it which has to happen in the other mod. + return grpList; + } + else if (HighLogic.LoadedSceneIsEditor) + { + Dictionary grpList = new Dictionary(); + foreach (AGXAction agAct in StaticData.CurrentVesselActions) + { + if (!grpList.ContainsKey(agAct.group)) + { + grpList.Add(agAct.group, AGXEditor.AGXguiNames[agAct.group]); + } + } + return grpList; + } + else + { + return new Dictionary(); + } + } + + public static Dictionary AGX2VslListOfAssignedGroups(uint flightID) + { + print("AGX Call: list of groups with assigned actions on vessel " + flightID); + try + { + + if (HighLogic.LoadedSceneIsFlight) //only workes in flight + { + if (FlightGlobals.ActiveVessel.rootPart.flightID == flightID) + { + return AGXListOfAssignedGroups(); + } + else + { + AGXOtherVessel otherVsl = new AGXOtherVessel(flightID); + Dictionary grpList = new Dictionary(); + foreach (AGXAction agAct in otherVsl.actionsList) + { + if (!grpList.ContainsKey(agAct.group)) + { + grpList.Add(agAct.group, AGXEditor.AGXguiNames[agAct.group]); + } + } + return grpList; + + } + } + else if (HighLogic.LoadedSceneIsEditor) + { + return AGXListOfAssignedGroups(); + } + + else + { + return new Dictionary(); + } + } + catch + { + return new Dictionary(); + } + } + } @@ -895,7 +973,7 @@ public int GetHashCode(AGXAction obj) public override string ToString() { string str = ""; - if(prt == null) + if (prt == null) { str = str + "PartNull"; } @@ -917,7 +995,7 @@ public override string ToString() //} //else //{ - str = str + ":" + group.ToString(); + str = str + ":" + group.ToString(); //} return str; } diff --git a/AGExt/Flight.cs b/AGExt/Flight.cs index 0f72e2d..e8edf95 100644 --- a/AGExt/Flight.cs +++ b/AGExt/Flight.cs @@ -1387,6 +1387,32 @@ public void DrawSettingsWin(int WindowID) if (GUI.Button(new Rect(10, 150, 130, 25), "Bypass RemoteTech", AGXBtnStyle)) { useRT = !useRT; + //mechject test stuff start + + //Type VSType = Type.GetType("MuMech.VesselState, MechJeb2"); //this is good, finds our VesselState type. + //Type MCType = Type.GetType("MuMech.MechJebCore, MechJeb2"); //this is goo, finds our MechJebCore type. + //foreach (Part p in FlightGlobals.ActiveVessel.Parts) //cycle all parts on our vessel, MechJeb attaches to parts with ModuleCommand + //{ + // if (p.Modules.Contains("MechJebCore")) + // { + // PartModule pm2 = p.Modules["MechJebCore"]; //Find our MechJeb module + // if (pm2 != null) //if part does not have a mechjeb module, pm2 is null at this point + // { + // Debug.Log("vslstatea found"); + // object vslState = MCType.GetField("vesselState").GetValue(pm2); //get our reference to the vessel state object + // Debug.Log("vslstate found"); + // foreach (PropertyInfo pinfo in VSType.GetProperties()) + // { + // Debug.Log("ping" + pinfo.Name + " " + pinfo.PropertyType); + // } + // var maxThrustAvail = VSType.GetProperty("thrustAvailable").GetValue(vslState,null); + // Debug.Log("found " + maxThrustAvail); + // break; //pull max thrust from the vessel state object. + // } + // } + //} + + //mechjeb test stuff end } AGXBtnStyle.normal.background = ButtonTexture; AGXBtnStyle.hover.background = ButtonTexture; diff --git a/AGExt/Instantly.cs b/AGExt/Instantly.cs index 079bd07..bd6a865 100644 --- a/AGExt/Instantly.cs +++ b/AGExt/Instantly.cs @@ -13,7 +13,7 @@ public class AGXMainMenu :PartModule //abandoned module, no longer needed for key rebinding public void Start() { - print("AGExt Ver. 1.34c loaded"); + print("AGExt Ver. 1.34d loaded"); }