Beispiel #1
0
        public static IView View()
        {
            // Load Auto Open status.
            ReloadConfig();

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

            bodySelector.CurrentlySelected = FlightGlobals.fetch == null ? null : FlightGlobals.ActiveVessel == null ? Planetarium.fetch.Home : FlightGlobals.ActiveVessel.mainBody;
            var lat    = new TextBoxView <double>("Lat", "Latitude (North/South). Between +90 (North) and -90 (South).", 0.001d, latTryParse);
            var lon    = new TextBoxView <double>("Lon", "Longitude (East/West). Converts to less than 360 degrees.", 0.001d, myTryParse);
            var alt    = new TextBoxView <double>("Alt", "Altitude (Up/Down). Distance above the surface.", 20, altTryParse);
            var setRot = new 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.
            Model.DoLander.LoadLast(load);

            return(new VerticalView(new IView[]
            {
                setAutoOpen,
                bodySelector,
                new ConditionalView(() => FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.mainBody != bodySelector.CurrentlySelected, new 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 ConditionalView(() => !lat.Valid, new 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 ConditionalView(() => alt.Object < 0, new LabelView("Altitude must be a positive number.", "This may destroy the vessel. Values less than 0 are sub-surface.")),
                setRot,
                new ConditionalView(() => !isValid(), new ButtonView("Cannot Land", "Entered location is invalid. Correct items in red.", null)),
                new ConditionalView(() => !Model.DoLander.IsLanding() && isValid(), new ButtonView("Land", "Teleport to entered location, then slowly lower to surface.", () => Model.DoLander.ToggleLanding(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected, setRot.Value, load))),
                new ConditionalView(() => Model.DoLander.IsLanding(), new ButtonView("Drop (CAUTION!)", "Release vessel to gravity.", () => Model.DoLander.ToggleLanding(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected, setRot.Value, load))),
                new ConditionalView(() => Model.DoLander.IsLanding(), new LabelView("LANDING IN PROGRESS.", "Vessel is being lowered to the surface.")),
                //Launch button here
                new ConditionalView(() => Model.DoLander.IsLanding(), new LabelView(changeHelpString(), "Change location slightly.")),
                new ConditionalView(() => !Model.DoLander.IsLanding(), new ButtonView("Land Here", "Stop at current location, then slowly lower to surface.", () => Model.DoLander.LandHere(load))),
                new ListSelectView <Vessel>("Set to vessel", Model.DoLander.LandedVessels, select => Model.DoLander.SetToLanded(load, select), Extensions.VesselToString),
                new ButtonView("Current", "Set to current location.", () => Model.DoLander.SetToCurrent(load)),
                new ConditionalView(isValid, new ButtonView("Save", "Save the entered location.", () => Model.DoLander.AddSavedCoords(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected))),
                new ButtonView("Load", "Load a saved location.", () => Model.DoLander.Load(load)),
                new ButtonView("Delete", "Delete a saved location.", Model.DoLander.Delete),
            }));
        }
Beispiel #2
0
        public static IView View()
        {
            var bodySelector = new ListSelectView <CelestialBody>("Planet", () => FlightGlobals.fetch == null ? null : FlightGlobals.fetch.bodies, null, Extensions.CbToString);

            bodySelector.CurrentlySelected = FlightGlobals.fetch == null ? null : FlightGlobals.ActiveVessel == null ? Planetarium.fetch.Home : FlightGlobals.ActiveVessel.mainBody;
            var lat    = new TextBoxView <double>("Lat", "Latitude of landing coordinates", 0.001d, myTryParse);
            var lon    = new TextBoxView <double>("Lon", "Longitude of landing coordinates", 0.001d, myTryParse);
            var alt    = new TextBoxView <double>("Alt", "Altitude of landing coordinates", 20, Model.SiSuffix.TryParse);
            var setRot = new ToggleView("Set rotation",
                                        "If set, rotates the vessel such that up on the vessel is up when landing. Otherwise, the same orientation is kept as before teleporting, relative to the planet",
                                        false);
            Func <bool> isValid = () => lat.Valid && lon.Valid && alt.Valid;
            Action <double, double, CelestialBody> load = (latVal, lonVal, body) =>
            {
                lat.Object = latVal;
                lon.Object = lonVal;
                bodySelector.CurrentlySelected = body;
            };

            return(new VerticalView(new IView[]
            {
                lat,
                lon,
                alt,
                bodySelector,
                setRot,
                new ConditionalView(() => FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.mainBody != bodySelector.CurrentlySelected,
                                    new LabelView("Landing on a body other than the current one is not recommended.",
                                                  "This causes lots of explosions, it's advisable to teleport to an orbit above the planet, then land on it directly")),
                new ConditionalView(() => lat.Valid && (lat.Object <-89.9 || lat.Object> 89.9),
                                    new LabelView("Setting latitude to -90 or 90 degrees (or near it) is dangerous, try 89.9 degrees",
                                                  "(This warning also appears when latitude is past 90 degrees)")),
                new DynamicToggleView("Landing", "Land the ship (or stop landing)", Model.DoLander.IsLanding,
                                      isValid, b => Model.DoLander.ToggleLanding(lat.Object, lon.Object, alt.Object, bodySelector.CurrentlySelected, setRot.Value, load)),
                new ConditionalView(() => Model.DoLander.IsLanding(), new LabelView(HelpString(), "Moves the landing vessel's coordinates slightly")),
                new ConditionalView(() => !Model.DoLander.IsLanding(), new ButtonView("Land here", "Stops the vessel and slowly lowers it to the ground (without teleporting)", () => Model.DoLander.LandHere(load))),
                new ConditionalView(isValid, new ButtonView("Save", "Save the entered location", () => Model.DoLander.AddSavedCoords(lat.Object, lon.Object, bodySelector.CurrentlySelected))),
                new ButtonView("Load", "Load a previously-saved location", () => Model.DoLander.Load(load)),
                new ButtonView("Delete", "Delete a previously-saved location", Model.DoLander.Delete),
                new ButtonView("Set to current", "Set lat/lon to the current position", () => Model.DoLander.SetToCurrent(load)),
                new ListSelectView <Vessel>("Set lat/lon to", Model.DoLander.LandedVessels, select => Model.DoLander.SetToLanded(load, select), Extensions.VesselToString),
            }));
        }
Beispiel #3
0
        public static IView View()
        {
            CelestialBody body = null;

            var geeAsl     = new TextBoxView <double>("Gravity multiplier", "1.0 is kerbin, 0.5 is half of kerbin's gravity, etc.", 1, Model.SiSuffix.TryParse);
            var ocean      = new ToggleView("Has ocean", "Does weird things to the ocean if off", false);
            var atmosphere = new ToggleView("Has atmosphere", "Toggles if the planet has atmosphere or not", false);
            var atmosphereContainsOxygen      = new ToggleView("Atmosphere contains oxygen", "Whether jet engines work or not", false);
            var atmosphereDepth               = new TextBoxView <double>("Atmosphere depth", "Theoretically atmosphere height. In reality, doesn't work too well.", 1, Model.SiSuffix.TryParse);
            var atmosphereTemperatureSeaLevel = new TextBoxView <double>("atmosphereTemperatureSeaLevel", "New 1.0 field. Unknown what this does.", 1, Model.SiSuffix.TryParse);
            var atmospherePressureSeaLevel    = new TextBoxView <double>("atmospherePressureSeaLevel", "New 1.0 field. Unknown what this does.", 1, Model.SiSuffix.TryParse);
            var atmosphereMolarMass           = new TextBoxView <double>("atmosphereMolarMass", "New 1.0 field. Unknown what this does.", 1, Model.SiSuffix.TryParse);
            var atmosphereAdiabaticIndex      = new TextBoxView <double>("atmosphereAdiabaticIndex", "New 1.0 field. Unknown what this does.", 1, Model.SiSuffix.TryParse);
            var rotates         = new ToggleView("Rotates", "If the planet rotates.", false);
            var rotationPeriod  = new TextBoxView <double>("Rotation period", "Rotation period of the planet, in seconds.", 1, Model.SiSuffix.TryParse);
            var initialRotation = new TextBoxView <double>("Initial rotation", "Absolute rotation in degrees of the planet at time=0", 1, Model.SiSuffix.TryParse);
            var tidallyLocked   = new ToggleView("Tidally locked", "If the planet is tidally locked. Overrides Rotation Period.", false);

            Action <CelestialBody> onSelect = cb => {
                body             = cb;
                geeAsl.Object    = body.GeeASL;
                ocean.Value      = body.ocean;
                atmosphere.Value = body.atmosphere;
                atmosphereContainsOxygen.Value       = body.atmosphereContainsOxygen;
                atmosphereDepth.Object               = body.atmosphereDepth;
                atmosphereTemperatureSeaLevel.Object = body.atmosphereTemperatureSeaLevel;
                atmospherePressureSeaLevel.Object    = body.atmospherePressureSeaLevel;
                atmosphereMolarMass.Object           = body.atmosphereMolarMass;
                atmosphereAdiabaticIndex.Object      = body.atmosphereAdiabaticIndex;
                rotates.Value          = body.rotates;
                rotationPeriod.Object  = body.rotationPeriod;
                initialRotation.Object = body.initialRotation;
                tidallyLocked.Value    = body.tidallyLocked;
            };

            var selectBody = new ConditionalView(() => FlightGlobals.fetch != null && FlightGlobals.Bodies != null,
                                                 new ListSelectView <CelestialBody>("Selected body", () => FlightGlobals.Bodies, onSelect, Extensions.CbToString));

            var apply = new ConditionalView(() =>
                                            geeAsl.Valid &&
                                            atmosphereDepth.Valid &&
                                            atmosphereTemperatureSeaLevel.Valid &&
                                            atmospherePressureSeaLevel.Valid &&
                                            atmosphereMolarMass.Valid &&
                                            atmosphereAdiabaticIndex.Valid &&
                                            rotationPeriod.Valid &&
                                            initialRotation.Valid,
                                            new ButtonView("Apply", "Applies the changes to the body", () => {
                new Model.PlanetEditor.PlanetSettings(
                    geeAsl.Object,
                    ocean.Value,
                    atmosphere.Value,
                    atmosphereContainsOxygen.Value,
                    atmosphereDepth.Object,
                    atmosphereTemperatureSeaLevel.Object,
                    atmospherePressureSeaLevel.Object,
                    atmosphereMolarMass.Object,
                    atmosphereAdiabaticIndex.Object,
                    rotates.Value,
                    rotationPeriod.Object,
                    initialRotation.Object,
                    tidallyLocked.Value,
                    body.orbit).CopyTo(body, false);
            }));

            var editFields = new ConditionalView(() => body != null, new VerticalView(new IView[]
            {
                geeAsl,
                ocean,
                atmosphere,
                atmosphereContainsOxygen,
                atmosphereDepth,
                atmosphereTemperatureSeaLevel,
                atmospherePressureSeaLevel,
                atmosphereMolarMass,
                atmosphereAdiabaticIndex,
                rotates,
                rotationPeriod,
                initialRotation,
                tidallyLocked,
                apply,
            }));

            var resetToDefault = new ConditionalView(() => body != null,
                                                     new ButtonView("Reset to defaults", "Reset the selected planet to defaults",
                                                                    () => { Model.PlanetEditor.ResetToDefault(body); onSelect(body); }));

            var copyToKerbin = new ConditionalView(() => body != null && body != Model.PlanetEditor.Kerbin,
                                                   new ButtonView("Copy to kerbin", "Copies the selected planet's settings to kerbin",
                                                                  () => new Model.PlanetEditor.PlanetSettings(body).CopyTo(Model.PlanetEditor.Kerbin, false)));

            var savePlanet = new ConditionalView(() => body != null,
                                                 new ButtonView("Save planet to config file", "Saves the current configuration of the planet to a file, so it stays edited even after a restart. Delete the file named the planet's name in " + IoExt.GetPath(null) + " to undo.",
                                                                () => Model.PlanetEditor.SavePlanet(body)));

            var reloadDefaults = new ConditionalView(() => FlightGlobals.fetch != null && FlightGlobals.Bodies != null,
                                                     new ButtonView("Reload config files", "Reloads the planet .cfg files in " + IoExt.GetPath(null),
                                                                    Model.PlanetEditor.ApplyFileDefaults));

            return(new VerticalView(new IView[]
            {
                selectBody,
                editFields,
                resetToDefault,
                copyToKerbin,
                savePlanet,
                reloadDefaults
            }));
        }