Пример #1
0
        public bool Validate(out string errorMsg)
        {
            AirlaunchTechLevel lvl = Utilities.IsSimulationActive ? AirlaunchTechLevel.GetHighestLevelIncludingUnderResearch() :
                                     AirlaunchTechLevel.GetCurrentLevel();

            if (lvl == null)
            {
                errorMsg = "No valid airlaunch configuration found";
                return(false);
            }

            double minKscDist = 0;

            if (KscAzimuth >= 360 || KscAzimuth < 0)
            {
                errorMsg = "Invalid KSC azimuth";
            }
            else if (LaunchAzimuth >= 360 || LaunchAzimuth < 0)
            {
                errorMsg = "Invalid Launch azimuth";
            }
            else if (Altitude > lvl.MaxAltitude || Altitude < lvl.MinAltitude)
            {
                errorMsg = $"Altitude needs to be between {lvl.MinAltitude} and {lvl.MaxAltitude} m";
            }
            else if (Velocity > lvl.MaxVelocity || Velocity < lvl.MinVelocity)
            {
                errorMsg = $"Velocity needs to be between {lvl.MinVelocity} and {lvl.MaxVelocity} m/s";
            }
            else if (KscDistance > lvl.MaxKscDistance || KscDistance < minKscDist)
            {
                errorMsg = $"Distance from Space Center needs to be between {minKscDist / 1000:0.#} and {lvl.MaxKscDistance / 1000:0.#} km";
            }
            else
            {
                errorMsg = null;
            }
            return(errorMsg == null);
        }
Пример #2
0
        public static void DrawAirlaunchWindow(int windowID)
        {
            if (_airlaunchParams == null)
            {
                _airlaunchParams = new AirlaunchParams();

                AirlaunchTechLevel lvl = Utilities.IsSimulationActive ? AirlaunchTechLevel.GetHighestLevelIncludingUnderResearch() :
                                         AirlaunchTechLevel.GetCurrentLevel();
                if (lvl != null)
                {
                    _sKscDistance = (lvl.MaxKscDistance / 1000).ToString();
                    _sAltitude    = lvl.MaxAltitude.ToString();
                    _sVelocity    = lvl.MaxVelocity.ToString();
                }
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Distance from Space Center: ", GUILayout.ExpandWidth(true));
            _sKscDistance = GUILayout.TextField(_sKscDistance, GUILayout.MaxWidth(70f));
            GUILayout.Label("km", GUILayout.Width(25f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Azimuth from Space Center: ", GUILayout.ExpandWidth(true));
            _sKscAzimuth = GUILayout.TextField(_sKscAzimuth, GUILayout.MaxWidth(70f));
            GUILayout.Label("°", GUILayout.Width(25f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Launch azimuth: ", GUILayout.ExpandWidth(true));
            _sAzimuth = GUILayout.TextField(_sAzimuth, GUILayout.MaxWidth(70f));
            GUILayout.Label("°", GUILayout.Width(25f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Altitude from SL: ", GUILayout.ExpandWidth(true));
            _sAltitude = GUILayout.TextField(_sAltitude, GUILayout.MaxWidth(70f));
            GUILayout.Label("m", GUILayout.Width(25f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Velocity: ", GUILayout.ExpandWidth(true));
            _sVelocity = GUILayout.TextField(_sVelocity, GUILayout.MaxWidth(70f));
            GUILayout.Label("m/s", GUILayout.Width(25f));
            GUILayout.EndHorizontal();

            if (_errorMsg != null)
            {
                if (_orangeText == null)
                {
                    _orangeText = new GUIStyle(GUI.skin.label);
                    _orangeText.normal.textColor = XKCDColors.Orange;
                }

                GUILayout.Label(_errorMsg, _orangeText);
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Launch"))
            {
                HandleLaunch();
            }
            if (GUILayout.Button("Cancel"))
            {
                _centralWindowPosition.width = 150;
                _centralWindowPosition.x     = (Screen.width - 150) / 2;
                GUIStates.ShowAirlaunch      = false;
                GUIStates.ShowBuildList      = true;
                _errorMsg = null;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            if (!Input.GetMouseButtonDown(1) && !Input.GetMouseButtonDown(2))
            {
                GUI.DragWindow();
            }
            ClampWindow(ref _airlaunchWindowPosition, strict: true);
        }