Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
-Fix Override Career so it works
-Add Precise Controol
  • Loading branch information
SirDiazo committed Dec 26, 2014
1 parent 1a49800 commit 619cfd9
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 35 deletions.
Binary file modified AutoAction.v12.suo
Binary file not shown.
191 changes: 157 additions & 34 deletions AutoAction/AutoActionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public class AutoActionEditor : MonoBehaviour
public int masterActivateGroupF = 0;
public bool masterSetThrottleYes = false;
public int masterSetThrottle = -50; //end variables
public bool masterSetPrecCtrl = false; //precise control?
ApplicationLauncherButton AAEditorButton = null; //stock toolbar button instance
ConfigNode AANode;

public void Start()
{
print("AutoActions Version 1.2a loaded.");
print("AutoActions Version 1.3 loaded.");
AAWinStyle = new GUIStyle(HighLogic.Skin.window); //make our style
AAFldStyle = new GUIStyle(HighLogic.Skin.textField);
AAFldStyle.fontStyle = FontStyle.Normal;
Expand Down Expand Up @@ -81,7 +83,7 @@ public void Start()
if (e.MouseButton == 0) //simply show/hide window on click
{
onStockToolbarClick();
}
};
}
Expand All @@ -91,7 +93,7 @@ public void Start()
//now using stock toolbar as fallback
AAEditorButton = ApplicationLauncher.Instance.AddModApplication(onStockToolbarClick, onStockToolbarClick, DummyVoid, DummyVoid, DummyVoid, DummyVoid, ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH, (Texture)GameDatabase.Instance.GetTexture("Diazo/AutoAction/AABtn", false));
}
ConfigNode AANode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AutoAction/AutoAction.cfg"); //load .cfg file
AANode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/AutoAction/AutoAction.cfg"); //load .cfg file
AAWin.x = Convert.ToInt32(AANode.GetValue("WinX"));
AAWin.y = Convert.ToInt32(AANode.GetValue("WinY"));

Expand Down Expand Up @@ -218,7 +220,7 @@ public void LoadAAPartModule() //load from partmodule
foreach (Part p in EditorLogic.SortedShipList)
{
foreach (ModuleAutoAction pmAA in p.Modules.OfType<ModuleAutoAction>())
{
{
masterActivateAbort = pmAA.activateAbort;
masterActivateGear = pmAA.activateGear;
masterActivateLights = pmAA.activateLights;
Expand All @@ -241,6 +243,7 @@ public void LoadAAPartModule() //load from partmodule
masterSetThrottle = -50;
masterSetThrottleYes = false;
}
masterSetPrecCtrl = pmAA.setPrecCtrl;
}
}
}
Expand Down Expand Up @@ -274,12 +277,55 @@ public void RefreshPartModules() //set values on all ModuleAutoActions on vessel
pmAA.activateBrakes = masterActivateBrakes;
pmAA.activateRCS = masterActivateRCS;
pmAA.activateSAS = masterActivateSAS;
pmAA.activateGroupA = masterActivateGroupA;
pmAA.activateGroupB = masterActivateGroupB;
pmAA.activateGroupC = masterActivateGroupC;
pmAA.activateGroupD = masterActivateGroupD;
pmAA.activateGroupE = masterActivateGroupE;
pmAA.activateGroupF = masterActivateGroupF;
if (masterActivateGroupA == -200)
{
pmAA.activateGroupA = 0;
}
else
{
pmAA.activateGroupA = masterActivateGroupA;
}
if (masterActivateGroupB == -200)
{
pmAA.activateGroupB = 0;
}
else
{
pmAA.activateGroupB = masterActivateGroupB;
}
if (masterActivateGroupC == -200)
{
pmAA.activateGroupC = 0;
}
else
{
pmAA.activateGroupC = masterActivateGroupC;
}
if (masterActivateGroupD == -200)
{
pmAA.activateGroupD = 0;
}
else
{
pmAA.activateGroupD = masterActivateGroupD;
}
if (masterActivateGroupE == -200)
{
pmAA.activateGroupE = 0;
}
else
{
pmAA.activateGroupE = masterActivateGroupE;
}
if (masterActivateGroupF == -200)
{
pmAA.activateGroupF = 0;
}
else
{
pmAA.activateGroupF = masterActivateGroupF;
}

