/// <summary> /// Restores the maneuvers. /// </summary> /// <param name="stored">Stored maneuver.</param> void RestoreManeuver(StoredManeuver stored) { DeleteAll(); StoredManeuver restore = stored; while (restore != null) { ManeuverNode node = FlightGlobals.ActiveVessel.patchedConicSolver.AddManeuverNode(restore.UT); node.OnGizmoUpdated(restore.DeltaV, restore.UT); restore = restore.Next; } }
public StoredManeuver(Vector3d dv, double UT, StoredManeuver next = null) { _dv = dv; _UT = UT; _next = next; }
/// <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(); }
/// <summary> /// Restores the maneuvers. /// </summary> /// <param name="stored">Stored maneuver.</param> private void RestoreManeuver(StoredManeuver stored) { DeleteAll (); StoredManeuver restore = stored; while (restore != null) { ManeuverNode node = FlightGlobals.ActiveVessel.patchedConicSolver.AddManeuverNode (restore.UT); node.OnGizmoUpdated (restore.DeltaV, restore.UT); restore = restore.Next; } }
/// <summary> /// Draw the main window. /// </summary> /// <param name="windowId">Window identifier.</param> private 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",_buttonStyle) && IsAllowed()) { _maneuver = solver.AddManeuverNode(Planetarium.GetUniversalTime() + (10.0 * 60.0)); _mindex = solver.maneuverNodes.IndexOf (_maneuver); } if (GUILayout.Button ("Delete",_buttonStyle) && _maneuver != null) { _maneuver.RemoveSelf (); } if (GUILayout.Button ("Delete All",_buttonStyle) && _maneuver != null) { DeleteAll(); } if (GUILayout.Button ("Store",_buttonStyle) && 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",_buttonStyle)) { _maneuverShow = false; } GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); GUILayout.Label ("Warp", _labelStyle); if (GUILayout.Button ("+10m", _buttonStyle)) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (Planetarium.GetUniversalTime () + 10.0*Util.ONE_KMIN); } if (GUILayout.Button ("+1h", _buttonStyle)) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (Planetarium.GetUniversalTime () + Util.ONE_KHOUR); } if (GUILayout.Button ("+1d", _buttonStyle)) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (Planetarium.GetUniversalTime () + Util.ONE_KDAY); } if (GUILayout.Button ("+10d", _buttonStyle)) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (Planetarium.GetUniversalTime () + 10.0*Util.ONE_KDAY); } if (FlightGlobals.ActiveVessel.orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) { if (GUILayout.Button ("Transition", _buttonStyle)) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (FlightGlobals.ActiveVessel.orbit.EndUT - Util.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, _labelStyle); if (GUILayout.Button ("Next", _buttonStyle)) { _mindex++; if (_mindex >= solver.maneuverNodes.Count) _mindex = 0; _maneuver = solver.maneuverNodes [_mindex]; _mvessel = FlightGlobals.ActiveVessel; } if (GUILayout.Button ("Prev", _buttonStyle)) { _mindex--; if (_mindex < 0) _mindex = solver.maneuverNodes.Count - 1; _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", _labelStyle); if (GUILayout.Button ("-1m", _buttonStyle) && -timeToNode > Util.ONE_KMIN) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (_maneuver.UT - Util.ONE_KMIN); } if (GUILayout.Button ("-10m", _buttonStyle) && -timeToNode > 10.0 * Util.ONE_KMIN) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (_maneuver.UT - 10.0 * Util.ONE_KMIN); } if (GUILayout.Button ("-1h", _buttonStyle) && -timeToNode > Util.ONE_KHOUR) { // Cancel any existing warp. TimeWarp.SetRate (0, true); // Warp to the maneuver. TimeWarp.fetch.WarpTo (_maneuver.UT - Util.ONE_KHOUR); } GUILayout.EndHorizontal (); } else { GUILayout.Label ("Warp To Maneuver - Switch to first maneuver", _labelStyle); } GUILayout.Label ("Time:" + KartographStyle.Instance.GetTimeString (timeToNode), _labelStyle); GUILayout.Label ("Δv:" + KartographStyle.Instance.GetNumberString (_maneuver.DeltaV.magnitude) + "m/s", _labelStyle); 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, _buttonStyle, 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:" + KartographStyle.Instance.GetNumberString (_maneuver.DeltaV.z) + "m/s", _labelStyle, GUILayout.MinWidth (200.0f)); if (GUILayout.Button ("+", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.z += _increment; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } if (GUILayout.Button ("-", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.z -= _increment; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } if (GUILayout.Button ("0", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.z = 0.0d; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); GUILayout.Label ("Normal :" + KartographStyle.Instance.GetNumberString (_maneuver.DeltaV.y) + "m/s", _labelStyle, GUILayout.MinWidth (200.0f)); if (GUILayout.Button ("+", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.y += _increment; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } if (GUILayout.Button ("-", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.y -= _increment; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } if (GUILayout.Button ("0", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.y = 0.0d; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); GUILayout.Label ("Radial :" + KartographStyle.Instance.GetNumberString (_maneuver.DeltaV.x) + "m/s", _labelStyle, GUILayout.MinWidth (200.0f)); if (GUILayout.Button ("+", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.x += _increment; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } if (GUILayout.Button ("-", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.x -= _increment; _maneuver.OnGizmoUpdated (dv, _maneuver.UT); } if (GUILayout.Button ("0", _buttonStyle)) { Vector3d dv = _maneuver.DeltaV; dv.x = 0.0d; _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", _buttonStyle)) { _maneuver.OnGizmoUpdated (_maneuver.DeltaV, Planetarium.GetUniversalTime () + (10.0 * 60.0)); } double period = _maneuver.patch.period; if (GUILayout.Button ("+1 Orbit", _buttonStyle) && period > 0) { _maneuver.OnGizmoUpdated (_maneuver.DeltaV, _maneuver.UT + period); } if (GUILayout.Button ("-1 Orbit", _buttonStyle) && period > 0 && -timeToNode > period) { _maneuver.OnGizmoUpdated (_maneuver.DeltaV, _maneuver.UT - period); } if (GUILayout.Button ("+10 Orbit", _buttonStyle) && period > 0) { _maneuver.OnGizmoUpdated (_maneuver.DeltaV, _maneuver.UT + (10.0 * period)); } if (GUILayout.Button ("-10 Orbit", _buttonStyle) && period > 0 && -timeToNode > 10.0*period) { _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 (); }