Beispiel #1
0
        public void UpdateManeuverNodes(PatchedConicSolver solver)
        {
            if (solver == null)
            {
                return;
            }

            // Avoid flickering by not overwriting nodes where possible

            var maneuversLength = this.Maneuvers == null ? 0 : this.Maneuvers.Length;
            int commonLength    = Math.Min(solver.maneuverNodes.Count, maneuversLength);

            // update the common ones
            for (int i = 0; i < commonLength; i++)
            {
                var node       = solver.maneuverNodes[i];
                var nodeUpdate = this.Maneuvers[i];
                node.UT     = nodeUpdate.UniversalTime;
                node.DeltaV = nodeUpdate.DeltaV;
                node.OnGizmoUpdated(node.DeltaV, node.UT);
            }

            // remove any extra ones
            for (int i = solver.maneuverNodes.Count; i > maneuversLength; i--)
            {
                var node = solver.maneuverNodes[i - 1];
                solver.RemoveManeuverNode(node);
            }

            // add any new ones
            for (int i = solver.maneuverNodes.Count; i < maneuversLength; i++)
            {
                var          maneuver = this.Maneuvers[i];
                ManeuverNode node     = solver.AddManeuverNode(maneuver.UniversalTime);
                node.DeltaV = maneuver.DeltaV;
                node.OnGizmoUpdated(node.DeltaV, node.UT);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Draw the main window.
        /// </summary>
        /// <param name="windowId">Window identifier.</param>
        void OnWindow(int windowId)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            PatchedConicSolver solver = FlightGlobals.ActiveVessel.patchedConicSolver;

            GUILayout.BeginVertical(GUILayout.Width(320.0f));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("New") && IsAllowed())
            {
                _maneuver = solver.AddManeuverNode(Planetarium.GetUniversalTime() + (10.0 * 60.0));
                _mindex   = solver.maneuverNodes.IndexOf(_maneuver);
            }
            if (GUILayout.Button("Delete") && _maneuver != null)
            {
                _maneuver.RemoveSelf();
            }
            if (GUILayout.Button("Delete All") && _maneuver != null)
            {
                DeleteAll();
            }
            if (GUILayout.Button("Store") && solver.maneuverNodes.Count > 0)
            {
                StoredManeuver start = null;
                StoredManeuver prev  = null;
                foreach (ManeuverNode node in solver.maneuverNodes)
                {
                    StoredManeuver temp = new StoredManeuver(node.DeltaV, node.UT);
                    if (start == null)
                    {
                        start = temp;
                    }
                    if (prev != null)
                    {
                        prev.Next = temp;
                    }
                    prev = temp;
                }
                _stored.Add(start);
            }
            if (GUILayout.Button("Close"))
            {
                ToggleWindow();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Warp");
            if (GUILayout.Button("+10m"))
            {
                // Cancel any existing warp.
                TimeWarp.SetRate(0, true);
                // Warp to the maneuver.
                TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + 10.0 * Format.ONE_KMIN);
            }
            if (GUILayout.Button("+1h"))
            {
                // Cancel any existing warp.
                TimeWarp.SetRate(0, true);
                // Warp to the maneuver.
                TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + Format.ONE_KHOUR);
            }
            if (GUILayout.Button("+1d"))
            {
                // Cancel any existing warp.
                TimeWarp.SetRate(0, true);
                // Warp to the maneuver.
                TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + Format.ONE_KDAY);
            }
            if (GUILayout.Button("+10d"))
            {
                // Cancel any existing warp.
                TimeWarp.SetRate(0, true);
                // Warp to the maneuver.
                TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + 10.0 * Format.ONE_KDAY);
            }
            if (FlightGlobals.ActiveVessel.orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL)
            {
                if (GUILayout.Button("Transition"))
                {
                    // Cancel any existing warp.
                    TimeWarp.SetRate(0, true);
                    // Warp to the maneuver.
                    TimeWarp.fetch.WarpTo(FlightGlobals.ActiveVessel.orbit.EndUT - Format.ONE_KMIN);
                }
            }
            GUILayout.EndHorizontal();

            if (solver.maneuverNodes.Count > 0)
            {
                if (_maneuver == null || _mvessel != FlightGlobals.ActiveVessel ||
                    !solver.maneuverNodes.Contains(_maneuver))
                {
                    _maneuver = solver.maneuverNodes [0];
                    _mvessel  = FlightGlobals.ActiveVessel;
                    _mindex   = 0;
                }
                GUILayout.BeginHorizontal();
                GUILayout.Label("Maneuver:" + (_mindex + 1) + " of " +
                                solver.maneuverNodes.Count);
                if (GUILayout.Button("Prev"))
                {
                    _mindex--;
                    if (_mindex < 0)
                    {
                        _mindex = solver.maneuverNodes.Count - 1;
                    }
                    _maneuver = solver.maneuverNodes [_mindex];
                    _mvessel  = FlightGlobals.ActiveVessel;
                }
                if (GUILayout.Button("Next"))
                {
                    _mindex++;
                    if (_mindex >= solver.maneuverNodes.Count)
                    {
                        _mindex = 0;
                    }
                    _maneuver = solver.maneuverNodes [_mindex];
                    _mvessel  = FlightGlobals.ActiveVessel;
                }
                GUILayout.EndHorizontal();
                if (_maneuver != null)
                {
                    double timeToNode = Planetarium.GetUniversalTime() - _maneuver.UT;
                    if (_mindex == 0)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Warp To Maneuver");
                        if (GUILayout.Button("-1m") && -timeToNode > Format.ONE_KMIN)
                        {
                            // Cancel any existing warp.
                            TimeWarp.SetRate(0, true);
                            // Warp to the maneuver.
                            TimeWarp.fetch.WarpTo(_maneuver.UT - Format.ONE_KMIN);
                        }
                        if (GUILayout.Button("-10m") && -timeToNode > 10.0 * Format.ONE_KMIN)
                        {
                            // Cancel any existing warp.
                            TimeWarp.SetRate(0, true);
                            // Warp to the maneuver.
                            TimeWarp.fetch.WarpTo(_maneuver.UT - 10.0 * Format.ONE_KMIN);
                        }
                        if (GUILayout.Button("-1h") && -timeToNode > Format.ONE_KHOUR)
                        {
                            // Cancel any existing warp.
                            TimeWarp.SetRate(0, true);
                            // Warp to the maneuver.
                            TimeWarp.fetch.WarpTo(_maneuver.UT - Format.ONE_KHOUR);
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        GUILayout.Label("Warp To Maneuver - Switch to first maneuver");
                    }
                    GUILayout.Label("Time:" + KSPUtil.dateTimeFormatter.PrintDateDeltaCompact(timeToNode, true, true, true));
                    GUILayout.Label("Δv:" + Format.GetNumberString(_maneuver.DeltaV.magnitude) + "m/s");

                    GUILayout.BeginHorizontal();
                    _menuSelection = GUILayout.SelectionGrid(_menuSelection,
                                                             new string [] { ".01 m/s", ".1 m/s", "1 m/s", "10 m/s", "100 m/s", "1000 m/s" }, 3,
                                                             GUILayout.MinWidth(300.0f));
                    if (_menuSelection == 0)
                    {
                        _increment = 0.01d;
                    }
                    else if (_menuSelection == 1)
                    {
                        _increment = 0.1d;
                    }
                    else if (_menuSelection == 2)
                    {
                        _increment = 1.0d;
                    }
                    else if (_menuSelection == 3)
                    {
                        _increment = 10.0d;
                    }
                    else if (_menuSelection == 4)
                    {
                        _increment = 100.0d;
                    }
                    else if (_menuSelection == 5)
                    {
                        _increment = 1000.0d;
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Prograde:" + Format.GetNumberString(_maneuver.DeltaV.z) + "m/s",
                                    GUILayout.MinWidth(200.0f));
                    if (GUILayout.Button("-"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.z -= _increment;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    if (GUILayout.Button("0"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.z = 0.0d;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    if (GUILayout.Button("+"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.z += _increment;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Normal  :" + Format.GetNumberString(_maneuver.DeltaV.y) + "m/s",
                                    GUILayout.MinWidth(200.0f));
                    if (GUILayout.Button("-"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.y -= _increment;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    if (GUILayout.Button("0"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.y = 0.0d;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    if (GUILayout.Button("+"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.y += _increment;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Radial  :" + Format.GetNumberString(_maneuver.DeltaV.x) + "m/s",
                                    GUILayout.MinWidth(200.0f));
                    if (GUILayout.Button("-"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.x -= _increment;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    if (GUILayout.Button("0"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.x = 0.0d;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    if (GUILayout.Button("+"))
                    {
                        Vector3d dv = _maneuver.DeltaV;
                        dv.x += _increment;
                        _maneuver.OnGizmoUpdated(dv, _maneuver.UT);
                    }
                    GUILayout.EndHorizontal();

                    double ut       = _maneuver.UT;
                    double utUpdate = _timeControl.TimeGUI(ut, FlightGlobals.ActiveVessel);
                    if (utUpdate != ut)
                    {
                        _maneuver.OnGizmoUpdated(_maneuver.DeltaV, utUpdate);
                    }

                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("=10min"))
                    {
                        _maneuver.OnGizmoUpdated(_maneuver.DeltaV, Planetarium.GetUniversalTime() + (10.0 * 60.0));
                    }
                    double period = _maneuver.patch.period;
                    if (GUILayout.Button("-10 Orbit") && period > 0 && -timeToNode > 10.0 * period)
                    {
                        _maneuver.OnGizmoUpdated(_maneuver.DeltaV, _maneuver.UT - (10.0 * period));
                    }
                    if (GUILayout.Button("-1 Orbit") && period > 0 && -timeToNode > period)
                    {
                        _maneuver.OnGizmoUpdated(_maneuver.DeltaV, _maneuver.UT - period);
                    }
                    if (GUILayout.Button("+1 Orbit") && period > 0)
                    {
                        _maneuver.OnGizmoUpdated(_maneuver.DeltaV, _maneuver.UT + period);
                    }
                    if (GUILayout.Button("+10 Orbit") && period > 0)
                    {
                        _maneuver.OnGizmoUpdated(_maneuver.DeltaV, _maneuver.UT + (10.0 * period));
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    _windowPos.height = 0;
                }
            }
            else if (_maneuver != null)
            {
                _maneuver         = null;
                _windowPos.height = 0;
            }

            GUILayout.EndVertical();
            GUI.DragWindow();
        }
Beispiel #3
0
        internal void createManeuverNode(PatchedConicSolver p)
        {
            ManeuverNode newnode = p.AddManeuverNode(UT);

            newnode.OnGizmoUpdated(deltaV, UT);
        }
Beispiel #4
0
 internal void createManeuverNode(PatchedConicSolver p)
 {
     ManeuverNode newnode = p.AddManeuverNode(UT);
     newnode.OnGizmoUpdated(deltaV, UT);
 }