if (masterSetThrottleYes)
{
pmAA.setThrottle = masterSetThrottle;
Expand All @@ -288,10 +334,18 @@ public void RefreshPartModules() //set values on all ModuleAutoActions on vessel
{
pmAA.setThrottle = -50;
}
pmAA.setPrecCtrl = masterSetPrecCtrl;
}
}
ConfigNode AANode = new ConfigNode();
if (AANode.HasValue("WinX"))
{
AANode.RemoveValue("WinX");
}
AANode.AddValue("WinX", AAWin.x.ToString());
if (AANode.HasValue("WinY"))
{
AANode.RemoveValue("WinY");
}
AANode.AddValue("WinY", AAWin.y.ToString());
AANode.Save(KSPUtil.ApplicationRootPath + "GameData/Diazo/AutoAction/AutoAction.cfg");//same^
}//end RefreshPartModules()
Expand All @@ -309,8 +363,8 @@ public void AAOnDraw() //our rendering manager

public void AAWindow(int WindowID)
{


if (masterActivateAbort)
{
AABtnStyle.normal.background = ButtonTextureGreen;
Expand Down Expand Up @@ -408,51 +462,81 @@ public void AAWindow(int WindowID)
}
if (showCustomGroups) //only show custom groups if unlocked in editor
{
string masterActivateGroupAString = masterActivateGroupA.ToString();
string masterActivateGroupAString = cvertToString(masterActivateGroupA);
masterActivateGroupAString = GUI.TextField(new Rect(5, 63, 30, 20), masterActivateGroupAString, 4, AAFldStyle);
try
{
masterActivateGroupA = Convert.ToInt32(masterActivateGroupAString); //convert string to number
int tempA = cvertToNum(masterActivateGroupAString); //convert string to number
if (tempA != masterActivateGroupA)
{
masterActivateGroupA = tempA;
RefreshPartModules();
}

}
catch
{
masterActivateGroupAString = masterActivateGroupA.ToString(); //conversion failed, reset change
}
string masterActivateGroupBString = masterActivateGroupB.ToString();
string masterActivateGroupBString = cvertToString(masterActivateGroupB);
masterActivateGroupBString = GUI.TextField(new Rect(35, 63, 30, 20), masterActivateGroupBString, 4, AAFldStyle);
try
{
masterActivateGroupB = Convert.ToInt32(masterActivateGroupBString); //convert string to number
int tempB = cvertToNum(masterActivateGroupBString); //convert string to number
if (tempB != masterActivateGroupB)
{
masterActivateGroupB = tempB;
RefreshPartModules();
}

}
catch
{
masterActivateGroupBString = masterActivateGroupB.ToString(); //conversion failed, reset change
}
string masterActivateGroupCString = masterActivateGroupC.ToString();
string masterActivateGroupCString = cvertToString(masterActivateGroupC);
masterActivateGroupCString = GUI.TextField(new Rect(65, 63, 30, 20), masterActivateGroupCString, 4, AAFldStyle);
try
{
masterActivateGroupC = Convert.ToInt32(masterActivateGroupCString); //convert string to number
int tempC = cvertToNum(masterActivateGroupCString); //convert string to number
if (tempC != masterActivateGroupC)
{
masterActivateGroupC = tempC;
RefreshPartModules();
}

}
catch
{
masterActivateGroupCString = masterActivateGroupC.ToString(); //conversion failed, reset change
}
string masterActivateGroupDString = masterActivateGroupD.ToString();
string masterActivateGroupDString = cvertToString(masterActivateGroupD);
masterActivateGroupDString = GUI.TextField(new Rect(95, 63, 30, 20), masterActivateGroupDString, 4, AAFldStyle);
try
{
masterActivateGroupD = Convert.ToInt32(masterActivateGroupDString); //convert string to number
int tempD = cvertToNum(masterActivateGroupDString); //convert string to number
if (tempD != masterActivateGroupD)
{
masterActivateGroupD = tempD;
RefreshPartModules();
}

}
catch
{
masterActivateGroupDString = masterActivateGroupD.ToString(); //conversion failed, reset change
}
string masterActivateGroupEString = masterActivateGroupE.ToString();
string masterActivateGroupEString = cvertToString(masterActivateGroupE);
masterActivateGroupEString = GUI.TextField(new Rect(125, 63, 30, 20), masterActivateGroupEString, 4, AAFldStyle);
try
{
masterActivateGroupE = Convert.ToInt32(masterActivateGroupEString); //convert string to number
int tempE = cvertToNum(masterActivateGroupEString); //convert string to number
if (tempE != masterActivateGroupE)
{
masterActivateGroupE = tempE;
RefreshPartModules();
}

}
catch
{
Expand All @@ -474,10 +558,10 @@ public void AAWindow(int WindowID)
AABtnStyle.normal.background = ButtonTextureRed;
AABtnStyle.hover.background = ButtonTextureRed;
}
if (GUI.Button(new Rect(5, 85, 80, 20), "Set throttle:", AABtnStyle))
if (GUI.Button(new Rect(5, 85, 50, 20), "Throttle:", AABtnStyle))
{
masterSetThrottleYes = !masterSetThrottleYes;
if(masterSetThrottleYes)
if (masterSetThrottleYes)
{
masterSetThrottle = 50;
}
Expand All @@ -488,36 +572,75 @@ public void AAWindow(int WindowID)
RefreshPartModules();
}

if(!masterSetThrottleYes)
if (!masterSetThrottleYes)
{
GUI.Label(new Rect(90, 85, 40, 20), "No", HighLogic.Skin.label);
GUI.Label(new Rect(68, 85, 40, 20), "No", HighLogic.Skin.label);
}
else
{
string masterSetThrottleString = masterSetThrottle.ToString();
masterSetThrottleString = GUI.TextField(new Rect(90, 85, 30, 20), masterSetThrottleString, 4, AAFldStyle);
masterSetThrottleString = GUI.TextField(new Rect(60, 85, 30, 20), masterSetThrottleString, 4, AAFldStyle);
try
{
masterSetThrottle = Convert.ToInt32(masterSetThrottleString); //convert string to number
RefreshPartModules();
RefreshPartModules();
}
catch
{
masterSetThrottleString = masterSetThrottle.ToString(); //conversion failed, reset change
}
GUI.Label(new Rect(122, 70, 10, 20), "%", HighLogic.Skin.label);
GUI.Label(new Rect(92, 70, 10, 20), "%", HighLogic.Skin.label);
}

if (masterSetPrecCtrl)
{
AABtnStyle.normal.background = ButtonTextureGreen;
AABtnStyle.hover.background = ButtonTextureGreen;
}
else
{
AABtnStyle.normal.background = ButtonTextureRed;
AABtnStyle.hover.background = ButtonTextureRed;
}
if (GUI.Button(new Rect(110, 85, 40, 20), "PCtrl", AABtnStyle))
{
masterSetPrecCtrl = !masterSetPrecCtrl;

RefreshPartModules();
}


AABtnStyle.normal.background = ButtonTextureGray;
AABtnStyle.hover.background = ButtonTextureGray;
GUI.DragWindow(); //window is draggable
}//close AAWindow()

GUI.DragWindow(); //window is draggable
}//close AAWindow()
//public void Update()
//{
// print("Upde" + BaseAction.ActionGroupsLength);
// print("Upde" + masterActivateGroupA);
//}
public string cvertToString(int num)
{
if(num == -200)
{
return "";
}
else
{
return num.ToString();
}
}
public int cvertToNum(string str)
{
if(str == "")
{
return -200;
}
else
{
return Convert.ToInt32(str);
}
}
}
}

