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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | // VOID // // VOID_CBInfoBrowser.cs // // Copyright © 2014, toadicus // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation and/or other // materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its contributors may be used // to endorse or promote products derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using KSP; using System; using System.Collections.Generic; using ToadicusTools; using UnityEngine; namespace VOID { public class VOID_CBInfoBrowser : VOID_WindowModule { [AVOID_SaveValue("selectedBodyIdx1")] protected VOID_SaveValue<int> selectedBodyIdx1 = 1; [AVOID_SaveValue("selectedBodyIdx2")] protected VOID_SaveValue<int> selectedBodyIdx2 = 2; protected CelestialBody selectedBody1; protected CelestialBody selectedBody2; [AVOID_SaveValue("toggleOrbital")] protected VOID_SaveValue<bool> toggleOrbital = false; [AVOID_SaveValue("togglePhysical")] protected VOID_SaveValue<bool> togglePhysical = false; public VOID_CBInfoBrowser() { this._Name = "Celestial Body Information Browser"; this.WindowPos.x = 10; this.WindowPos.y = 85; } public override void ModuleWindow(int _) { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginVertical(GUILayout.Width(150)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Width(150)); selectedBody1 = VOID_Core.Instance.allBodies[selectedBodyIdx1]; selectedBody2 = VOID_Core.Instance.allBodies[selectedBodyIdx2]; GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("<", GUILayout.ExpandWidth(false))) { selectedBodyIdx1--; if (selectedBodyIdx1 < 0) selectedBodyIdx1 = VOID_Core.Instance.allBodies.Count - 1; } GUILayout.Label(VOID_Core.Instance.allBodies[selectedBodyIdx1].bodyName, VOID_Core.Instance.LabelStyles["center_bold"], GUILayout.ExpandWidth(true)); if (GUILayout.Button(">", GUILayout.ExpandWidth(false))) { selectedBodyIdx1++; if (selectedBodyIdx1 > VOID_Core.Instance.allBodies.Count - 1) selectedBodyIdx1 = 0; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Width(150)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("<", GUILayout.ExpandWidth(false))) { selectedBodyIdx2--; if (selectedBodyIdx2 < 0) selectedBodyIdx2 = VOID_Core.Instance.allBodies.Count - 1; } GUILayout.Label(VOID_Core.Instance.allBodies[selectedBodyIdx2].bodyName, VOID_Core.Instance.LabelStyles["center_bold"], GUILayout.ExpandWidth(true)); if (GUILayout.Button(">", GUILayout.ExpandWidth(false))) { selectedBodyIdx2++; if (selectedBodyIdx2 > VOID_Core.Instance.allBodies.Count - 1) selectedBodyIdx2 = 0; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); //toggle for orbital info chunk if (GUILayout.Button("Orbital Characteristics", GUILayout.ExpandWidth(true))) toggleOrbital.value = !toggleOrbital; if (toggleOrbital) { //begin orbital into horizontal chunk //print("begin orbital info section..."); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //begin orbital value labels column GUILayout.BeginVertical(GUILayout.Width(150)); //print("printing row labels..."); GUILayout.Label("Apoapsis:"); GUILayout.Label("Time to Ap:"); GUILayout.Label("Periapsis:"); GUILayout.Label("Time to Pe:"); GUILayout.Label("Semi-major axis:"); GUILayout.Label("Eccentricity:"); GUILayout.Label("Orbital period:"); GUILayout.Label("Rotational period:"); GUILayout.Label("Velocity:"); GUILayout.Label("Mean anomaly:"); GUILayout.Label("True anomaly:"); GUILayout.Label("Eccentric anomaly:"); GUILayout.Label("Inclination:"); GUILayout.Label("Long. ascending node:"); GUILayout.Label("Arg. of periapsis:"); GUILayout.Label("Tidally locked:"); //end orbital value labels column GUILayout.EndVertical(); //begin primary orbital values column GUILayout.BeginVertical(GUILayout.Width(150)); body_OP_show_orbital_info(selectedBody1); //end primary orbital values column GUILayout.EndVertical(); //begin secondary orbital values column GUILayout.BeginVertical(GUILayout.Width(150)); body_OP_show_orbital_info(selectedBody2); //end secondary orbital values column GUILayout.EndVertical(); //end orbital info horizontal chunk GUILayout.EndHorizontal(); } //toggle for physical info chunk if (GUILayout.Button("Physical Characteristics", GUILayout.ExpandWidth(true))) togglePhysical.value = !togglePhysical; if (togglePhysical) { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //begin physical info value label column GUILayout.BeginVertical(GUILayout.Width(150)); GUILayout.Label("Radius:"); GUILayout.Label("Surface area:"); GUILayout.Label("Volume:"); GUILayout.Label("Mass:"); GUILayout.Label("Density:"); GUILayout.Label("Sphere of influence:"); GUILayout.Label("Natural satellites:"); GUILayout.Label("Artificial satellites:"); GUILayout.Label("Surface gravity:"); GUILayout.Label("Atmosphere altitude:"); GUILayout.Label("Atmospheric O\u2082:"); GUILayout.Label("Has ocean:"); //end physical info value label column GUILayout.EndVertical(); //begin primary physical values column GUILayout.BeginVertical(GUILayout.Width(150)); body_OP_show_physical_info(selectedBody1); //end primary physical column GUILayout.EndVertical(); //begin secondary physical values column GUILayout.BeginVertical(GUILayout.Width(150)); body_OP_show_physical_info(selectedBody2); //end target physical values column GUILayout.EndVertical(); //end physical value horizontal chunk GUILayout.EndHorizontal(); } GUI.DragWindow(); } private void body_OP_show_orbital_info(CelestialBody body) { if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label((body.orbit.ApA / 1000).ToString("##,#") + "km", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(VOID_Tools.ConvertInterval(body.orbit.timeToAp), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label((body.orbit.PeA / 1000).ToString("##,#") + "km", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(VOID_Tools.ConvertInterval(body.orbit.timeToPe), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label((body.orbit.semiMajorAxis / 1000).ToString("##,#") + "km", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(body.orbit.eccentricity.ToString("F4") + "", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(VOID_Tools.ConvertInterval(body.orbit.period), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(VOID_Tools.ConvertInterval(body.rotationPeriod), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label((body.orbit.orbitalSpeed / 1000).ToString("F2") + "km/s", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); // Toadicus edit: convert mean anomaly into degrees. if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label((body.orbit.meanAnomaly * 180d / Math.PI).ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(body.orbit.trueAnomaly.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); // Toadicus edit: convert eccentric anomaly into degrees. if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label((body.orbit.eccentricAnomaly * 180d / Math.PI).ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(body.orbit.inclination.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(body.orbit.LAN.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(body.orbit.argumentOfPeriapsis.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else { string body_tidally_locked = "No"; if (body.tidallyLocked) body_tidally_locked = "Yes"; GUILayout.Label(body_tidally_locked, VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); } } private void body_OP_show_physical_info(CelestialBody body) { GUILayout.Label((body.Radius / 1000).ToString("##,#") + "km", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); GUILayout.Label((((body.Radius * body.Radius) * 4 * Math.PI) / 1000).ToString("0.00e+00") + "km²", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); // divide by 1000 to convert m to km GUILayout.Label((((4d / 3) * Math.PI * (body.Radius * body.Radius * body.Radius)) / 1000).ToString("0.00e+00") + "km³", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); GUILayout.Label(body.Mass.ToString("0.00e+00") + "kg", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); double p = body.Mass / ((body.Radius * body.Radius * body.Radius) * (4d / 3) * Math.PI); GUILayout.Label(p.ToString("##,#") + "kg/m³", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.bodyName == "Sun") GUILayout.Label(Tools.MuMech_ToSI(body.sphereOfInfluence), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); else GUILayout.Label(Tools.MuMech_ToSI(body.sphereOfInfluence), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); GUILayout.Label(body.orbitingBodies.Count.ToString(), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); //show # artificial satellites int num_art_sats = 0; foreach (Vessel v in FlightGlobals.Vessels) { if (v.mainBody == body && v.situation.ToString() == "ORBITING") num_art_sats++; } GUILayout.Label(num_art_sats.ToString(), VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); double g_ASL = (VOID_Core.Constant_G * body.Mass) / (body.Radius * body.Radius); GUILayout.Label(Tools.MuMech_ToSI(g_ASL) + "m/s²", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); if (body.atmosphere) { GUILayout.Label("≈ " + Tools.MuMech_ToSI(body.maxAtmosphereAltitude) + "m", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); string O2 = "No"; if (body.atmosphereContainsOxygen == true) O2 = "Yes"; GUILayout.Label(O2, VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); } else { GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); GUILayout.Label("N/A", VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); } string ocean = "No"; if (body.ocean == true) ocean = "Yes"; GUILayout.Label(ocean, VOID_Core.Instance.LabelStyles["right"], GUILayout.ExpandWidth(true)); } } } |