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 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | // // Kerbal Engineer Redux // // Copyright (C) 2014 CYBUTEK // // 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/>. // namespace KerbalEngineer.Editor { #region Using Directives using System; using Extensions; using Flight; using Helpers; using Settings; using UIControls; using UnityEngine; using VesselSimulator; #endregion [KSPAddon(KSPAddon.Startup.EditorAny, false)] public class BuildAdvanced : MonoBehaviour { #region Fields public static float Altitude = 0.0f; private GUIStyle areaSettingStyle; private GUIStyle areaStyle; private float atmosphericMach; private GUIStyle bodiesButtonActiveStyle; private GUIStyle bodiesButtonStyle; private DropDown bodiesList; private Rect bodiesListPosition; private GUIStyle buttonStyle; private int compactCheck; private bool compactCollapseRight; private bool compactMode; private float compactRight; private bool hasChanged; private GUIStyle infoStyle; private bool isEditorLocked; private float maxMach; private int numberOfStages; private Rect position = new Rect(265.0f, 45.0f, 0, 0); private GUIStyle settingAtmoStyle; private GUIStyle settingStyle; private bool showAllStages; private bool showAtmosphericDetails; private bool showSettings; private Stage[] stages; private GUIStyle titleStyle; private bool visible = true; private GUIStyle windowStyle; #endregion #region Properties /// <summary> /// Gets the current instance if started or returns null. /// </summary> public static BuildAdvanced Instance { get; private set; } /// <summary> /// Gets and sets whether to show in compact mode. /// </summary> public bool CompactMode { get { return compactMode; } set { compactMode = value; } } /// <summary> /// Gets and sets whether to show all stages. /// </summary> public bool ShowAllStages { get { return showAllStages; } set { showAllStages = value; } } /// <summary> /// Gets and sets whether to use atmospheric details. /// </summary> public bool ShowAtmosphericDetails { get { return showAtmosphericDetails; } set { showAtmosphericDetails = value; } } /// <summary> /// Gets and sets whether to show the settings display. /// </summary> public bool ShowSettings { get { return showSettings; } set { showSettings = value; } } /// <summary> /// Gets and sets whether the display is enabled. /// </summary> public bool Visible { get { return visible; } set { visible = value; } } #endregion #region Methods private static Rect compactModeRect = new Rect(0.0f, 5.0f, 0.0f, 20.0f); private static Stage stage; private static int stagesCount; private static int stagesLength; private static string title; protected void Awake() { try { Instance = this; bodiesList = gameObject.AddComponent<DropDown>(); bodiesList.DrawCallback = DrawBodiesList; Load(); SimManager.UpdateModSettings(); SimManager.OnReady -= GetStageInfo; SimManager.OnReady += GetStageInfo; } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.Awake()"); } } /// <summary> /// Saves the settings when this object is destroyed. /// </summary> protected void OnDestroy() { try { SettingHandler handler = new SettingHandler(); handler.Set("visible", visible); handler.Set("windowPositionX", position.x); handler.Set("windowPositionY", position.y); handler.Set("compactMode", compactMode); handler.Set("compactCollapseRight", compactCollapseRight); handler.Set("showAllStages", showAllStages); handler.Set("showAtmosphericDetails", showAtmosphericDetails); handler.Set("showSettings", showSettings); handler.Set("selectedBodyName", CelestialBodies.SelectedBody.Name); handler.Save("BuildAdvanced.xml"); GuiDisplaySize.OnSizeChanged -= OnSizeChanged; } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.OnDestroy()"); } } protected void OnGUI() { try { if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts) { return; } if (stages == null) { return; } // Change the window title based on whether in compact mode or not. title = !compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.ASSEMBLY_VERSION : "K.E.R. " + EngineerGlobals.ASSEMBLY_VERSION; // Reset the window size when the staging or something else has changed. stagesLength = stages.Length; if (showAllStages) { stagesCount = stagesLength; } if (showAllStages == false) { stagesCount = 0; for (int i = 0; i < stagesLength; ++i) { if (stages[i].deltaV > 0.0f) { stagesCount = stagesCount + 1; } } } if (hasChanged || stagesCount != numberOfStages) { hasChanged = false; numberOfStages = stagesCount; position.width = 0; position.height = 0; } GUI.skin = null; position = GUILayout.Window(GetInstanceID(), position, Window, title, windowStyle).ClampToScreen(); if (compactCheck > 0 && compactCollapseRight) { position.x = compactRight - position.width; compactCheck--; } else if (compactCheck > 0) { compactCheck = 0; } // Check editor lock to manage click-through. CheckEditorLock(); } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.OnGUI()"); } } protected void Start() { try { InitialiseStyles(); GuiDisplaySize.OnSizeChanged += OnSizeChanged; } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.Start()"); } } protected void Update() { try { if (Input.GetKeyDown(KeyBinder.EditorShowHide)) { visible = !visible; if (!visible) { EditorLock(false); } } if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0) { bodiesList.enabled = false; return; } // Configure the simulation parameters based on the selected reference body. SimManager.Gravity = CelestialBodies.SelectedBody.Gravity; if (showAtmosphericDetails) { SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(Altitude); } else { SimManager.Atmosphere = 0; } SimManager.Mach = atmosphericMach; SimManager.RequestSimulation(); SimManager.TryStartSimulation(); } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.Update()"); } } /// <summary> /// Checks whether the editor should be locked to stop click-through. /// </summary> private void CheckEditorLock() { if ((position.MouseIsOver() || bodiesList.Position.MouseIsOver()) && !isEditorLocked) { EditorLock(true); } else if (!position.MouseIsOver() && !bodiesList.Position.MouseIsOver() && isEditorLocked) { EditorLock(false); } } /// <summary> /// Draws the atmospheric settings. /// </summary> private void DrawAtmosphericDetails() { try { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Altitude: " + (Altitude * 0.001f).ToString("F1") + "km", settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset)); GUI.skin = HighLogic.Skin; Altitude = GUILayout.HorizontalSlider(Altitude, 0.0f, (float)(CelestialBodies.SelectedBody.CelestialBody.atmosphereDepth)); GUI.skin = null; GUILayout.EndVertical(); GUILayout.Space(5.0f); GUILayout.BeginVertical(); GUILayout.Label("Mach: " + atmosphericMach.ToString("F2"), settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset)); GUI.skin = HighLogic.Skin; atmosphericMach = GUILayout.HorizontalSlider(Mathf.Clamp(atmosphericMach, 0.0f, maxMach), 0.0f, maxMach); GUI.skin = null; GUILayout.EndVertical(); GUILayout.EndHorizontal(); } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.DrawAtmosphericDetails()"); } } private void DrawBodiesList() { if (CelestialBodies.SystemBody == CelestialBodies.SelectedBody) { DrawBody(CelestialBodies.SystemBody); } else { foreach (CelestialBodies.BodyInfo body in CelestialBodies.SystemBody.Children) { DrawBody(body); } } } private void DrawBody(CelestialBodies.BodyInfo bodyInfo, int depth = 0) { GUILayout.BeginHorizontal(); GUILayout.Space(20.0f * depth); if (GUILayout.Button(bodyInfo.Children.Count > 0 ? bodyInfo.Name + " [" + bodyInfo.Children.Count + "]" : bodyInfo.Name, bodyInfo.Selected && bodyInfo.SelectedDepth == 0 ? bodiesButtonActiveStyle : bodiesButtonStyle)) { CelestialBodies.SetSelectedBody(bodyInfo.Name); Altitude = 0.0f; bodiesList.Resize = true; } GUILayout.EndHorizontal(); if (bodyInfo.Selected) { for (int i = 0; i < bodyInfo.Children.Count; ++i) { DrawBody(bodyInfo.Children[i], depth + 1); } } } /// <summary> /// Draws the burn time column. /// </summary> private void DrawBurnTime() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); GUILayout.Label("BURN", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(TimeFormatter.ConvertToString(stage.time), infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the cost column. /// </summary> private void DrawCost() { GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset)); GUILayout.Label("COST", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(Units.Cost(stage.cost, stage.totalCost), infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the deltaV column. /// </summary> private void DrawDeltaV() { GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.Label("DELTA-V", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the specific impluse column. /// </summary> private void DrawIsp() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); GUILayout.Label("ISP", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(stage.isp.ToString("F1") + "s", infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the mass column. /// </summary> private void DrawMass() { GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset)); GUILayout.Label("MASS", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(Units.ToMass(stage.mass, stage.totalMass), infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the part count column. /// </summary> private void DrawPartCount() { GUILayout.BeginVertical(GUILayout.Width(50.0f * GuiDisplaySize.Offset)); GUILayout.Label("PARTS", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(stage.partCount + " / " + stage.totalPartCount, infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the settings panel. /// </summary> private void DrawSettings() { GUILayout.BeginHorizontal(); GUILayout.Label("Compact mode collapses to the:", settingStyle); compactCollapseRight = !GUILayout.Toggle(!compactCollapseRight, "LEFT", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); compactCollapseRight = GUILayout.Toggle(compactCollapseRight, "RIGHT", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Simulate using vectored thrust values:"); SimManager.vectoredThrust = GUILayout.Toggle(SimManager.vectoredThrust, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Verbose Simulation Log:"); SimManager.logOutput = GUILayout.Toggle(SimManager.logOutput, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Build Engineer Overlay:", settingStyle); BuildOverlay.Visible = GUILayout.Toggle(BuildOverlay.Visible, "VISIBLE", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); BuildOverlayPartInfo.NamesOnly = GUILayout.Toggle(BuildOverlayPartInfo.NamesOnly, "NAMES ONLY", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); BuildOverlayPartInfo.ClickToOpen = GUILayout.Toggle(BuildOverlayPartInfo.ClickToOpen, "CLICK TO OPEN", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Flight Engineer activation mode:", settingStyle); FlightEngineerCore.IsCareerMode = GUILayout.Toggle(FlightEngineerCore.IsCareerMode, "CAREER", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); FlightEngineerCore.IsCareerMode = !GUILayout.Toggle(!FlightEngineerCore.IsCareerMode, "PARTLESS", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Flight Engineer Career Limitations:", settingStyle); FlightEngineerCore.IsKerbalLimited = GUILayout.Toggle(FlightEngineerCore.IsKerbalLimited, "KERBAL", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); FlightEngineerCore.IsTrackingStationLimited = GUILayout.Toggle(FlightEngineerCore.IsTrackingStationLimited, "TRACKING", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, settingStyle); if (GUILayout.Button("<", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset))) { GuiDisplaySize.Increment--; } if (GUILayout.Button(">", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset))) { GuiDisplaySize.Increment++; } GUILayout.EndHorizontal(); GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.TotalMilliseconds + "ms", settingStyle); GUI.skin = HighLogic.Skin; SimManager.minSimTime = TimeSpan.FromMilliseconds(GUILayout.HorizontalSlider((float)SimManager.minSimTime.TotalMilliseconds, 0, 2000.0f)); GUI.skin = null; } /// <summary> /// Draws the stage number column. /// </summary> private void DrawStageNumbers() { GUILayout.BeginVertical(GUILayout.Width(30.0f * GuiDisplaySize.Offset)); GUILayout.Label(string.Empty, titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label("S" + stage.number, titleStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the thrust column. /// </summary> private void DrawThrust() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); GUILayout.Label("THRUST", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(stage.thrust.ToForce(), infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Draws the torque column. /// </summary> private void DrawTorque() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); GUILayout.Label("TORQUE", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(stage.maxThrustTorque.ToTorque(), infoStyle); } } GUILayout.EndVertical(); } /// <summary> /// Drwas the thrust to weight ratio column. /// </summary> private void DrawTwr() { GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.Label("TWR (MAX)", titleStyle); for (int i = 0; i < stagesLength; ++i) { stage = stages[i]; if (showAllStages || stage.deltaV > 0.0) { GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", infoStyle); } } GUILayout.EndVertical(); } private void EditorLock(bool state) { if (state) { InputLockManager.SetControlLock(ControlTypes.All, "KER_BuildAdvanced"); BuildOverlayPartInfo.Hidden = true; isEditorLocked = true; } else { InputLockManager.SetControlLock(ControlTypes.None, "KER_BuildAdvanced"); BuildOverlayPartInfo.Hidden = false; isEditorLocked = false; } } private void GetStageInfo() { stages = SimManager.Stages; if (stages != null && stages.Length > 0) { maxMach = stages[stages.Length - 1].maxMach; } } /// <summary> /// Initialises all the styles that are required. /// </summary> private void InitialiseStyles() { windowStyle = new GUIStyle(HighLogic.Skin.window) { alignment = TextAnchor.UpperLeft }; areaStyle = new GUIStyle(HighLogic.Skin.box) { padding = new RectOffset(0, 0, 9, 0) }; areaSettingStyle = new GUIStyle(HighLogic.Skin.box) { padding = new RectOffset(10, 10, 10, 10) }; buttonStyle = new GUIStyle(HighLogic.Skin.button) { normal = { textColor = Color.white }, fontSize = (int)(11 * GuiDisplaySize.Offset), fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter }; titleStyle = new GUIStyle(HighLogic.Skin.label) { normal = { textColor = Color.white }, fontSize = (int)(11 * GuiDisplaySize.Offset), fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter, stretchWidth = true, }; infoStyle = new GUIStyle(HighLogic.Skin.label) { fontSize = (int)(11 * GuiDisplaySize.Offset), fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter, stretchWidth = true }; settingStyle = new GUIStyle(titleStyle) { alignment = TextAnchor.MiddleLeft, stretchWidth = true, stretchHeight = true }; settingAtmoStyle = new GUIStyle(titleStyle) { margin = new RectOffset(), padding = new RectOffset(), alignment = TextAnchor.UpperLeft }; bodiesButtonStyle = new GUIStyle(HighLogic.Skin.button) { margin = new RectOffset(0, 0, 2, 0), padding = new RectOffset(5, 5, 5, 5), normal = { textColor = Color.white }, active = { textColor = Color.white }, fontSize = (int)(11 * GuiDisplaySize.Offset), fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter, fixedHeight = 20.0f }; bodiesButtonActiveStyle = new GUIStyle(bodiesButtonStyle) { normal = bodiesButtonStyle.onNormal, hover = bodiesButtonStyle.onHover }; } /// <summary> /// Loads the settings when this object is created. /// </summary> private void Load() { try { SettingHandler handler = SettingHandler.Load("BuildAdvanced.xml"); handler.Get("visible", ref visible); position.x = handler.Get("windowPositionX", position.x); position.y = handler.Get("windowPositionY", position.y); handler.Get("compactMode", ref compactMode); handler.Get("compactCollapseRight", ref compactCollapseRight); handler.Get("showAllStages", ref showAllStages); handler.Get("showAtmosphericDetails", ref showAtmosphericDetails); handler.Get("showSettings", ref showSettings); CelestialBodies.SetSelectedBody(handler.Get("selectedBodyName", CelestialBodies.SelectedBody.Name)); } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.Load()"); } } private void OnSizeChanged() { InitialiseStyles(); hasChanged = true; } /// <summary> /// Draws the OnGUI window. /// </summary> private void Window(int windowId) { try { compactModeRect = new Rect(position.width - 70.0f * GuiDisplaySize.Offset, 5.0f, 65.0f * GuiDisplaySize.Offset, 20.0f); // Draw the compact mode toggle. if (GUI.Toggle(compactModeRect, compactMode, "COMPACT", buttonStyle) != compactMode) { hasChanged = true; compactCheck = 2; compactRight = position.xMax; compactMode = !compactMode; } // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles. if (!compactMode) { if (GUI.Toggle(new Rect(position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), showSettings, "SETTINGS", buttonStyle) != showSettings) { hasChanged = true; showSettings = !showSettings; } if (GUI.Toggle(new Rect(position.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), showAllStages, "ALL STAGES", buttonStyle) != showAllStages) { hasChanged = true; showAllStages = !showAllStages; } if (GUI.Toggle(new Rect(position.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), showAtmosphericDetails, "ATMOSPHERIC", buttonStyle) != showAtmosphericDetails) { hasChanged = true; showAtmosphericDetails = !showAtmosphericDetails; } bodiesListPosition = new Rect(position.width - 452.0f * GuiDisplaySize.Offset, 5.0f, 125.0f * GuiDisplaySize.Offset, 20.0f); bodiesList.enabled = GUI.Toggle(bodiesListPosition, bodiesList.enabled, "BODY: " + CelestialBodies.SelectedBody.Name.ToUpper(), buttonStyle); bodiesList.SetPosition(bodiesListPosition.Translate(position)); } else { if (GUI.Toggle(new Rect(position.width - 133.0f * GuiDisplaySize.Offset, 5.0f, 60.0f * GuiDisplaySize.Offset, 20.0f), showAtmosphericDetails, "ATMO", buttonStyle) != showAtmosphericDetails) { hasChanged = true; showAtmosphericDetails = !showAtmosphericDetails; } } // Draw the main informational display box. if (!compactMode) { GUILayout.BeginHorizontal(areaStyle); DrawStageNumbers(); DrawPartCount(); DrawCost(); DrawMass(); DrawIsp(); DrawThrust(); DrawTorque(); DrawTwr(); DrawDeltaV(); DrawBurnTime(); GUILayout.EndHorizontal(); if (showAtmosphericDetails && !compactMode) { GUILayout.BeginVertical(areaSettingStyle); DrawAtmosphericDetails(); GUILayout.EndVertical(); } if (showSettings) { GUILayout.BeginVertical(areaSettingStyle); DrawSettings(); GUILayout.EndVertical(); } } else // Draw only a few details when in compact mode. { GUILayout.BeginHorizontal(areaStyle); DrawStageNumbers(); DrawTwr(); DrawDeltaV(); GUILayout.EndHorizontal(); } GUI.DragWindow(); } catch (Exception ex) { Logger.Exception(ex, "BuildAdvanced.Window()"); } } #endregion } } |