コード例 #1
0
ファイル: Lander.cs プロジェクト: fronbow/HyperEditX
        public static void ToggleLanding(double latitude, double longitude, double altitude, CelestialBody body,
                                         bool setRotation, Action <double, double, double, CelestialBody> onManualEdit)
        {
            if (FlightGlobals.fetch == null || FlightGlobals.ActiveVessel == null || body == null)
            {
                return;
            }

            Utils.Log("ToggleLanding");
            Utils.Log("-------------");

            var lander = FlightGlobals.ActiveVessel.GetComponent <LanderAttachment>();

            if (lander == null)
            {
                DoLander.AddLastCoords(latitude, longitude, altitude, body);
                lander = FlightGlobals.ActiveVessel.gameObject.AddComponent <LanderAttachment>();

                if (latitude == 0.0f)
                {
                    latitude = 0.001;
                }

                if (longitude == 0.0f)
                {
                    longitude = 0.001;
                }

                lander.Latitude  = latitude;
                lander.Longitude = longitude;

                lander.InterimAltitude = body.Radius + body.atmosphereDepth + 10000d; //Altitude threshold

                lander.Altitude     = altitude;
                lander.SetRotation  = setRotation;
                lander.Body         = body;
                lander.OnManualEdit = onManualEdit;

                Utils.Log("Latitude : " + latitude.ToString());
                Utils.Log("Longitude: " + longitude.ToString());
                Utils.Log("Altitude : " + altitude.ToString());
                Utils.Log("Body     : " + body.ToString());
                Utils.Log("B-Radius : " + body.Radius.ToString());
                //Utils.Log("B-Depth  : " + body.atmosphereDepth.ToString());
                Utils.Log("NEW:");
                Utils.Log("lander = " + lander.ToString());
                Utils.Log("interimAltitude = " + lander.InterimAltitude);
                Utils.Log("-----------------------------");
            }
            else
            {
                //lander != null
                Utils.Log("Unity destroy lander");
                UnityEngine.Object.Destroy(lander);
            }
        }
コード例 #2
0
ファイル: Lander.cs プロジェクト: fronbow/HyperEditX
        public static UiHelper.IView View()
        {
            // Load Auto Open status.
            ReloadConfig();

            var setAutoOpen = new UiHelper.DynamicToggleView("Auto Open", "Open this view when entering the Flight or Tracking Center scenes.",
                                                             () => AutoOpenLander, () => true, v => AutoOpenLander = v);
            var bodySelector = new UiHelper.ListSelectView <CelestialBody>("Body", () => FlightGlobals.fetch == null ? null : FlightGlobals.fetch.bodies, null, Utils.CbToString);

            bodySelector.CurrentlySelected = FlightGlobals.fetch == null ? null : FlightGlobals.ActiveVessel == null ? Planetarium.fetch.Home : FlightGlobals.ActiveVessel.mainBody;
            var lat    = new UiHelper.TextBoxView <double>("Lat", "Latitude (North/South). Between +90 (North) and -90 (South).", 0.001d, latTryParse);
            var lon    = new UiHelper.TextBoxView <double>("Lon", "Longitude (East/West). Converts to less than 360 degrees.", 0.001d, myTryParse);
            var alt    = new UiHelper.TextBoxView <double>("Alt", "Altitude (Up/Down). Distance above the surface.", 20, altTryParse);
            var setRot = new UiHelper.ToggleView("Force Rotation",
                                                 "Rotates vessel such that up on the vessel is up when landing. Otherwise, the current orientation is kept relative to the body.",
                                                 true);
            Func <bool> isValid = () => lat.Valid && lon.Valid && alt.Valid;
            Action <double, double, double, CelestialBody> load = (latVal, lonVal, altVal, body) => {
                lat.Object = latVal;
                lon.Object = lonVal;
                alt.Object = altVal;
                bodySelector.CurrentlySelected = body;
            };

            // Load last entered values.
            DoLander.LoadLast(load);

            return(new UiHelper.VerticalView(new UiHelper.IView[]
            {
                setAutoOpen,
                bodySelector,
                new UiHelper.ConditionalView(() => FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.mainBody != bodySelector.CurrentlySelected, new UiHelper.LabelView("Landing on a different body is not recommended.", "This may destroy the vessel. Use the Orbit Editor to orbit the body first, then land on it.")),
                lat,
                new UiHelper.ConditionalView(() => !lat.Valid, new UiHelper.LabelView("Latitude must be a number from 0 to (+/-)89.9.", "Values too close to the poles ((+/-)90) can crash KSP, values beyond that are invalid for a latitude.")),
                lon,
                alt,
                new UiHelper.ConditionalView(() => alt.Object < 0, new UiHelper.LabelView("Altitude must be a positive number.", "This may destroy the vessel. Values less than 0 are sub-surface.")),
                setRot,
                new UiHelper.ConditionalView(() => !isValid(), new UiHelper.ButtonView("Cannot Land", "Entered location is invalid. Correct items in red.", null)),
                new UiHelper.ConditionalView(() => !DoLander.IsLanding() && isValid(), new UiHelper.ButtonView("Land", "Teleport to entered location, then slowly lower to surface.", () => DoLander.ToggleLanding(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected, setRot.Value, load))),
                new UiHelper.ConditionalView(() => DoLander.IsLanding(), new UiHelper.ButtonView("Drop (CAUTION!)", "Release vessel to gravity.", () => DoLander.ToggleLanding(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected, setRot.Value, load))),
                new UiHelper.ConditionalView(() => DoLander.IsLanding(), new UiHelper.LabelView("LANDING IN PROGRESS.", "Vessel is being lowered to the surface.")),
                //Launch button here
                new UiHelper.ConditionalView(() => DoLander.IsLanding(), new UiHelper.LabelView(changeHelpString(), "Change location slightly.")),
                new UiHelper.ConditionalView(() => !DoLander.IsLanding(), new UiHelper.ButtonView("Land Here", "Stop at current location, then slowly lower to surface.", () => DoLander.LandHere(load))),
                new UiHelper.ListSelectView <Vessel>("Set to vessel", DoLander.LandedVessels, select => DoLander.SetToLanded(load, select), Extensions.VesselToString),
                new UiHelper.ButtonView("Current", "Set to current location.", () => DoLander.SetToCurrent(load)),
                new UiHelper.ConditionalView(isValid, new UiHelper.ButtonView("Save", "Save the entered location.", () => DoLander.AddSavedCoords(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected))),
                new UiHelper.ButtonView("Load", "Load a saved location.", () => DoLander.Load(load)),
                new UiHelper.ButtonView("Delete", "Delete a saved location.", DoLander.Delete),
            }));
        }