private static int windowDisplayField = 0; // Bitfield describing what is visible in the flight window - used to determine when the height needs to be updated

        private void Awake()
        {
            FlightDataWrapper.Init();

            LoadSettingsFromConfig();

            if (ToolbarManager.ToolbarAvailable)
            {
                CreateToolbarButtonBlizzy();
            }
            else
            {
                GameEvents.onGUIApplicationLauncherReady.Add(CreateToolbarButtonStock);
            }

            Log.info("Toolbar manager available: {0}" + ToolbarManager.ToolbarAvailable);
        }
Beispiel #2
0
        private static int windowDisplayField = 0; // Bitfield describing what is visible in the flight window - used to determine when the height needs to be updated

        private void Awake()
        {
            FlightDataWrapper.Init();

            LoadSettingsFromConfig();

            if (ToolbarManager.ToolbarAvailable)
            {
                CreateToolbarButtonBlizzy();
            }
            else
            {
                CreateToolbarButtonStock();
            }

            Debug.Log("Toolbar manager available: " + ToolbarManager.ToolbarAvailable.ToString());
        }
        public void FlightWindowGUI(int windowID)
        {
            inAtmosphere = vessel.altitude < vessel.mainBody.atmosphereDepth;
            int tmpDisplayField = windowDisplayField;

            windowDisplayField = 0;
            int counter = 1;

            GUILayout.BeginVertical();

            if (FlightGUISettings.ShowAmbientTemp)
            {
                GUIUtil.FlightWindowField("Ambient Temperature", GUIUnitsSettings.TemperatureUnits.Format(vessel.atmosphericTemperature, GUIUnits.Temperature.kelvin));
                windowDisplayField += counter;
            }
            counter *= 2;
            if (FlightGUISettings.ShowAmbientPressure)
            {
                GUIUtil.FlightWindowField("Ambient Pressure", GUIUnitsSettings.PressureUnits.Format(vessel.staticPressurekPa, GUIUnits.Pressure.kPa));
                windowDisplayField += counter;
            }
            counter *= 2;
            if (FlightGUISettings.ShowRecoveryTemp && inAtmosphere && flightSys.InletArea > 0f && flightSys.EngineArea > 0f)
            {
                GUIUtil.FlightWindowField("Recovery Temperature", GUIUnitsSettings.TemperatureUnits.Format(flightSys.InletTherm.T, GUIUnits.Temperature.kelvin));
                windowDisplayField += counter;
            }
            counter *= 2;
            if (FlightGUISettings.ShowRecoveryPressure && inAtmosphere && flightSys.InletArea > 0f && flightSys.EngineArea > 0f)
            {
                GUIUtil.FlightWindowField("Recovery Pressure", GUIUnitsSettings.PressureUnits.Format(flightSys.InletTherm.P, GUIUnits.Pressure.Pa));
                windowDisplayField += counter;
            }
            counter *= 2;
            if (FlightGUISettings.ShowInletPercent && inAtmosphere && flightSys.EngineArea > 0f)
            {
                GUIStyle inletPercentStyle = new GUIStyle(GUIUtil.LeftLabel);
                double.IsInfinity(flightSys.AreaRatio);

                string areaPercentString = "";
                if (double.IsInfinity(flightSys.AreaRatio) || double.IsNaN(flightSys.AreaRatio))
                {
                    areaPercentString = "n/a";
                }
                else
                {
                    areaPercentString = flightSys.AreaRatio.ToString("P2");
                    Color inletPercentColor = Color.white;
                    if (flightSys.AreaRatio >= 1)
                    {
                        inletPercentColor = Color.green;
                    }
                    else if (flightSys.AreaRatio < 1)
                    {
                        inletPercentColor = Color.red;
                    }
                    inletPercentStyle.normal.textColor = inletPercentStyle.focused.textColor = inletPercentStyle.hover.textColor = inletPercentStyle.onNormal.textColor = inletPercentStyle.onFocused.textColor = inletPercentStyle.onHover.textColor = inletPercentStyle.onActive.textColor = inletPercentColor;
                }

                GUIUtil.FlightWindowField("Inlet", areaPercentString);
                windowDisplayField += counter;
            }
            counter *= 2;

            if (FlightGUISettings.ShowTPR && inAtmosphere && flightSys.InletArea > 0f && flightSys.EngineArea > 0f)
            {
                GUIUtil.FlightWindowField("TPR", flightSys.OverallTPR.ToString("P2"));
                windowDisplayField += counter;
            }
            counter *= 2;

            if (FlightGUISettings.ShowInletPressureRatio && inAtmosphere && flightSys.InletArea > 0f && flightSys.EngineArea > 0f)
            {
                GUIUtil.FlightWindowField("Inlet Pressure Ratio", (flightSys.InletTherm.P / flightSys.AmbientTherm.P).ToString("F2"));
                windowDisplayField += counter;
            }
            counter *= 2;

            double totalThrust = 0;
            double totalMDot   = 0;

            if (FlightGUISettings.ShowThrust || FlightGUISettings.ShowTWR || FlightGUISettings.ShowTDR || FlightGUISettings.ShowIsp || FlightGUISettings.ShowTSFC)
            {
                List <ModuleEngines> allEngines = flightSys.EngineList;
                for (int i = 0; i < allEngines.Count; i++)
                {
                    if (allEngines[i].EngineIgnited)
                    {
                        totalThrust += allEngines[i].finalThrust; // kN
                        totalMDot   += allEngines[i].finalThrust / allEngines[i].realIsp;
                    }
                }
                totalMDot /= 9.81d;
                totalMDot *= 1000d; // kg/s
            }

            if (FlightGUISettings.ShowThrust)
            {
                GUIUtil.FlightWindowField("Thrust", GUIUnitsSettings.ForceUnits.Format(totalThrust, GUIUnits.Force.kN));
                windowDisplayField += counter;
            }
            counter *= 2;
            if (FlightGUISettings.ShowTWR)
            {
                double TWR    = 0d;
                double weight = (FlightGlobals.getGeeForceAtPosition(vessel.CoM).magnitude *vessel.GetTotalMass());
                if (totalThrust > 0d && weight > 0d)
                {
                    TWR = totalThrust / (FlightGlobals.getGeeForceAtPosition(vessel.CoM).magnitude *vessel.GetTotalMass());
                }

                GUIUtil.FlightWindowField("TWR", TWR.ToString("F2"));
                windowDisplayField += counter;
            }
            counter *= 2;

            if (FlightGUISettings.ShowTDR && inAtmosphere)
            {
                double totalDrag = FlightDataWrapper.VesselTotalDragkN(vessel);
                double tdr       = 0;
                if (FlightDataWrapper.VesselDynPreskPa(vessel) > 0.01d)
                {
                    tdr = totalThrust / totalDrag;
                }

                GUIUtil.FlightWindowField("Thrust / Drag", tdr.ToString("G3"));
                windowDisplayField += counter;
            }
            counter *= 2;

            if (FlightGUISettings.ShowIsp)
            {
                double Isp = 0d;
                if (totalThrust > 0d && totalMDot > 0d)
                {
                    Isp = totalThrust / totalMDot; // kN/(kg/s) = km/s
                }
                GUIUtil.FlightWindowField("Specific Impulse", GUIUnitsSettings.IspUnits.Format(Isp, GUIUnits.Isp.km__s));
                windowDisplayField += counter;
            }
            counter *= 2;
            if (FlightGUISettings.ShowTSFC)
            {
                double SFC = 0d;
                if (totalThrust > 0d && totalMDot > 0d)
                {
                    SFC = totalMDot / totalThrust; // (kg/s)/kN
                }
                GUIUtil.FlightWindowField("TSFC", GUIUnitsSettings.TSFCUnits.Format(SFC, GUIUnits.TSFC.kg__kN_s));
                windowDisplayField += counter;
            }

            if (windowDisplayField != tmpDisplayField)
            {
                FlightWindowPos.height = 0;
            }

            GUILayout.BeginHorizontal();
            FlightGUISettings.ShowSettingsWindow     = GUILayout.Toggle(FlightGUISettings.ShowSettingsWindow, "Settings", GUIUtil.ButtonToggle, GUIUtil.normalWidth);
            GUIUnitsSettings.ShowUnitsSettingsWindow = GUILayout.Toggle(GUIUnitsSettings.ShowUnitsSettingsWindow, "Units", GUIUtil.ButtonToggle, GUIUtil.smallWidth);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUI.DragWindow();

            FlightWindowPos = GUIUtil.ClampToScreen(FlightWindowPos);
        }