Skip to content

Commit

Permalink
Add toggle to debug GUI for temporarily disabling all joints
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Mar 29, 2023
1 parent 527c467 commit 0d85fe1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions KerbalJointReinforcement/KerbalJointReinforcement/KJRManager.cs
Expand Up @@ -37,6 +37,7 @@ public class KJRManager : MonoBehaviour
private KJRMultiJointManager decouplerJointManager;
private bool isEVAConstructionModeActive = false;

private bool disableAllJoints = false;
private bool showAdditionalJoints = true;
private bool showInterstageJoints = true;
private List<LineRenderer> jointRenderers;
Expand Down Expand Up @@ -144,6 +145,7 @@ private void OnVesselOffRails(Vessel v)
if (v is null || v.isEVA)
return;

disableAllJoints = false;
bool vesselHasLaunchClamps = false;

RunVesselJointUpdateFunction(v);
Expand Down Expand Up @@ -1108,6 +1110,22 @@ private void WindowFunction(int windowID)
{
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(400), GUILayout.Height(500));
GUILayout.BeginVertical();

bool prevVal = disableAllJoints;
disableAllJoints = GUILayout.Toggle(disableAllJoints, "Disable all joints");
if (disableAllJoints != prevVal)
{
updatedVessels.Remove(FlightGlobals.ActiveVessel);
if (disableAllJoints)
{
DestroyAllExtraJoints(FlightGlobals.ActiveVessel);
}
else
{
StartCoroutine(RunVesselJointUpdateFunctionWhenSafe(FlightGlobals.ActiveVessel));
}
}

showAdditionalJoints = GUILayout.Toggle(showAdditionalJoints, "Show Additional Joints");
if (showAdditionalJoints)
{
Expand Down Expand Up @@ -1139,6 +1157,15 @@ private void WindowFunction(int windowID)
GUI.DragWindow();
}

private void DestroyAllExtraJoints(Vessel vessel)
{
foreach (Part p in vessel.Parts)
{
multiJointManager.OnJointBreak(p);
decouplerJointManager.OnJointBreak(p);
}
}

private void CleanUpDebugRenderers()
{
if (jointRenderers != null)
Expand Down

0 comments on commit 0d85fe1

Please sign in to comment.