protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUIStyle s = new GUIStyle(GUI.skin.label); s.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Landing", s); Runway[] runways = MechJebModuleSpaceplaneAutopilot.runways; int runwayIndex = Array.IndexOf(runways, autopilot.runway); runwayIndex = GuiUtils.ArrowSelector(runwayIndex, runways.Length, autopilot.runway.name); autopilot.runway = runways[runwayIndex]; GUILayout.Label("Distance to runway: " + MuUtils.ToSI(Vector3d.Distance(vesselState.CoM, autopilot.runway.Start(vesselState.CoM)), 0) + "m"); showLandingTarget = GUILayout.Toggle(showLandingTarget, "Show landing navball guidance"); if (GUILayout.Button("Autoland")) { autopilot.Autoland(this); } if (autopilot.enabled && autopilot.mode == MechJebModuleSpaceplaneAutopilot.Mode.AUTOLAND && GUILayout.Button("Abort")) { autopilot.AutopilotOff(); } GuiUtils.SimpleTextBox("Autoland glideslope:", autopilot.glideslope, "º"); GUILayout.Label("Hold", s); GUILayout.BeginHorizontal(); if (GUILayout.Button("Initiate hold:")) { autopilot.HoldHeadingAndAltitude(this); } GUILayout.Label("Heading:"); autopilot.targetHeading.text = GUILayout.TextField(autopilot.targetHeading.text, GUILayout.Width(40)); GUILayout.Label("º Altitude:"); autopilot.targetAltitude.text = GUILayout.TextField(autopilot.targetAltitude.text, GUILayout.Width(40)); GUILayout.Label("m"); GUILayout.EndHorizontal(); if (autopilot.enabled && autopilot.mode == MechJebModuleSpaceplaneAutopilot.Mode.HOLD && GUILayout.Button("Abort")) { autopilot.AutopilotOff(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ArrowSelector((int)warpTarget, numWarpTargets, warpTargetStrings[(int)warpTarget]); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); if (warping) { if (GUILayout.Button("Abort")) { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button("Warp")) { warping = true; } } GUILayout.EndHorizontal(); if (warping) { GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); } GUILayout.EndVertical(); GUI.DragWindow(); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); if (editedWindow == null) { editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>(); } if (editedWindow == null) { if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button1"))) { AddNewWindow(); //New window } } else { GUILayout.BeginHorizontal(); if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button1"))) { AddNewWindow(); //New window } if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button2"))) { RemoveCurrentWindow(); //Delete window } GUILayout.EndHorizontal(); } if (editedWindow != null) { List <ComputerModule> allWindows = core.GetComputerModules <MechJebModuleCustomInfoWindow>(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_Edtitle"), GUILayout.ExpandWidth(false));//Title: int editedWindowIndex = allWindows.IndexOf(editedWindow); editedWindowIndex = GuiUtils.ArrowSelector(editedWindowIndex, allWindows.Count, () => { string newTitle = GUILayout.TextField(editedWindow.title, GUILayout.Width(120), GUILayout.ExpandWidth(false)); if (editedWindow.title != newTitle) { editedWindow.title = newTitle; editedWindow.dirty = true; } }); editedWindow = (MechJebModuleCustomInfoWindow)allWindows[editedWindowIndex]; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label1")); //Show in: editedWindow.ShowInFlight = GUILayout.Toggle(editedWindow.ShowInFlight, Localizer.Format("#MechJeb_WindowEd_checkbox1"), GUILayout.Width(60)); //Flight editedWindow.ShowInEditor = GUILayout.Toggle(editedWindow.ShowInEditor, Localizer.Format("#MechJeb_WindowEd_checkbox2")); //Editor GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); editedWindow.IsOverlay = GUILayout.Toggle(editedWindow.IsOverlay, Localizer.Format("#MechJeb_WindowEd_checkbox3")); //Overlay editedWindow.Locked = GUILayout.Toggle(editedWindow.Locked, Localizer.Format("#MechJeb_WindowEd_checkbox4")); //Locked editedWindow.IsCompact = GUILayout.Toggle(editedWindow.IsCompact, Localizer.Format("#MechJeb_WindowEd_checkbox5")); //Compact GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label2"));//Color: bool previous = editingText; editingText = GUILayout.Toggle(editingText, Localizer.Format("#MechJeb_WindowEd_checkbox6"));//Text if (editingText && editingText != previous) { editingBackground = false; } previous = editingBackground; editingBackground = GUILayout.Toggle(editingBackground, Localizer.Format("#MechJeb_WindowEd_checkbox7"));//Background if (editingBackground && editingBackground != previous) { editingText = false; } GUILayout.EndHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label3"));//Window contents (click to edit): GUILayout.BeginVertical(GUILayout.Height(100)); scrollPos = GUILayout.BeginScrollView(scrollPos); for (int i = 0; i < editedWindow.items.Count; i++) { GUIStyle s = new GUIStyle(GUI.skin.label); if (i == selectedItemIndex) { s.normal.textColor = Color.yellow; } if (GUILayout.Button(Localizer.Format(editedWindow.items[i].description), s)) { selectedItemIndex = i; // } } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); if (!(selectedItemIndex >= 0 && selectedItemIndex < editedWindow.items.Count)) { selectedItemIndex = -1; } if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button3")) && selectedItemIndex != -1) { editedWindow.items.RemoveAt(selectedItemIndex); //Remove } if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button4")) && selectedItemIndex != -1) //"Move up" { if (selectedItemIndex > 0) { InfoItem item = editedWindow.items[selectedItemIndex]; editedWindow.items.RemoveAt(selectedItemIndex); editedWindow.items.Insert(selectedItemIndex - 1, item); selectedItemIndex -= 1; } } if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button5")) && selectedItemIndex != -1)//Move down { if (selectedItemIndex < editedWindow.items.Count) { InfoItem item = editedWindow.items[selectedItemIndex]; editedWindow.items.RemoveAt(selectedItemIndex); editedWindow.items.Insert(selectedItemIndex + 1, item); selectedItemIndex += 1; } } GUILayout.EndHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label4"));//Click an item to add it to the info window: itemCategory = (InfoItem.Category)GuiUtils.ComboBox.Box((int)itemCategory, categories, this); scrollPos2 = GUILayout.BeginScrollView(scrollPos2); foreach (InfoItem item in registry.Where(it => it.category == itemCategory).OrderBy(it => it.description)) { if (GUILayout.Button(Localizer.Format(item.description), GuiUtils.yellowOnHover))// { editedWindow.items.Add(item); } } GUILayout.EndScrollView(); } GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label5"), new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter }); //Window presets: presetIndex = GuiUtils.ArrowSelector(presetIndex, CustomWindowPresets.presets.Length, () => { if (GUILayout.Button(CustomWindowPresets.presets[presetIndex].name)) { MechJebModuleCustomInfoWindow newWindow = CreateWindowFromSharingString(CustomWindowPresets.presets[presetIndex].sharingString); if (newWindow != null) { editedWindow = newWindow; } } }); GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { if (vessel.patchedConicSolver.maneuverNodes.Count == 0) { GUILayout.Label(Localizer.Format("#MechJeb_NodeEd_Label1"));//"No maneuver nodes to edit." RelativityModeSelectUI(); base.WindowGUI(windowID); return; } GUILayout.BeginVertical(); ManeuverNode oldNode = node; if (vessel.patchedConicSolver.maneuverNodes.Count == 1) { node = vessel.patchedConicSolver.maneuverNodes[0]; } else { if (!vessel.patchedConicSolver.maneuverNodes.Contains(node)) { node = vessel.patchedConicSolver.maneuverNodes[0]; } int nodeIndex = vessel.patchedConicSolver.maneuverNodes.IndexOf(node); int numNodes = vessel.patchedConicSolver.maneuverNodes.Count; nodeIndex = GuiUtils.ArrowSelector(nodeIndex, numNodes, "Maneuver node #" + (nodeIndex + 1)); node = vessel.patchedConicSolver.maneuverNodes[nodeIndex]; if (nodeIndex < (numNodes - 1) && GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button1"))) { MergeNext(nodeIndex); //"Merge next node" } } if (node != oldNode) { prograde = node.DeltaV.z; radialPlus = node.DeltaV.x; normalPlus = node.DeltaV.y; } if (gizmo != node.attachedGizmo) { if (gizmo != null) { gizmo.OnGizmoUpdated -= GizmoUpdateHandler; } gizmo = node.attachedGizmo; if (gizmo != null) { gizmo.OnGizmoUpdated += GizmoUpdateHandler; } } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_NodeEd_Label2"), prograde, "m/s", 60);//"Prograde:" if (LimitedRepeatButtoon("-")) { prograde -= progradeDelta; node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } progradeDelta.text = GUILayout.TextField(progradeDelta.text, GUILayout.Width(50)); if (LimitedRepeatButtoon("+")) { prograde += progradeDelta; node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_NodeEd_Label3"), radialPlus, "m/s", 60);//"Radial+:" if (LimitedRepeatButtoon("-")) { radialPlus -= radialPlusDelta; node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } radialPlusDelta.text = GUILayout.TextField(radialPlusDelta.text, GUILayout.Width(50)); if (LimitedRepeatButtoon("+")) { radialPlus += radialPlusDelta; node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_NodeEd_Label4"), normalPlus, "m/s", 60);//"Normal+:" if (LimitedRepeatButtoon("-")) { normalPlus -= normalPlusDelta; node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } normalPlusDelta.text = GUILayout.TextField(normalPlusDelta.text, GUILayout.Width(50)); if (LimitedRepeatButtoon("+")) { normalPlus += normalPlusDelta; node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_NodeEd_Label5"), GUILayout.ExpandWidth(true));//"Set delta to:" if (GUILayout.Button("0.01", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 0.01; } if (GUILayout.Button("0.1", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 0.1; } if (GUILayout.Button("1", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 1; } if (GUILayout.Button("10", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 10; } if (GUILayout.Button("100", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 100; } GUILayout.EndHorizontal(); if (GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button2"))) { node.UpdateNode(new Vector3d(radialPlus, normalPlus, prograde), node.UT); //"Update" } GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_NodeEd_Label6"), GUILayout.ExpandWidth(true));//"Shift time" if (GUILayout.Button("-o", GUILayout.ExpandWidth(false))) { node.UpdateNode(node.DeltaV, node.UT - node.patch.period); } if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { node.UpdateNode(node.DeltaV, node.UT - timeOffset); } timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { node.UpdateNode(node.DeltaV, node.UT + timeOffset); } if (GUILayout.Button("+o", GUILayout.ExpandWidth(false))) { node.UpdateNode(node.DeltaV, node.UT + node.patch.period); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button3"), GUILayout.ExpandWidth(true)))//"Snap node to" { Orbit o = node.patch; double UT = node.UT; switch (snap) { case Snap.PERIAPSIS: UT = o.NextPeriapsisTime(o.eccentricity < 1 ? UT - o.period / 2 : UT); break; case Snap.APOAPSIS: if (o.eccentricity < 1) { UT = o.NextApoapsisTime(UT - o.period / 2); } break; case Snap.EQ_ASCENDING: if (o.AscendingNodeEquatorialExists()) { UT = o.TimeOfAscendingNodeEquatorial(UT - o.period / 2); } break; case Snap.EQ_DESCENDING: if (o.DescendingNodeEquatorialExists()) { UT = o.TimeOfDescendingNodeEquatorial(UT - o.period / 2); } break; case Snap.REL_ASCENDING: if (core.target.NormalTargetExists && core.target.TargetOrbit.referenceBody == o.referenceBody) { if (o.AscendingNodeExists(core.target.TargetOrbit)) { UT = o.TimeOfAscendingNode(core.target.TargetOrbit, UT - o.period / 2); } } break; case Snap.REL_DESCENDING: if (core.target.NormalTargetExists && core.target.TargetOrbit.referenceBody == o.referenceBody) { if (o.DescendingNodeExists(core.target.TargetOrbit)) { UT = o.TimeOfDescendingNode(core.target.TargetOrbit, UT - o.period / 2); } } break; } node.UpdateNode(node.DeltaV, UT); } snap = (Snap)GuiUtils.ArrowSelector((int)snap, numSnaps, snapStrings[(int)snap]); GUILayout.EndHorizontal(); RelativityModeSelectUI(); if (core.node != null) { if (vessel.patchedConicSolver.maneuverNodes.Count > 0 && !core.node.enabled) { if (GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button4")))//"Execute next node" { core.node.ExecuteOneNode(this); } if (MechJebModuleGuidanceController.isLoadedPrincipia && GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button7")))//Execute next Principia node { core.node.ExecuteOnePNode(this); } if (vessel.patchedConicSolver.maneuverNodes.Count > 1) { if (GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button5")))//"Execute all nodes" { core.node.ExecuteAllNodes(this); } } } else if (core.node.enabled) { if (GUILayout.Button(Localizer.Format("#MechJeb_NodeEd_button6")))//"Abort node execution" { core.node.Abort(); } } GUILayout.BeginHorizontal(); core.node.autowarp = GUILayout.Toggle(core.node.autowarp, Localizer.Format("#MechJeb_NodeEd_checkbox1"), GUILayout.ExpandWidth(true)); //"Auto-warp" GUILayout.Label(Localizer.Format("#MechJeb_NodeEd_Label7"), GUILayout.ExpandWidth(false)); //"Tolerance:" core.node.tolerance.text = GUILayout.TextField(core.node.tolerance.text, GUILayout.Width(35), GUILayout.ExpandWidth(false)); GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); if (editedWindow == null) { editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>(); } if (editedWindow == null) { if (GUILayout.Button("New window")) { AddNewWindow(); } } else { GUILayout.BeginHorizontal(); if (GUILayout.Button("New window")) { AddNewWindow(); } if (GUILayout.Button("Delete window")) { RemoveCurrentWindow(); } GUILayout.EndHorizontal(); } if (editedWindow != null) { List <MechJebModuleCustomInfoWindow> allWindows = core.GetComputerModules <MechJebModuleCustomInfoWindow>(); GUILayout.BeginHorizontal(); GUILayout.Label("Title:", GUILayout.ExpandWidth(false)); int editedWindowIndex = allWindows.IndexOf(editedWindow); editedWindowIndex = GuiUtils.ArrowSelector(editedWindowIndex, allWindows.Count, () => { editedWindow.title = GUILayout.TextField(editedWindow.title, GUILayout.Width(120), GUILayout.ExpandWidth(false)); }); editedWindow = allWindows[editedWindowIndex]; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Show in:"); editedWindow.showInFlight = GUILayout.Toggle(editedWindow.showInFlight, "Flight", GUILayout.Width(60)); editedWindow.showInEditor = GUILayout.Toggle(editedWindow.showInEditor, "Editor"); GUILayout.EndHorizontal(); GUILayout.Label("Window contents (click to edit):"); GUILayout.BeginVertical(GUILayout.Height(100)); scrollPos = GUILayout.BeginScrollView(scrollPos); for (int i = 0; i < editedWindow.items.Count; i++) { GUIStyle s = new GUIStyle(GUI.skin.label); if (i == selectedItemIndex) { s.normal.textColor = Color.yellow; } if (GUILayout.Button(editedWindow.items[i].description, s)) { selectedItemIndex = i; } } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); if (!(selectedItemIndex >= 0 && selectedItemIndex < editedWindow.items.Count)) { selectedItemIndex = -1; } if (GUILayout.Button("Remove") && selectedItemIndex != -1) { editedWindow.items.RemoveAt(selectedItemIndex); } if (GUILayout.Button("Move up") && selectedItemIndex != -1) { if (selectedItemIndex > 0) { InfoItem item = editedWindow.items[selectedItemIndex]; editedWindow.items.RemoveAt(selectedItemIndex); editedWindow.items.Insert(selectedItemIndex - 1, item); selectedItemIndex -= 1; } } if (GUILayout.Button("Move down") && selectedItemIndex != -1) { if (selectedItemIndex < editedWindow.items.Count) { InfoItem item = editedWindow.items[selectedItemIndex]; editedWindow.items.RemoveAt(selectedItemIndex); editedWindow.items.Insert(selectedItemIndex + 1, item); selectedItemIndex += 1; } } GUILayout.EndHorizontal(); GUILayout.Label("Click an item to add it to the info window:"); itemCategory = (InfoItem.Category)GuiUtils.ArrowSelector((int)itemCategory, numCategories, itemCategory.ToString()); scrollPos2 = GUILayout.BeginScrollView(scrollPos2); foreach (InfoItem item in registry.Where(it => it.category == itemCategory).OrderBy(it => it.description)) { if (GUILayout.Button(item.description, GuiUtils.yellowOnHover)) { editedWindow.items.Add(item); } } GUILayout.EndScrollView(); } GUILayout.Label("Window presets:", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter }); presetIndex = GuiUtils.ArrowSelector(presetIndex, CustomWindowPresets.presets.Length, () => { if (GUILayout.Button(CustomWindowPresets.presets[presetIndex].name)) { MechJebModuleCustomInfoWindow newWindow = CreateWindowFromSharingString(CustomWindowPresets.presets[presetIndex].sharingString); if (newWindow != null) { editedWindow = newWindow; } } }); GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { if (vessel.patchedConicSolver.maneuverNodes.Count == 0) { GUILayout.Label("No maneuver nodes to edit."); RelativityModeSelectUI(); base.WindowGUI(windowID); return; } GUILayout.BeginVertical(); ManeuverNode oldNode = node; if (vessel.patchedConicSolver.maneuverNodes.Count == 1) { node = vessel.patchedConicSolver.maneuverNodes[0]; } else { if (!vessel.patchedConicSolver.maneuverNodes.Contains(node)) { node = vessel.patchedConicSolver.maneuverNodes[0]; } int nodeIndex = vessel.patchedConicSolver.maneuverNodes.IndexOf(node); int numNodes = vessel.patchedConicSolver.maneuverNodes.Count; nodeIndex = GuiUtils.ArrowSelector(nodeIndex, numNodes, "Maneuver node #" + (nodeIndex + 1)); node = vessel.patchedConicSolver.maneuverNodes[nodeIndex]; } if (node != oldNode) { prograde = node.DeltaV.z; radialPlus = node.DeltaV.x; normalPlus = node.DeltaV.y; } if (gizmo != node.attachedGizmo) { if (gizmo != null) { gizmo.OnGizmoUpdated -= GizmoUpdateHandler; } gizmo = node.attachedGizmo; if (gizmo != null) { gizmo.OnGizmoUpdated += GizmoUpdateHandler; } } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Prograde:", prograde, "m/s", 60); if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { prograde -= progradeDelta; node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } progradeDelta.text = GUILayout.TextField(progradeDelta.text, GUILayout.Width(50)); if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { prograde += progradeDelta; node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Radial+:", radialPlus, "m/s", 60); if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { radialPlus -= radialPlusDelta; node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } radialPlusDelta.text = GUILayout.TextField(radialPlusDelta.text, GUILayout.Width(50)); if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { radialPlus += radialPlusDelta; node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Normal+:", normalPlus, "m/s", 60); if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { normalPlus -= normalPlusDelta; node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } normalPlusDelta.text = GUILayout.TextField(normalPlusDelta.text, GUILayout.Width(50)); if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { normalPlus += normalPlusDelta; node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Set delta to:", GUILayout.ExpandWidth(true)); if (GUILayout.Button("0.01", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 0.01; } if (GUILayout.Button("0.1", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 0.1; } if (GUILayout.Button("1", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 1; } if (GUILayout.Button("10", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 10; } if (GUILayout.Button("100", GUILayout.ExpandWidth(true))) { progradeDelta = radialPlusDelta = normalPlusDelta = 100; } GUILayout.EndHorizontal(); if (GUILayout.Button("Update")) { node.OnGizmoUpdated(new Vector3d(radialPlus, normalPlus, prograde), node.UT); } GUILayout.BeginHorizontal(); GUILayout.Label("Shift time", GUILayout.ExpandWidth(true)); if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { node.OnGizmoUpdated(node.DeltaV, node.UT - timeOffset); } timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { node.OnGizmoUpdated(node.DeltaV, node.UT + timeOffset); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Snap node to", GUILayout.ExpandWidth(true))) { Orbit o = node.patch; double UT = node.UT; switch (snap) { case Snap.PERIAPSIS: UT = o.NextPeriapsisTime(UT - o.period / 2); //period is who-knows-what for e > 1, but this should still work break; case Snap.APOAPSIS: if (o.eccentricity < 1) { UT = o.NextApoapsisTime(UT - o.period / 2); } break; case Snap.EQ_ASCENDING: if (o.AscendingNodeEquatorialExists()) { UT = o.TimeOfAscendingNodeEquatorial(UT - o.period / 2); } break; case Snap.EQ_DESCENDING: if (o.DescendingNodeEquatorialExists()) { UT = o.TimeOfDescendingNodeEquatorial(UT - o.period / 2); } break; case Snap.REL_ASCENDING: if (core.target.NormalTargetExists && core.target.TargetOrbit.referenceBody == o.referenceBody) { if (o.AscendingNodeExists(core.target.TargetOrbit)) { UT = o.TimeOfAscendingNode(core.target.TargetOrbit, UT - o.period / 2); } } break; case Snap.REL_DESCENDING: if (core.target.NormalTargetExists && core.target.TargetOrbit.referenceBody == o.referenceBody) { if (o.DescendingNodeExists(core.target.TargetOrbit)) { UT = o.TimeOfDescendingNode(core.target.TargetOrbit, UT - o.period / 2); } } break; } node.OnGizmoUpdated(node.DeltaV, UT); } snap = (Snap)GuiUtils.ArrowSelector((int)snap, numSnaps, snapStrings[(int)snap]); GUILayout.EndHorizontal(); RelativityModeSelectUI(); if (core.node != null) { if (vessel.patchedConicSolver.maneuverNodes.Count > 0 && !core.node.enabled) { if (GUILayout.Button("Execute next node")) { core.node.ExecuteOneNode(this); } if (vessel.patchedConicSolver.maneuverNodes.Count > 1) { if (GUILayout.Button("Execute all nodes")) { core.node.ExecuteAllNodes(this); } } } else if (core.node.enabled) { if (GUILayout.Button("Abort node execution")) { core.node.Abort(); } } GUILayout.BeginHorizontal(); core.node.autowarp = GUILayout.Toggle(core.node.autowarp, "Auto-warp", GUILayout.ExpandWidth(true)); GUILayout.Label("Tolerance:", GUILayout.ExpandWidth(false)); core.node.tolerance.text = GUILayout.TextField(core.node.tolerance.text, GUILayout.Width(35), GUILayout.ExpandWidth(false)); GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { if (!core.target.NormalTargetExists) { GUILayout.Label("Select a target to rendezvous with."); base.WindowGUI(windowID); return; } if (core.target.Orbit.referenceBody != orbit.referenceBody) { GUILayout.Label("Rendezvous target must be in the same sphere of influence."); base.WindowGUI(windowID); return; } GUILayout.BeginVertical(); step = (Step)GuiUtils.ArrowSelector((int)step, numSteps, stepStrings[(int)step]); double leadTime = 30; switch (step) { case Step.AlignPlanes: GUILayout.Label("First, bring your relative inclination to zero by aligning your orbital plane with the target's orbital plane:"); GUILayout.Label("Relative inclination: " + orbit.RelativeInclination(core.target.Orbit).ToString("F2") + "º"); if (GUILayout.Button("Align Planes")) { double UT; Vector3d dV; if (orbit.AscendingNodeExists(core.target.Orbit)) { dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesAscending(orbit, core.target.Orbit, vesselState.time, out UT); } else { dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesDescending(orbit, core.target.Orbit, vesselState.time, out UT); } vessel.PlaceManeuverNode(orbit, dV, UT); } break; case Step.PhasingOrbit: double phasingOrbitRadius = 0.9 * core.target.Orbit.PeR; if (phasingOrbitRadius < orbit.referenceBody.Radius + orbit.referenceBody.RealMaxAtmosphereAltitude()) { phasingOrbitRadius = 1.1 * core.target.Orbit.ApR; } double phasingOrbitAltitude = phasingOrbitRadius - mainBody.Radius; GUILayout.Label("Next, establish a circular phasing orbit close to the target orbit."); GUILayout.Label("Target orbit: " + MuUtils.ToSI(core.target.Orbit.PeA, 3) + "m x " + MuUtils.ToSI(core.target.Orbit.ApA, 3) + "m"); GUILayout.Label("Suggested phasing orbit: " + MuUtils.ToSI(phasingOrbitAltitude, 3) + "m x " + MuUtils.ToSI(phasingOrbitAltitude, 3) + "m"); GUILayout.Label("Current orbit: " + MuUtils.ToSI(orbit.PeA, 3) + "m x " + MuUtils.ToSI(orbit.ApA, 3) + "m"); if (GUILayout.Button("Establish Phasing Orbit")) { if (orbit.ApR < phasingOrbitRadius) { double UT1 = vesselState.time + leadTime; Vector3d dV1 = OrbitalManeuverCalculator.DeltaVToChangeApoapsis(orbit, UT1, phasingOrbitRadius); vessel.PlaceManeuverNode(orbit, dV1, UT1); Orbit transferOrbit = vessel.patchedConicSolver.maneuverNodes[0].nextPatch; double UT2 = transferOrbit.NextApoapsisTime(UT1); Vector3d dV2 = OrbitalManeuverCalculator.DeltaVToCircularize(transferOrbit, UT2); vessel.PlaceManeuverNode(transferOrbit, dV2, UT2); } else if (orbit.PeR > phasingOrbitRadius) { double UT1 = vesselState.time + leadTime; Vector3d dV1 = OrbitalManeuverCalculator.DeltaVToChangePeriapsis(orbit, UT1, phasingOrbitRadius); vessel.PlaceManeuverNode(orbit, dV1, UT1); Orbit transferOrbit = vessel.patchedConicSolver.maneuverNodes[0].nextPatch; double UT2 = transferOrbit.NextPeriapsisTime(UT1); Vector3d dV2 = OrbitalManeuverCalculator.DeltaVToCircularize(transferOrbit, UT2); vessel.PlaceManeuverNode(transferOrbit, dV2, UT2); } else { double UT = orbit.NextTimeOfRadius(vesselState.time, phasingOrbitRadius); Vector3d dV = OrbitalManeuverCalculator.DeltaVToCircularize(orbit, UT); vessel.PlaceManeuverNode(orbit, dV, UT); } } break; case Step.Transfer: GUILayout.Label("Once in the phasing orbit, transfer to the target orbit at just the right time to intercept the target:"); if (GUILayout.Button("Intercept with Hohmann transfer")) { double UT; Vector3d dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(orbit, core.target.Orbit, vesselState.time, out UT); vessel.PlaceManeuverNode(orbit, dV, UT); } double closestApproachTime = orbit.NextClosestApproachTime(core.target.Orbit, vesselState.time); GUILayout.Label("Once on a transfer trajectory, match velocities at closest approach:"); GUILayout.Label("Time until closest approach: " + GuiUtils.TimeToDHMS(closestApproachTime - vesselState.time)); GUILayout.Label("Separation at closest approach: " + MuUtils.ToSI(orbit.Separation(core.target.Orbit, closestApproachTime), 0) + "m"); if (GUILayout.Button("Match velocities at closest approach")) { double UT = closestApproachTime; Vector3d dV = OrbitalManeuverCalculator.DeltaVToMatchVelocities(orbit, UT, core.target.Orbit); vessel.PlaceManeuverNode(orbit, dV, UT); } break; case Step.GetCloser: GUILayout.Label("If you aren't close enough after matching velocities, thrust gently toward the target:"); if (GUILayout.Button("Get closer")) { double UT = vesselState.time; double interceptUT = UT + 100; Vector3d dV = OrbitalManeuverCalculator.DeltaVToInterceptAtTime(orbit, UT, core.target.Orbit, interceptUT, 10); vessel.PlaceManeuverNode(orbit, dV, UT); } GUILayout.Label("Then match velocities again at closest approach"); break; } GUILayout.EndVertical(); MechJebModuleRendezvousAutopilot autopilot = core.GetComputerModule <MechJebModuleRendezvousAutopilot>(); if (autopilot != null) { bool active = GUILayout.Toggle(autopilot.enabled, "Autopilot enable"); if (autopilot.enabled != active) { if (active) { autopilot.users.Add(this); } else { autopilot.users.Remove(this); } } if (autopilot.enabled) { GUILayout.Label("Status: " + autopilot.status); } } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); List <ManeuverNode> maneuverNodes = GetManeuverNodes(); bool anyNodeExists = (maneuverNodes.Count() > 0); if (anyNodeExists) { GUILayout.BeginHorizontal(); if (GUILayout.Button(createNode ? "Create a new" : "Change the last")) { createNode = !createNode; } GUILayout.Label("maneuver node to:"); GUILayout.EndHorizontal(); } else { GUILayout.Label("Create a new maneuver node to:"); createNode = true; } operation = (Operation)GuiUtils.ArrowSelector((int)operation, numOperations, operationStrings[(int)operation]); DoOperationParametersGUI(); double UT = DoChooseTimeGUI(); if (GUILayout.Button("Go")) { //handle updating an existing node by removing it and then re-creating it ManeuverNode removedNode = null; if (!createNode) { removedNode = maneuverNodes.Last(); vessel.patchedConicSolver.RemoveManeuverNode(removedNode); } Orbit o = vessel.GetPatchAtUT(UT); if (CheckPreconditions(o, UT)) { MakeNodeForOperation(o, UT); } else if (!createNode) { //Add removed node back in, since we decided not to create a new one. vessel.patchedConicSolver.AddManeuverNode(removedNode.UT).OnGizmoUpdated(removedNode.DeltaV, removedNode.UT); } } if (errorMessage.Length > 0) { GUIStyle s = new GUIStyle(GUI.skin.label); s.normal.textColor = Color.yellow; GUILayout.Label(errorMessage, s); } if (GUILayout.Button("Remove ALL nodes")) { vessel.RemoveAllManeuverNodes(); } if (core.node != null) { if (anyNodeExists && !core.node.enabled) { if (GUILayout.Button("Execute next node")) { core.node.ExecuteOneNode(this); } if (vessel.patchedConicSolver.maneuverNodes.Count > 1) { if (GUILayout.Button("Execute all nodes")) { core.node.ExecuteAllNodes(this); } } } else if (core.node.enabled) { if (GUILayout.Button("ABORT")) { core.node.Abort(); } } GUILayout.BeginHorizontal(); core.node.autowarp = GUILayout.Toggle(core.node.autowarp, "Auto-warp", GUILayout.ExpandWidth(true)); GUILayout.Label("Tolerance:", GUILayout.ExpandWidth(false)); core.node.tolerance.text = GUILayout.TextField(core.node.tolerance.text, GUILayout.Width(35), GUILayout.ExpandWidth(false)); GUILayout.Label("m/s", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
double DoChooseTimeGUI() { Dictionary <Operation, TimeReference[]> references = new Dictionary <Operation, TimeReference[]>(); references[Operation.CIRCULARIZE] = new TimeReference[] { TimeReference.APOAPSIS, TimeReference.PERIAPSIS, TimeReference.ALTITUDE, TimeReference.X_FROM_NOW }; references[Operation.PERIAPSIS] = new TimeReference[] { TimeReference.X_FROM_NOW, TimeReference.APOAPSIS, TimeReference.PERIAPSIS }; references[Operation.APOAPSIS] = new TimeReference[] { TimeReference.X_FROM_NOW, TimeReference.APOAPSIS, TimeReference.PERIAPSIS }; references[Operation.ELLIPTICIZE] = new TimeReference[] { TimeReference.X_FROM_NOW }; references[Operation.INCLINATION] = new TimeReference[] { TimeReference.EQ_ASCENDING, TimeReference.EQ_DESCENDING, TimeReference.X_FROM_NOW }; references[Operation.PLANE] = new TimeReference[] { TimeReference.REL_ASCENDING, TimeReference.REL_DESCENDING }; references[Operation.TRANSFER] = new TimeReference[] { TimeReference.COMPUTED }; references[Operation.MOON_RETURN] = new TimeReference[] { TimeReference.COMPUTED }; references[Operation.INTERPLANETARY_TRANSFER] = new TimeReference[] { TimeReference.COMPUTED }; references[Operation.COURSE_CORRECTION] = new TimeReference[] { TimeReference.COMPUTED }; references[Operation.LAMBERT] = new TimeReference[] { TimeReference.X_FROM_NOW }; references[Operation.KILL_RELVEL] = new TimeReference[] { TimeReference.CLOSEST_APPROACH, TimeReference.X_FROM_NOW }; TimeReference[] allowedReferences = references[operation]; int referenceIndex = 0; if (allowedReferences.Contains(timeReference)) { referenceIndex = Array.IndexOf(allowedReferences, timeReference); } referenceIndex = GuiUtils.ArrowSelector(referenceIndex, allowedReferences.Length, () => { switch (timeReference) { case TimeReference.APOAPSIS: GUILayout.Label("at the next apoapsis"); break; case TimeReference.CLOSEST_APPROACH: GUILayout.Label("at closest approach to target"); break; case TimeReference.EQ_ASCENDING: GUILayout.Label("at the equatorial AN"); break; case TimeReference.EQ_DESCENDING: GUILayout.Label("at the equatorial DN"); break; case TimeReference.PERIAPSIS: GUILayout.Label("at the next periapsis"); break; case TimeReference.REL_ASCENDING: GUILayout.Label("at the next AN with the target."); break; case TimeReference.REL_DESCENDING: GUILayout.Label("at the next DN with the target."); break; case TimeReference.X_FROM_NOW: leadTime.text = GUILayout.TextField(leadTime.text, GUILayout.Width(50)); GUILayout.Label(" from now"); break; case TimeReference.ALTITUDE: GuiUtils.SimpleTextBox("at an altitude of", circularizeAltitude, "km"); break; } }); timeReference = allowedReferences[referenceIndex]; bool error = false; string timeErrorMessage = ""; double UT = vesselState.time; Orbit o = orbit; List <ManeuverNode> maneuverNodes = GetManeuverNodes(); if (maneuverNodes.Count() > 0) { GUILayout.Label("after the last maneuver node."); ManeuverNode last = maneuverNodes.Last(); UT = last.UT; o = last.nextPatch; } switch (timeReference) { case TimeReference.X_FROM_NOW: UT += leadTime; break; case TimeReference.APOAPSIS: if (o.eccentricity < 1) { UT = o.NextApoapsisTime(UT); } else { error = true; timeErrorMessage = "Warning: orbit is hyperbolic, so apoapsis doesn't exist."; } break; case TimeReference.PERIAPSIS: UT = o.NextPeriapsisTime(UT); break; case TimeReference.CLOSEST_APPROACH: if (core.target.NormalTargetExists) { UT = o.NextClosestApproachTime(core.target.Orbit, UT); } else { error = true; timeErrorMessage = "Warning: no target selected."; } break; case TimeReference.ALTITUDE: if (circularizeAltitude > o.PeA && circularizeAltitude < o.ApA) { UT = o.NextTimeOfRadius(UT, o.referenceBody.Radius + circularizeAltitude); } else { error = true; timeErrorMessage = "Warning: can't circularize at this altitude, since current orbit does not reach it."; } break; case TimeReference.EQ_ASCENDING: if (o.AscendingNodeEquatorialExists()) { UT = o.TimeOfAscendingNodeEquatorial(UT); } else { error = true; timeErrorMessage = "Warning: equatorial ascending node doesn't exist."; } break; case TimeReference.EQ_DESCENDING: if (o.DescendingNodeEquatorialExists()) { UT = o.TimeOfDescendingNodeEquatorial(UT); } else { error = true; timeErrorMessage = "Warning: equatorial descending node doesn't exist."; } break; } if (operation == Operation.COURSE_CORRECTION && core.target.NormalTargetExists) { Orbit correctionPatch = o; while (correctionPatch != null) { if (correctionPatch.referenceBody == core.target.Orbit.referenceBody) { o = correctionPatch; UT = correctionPatch.StartUT; break; } correctionPatch = vessel.GetNextPatch(correctionPatch); } } if (error) { GUIStyle s = new GUIStyle(GUI.skin.label); s.normal.textColor = Color.yellow; GUILayout.Label(timeErrorMessage, s); } return(UT); }
double DoChooseTimeGUI(Operation op, TimeReference timeRef, out string timeErrorMessage, bool InvolveGUI = true, double leadingTime = 0) { if (InvolveGUI) { TimeReference[] allowedReferences = references[op]; int referenceIndex = 0; if (allowedReferences.Contains(timeReference)) { referenceIndex = Array.IndexOf(allowedReferences, timeReference); } referenceIndex = GuiUtils.ArrowSelector(referenceIndex, allowedReferences.Length, () => { switch (timeReference) { case TimeReference.APOAPSIS: GUILayout.Label("at the next apoapsis"); break; case TimeReference.CLOSEST_APPROACH: GUILayout.Label("at closest approach to target"); break; case TimeReference.EQ_ASCENDING: GUILayout.Label("at the equatorial AN"); break; case TimeReference.EQ_DESCENDING: GUILayout.Label("at the equatorial DN"); break; case TimeReference.PERIAPSIS: GUILayout.Label("at the next periapsis"); break; case TimeReference.REL_ASCENDING: GUILayout.Label("at the next AN with the target."); break; case TimeReference.REL_DESCENDING: GUILayout.Label("at the next DN with the target."); break; case TimeReference.X_FROM_NOW: leadTime.text = GUILayout.TextField(leadTime.text, GUILayout.Width(50)); GUILayout.Label(" from now"); break; case TimeReference.ALTITUDE: GuiUtils.SimpleTextBox("at an altitude of", circularizeAltitude, "km"); break; } }); timeReference = allowedReferences[referenceIndex]; } timeErrorMessage = ""; bool error = false; double UT = vesselState.time; Orbit o = orbit; List <ManeuverNode> maneuverNodes = GetManeuverNodes(); if (maneuverNodes.Any()) { if (InvolveGUI) { GUILayout.Label("after the last maneuver node."); } ManeuverNode last = maneuverNodes.Last(); UT = last.UT; o = last.nextPatch; } switch (InvolveGUI ? timeReference : timeRef) { case TimeReference.X_FROM_NOW: UT += (InvolveGUI ? leadTime.val : leadingTime); break; case TimeReference.APOAPSIS: if (o.eccentricity < 1) { UT = o.NextApoapsisTime(UT); } else { error = true; timeErrorMessage = "Warning: orbit is hyperbolic, so apoapsis doesn't exist."; } break; case TimeReference.PERIAPSIS: UT = o.NextPeriapsisTime(UT); break; case TimeReference.CLOSEST_APPROACH: if (core.target.NormalTargetExists) { UT = o.NextClosestApproachTime(core.target.TargetOrbit, UT); } else { error = true; timeErrorMessage = "Warning: no target selected."; } break; case TimeReference.ALTITUDE: if (circularizeAltitude > o.PeA && (circularizeAltitude < o.ApA || o.eccentricity >= 1)) { UT = o.NextTimeOfRadius(UT, o.referenceBody.Radius + circularizeAltitude); } else { error = true; timeErrorMessage = "Warning: can't circularize at this altitude, since current orbit does not reach it."; } break; case TimeReference.EQ_ASCENDING: if (o.AscendingNodeEquatorialExists()) { UT = o.TimeOfAscendingNodeEquatorial(UT); } else { error = true; timeErrorMessage = "Warning: equatorial ascending node doesn't exist."; } break; case TimeReference.EQ_DESCENDING: if (o.DescendingNodeEquatorialExists()) { UT = o.TimeOfDescendingNodeEquatorial(UT); } else { error = true; timeErrorMessage = "Warning: equatorial descending node doesn't exist."; } break; } if (op == Operation.COURSE_CORRECTION && core.target.NormalTargetExists) { Orbit correctionPatch = o; while (correctionPatch != null) { if (correctionPatch.referenceBody == core.target.TargetOrbit.referenceBody) { o = correctionPatch; UT = correctionPatch.StartUT; break; } correctionPatch = vessel.GetNextPatch(correctionPatch); } } if (error && InvolveGUI) { GUIStyle s = new GUIStyle(GUI.skin.label); s.normal.textColor = Color.yellow; GUILayout.Label(timeErrorMessage, s); } return(UT); }
protected override void WindowGUI(int windowID) { if (btNormal == null) { btNormal = new GUIStyle(GUI.skin.button); btNormal.normal.textColor = btNormal.focused.textColor = Color.white; btNormal.hover.textColor = btNormal.active.textColor = Color.yellow; btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green; btNormal.padding = new RectOffset(8, 8, 8, 8); btActive = new GUIStyle(btNormal); btActive.active = btActive.onActive; btActive.normal = btActive.onNormal; btActive.onFocused = btActive.focused; btActive.hover = btActive.onHover; btAuto = new GUIStyle(btNormal); btAuto.normal.textColor = Color.red; btAuto.onActive = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal; } // If any other module use the attitude controler then let them do it if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0) { GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true)); } else { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); TargetButton(Target.OFF); TargetButton(Target.KILLROT); TargetButton(Target.NODE); GUILayout.EndHorizontal(); GUILayout.Label("Mode:"); GUILayout.BeginHorizontal(); ModeButton(Mode.ORBITAL); ModeButton(Mode.SURFACE); ModeButton(Mode.TARGET); ModeButton(Mode.ADVANCED); GUILayout.EndHorizontal(); switch (mode) { case Mode.ORBITAL: GUILayout.BeginHorizontal(); TargetButton(Target.PROGRADE); TargetButton(Target.NORMAL_PLUS); TargetButton(Target.RADIAL_PLUS); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); TargetButton(Target.RETROGRADE); TargetButton(Target.NORMAL_MINUS); TargetButton(Target.RADIAL_MINUS); GUILayout.EndHorizontal(); ForceRoll(); break; case Mode.SURFACE: GuiUtils.SimpleTextBox("HDG:", srfHdg); GuiUtils.SimpleTextBox("PIT:", srfPit); GuiUtils.SimpleTextBox("ROL:", srfRol); if (GUILayout.Button("EXECUTE", GUILayout.ExpandWidth(true))) { target = Target.SURFACE; Engage(); } break; case Mode.TARGET: if (core.target.NormalTargetExists) { GUILayout.BeginHorizontal(); TargetButton(Target.TARGET_PLUS); TargetButton(Target.RELATIVE_PLUS); TargetButton(Target.PARALLEL_PLUS); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); TargetButton(Target.TARGET_MINUS); TargetButton(Target.RELATIVE_MINUS); TargetButton(Target.PARALLEL_MINUS); GUILayout.EndHorizontal(); ForceRoll(); } else { GUILayout.Label("Please select a target"); } break; case Mode.ADVANCED: GUILayout.Label("Reference:"); advReference = (AttitudeReference)GuiUtils.ArrowSelector((int)advReference, Enum.GetValues(typeof(AttitudeReference)).Length, advReference.ToString()); GUILayout.Label("Direction:"); advDirection = (Vector6.Direction)GuiUtils.ArrowSelector((int)advDirection, Enum.GetValues(typeof(Vector6.Direction)).Length, advDirection.ToString()); if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true))) { target = Target.ADVANCED; Engage(); } break; case Mode.AUTO: break; } GUILayout.EndVertical(); } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ArrowSelector((int)warpTarget, numWarpTargets, warpTargetStrings[(int)warpTarget]); GUILayout.EndHorizontal(); if (warpTarget == WarpTarget.Time) { GUILayout.BeginHorizontal(); GUILayout.Label("Warp for: ", GUILayout.ExpandWidth(true)); timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); GUILayout.EndHorizontal(); } else if (warpTarget == WarpTarget.PhaseAngleT) { // I wonder if I should check for target that don't make sense if (!core.target.NormalTargetExists) { GUILayout.Label("You need a target"); } else { GuiUtils.SimpleTextBox("Phase Angle:", phaseAngle, "º", 60); } } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); if (warping) { if (GUILayout.Button("Abort")) { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button("Warp")) { warping = true; switch (warpTarget) { case WarpTarget.Periapsis: targetUT = orbit.NextPeriapsisTime(vesselState.time); break; case WarpTarget.Apoapsis: if (orbit.eccentricity < 1) { targetUT = orbit.NextApoapsisTime(vesselState.time); } break; case WarpTarget.SoI: if (orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) { targetUT = orbit.EndUT; } break; case WarpTarget.Node: if (vessel.patchedConicSolver.maneuverNodes.Any()) { targetUT = vessel.patchedConicSolver.maneuverNodes[0].UT; } break; case WarpTarget.Time: targetUT = vesselState.time + timeOffset; break; case WarpTarget.PhaseAngleT: if (core.target.NormalTargetExists) { Orbit reference; if (core.target.Orbit.referenceBody == orbit.referenceBody) { reference = orbit; // we orbit arround the same body } else { reference = orbit.referenceBody.orbit; } // From Kerbal Alarm Clock double angleChangePerSec = (360 / core.target.Orbit.period) - (360 / reference.period); double currentAngle = reference.PhaseAngle(core.target.Orbit, vesselState.time); double angleDigff = currentAngle - phaseAngle; if (angleDigff > 0 && angleChangePerSec > 0) { angleDigff -= 360; } if (angleDigff < 0 && angleChangePerSec < 0) { angleDigff += 360; } double TimeToTarget = Math.Floor(Math.Abs(angleDigff / angleChangePerSec)); targetUT = vesselState.time + TimeToTarget; } break; default: targetUT = vesselState.time; break; } } } GUILayout.EndHorizontal(); if (warping) { GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
public void AllStageStats() { // Unity throws an exception if we change our layout between the Layout event and // the Repaint event, so only get new data right before the Layout event. if (Event.current.type == EventType.Layout) { MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>(); vacStats = stats.vacStats; atmoStats = stats.atmoStats; stats.RequestUpdate(this); } int numStages = atmoStats.Length; var stages = Enumerable.Range(0, numStages); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Stage stats", GUILayout.ExpandWidth(true)); double geeASL; if (HighLogic.LoadedSceneIsEditor) { // We're in the VAB/SPH TWRbody = (int)GuiUtils.ArrowSelector(TWRbody, FlightGlobals.Bodies.Count, FlightGlobals.Bodies[(int)TWRbody].GetName()); geeASL = FlightGlobals.Bodies[TWRbody].GeeASL; } else { // We're in flight geeASL = mainBody.GeeASL; } if (GUILayout.Button("All stats", GUILayout.ExpandWidth(false))) { // NK detect necessity of atmo initial TWR bool hasMFE = false; if (HighLogic.LoadedSceneIsEditor) { foreach (Part p in parts) { if (p.Modules.Contains("ModuleEngineConfigs") || p.Modules.Contains("ModuleHybridEngine") || p.Modules.Contains("ModuleHybridEngines")) { hasMFE = true; break; } } } else { hasMFE = vesselState.hasMFE; } if (showInitialMass) { showInitialTWR = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true; showAtmoInitialTWR = hasMFE; // NK showInitialMass = showFinalMass = showMaxTWR = false; } else { showInitialMass = showInitialTWR = showMaxTWR = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true; showAtmoInitialTWR = hasMFE; // NK } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); DrawStageStatsColumn("Stage", stages.Select(s => s.ToString())); if (showInitialMass) { showInitialMass = !DrawStageStatsColumn("Start mass", stages.Select(s => vacStats[s].startMass.ToString("F1") + " t")); } if (showFinalMass) { showFinalMass = !DrawStageStatsColumn("End mass", stages.Select(s => vacStats[s].endMass.ToString("F1") + " t")); } if (showInitialTWR) { showInitialTWR = !DrawStageStatsColumn("TWR", stages.Select(s => vacStats[s].StartTWR(geeASL).ToString("F2"))); } if (showAtmoInitialTWR) { showAtmoInitialTWR = !DrawStageStatsColumn("SLT", stages.Select(s => atmoStats[s].StartTWR(geeASL).ToString("F2"))); // NK } if (showMaxTWR) { showMaxTWR = !DrawStageStatsColumn("Max TWR", stages.Select(s => vacStats[s].MaxTWR(geeASL).ToString("F2"))); } if (showAtmoDeltaV) { showAtmoDeltaV = !DrawStageStatsColumn("Atmo ΔV", stages.Select(s => atmoStats[s].deltaV.ToString("F0") + " m/s")); } if (showAtmoTime) { showAtmoTime = !DrawStageStatsColumn("Atmo time", stages.Select(s => GuiUtils.TimeToDHMS(atmoStats[s].deltaTime))); } if (showVacDeltaV) { showVacDeltaV = !DrawStageStatsColumn("Vac ΔV", stages.Select(s => vacStats[s].deltaV.ToString("F0") + " m/s")); } if (showVacTime) { showVacTime = !DrawStageStatsColumn("Vac time", stages.Select(s => GuiUtils.TimeToDHMS(vacStats[s].deltaTime))); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }