--- a/KerbalEngineer/Editor/BuildAdvanced.cs +++ b/KerbalEngineer/Editor/BuildAdvanced.cs @@ -17,33 +17,29 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#region Using Directives - -using System; -using System.Linq; - -using KerbalEngineer.Extensions; -using KerbalEngineer.Flight; -using KerbalEngineer.Helpers; -using KerbalEngineer.Settings; -using KerbalEngineer.UIControls; -using KerbalEngineer.VesselSimulator; - -using UnityEngine; - -#endregion - 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 atmosphericPercentage = 1.0f; - private float atmosphericVelocity; + private float atmosphericMach; private GUIStyle bodiesButtonActiveStyle; private GUIStyle bodiesButtonStyle; private DropDown bodiesList; @@ -56,6 +52,7 @@ 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; @@ -67,11 +64,9 @@ private GUIStyle titleStyle; private bool visible = true; private GUIStyle windowStyle; - #endregion #region Properties - /// <summary> /// Gets the current instance if started or returns null. /// </summary> @@ -82,8 +77,14 @@ /// </summary> public bool CompactMode { - get { return this.compactMode; } - set { this.compactMode = value; } + get + { + return compactMode; + } + set + { + compactMode = value; + } } /// <summary> @@ -91,8 +92,14 @@ /// </summary> public bool ShowAllStages { - get { return this.showAllStages; } - set { this.showAllStages = value; } + get + { + return showAllStages; + } + set + { + showAllStages = value; + } } /// <summary> @@ -100,8 +107,14 @@ /// </summary> public bool ShowAtmosphericDetails { - get { return this.showAtmosphericDetails; } - set { this.showAtmosphericDetails = value; } + get + { + return showAtmosphericDetails; + } + set + { + showAtmosphericDetails = value; + } } /// <summary> @@ -109,8 +122,14 @@ /// </summary> public bool ShowSettings { - get { return this.showSettings; } - set { this.showSettings = value; } + get + { + return showSettings; + } + set + { + showSettings = value; + } } /// <summary> @@ -118,26 +137,40 @@ /// </summary> public bool Visible { - get { return this.visible; } - set { this.visible = value; } - } - + get + { + return visible; + } + set + { + visible = value; + } + } #endregion - #region Methods: protected + #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; - this.bodiesList = this.gameObject.AddComponent<DropDown>(); - this.bodiesList.DrawCallback = this.DrawBodiesList; - this.Load(); + bodiesList = gameObject.AddComponent<DropDown>(); + bodiesList.DrawCallback = DrawBodiesList; + Load(); + + SimManager.UpdateModSettings(); + SimManager.OnReady -= GetStageInfo; + SimManager.OnReady += GetStageInfo; } catch (Exception ex) { - Logger.Exception(ex); + Logger.Exception(ex, "BuildAdvanced.Awake()"); } } @@ -148,22 +181,22 @@ { try { - var handler = new SettingHandler(); - handler.Set("visible", this.visible); - handler.Set("windowPositionX", this.position.x); - handler.Set("windowPositionY", this.position.y); - handler.Set("compactMode", this.compactMode); - handler.Set("compactCollapseRight", this.compactCollapseRight); - handler.Set("showAllStages", this.showAllStages); - handler.Set("showAtmosphericDetails", this.showAtmosphericDetails); - handler.Set("showSettings", this.showSettings); + 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 -= this.OnSizeChanged; + GuiDisplaySize.OnSizeChanged -= OnSizeChanged; } catch (Exception ex) { - Logger.Exception(ex); + Logger.Exception(ex, "BuildAdvanced.OnDestroy()"); } } @@ -171,56 +204,65 @@ { try { - if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts) + if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts) { return; } - if (SimManager.ResultsReady()) - { - this.stages = SimManager.Stages; - } - - SimManager.RequestSimulation(); - - if (this.stages == null) + if (stages == null) { return; } // Change the window title based on whether in compact mode or not. - var title = !this.compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion; + 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. - var stageCount = this.stages.Count(stage => this.showAllStages || stage.deltaV > 0); - if (this.hasChanged || stageCount != this.numberOfStages) - { - this.hasChanged = false; - this.numberOfStages = stageCount; - - this.position.width = 0; - this.position.height = 0; + 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; - this.position = GUILayout.Window(this.GetInstanceID(), this.position, this.Window, title, this.windowStyle).ClampToScreen(); - - if (this.compactCheck > 0 && this.compactCollapseRight) - { - this.position.x = this.compactRight - this.position.width; - this.compactCheck--; - } - else if (this.compactCheck > 0) - { - this.compactCheck = 0; + 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. - this.CheckEditorLock(); + CheckEditorLock(); } catch (Exception ex) { - Logger.Exception(ex); + Logger.Exception(ex, "BuildAdvanced.OnGUI()"); } } @@ -228,12 +270,12 @@ { try { - this.InitialiseStyles(); - GuiDisplaySize.OnSizeChanged += this.OnSizeChanged; + InitialiseStyles(); + GuiDisplaySize.OnSizeChanged += OnSizeChanged; } catch (Exception ex) { - Logger.Exception(ex); + Logger.Exception(ex, "BuildAdvanced.Start()"); } } @@ -243,56 +285,54 @@ { if (Input.GetKeyDown(KeyBinder.EditorShowHide)) { - this.visible = !this.visible; - } - - if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0) - { - this.bodiesList.enabled = false; + 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 (this.showAtmosphericDetails) - { - SimManager.Atmosphere = CelestialBodies.SelectedBody.Atmosphere * 0.01d * this.atmosphericPercentage; + if (showAtmosphericDetails) + { + SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(Altitude); } else { SimManager.Atmosphere = 0; } - SimManager.Velocity = this.atmosphericVelocity; + SimManager.Mach = atmosphericMach; + + SimManager.RequestSimulation(); SimManager.TryStartSimulation(); } catch (Exception ex) { - Logger.Exception(ex, "BuildAdvanced->Update"); - } - } - - #endregion - - #region Methods: private + Logger.Exception(ex, "BuildAdvanced.Update()"); + } + } /// <summary> /// Checks whether the editor should be locked to stop click-through. /// </summary> private void CheckEditorLock() { - if ((this.position.MouseIsOver() || this.bodiesList.Position.MouseIsOver()) && !this.isEditorLocked) - { - EditorLogic.fetch.Lock(true, true, true, "KER_BuildAdvanced"); - BuildOverlay.BuildOverlayPartInfo.Hidden = true; - this.isEditorLocked = true; - } - else if (!this.position.MouseIsOver() && !this.bodiesList.Position.MouseIsOver() && this.isEditorLocked) - { - EditorLogic.fetch.Unlock("KER_BuildAdvanced"); - BuildOverlay.BuildOverlayPartInfo.Hidden = false; - this.isEditorLocked = false; + if ((position.MouseIsOver() || bodiesList.Position.MouseIsOver()) && !isEditorLocked) + { + EditorLock(true); + } + else if (!position.MouseIsOver() && !bodiesList.Position.MouseIsOver() && isEditorLocked) + { + EditorLock(false); } } @@ -301,42 +341,43 @@ /// </summary> private void DrawAtmosphericDetails() { - GUILayout.BeginHorizontal(); - GUILayout.Label("Pressure: " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset)); - GUI.skin = HighLogic.Skin; - GUILayout.BeginVertical(); - GUILayout.FlexibleSpace(); - this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f); - GUILayout.FlexibleSpace(); - GUILayout.EndVertical(); - GUI.skin = null; - GUILayout.EndHorizontal(); - - GUILayout.Space(5.0f); - - GUILayout.BeginHorizontal(); - GUILayout.Label("Velocity: " + this.atmosphericVelocity.ToString("F1") + "m/s", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset)); - GUI.skin = HighLogic.Skin; - GUILayout.BeginVertical(); - GUILayout.FlexibleSpace(); - this.atmosphericVelocity = GUILayout.HorizontalSlider(this.atmosphericVelocity, 0, 2500f); - GUILayout.FlexibleSpace(); - GUILayout.EndVertical(); - GUI.skin = null; - GUILayout.EndHorizontal(); + 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) { - this.DrawBody(CelestialBodies.SystemBody); + DrawBody(CelestialBodies.SystemBody); } else { - foreach (var body in CelestialBodies.SystemBody.Children) - { - this.DrawBody(body); + foreach (CelestialBodies.BodyInfo body in CelestialBodies.SystemBody.Children) + { + DrawBody(body); } } } @@ -345,18 +386,19 @@ { 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 ? this.bodiesButtonActiveStyle : this.bodiesButtonStyle)) + 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); - this.bodiesList.Resize = true; + Altitude = 0.0f; + bodiesList.Resize = true; } GUILayout.EndHorizontal(); if (bodyInfo.Selected) { - foreach (var body in bodyInfo.Children) - { - this.DrawBody(body, depth + 1); + for (int i = 0; i < bodyInfo.Children.Count; ++i) + { + DrawBody(bodyInfo.Children[i], depth + 1); } } } @@ -367,12 +409,13 @@ private void DrawBurnTime() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); - GUILayout.Label("BURN", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(TimeFormatter.ConvertToString(stage.time), this.infoStyle); + 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(); @@ -384,12 +427,13 @@ private void DrawCost() { GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset)); - GUILayout.Label("COST", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(stage.cost.ToString("N0") + " / " + stage.totalCost.ToString("N0"), this.infoStyle); + 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(); @@ -401,12 +445,13 @@ private void DrawDeltaV() { GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset)); - GUILayout.Label("DELTA-V", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle); + 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(); @@ -418,12 +463,13 @@ private void DrawIsp() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); - GUILayout.Label("ISP", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle); + 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(); @@ -435,12 +481,13 @@ private void DrawMass() { GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset)); - GUILayout.Label("MASS", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(Units.ToMass(stage.mass, stage.totalMass), this.infoStyle); + 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(); @@ -452,12 +499,13 @@ private void DrawPartCount() { GUILayout.BeginVertical(GUILayout.Width(50.0f * GuiDisplaySize.Offset)); - GUILayout.Label("PARTS", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(stage.partCount.ToString("N0"), this.infoStyle); + 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(); @@ -469,39 +517,55 @@ private void DrawSettings() { GUILayout.BeginHorizontal(); - GUILayout.Label("Compact mode collapses to the:", this.settingStyle); - this.compactCollapseRight = !GUILayout.Toggle(!this.compactCollapseRight, "LEFT", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); - this.compactCollapseRight = GUILayout.Toggle(this.compactCollapseRight, "RIGHT", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); + 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("Build Engineer Overlay:", this.settingStyle); - BuildOverlay.Visible = GUILayout.Toggle(BuildOverlay.Visible, "VISIBLE", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); - BuildOverlay.BuildOverlayPartInfo.NamesOnly = GUILayout.Toggle(BuildOverlay.BuildOverlayPartInfo.NamesOnly, "NAMES ONLY", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); - BuildOverlay.BuildOverlayPartInfo.ClickToOpen = GUILayout.Toggle(BuildOverlay.BuildOverlayPartInfo.ClickToOpen, "CLICK TO OPEN", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); + GUILayout.Label("Simulate using vectored thrust values:", settingStyle); + SimManager.vectoredThrust = GUILayout.Toggle(SimManager.vectoredThrust, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - GUILayout.Label("Flight Engineer activation mode:", this.settingStyle); - FlightEngineerPartless.IsPartless = GUILayout.Toggle(FlightEngineerPartless.IsPartless, "PARTLESS", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); - FlightEngineerPartless.IsPartless = !GUILayout.Toggle(!FlightEngineerPartless.IsPartless, "MODULE", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); + GUILayout.Label("Verbose Simulation Log:", settingStyle); + SimManager.logOutput = GUILayout.Toggle(SimManager.logOutput, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, this.settingStyle); - if (GUILayout.Button("<", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset))) + 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(">", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset))) + if (GUILayout.Button(">", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset))) { GuiDisplaySize.Increment++; } GUILayout.EndHorizontal(); - GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime + "ms", this.settingStyle); + GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.TotalMilliseconds + "ms", settingStyle); GUI.skin = HighLogic.Skin; - SimManager.minSimTime = (long)GUILayout.HorizontalSlider(SimManager.minSimTime, 0, 2000.0f); + SimManager.minSimTime = TimeSpan.FromMilliseconds(GUILayout.HorizontalSlider((float)SimManager.minSimTime.TotalMilliseconds, 0, 2000.0f)); GUI.skin = null; } @@ -511,12 +575,13 @@ private void DrawStageNumbers() { GUILayout.BeginVertical(GUILayout.Width(30.0f * GuiDisplaySize.Offset)); - GUILayout.Label(string.Empty, this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label("S" + stage.number, this.titleStyle); + 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(); @@ -528,12 +593,31 @@ private void DrawThrust() { GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset)); - GUILayout.Label("THRUST", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(stage.thrust.ToForce(), this.infoStyle); + 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(); @@ -545,15 +629,41 @@ private void DrawTwr() { GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset)); - GUILayout.Label("TWR (MAX)", this.titleStyle); - foreach (var stage in this.stages) - { - if (this.showAllStages || stage.deltaV > 0) - { - GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle); - } - } - GUILayout.EndVertical(); + 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> @@ -561,22 +671,22 @@ /// </summary> private void InitialiseStyles() { - this.windowStyle = new GUIStyle(HighLogic.Skin.window) + windowStyle = new GUIStyle(HighLogic.Skin.window) { alignment = TextAnchor.UpperLeft }; - this.areaStyle = new GUIStyle(HighLogic.Skin.box) + areaStyle = new GUIStyle(HighLogic.Skin.box) { padding = new RectOffset(0, 0, 9, 0) }; - this.areaSettingStyle = new GUIStyle(HighLogic.Skin.box) + areaSettingStyle = new GUIStyle(HighLogic.Skin.box) { padding = new RectOffset(10, 10, 10, 10) }; - this.buttonStyle = new GUIStyle(HighLogic.Skin.button) + buttonStyle = new GUIStyle(HighLogic.Skin.button) { normal = { @@ -587,7 +697,7 @@ alignment = TextAnchor.MiddleCenter }; - this.titleStyle = new GUIStyle(HighLogic.Skin.label) + titleStyle = new GUIStyle(HighLogic.Skin.label) { normal = { @@ -599,7 +709,7 @@ stretchWidth = true, }; - this.infoStyle = new GUIStyle(HighLogic.Skin.label) + infoStyle = new GUIStyle(HighLogic.Skin.label) { fontSize = (int)(11 * GuiDisplaySize.Offset), fontStyle = FontStyle.Bold, @@ -607,21 +717,21 @@ stretchWidth = true }; - this.settingStyle = new GUIStyle(this.titleStyle) + settingStyle = new GUIStyle(titleStyle) { alignment = TextAnchor.MiddleLeft, stretchWidth = true, stretchHeight = true }; - this.settingAtmoStyle = new GUIStyle(this.titleStyle) + settingAtmoStyle = new GUIStyle(titleStyle) { margin = new RectOffset(), padding = new RectOffset(), alignment = TextAnchor.UpperLeft }; - this.bodiesButtonStyle = new GUIStyle(HighLogic.Skin.button) + bodiesButtonStyle = new GUIStyle(HighLogic.Skin.button) { margin = new RectOffset(0, 0, 2, 0), padding = new RectOffset(5, 5, 5, 5), @@ -639,10 +749,10 @@ fixedHeight = 20.0f }; - this.bodiesButtonActiveStyle = new GUIStyle(this.bodiesButtonStyle) - { - normal = this.bodiesButtonStyle.onNormal, - hover = this.bodiesButtonStyle.onHover + bodiesButtonActiveStyle = new GUIStyle(bodiesButtonStyle) + { + normal = bodiesButtonStyle.onNormal, + hover = bodiesButtonStyle.onHover }; } @@ -653,27 +763,27 @@ { try { - var handler = SettingHandler.Load("BuildAdvanced.xml"); - handler.Get("visible", ref this.visible); - this.position.x = handler.Get("windowPositionX", this.position.x); - this.position.y = handler.Get("windowPositionY", this.position.y); - handler.Get("compactMode", ref this.compactMode); - handler.Get("compactCollapseRight", ref this.compactCollapseRight); - handler.Get("showAllStages", ref this.showAllStages); - handler.Get("showAtmosphericDetails", ref this.showAtmosphericDetails); - handler.Get("showSettings", ref this.showSettings); + 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"); + Logger.Exception(ex, "BuildAdvanced.Load()"); } } private void OnSizeChanged() { - this.InitialiseStyles(); - this.hasChanged = true; + InitialiseStyles(); + hasChanged = true; } /// <summary> @@ -683,76 +793,87 @@ { 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(new Rect(this.position.width - 70.0f * GuiDisplaySize.Offset, 5.0f, 65.0f * GuiDisplaySize.Offset, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode) - { - this.hasChanged = true; - this.compactCheck = 2; - this.compactRight = this.position.xMax; - this.compactMode = !this.compactMode; + 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 (!this.compactMode) - { - if (GUI.Toggle(new Rect(this.position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), this.showSettings, "SETTINGS", this.buttonStyle) != this.showSettings) + 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) { - this.hasChanged = true; - this.showSettings = !this.showSettings; + hasChanged = true; + showSettings = !showSettings; } - if (GUI.Toggle(new Rect(this.position.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages) + if (GUI.Toggle(new Rect(position.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), showAllStages, "ALL STAGES", buttonStyle) != showAllStages) { - this.hasChanged = true; - this.showAllStages = !this.showAllStages; + hasChanged = true; + showAllStages = !showAllStages; } - if (GUI.Toggle(new Rect(this.position.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails) + if (GUI.Toggle(new Rect(position.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), showAtmosphericDetails, "ATMOSPHERIC", buttonStyle) != showAtmosphericDetails) { - this.hasChanged = true; - this.showAtmosphericDetails = !this.showAtmosphericDetails; + hasChanged = true; + showAtmosphericDetails = !showAtmosphericDetails; } - this.bodiesListPosition = new Rect(this.position.width - 452.0f * GuiDisplaySize.Offset, 5.0f, 125.0f * GuiDisplaySize.Offset, 20.0f); - this.bodiesList.enabled = GUI.Toggle(this.bodiesListPosition, this.bodiesList.enabled, "BODY: " + CelestialBodies.SelectedBody.Name.ToUpper(), this.buttonStyle); - this.bodiesList.SetPosition(this.bodiesListPosition.Translate(this.position)); + 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 (!this.compactMode) - { - GUILayout.BeginHorizontal(this.areaStyle); - this.DrawStageNumbers(); - this.DrawPartCount(); - this.DrawCost(); - this.DrawMass(); - this.DrawIsp(); - this.DrawThrust(); - this.DrawTwr(); - this.DrawDeltaV(); - this.DrawBurnTime(); + if (!compactMode) + { + GUILayout.BeginHorizontal(areaStyle); + DrawStageNumbers(); + DrawPartCount(); + DrawCost(); + DrawMass(); + DrawIsp(); + DrawThrust(); + DrawTorque(); + DrawTwr(); + DrawDeltaV(); + DrawBurnTime(); GUILayout.EndHorizontal(); - if (this.showAtmosphericDetails) + if (showAtmosphericDetails && !compactMode) { - GUILayout.BeginVertical(this.areaSettingStyle); - this.DrawAtmosphericDetails(); + GUILayout.BeginVertical(areaSettingStyle); + DrawAtmosphericDetails(); GUILayout.EndVertical(); } - if (this.showSettings) + if (showSettings) { - GUILayout.BeginVertical(this.areaSettingStyle); - this.DrawSettings(); + GUILayout.BeginVertical(areaSettingStyle); + DrawSettings(); GUILayout.EndVertical(); } } else // Draw only a few details when in compact mode. { - GUILayout.BeginHorizontal(this.areaStyle); - this.DrawStageNumbers(); - this.DrawTwr(); - this.DrawDeltaV(); + GUILayout.BeginHorizontal(areaStyle); + DrawStageNumbers(); + DrawTwr(); + DrawDeltaV(); GUILayout.EndHorizontal(); } @@ -760,10 +881,9 @@ } catch (Exception ex) { - Logger.Exception(ex); - } - } - + Logger.Exception(ex, "BuildAdvanced.Window()"); + } + } #endregion } }