26 changes: 25 additions & 1 deletion AutoAction/AutoActionFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,31 @@ public void Update()
FlightInputHandler.state.mainThrottle = Mathf.Max(0, Mathf.Min((float)aaPM.setThrottle / 100, 1)); //set throttle, from 0 to 1
//setThrottle = -50;
}
if (aaPM.setPrecCtrl)
{

FlightInputHandler.fetch.precisionMode = true;
foreach(Renderer rend in FlightInputHandler.fetch.inputGaugeRenderers)
{
//rend.material.color = new Color(0.976f, 0.451f, 0.024f);
rend.material.color = new Color(0.255f, 0.992f, 0.996f);
}

}
else
{


FlightInputHandler.fetch.precisionMode = false;
foreach (Renderer rend in FlightInputHandler.fetch.inputGaugeRenderers)
{
//rend.material.color = new Color(0.255f, 0.992f, 0.996f);
rend.material.color = new Color(0.976f, 0.451f, 0.024f);
}
}
aaPM.hasActivated = true; //this aaPM has been processed
aaPMfound = true;

}
}
else //aaPM has been found and processed already on this vessel, ignore any more aaPM's we find and mark them processed.
Expand All @@ -112,7 +135,8 @@ public void Update()
aaRootPart = FlightGlobals.ActiveVessel.rootPart;
}
}
}
//print("test " + FlightUIController.fetch.stgPitch.Value + "|" + FlightUIController.fetch.stgPitch.pointer.renderer.material.color);
} //close Update()

public void callActionGroup(int group)
{
Expand Down
2 changes: 2 additions & 0 deletions AutoAction/ModuleAutoAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ModuleAutoAction : PartModule
public int activateGroupF = 0;
[KSPField(isPersistant = true, guiActive = false, guiActiveEditor = false)]
public int setThrottle = -50;
[KSPField(isPersistant = true, guiActive = false, guiActiveEditor = false)] //activate SAS? same as T key
public bool setPrecCtrl = false;

//public void Start()
//{
Expand Down

0 comments on commit 619cfd9

Please sign in to comment.