private string GetVesselState(VesselPhysicsHold instance) { sb.Clear(); if (instance.Vessel.isActiveVessel) { sb.Append("ACTIVE VESSEL - "); } if (instance.Vessel.Landed) { sb.Append("landed"); } else { sb.Append("not landed"); } if (instance.physicsHold) { sb.Append(", physics on hold"); } else if (instance.Vessel.packed) { sb.Append(", packed"); } else { sb.Append(", in physics"); } return(sb.ToString()); }
static bool Prefix(ModuleWheelBase __instance, GameEvents.FromToAction <Part, Part> FromTo) { if (FromTo.from.vessel == __instance.vessel || FromTo.to.vessel == __instance.vessel) { VesselPhysicsHold physicsHold = __instance.vessel.GetComponent <VesselPhysicsHold>(); if (physicsHold != null && (physicsHold.physicsHold || physicsHold.delayedPhysicsHoldEnableRequest)) { return(false); } } return(true); }
public static void RemoveInstance(VesselPhysicsHold instance) { if (Instance == null) { return; } Lib.LogDebug($"Removing VesselPhysicsHold instance for {instance.Vessel.vesselName}"); if (Instance.physicsHoldInstances.Remove(instance) && Instance.currentDialog != null) { Instance.DismissDialog(); Instance.ToggleDialog(); } }
// called after a new vessel is created following undocking private void OnVesselsUndocking(Vessel oldVessel, Vessel newVessel) { Lib.LogDebug($"OnVesselsUndocking called on {vessel.vesselName}, oldVessel {oldVessel.vesselName}, newVessel {newVessel.vesselName}"); if (vessel != oldVessel) { return; } if (physicsHold) { VesselPhysicsHold newVesselHoldInstance = newVessel.GetComponent <VesselPhysicsHold>(); newVesselHoldInstance.delayedPhysicsHoldEnableRequest = true; } }
// Called when a docking/coupling action is about to happen. Gives access to old and new vessel // Remove PAW buttons from the command parts and disable ourselves when the vessel // is about to be removed following a docking / coupling operation. private void OnPartCouple(GameEvents.FromToAction <Part, Part> data) { Lib.LogDebug($"OnPartCouple on {vessel.vesselName}, docked vessel : {data.from.vessel.vesselName}, dominant vessel : {data.to.vessel.vesselName}"); // in the case of KIS-adding parts, from / to vessel are the same : // we ignore the event and just pack the part. if (data.from.vessel == data.to.vessel && data.from.vessel == vessel && physicsHold) { OnPackPartTweaks(data.from, true, false, true); return; } // "from" is the part on the vessel that will be removed following coupling/docking // when docking to a packed vessel, depending on the stock choice for which one is the dominant vessel, we have two cases : // A. the dominant vessel is the on-hold vessel // - non-packed parts will be transferred to the resulting (already packed) vessel, we have to pack them // B. the dominant vessel is the not-on-hold vessel : // - the resulting vessel isn't packed, and physicsHold is false // - transferred parts will be packed, the others won't // from : docking vessel that will be removed if (data.from.vessel == vessel) { PhysicsHoldManager.RemoveInstance(this); // case B handling if (physicsHold) { DisablePhysicsHold(true); VesselPhysicsHold fromInstance = data.to.vessel.GetComponent <VesselPhysicsHold>(); fromInstance.delayedPhysicsHoldEnableRequest = true; } physicsHold = false; ClearEvents(); isEnabled = false; } // case A handling if (data.to.vessel == vessel && physicsHold) { foreach (Part part in data.from.vessel.Parts) { OnPackPartTweaks(part, true, false, true); } } }
static bool Prefix(ModuleWheelBase __instance, Vessel fromVessel, Vessel toVessel) { if (fromVessel == __instance.vessel || toVessel == __instance.vessel) { VesselPhysicsHold toVesselPhysicsHold = fromVessel.GetComponent <VesselPhysicsHold>(); if (toVesselPhysicsHold != null && (toVesselPhysicsHold.physicsHold || toVesselPhysicsHold.delayedPhysicsHoldEnableRequest)) { return(false); } VesselPhysicsHold fromVesselPhysicsHold = toVessel.GetComponent <VesselPhysicsHold>(); if (fromVesselPhysicsHold != null && (fromVesselPhysicsHold.physicsHold || fromVesselPhysicsHold.delayedPhysicsHoldEnableRequest)) { return(false); } } return(true); }
private string GetVesselName(VesselPhysicsHold instance) { sb.Clear(); int length = instance.Vessel.vesselName.Length; if (length > 40) { sb.Append(instance.Vessel.vesselName.Substring(0, 30)); sb.Append("..."); sb.Append(instance.Vessel.vesselName.Substring(length - 10, 10)); } else { sb.Append(instance.Vessel.vesselName); } return(sb.ToString()); }
public DialogGuiVesselWidget(VesselPhysicsHold instance) { this.instance = instance; vesselTitle = new DialogGUILabel(() => GetVesselName(instance), 270f); DialogGUIVerticalLayout vesselInfo = new DialogGUIVerticalLayout( vesselTitle, new DialogGUILabel(() => GetVesselState(instance))); vesselInfo.padding = new RectOffset(5, 0, 0, 0); switchToButton = new DialogGUIButton(string.Empty, () => FlightGlobals.SetActiveVessel(instance.Vessel), 28f, 28f, false); switchToButton.OptionInteractableCondition += () => instance.Vessel.loaded && !instance.Vessel.isActiveVessel; DialogGUIHorizontalLayout boxTopSection = new DialogGUIHorizontalLayout(switchToButton, vesselInfo); boxTopSection.anchor = TextAnchor.MiddleLeft; holdToggle = new DialogGUIToggle(() => instance.physicsHold, "Physics hold", instance.OnToggleHold, 80f, 32f); holdToggle.OptionInteractableCondition += instance.CanTogglePhysicsHold; roboticsToggle = new DialogGUIToggle(() => instance.roboticsOverride, "Exclude robotics", instance.OnToggleRobotics, 80f, 32f); roboticsToggle.OptionInteractableCondition += instance.CanToggleRobotics; deformationButton = new DialogGUIButton("", () => instance.OnApplyDeformation(), false); deformationButton.OptionInteractableCondition += instance.CanApplyDeformation; deformationButton.size = new Vector2(32f, 32f); deformationButton.AddChild(new DialogGUIImage(new Vector2(32f, 32f), new Vector2(0f, 0f), Color.white, Lib.DeformTexture)); deformationButtonLabel = new DialogGUILabel("Apply deformation", 80f, 32f); deformationButtonLabel.OptionInteractableCondition += instance.CanApplyDeformation; DialogGUIHorizontalLayout buttonsSection = new DialogGUIHorizontalLayout(holdToggle, roboticsToggle, deformationButton, deformationButtonLabel); DialogGUIVerticalLayout boxContent = new DialogGUIVerticalLayout(boxTopSection, buttonsSection); boxContent.padding = new RectOffset(5, 5, 5, 0); widgetBox = new DialogGUIBox("", 280f, 80f, null, boxContent); }
public static void AddInstance(VesselPhysicsHold instance) { if (Instance == null) { return; } if (Instance.physicsHoldInstances.Contains(instance)) { return; } Lib.LogDebug($"Adding VesselPhysicsHold instance for {instance.Vessel.vesselName}"); Instance.physicsHoldInstances.Add(instance); if (Instance.currentDialog != null) { Instance.DismissDialog(); Instance.ToggleDialog(); } }