private void clApp() { if (_patch == null) { return; } ITargetable tgt = FlightGlobals.fetch.VesselTarget; if (tgt == null) { return; } double clApp = 0; if (tgt.GetVessel() == null) { clApp = _patch.closestTgtApprUT; } else { clApp = ManeuverUtilities.closestVessel(0, _patch, tgt.GetOrbit(), true, 0, 0); } if (clApp <= 0) { return; } if (_patch.UTsoi > 0 && clApp > _patch.UTsoi) { return; } else if (clApp < Planetarium.GetUniversalTime()) { return; } else { setNodeTime(clApp); } }
private void checkOrbit() { if (_manager.SelectedManeuverNode == null || _snapTab == null) { return; } if (_patch == null) { SetFields(); } double UT = Planetarium.GetUniversalTime(); //_snapTab.CurrentTime.OnTextUpdate.Invoke(string.Format("Maneuver Node #{0}: T {1}", _index + 1, KSPUtil.PrintTime(UT - _manager.SelectedManeuverNode.UT, 3, true))); _snapTab.ResetTime.OnTextUpdate.Invoke(string.Format("{0}", KSPUtil.PrintTime(_startUT - UT, 3, false))); if (_patch.eccentricity >= 1) { if (_manager.SelectedManeuverNode.attachedGizmo != null) { _manager.SelectedManeuverNode.attachedGizmo.orbitsAdded = 0; } _orbitsAdded = 0; _snapTab.NextOrbitButton.gameObject.SetActive(false); _snapTab.PreviousOrbitButton.gameObject.SetActive(false); _snapTab.ApoButton.gameObject.SetActive(false); if (_patch.timeToPe < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.PeR < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && _patch.timeToPe + _patch.StartUT > _patch.UTsoi) { _snapTab.PeriButton.gameObject.SetActive(false); } else { _snapTab.PeriButton.gameObject.SetActive(true); periUT = _patch.StartUT + _patch.timeToPe; } if ((_patch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE || _patch.patchEndTransition == Orbit.PatchTransitionType.MANEUVER) && (_patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE)) { _snapTab.NextPatchButton.gameObject.SetActive(true); if (_patch.nextPatch.nextPatch.UTsoi > 0) { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.UTsoi - _patch.nextPatch.nextPatch.StartUT) / 2); } else if (_patch.nextPatch.nextPatch.eccentricity < 1 && !double.IsNaN(_patch.nextPatch.nextPatch.period) && !double.IsInfinity(_patch.nextPatch.nextPatch.period)) { nextPUT = _patch.nextPatch.nextPatch.StartUT + (_patch.nextPatch.nextPatch.period / 2); } else { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.EndUT - _patch.nextPatch.nextPatch.StartUT) / 2); } } else { _snapTab.NextPatchButton.gameObject.SetActive(false); } if (_patch.patchStartTransition == Orbit.PatchTransitionType.INITIAL || _patch.patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { _snapTab.PreviousPatchButton.gameObject.SetActive(false); } else { _snapTab.PreviousPatchButton.gameObject.SetActive(true); if (_patch.previousPatch.UTsoi > 0) { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.UTsoi - _patch.previousPatch.StartUT) / 2); } else if (_patch.previousPatch.eccentricity < 1 && !double.IsNaN(_patch.previousPatch.period) && !double.IsInfinity(_patch.previousPatch.period)) { prevPUT = _patch.previousPatch.StartUT + (_patch.previousPatch.period / 2); } else { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.EndUT - _patch.previousPatch.StartUT) / 2); } } eqAscUT = ManeuverUtilities.EqAscTime(_patch); if (_patch.UTsoi > 0 && eqAscUT > _patch.UTsoi) { _snapTab.EqAscButton.gameObject.SetActive(false); } else if (eqAscUT < UT) { _snapTab.EqAscButton.gameObject.SetActive(false); } else { _snapTab.EqAscButton.gameObject.SetActive(true); } eqDescUT = ManeuverUtilities.EqDescTime(_patch); if (_patch.UTsoi > 0 && eqDescUT > _patch.UTsoi) { _snapTab.EqDescButton.gameObject.SetActive(false); } else if (eqDescUT < UT) { _snapTab.EqDescButton.gameObject.SetActive(false); } else { _snapTab.EqDescButton.gameObject.SetActive(true); } ITargetable target = FlightGlobals.fetch.VesselTarget; if (target == null) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { Orbit tgtPatch = target.GetOrbit(); if (tgtPatch.referenceBody != _patch.referenceBody) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { relAscUT = ManeuverUtilities.RelAscTime(_patch, target); if (_patch.UTsoi > 0 && relAscUT > _patch.UTsoi) { _snapTab.RelAscButton.gameObject.SetActive(false); } else if (relAscUT < UT) { _snapTab.RelAscButton.gameObject.SetActive(false); } else { _snapTab.RelAscButton.gameObject.SetActive(true); } relDescUT = ManeuverUtilities.RelDescTime(_patch, target); if (_patch.UTsoi > 0 && relDescUT > _patch.UTsoi) { _snapTab.RelDescButton.gameObject.SetActive(false); } else if (relDescUT < UT) { _snapTab.RelDescButton.gameObject.SetActive(false); } else { _snapTab.RelDescButton.gameObject.SetActive(true); } if (target.GetVessel() == null) { clAppUT = _patch.closestTgtApprUT; } else { clAppUT = ManeuverUtilities.closestVessel(0, _patch, tgtPatch, true, 0, 0); } if (clAppUT <= 0) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && clAppUT > _patch.UTsoi) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (clAppUT < UT) { _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.ClAppButton.gameObject.SetActive(true); } } } } else { if (_patch.patchEndTransition == Orbit.PatchTransitionType.FINAL) { if (!double.IsNaN(_patch.period) && !double.IsInfinity(_patch.period)) { _snapTab.NextOrbitButton.gameObject.SetActive(true); nextOUT = _manager.SelectedManeuverNode.UT + _patch.period; } else { _snapTab.NextOrbitButton.gameObject.SetActive(false); } if (double.IsNaN(_patch.period) || double.IsInfinity(_patch.period) || _manager.SelectedManeuverNode.UT - _patch.period < UT) { _snapTab.PreviousOrbitButton.gameObject.SetActive(false); } else { _snapTab.PreviousOrbitButton.gameObject.SetActive(true); prevOUT = _manager.SelectedManeuverNode.UT - _patch.period; } _snapTab.ApoButton.gameObject.SetActive(true); apoUT = _patch.StartUT + _patch.timeToAp; _snapTab.PeriButton.gameObject.SetActive(true); periUT = _patch.StartUT + _patch.timeToPe; _snapTab.NextPatchButton.gameObject.SetActive(false); if (_patch.patchStartTransition == Orbit.PatchTransitionType.INITIAL || _patch.patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { _snapTab.PreviousPatchButton.gameObject.SetActive(false); } else { _snapTab.PreviousPatchButton.gameObject.SetActive(true); if (_patch.previousPatch.UTsoi > 0) { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.UTsoi - _patch.previousPatch.StartUT) / 2); } else if (_patch.previousPatch.eccentricity < 1 && !double.IsNaN(_patch.previousPatch.period) && !double.IsInfinity(_patch.previousPatch.period)) { prevPUT = _patch.previousPatch.StartUT + (_patch.previousPatch.period / 2); } else { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.EndUT - _patch.previousPatch.StartUT) / 2); } } _snapTab.EqAscButton.gameObject.SetActive(true); eqAscUT = ManeuverUtilities.EqAscTime(_patch); _snapTab.EqDescButton.gameObject.SetActive(true); eqDescUT = ManeuverUtilities.EqDescTime(_patch); ITargetable target = FlightGlobals.fetch.VesselTarget; if (target == null) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { Orbit tgtPatch = target.GetOrbit(); if (tgtPatch.referenceBody != _patch.referenceBody) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.RelAscButton.gameObject.SetActive(true); relAscUT = ManeuverUtilities.RelAscTime(_patch, target); _snapTab.RelDescButton.gameObject.SetActive(true); relDescUT = ManeuverUtilities.RelDescTime(_patch, target); if (target.GetVessel() == null) { clAppUT = _patch.closestTgtApprUT; } else { clAppUT = ManeuverUtilities.closestVessel(0, _patch, tgtPatch, true, 0, 0); } if (clAppUT <= 0) { _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.ClAppButton.gameObject.SetActive(true); } } } } else { if (_manager.SelectedManeuverNode.attachedGizmo != null) { _manager.SelectedManeuverNode.attachedGizmo.orbitsAdded = 0; } _orbitsAdded = 0; _snapTab.NextOrbitButton.gameObject.SetActive(false); _snapTab.PreviousOrbitButton.gameObject.SetActive(false); if (_patch.timeToAp < 0) { _snapTab.ApoButton.gameObject.SetActive(false); } if (_patch.UTsoi > 0 && _patch.timeToAp + _patch.StartUT > _patch.UTsoi) { _snapTab.ApoButton.gameObject.SetActive(false); } if (_patch.ApA > _patch.referenceBody.sphereOfInfluence) { _snapTab.ApoButton.gameObject.SetActive(false); } else { _snapTab.ApoButton.gameObject.SetActive(true); apoUT = _patch.StartUT + _patch.timeToAp; } if (_patch.timeToPe < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.PeR < 0) { _snapTab.PeriButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && _patch.timeToPe + _patch.StartUT > _patch.UTsoi) { _snapTab.PeriButton.gameObject.SetActive(false); } else { _snapTab.PeriButton.gameObject.SetActive(true); periUT = _patch.StartUT + _patch.timeToPe; } if ((_patch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE || _patch.patchEndTransition == Orbit.PatchTransitionType.MANEUVER) && (_patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER || _patch.nextPatch.patchEndTransition == Orbit.PatchTransitionType.ESCAPE)) { _snapTab.NextPatchButton.gameObject.SetActive(true); if (_patch.nextPatch.nextPatch.UTsoi > 0) { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.UTsoi - _patch.nextPatch.nextPatch.StartUT) / 2); } else if (_patch.nextPatch.nextPatch.eccentricity < 1 && !double.IsNaN(_patch.nextPatch.nextPatch.period) && !double.IsInfinity(_patch.nextPatch.nextPatch.period)) { nextPUT = _patch.nextPatch.nextPatch.StartUT + (_patch.nextPatch.nextPatch.period / 2); } else { nextPUT = _patch.nextPatch.nextPatch.StartUT + ((_patch.nextPatch.nextPatch.EndUT - _patch.nextPatch.nextPatch.StartUT) / 2); } } else { _snapTab.NextPatchButton.gameObject.SetActive(false); } if (_patch.patchStartTransition == Orbit.PatchTransitionType.INITIAL || _patch.patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { _snapTab.PreviousPatchButton.gameObject.SetActive(false); } else { _snapTab.PreviousPatchButton.gameObject.SetActive(true); if (_patch.previousPatch.UTsoi > 0) { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.UTsoi - _patch.previousPatch.StartUT) / 2); } else if (_patch.previousPatch.eccentricity < 1 && !double.IsNaN(_patch.previousPatch.period) && !double.IsInfinity(_patch.previousPatch.period)) { prevPUT = _patch.previousPatch.StartUT + (_patch.previousPatch.period / 2); } else { prevPUT = _patch.previousPatch.StartUT + ((_patch.previousPatch.EndUT - _patch.previousPatch.StartUT) / 2); } } eqAscUT = ManeuverUtilities.EqAscTime(_patch); if (_patch.UTsoi > 0 && eqAscUT > _patch.UTsoi) { _snapTab.EqAscButton.gameObject.SetActive(false); } else if (eqAscUT < UT) { _snapTab.EqAscButton.gameObject.SetActive(false); } else { _snapTab.EqAscButton.gameObject.SetActive(true); } eqDescUT = ManeuverUtilities.EqDescTime(_patch); if (_patch.UTsoi > 0 && eqDescUT > _patch.UTsoi) { _snapTab.EqDescButton.gameObject.SetActive(false); } else if (eqDescUT < UT) { _snapTab.EqDescButton.gameObject.SetActive(false); } else { _snapTab.EqDescButton.gameObject.SetActive(true); } ITargetable target = FlightGlobals.fetch.VesselTarget; if (target == null) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { Orbit tgtPatch = target.GetOrbit(); if (tgtPatch.referenceBody != _patch.referenceBody) { _snapTab.RelAscButton.gameObject.SetActive(false); _snapTab.RelDescButton.gameObject.SetActive(false); _snapTab.ClAppButton.gameObject.SetActive(false); } else { relAscUT = ManeuverUtilities.RelAscTime(_patch, target); if (_patch.UTsoi > 0 && relAscUT > _patch.UTsoi) { _snapTab.RelAscButton.gameObject.SetActive(false); } else if (relAscUT < UT) { _snapTab.RelAscButton.gameObject.SetActive(false); } else { _snapTab.RelAscButton.gameObject.SetActive(true); } relDescUT = ManeuverUtilities.RelDescTime(_patch, target); if (_patch.UTsoi > 0 && relDescUT > _patch.UTsoi) { _snapTab.RelDescButton.gameObject.SetActive(false); } else if (relDescUT < UT) { _snapTab.RelDescButton.gameObject.SetActive(false); } else { _snapTab.RelDescButton.gameObject.SetActive(true); } if (target.GetVessel() == null) { clAppUT = _patch.closestTgtApprUT; } else { clAppUT = ManeuverUtilities.closestVessel(0, _patch, tgtPatch, true, 0, 0); } if (clAppUT <= 0) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (_patch.UTsoi > 0 && clAppUT > _patch.UTsoi) { _snapTab.ClAppButton.gameObject.SetActive(false); } else if (clAppUT < UT) { _snapTab.ClAppButton.gameObject.SetActive(false); } else { _snapTab.ClAppButton.gameObject.SetActive(true); } } } } } }