1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | // // VOID_Orbital.cs // // Author: // toadicus <> // // Copyright (c) 2013 toadicus // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. using KSP; using System; using System.Collections.Generic; using UnityEngine; namespace VOID { public class VOID_Transfer : VOID_WindowModule { protected List<CelestialBody> selectedBodies = new List<CelestialBody>(); public VOID_Transfer() { this._Name = "Transfer Angle Information"; this.WindowPos.x = 475; this.WindowPos.y = 85; this.defWidth = 315; } public override void ModuleWindow(int _) { GUILayout.BeginVertical(); if (vessel.mainBody.name == "Sun") //Vessel is orbiting the Sun { foreach (CelestialBody body in vessel.mainBody.orbitingBodies) { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button(body.bodyName)) { //add or remove this body to this list of bodies to display more info on if (selectedBodies.Contains(body)) selectedBodies.Remove(body); else selectedBodies.Add(body); } GUILayout.Label("Inclined " + body.orbit.inclination.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if (selectedBodies.Contains(body)) { Tools.display_transfer_angles_SUN2PLANET(body, vessel); //show phase angles for each selected body tad_targeting(body); //display Set/Unset Target button for each selected body } } } else if (vessel.mainBody.referenceBody.name == "Sun") //Vessel is orbiting a planet { foreach (CelestialBody body in vessel.mainBody.referenceBody.orbitingBodies) { if (body.name != vessel.mainBody.name) // show other planets { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button(body.bodyName)) { //add or remove this body to this list of bodies to display more info on if (selectedBodies.Contains(body)) selectedBodies.Remove(body); else selectedBodies.Add(body); } GUILayout.Label("Inclined " + body.orbit.inclination.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if (selectedBodies.Contains(body)) { Tools.display_transfer_angles_PLANET2PLANET(body, vessel); tad_targeting(body); //display Set/Unset Target button } } } foreach (CelestialBody body in vessel.mainBody.orbitingBodies) // show moons { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button(body.bodyName)) { //add or remove this body to this list of bodies to display more info on if (selectedBodies.Contains(body)) selectedBodies.Remove(body); else selectedBodies.Add(body); } GUILayout.Label("Inclined " + body.orbit.inclination.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if (selectedBodies.Contains(body)) { Tools.display_transfer_angles_PLANET2MOON(body, vessel); tad_targeting(body); //display Set/Unset Target button } } } else if (vessel.mainBody.referenceBody.referenceBody.name == "Sun") // Vessel is orbiting a moon { foreach (CelestialBody body in vessel.mainBody.referenceBody.orbitingBodies) { if (body.name != vessel.mainBody.name) // show other moons { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button(body.bodyName)) { //add or remove this body to this list of bodies to display more info on if (selectedBodies.Contains(body)) selectedBodies.Remove(body); else selectedBodies.Add(body); } GUILayout.Label("Inclined " + body.orbit.inclination.ToString("F3") + "°", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); if (selectedBodies.Contains(body)) { Tools.display_transfer_angles_MOON2MOON(body, vessel); tad_targeting(body); //display Set/Unset Target button } } } } GUILayout.EndVertical(); GUI.DragWindow(); } private void tad_targeting(CelestialBody body) { //Target Set/Unset buttons if (FlightGlobals.fetch.VesselTarget == null || (FlightGlobals.fetch.VesselTarget != null && FlightGlobals.fetch.VesselTarget.GetVessel() == null)) { //No TGT set or TGT is a Body if ((CelestialBody)FlightGlobals.fetch.VesselTarget != body) { if (GUILayout.Button("Set Target", GUILayout.ExpandWidth(false))) { FlightGlobals.fetch.SetVesselTarget(body); Tools.PostDebugMessage("[VOID] KSP Target set to CelestialBody " + body.bodyName); } } else if ((CelestialBody)FlightGlobals.fetch.VesselTarget == body) { if (GUILayout.Button("Unset Target", GUILayout.ExpandWidth(false))) { FlightGlobals.fetch.SetVesselTarget(null); Tools.PostDebugMessage("[VOID] KSP Target set to null"); } } } else if (FlightGlobals.fetch.VesselTarget == null || (FlightGlobals.fetch.VesselTarget != null && FlightGlobals.fetch.VesselTarget.GetVessel() != null)) { //No TGT or TGT is a vessel if (GUILayout.Button("Set Target", GUILayout.ExpandWidth(false))) { FlightGlobals.fetch.SetVesselTarget(body); Tools.PostDebugMessage("[VOID] KSP Target set to CelestialBody " + body.bodyName); } } } } } |