Skip to content

Commit

Permalink
Version 2.0a
Browse files Browse the repository at this point in the history
UI Show/Hide on F2
MM cache compatibility
Flags Nullref fix
  • Loading branch information
SirDiazo committed May 24, 2016
1 parent 92e0185 commit 541fd65
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 281 deletions.
29 changes: 24 additions & 5 deletions AGExt/CommonMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,38 @@ public static class AGXStaticData
public static ConfigNode AGExtConfig;
public static bool nodeLoaded = false;
public static ConfigNode LoadBaseConfigNode()

{
if (nodeLoaded)
{
return AGExtConfig;
}
else
{
ConfigNode nodeLoad = new ConfigNode("AGExtConfig");
nodeLoad = GameDatabase.Instance.GetConfigNode("Diazo/AGExt/AGExt/AGExtConfig");
if (nodeLoad == null)
ConfigNode nodeLoad =new ConfigNode("AGExtConfig");
if(System.IO.File.Exists(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.settings"))
{
ConfigNode tempNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.settings");
nodeLoad = tempNode.GetNode("AGExtConfig");
Debug.Log("AGX case 1 " + nodeLoad.ToString());
}
else if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGext.cfg"))
{
ConfigNode tempNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGext.cfg");
nodeLoad = tempNode.GetNode("AGExtConfig");
System.IO.File.Delete(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGext.cfg");
Debug.Log("AGX case 2 " + nodeLoad.ToString());
}
else
{
nodeLoad = new ConfigNode("AGExtConfig");
Debug.Log("AGX case 3 " + nodeLoad.ToString());
}

//nodeLoad = GameDatabase.Instance.GetConfigNode("Diazo/AGExt/AGExt/AGExtConfig");
//if (nodeLoad == null)
//{
// nodeLoad = new ConfigNode("AGExtConfig");
//}
if (!nodeLoad.HasValue("name"))
{
nodeLoad.AddValue("name", "AGExtConfig");
Expand Down Expand Up @@ -327,7 +346,7 @@ public static void SaveBaseConfigNode(ConfigNode cNode)
{
ConfigNode toSave = new ConfigNode("AGExtConfig");
toSave.AddNode(cNode);
toSave.Save(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.cfg");
toSave.Save(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/AGExt.settings");

}
}
Expand Down
44 changes: 36 additions & 8 deletions AGExt/Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace ActionGroupsExtended
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class AGXFlight : PartModule
{
public bool showMyUI = true;
public static AGXFlight thisModule;
private bool buttonCreated = false;
private bool showDockedSubVesselIndicators = false;
Expand Down Expand Up @@ -176,6 +177,16 @@ public class AGXFlight : PartModule
public static Dictionary<int, bool> groupActivatedState; //group activated state, this does NOT save, provided for kOS script usage
private static uint currentMissionId;

public void onMyUIShow()
{
showMyUI = true;
}

public void onMyUIHide()
{
showMyUI = false;
}

IEnumerator DockedSubVesselsIconTimer()
{
for(int i =1;i<30;i++)
Expand Down Expand Up @@ -668,6 +679,8 @@ public void Start()
print("AGX Flight Start FAIL " + errLine + " " + e);
print("AGX AGExt node dump: " + AGExtNode);
}
GameEvents.onShowUI.Add(onMyUIShow);
GameEvents.onHideUI.Add(onMyUIHide);
}

IEnumerator AddButtons()
Expand Down Expand Up @@ -1157,6 +1170,8 @@ public void OnDisable()
AGXLockSet = false;
}
StaticData.CurrentVesselActions.Clear();
GameEvents.onShowUI.Remove(onMyUIShow);
GameEvents.onHideUI.Remove(onMyUIHide);

}

Expand Down Expand Up @@ -1240,7 +1255,7 @@ public void OnGUI()
}


if (ShowAGXMod)
if (ShowAGXMod && showMyUI)
{
if (!showCareerCustomAGs)
{
Expand Down Expand Up @@ -1377,7 +1392,7 @@ public void OnGUI()
}
}

if (showAGXRightClickMenu)
if (showAGXRightClickMenu && showMyUI)
{
Rect SettingsWin = new Rect(Screen.width - 200, 40, 150, 180);
GUI.Window(2233452, SettingsWin, DrawSettingsWin, "AGX Settings", AGXWinStyle);
Expand Down Expand Up @@ -3059,8 +3074,8 @@ public void LoadVesselDataFromPM(ModuleAGX rootAGX)
foreach (Part p in rootAGX.vessel.Parts)
{
errLine = "7o";
if (!p.Modules.Contains("KerbalEVA"))
{
//if (!p.Modules.Contains("KerbalEVA"))
//{
foreach (AGXAction agAct in p.Modules.OfType<ModuleAGX>().FirstOrDefault().agxActionsThisPart)
{
errLine = "7p";
Expand All @@ -3070,7 +3085,7 @@ public void LoadVesselDataFromPM(ModuleAGX rootAGX)
StaticData.CurrentVesselActions.Add(agAct); //add action from part if not already present, not sure what could cause doubles but error trap it
}
}
}
//}
}
errLine = "7r";

Expand Down Expand Up @@ -4704,10 +4719,21 @@ public void Update()
errLine = "7d";
//note we generally do not save data here, all saving of data is done by the GUI buttons to the ModuleAGX partmodule directly in flight mode
ModuleAGX rootAGX = null;
if (FlightGlobals.ActiveVessel.rootPart.Modules.Contains("KerbalEVA")) //kerbals have no actions so...
Debug.Log("AGX " + FlightGlobals.ActiveVessel.vesselType.ToString());
if (FlightGlobals.ActiveVessel.rootPart.Modules.Contains("KerbalEVA") || FlightGlobals.ActiveVessel.vesselType==VesselType.Flag) //kerbals have no actions so...
{
rootAGX = new ModuleAGX();
rootAGX.hasData = true;
Debug.Log("AGX oddball");
foreach(Part p in FlightGlobals.ActiveVessel.Parts)
{
if(!p.Modules.Contains("ModuleAGX"))
{
Debug.Log("AGX AGXModule being added");
rootAGX = (ModuleAGX)p.AddModule("ModuleAGX");
}
}
rootAGX = (ModuleAGX)FlightGlobals.ActiveVessel.rootPart.Modules["ModuleAGX"];
//rootAGX = new ModuleAGX();
//rootAGX.hasData = true;
//Debug.Log("AGX EvA");

}
Expand Down Expand Up @@ -4815,13 +4841,15 @@ public void Update()
//Debug.Log("AGX " + FlightGlobals.ActiveVessel.isEVA);
//Debug.Log("AGX2 " + rootAGX.vessel.isEVA);
errLine = "7h9a";

if (FlightGlobals.ActiveVessel.isEVA)
{
errLine = "7h9b";
currentMissionId = 1; //we are a kerbal (or somethings screwy), just set this to 1 so it never matches. 0 is default so that might match something
}
else
{
errLine = "7h9c";
if (rootAGX.focusFlightID == 0) //check we have a master vesel assigned, this will trigger on launching a new vessel, etc.
{
errLine = "7h10";
Expand Down
2 changes: 1 addition & 1 deletion AGExt/Instantly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AGXMainMenu :PartModule
//abandoned module, no longer needed for key rebinding
public void Start()
{
print("AGExt Ver. 2.0 loaded");
print("AGExt Ver. 2.0a loaded");


}
Expand Down
Loading

0 comments on commit 541fd65

Please sign in to comment.