예제 #1
0
        private void AttachVessel()
        {
            Util.DebugLog("Loading profiles for vessel");

            AttachedVessel = FlightGlobals.ActiveVessel;

            if (AttachedVessel == null)
            {
                Util.DebugLog("No vessel");
                DescentProfile.Clear();
                TargetProfile.Clear();
                TargetProfile.ManualText = "";
            }
            else
            {
                TrajectoriesVesselSettings module = AttachedVessel.Parts.SelectMany(p => p.Modules.OfType <TrajectoriesVesselSettings>()).FirstOrDefault();
                if (module == null)
                {
                    Util.DebugLog("No TrajectoriesVesselSettings module");
                    DescentProfile.Clear();
                    TargetProfile.Clear();
                    TargetProfile.ManualText = "";
                }
                else if (!module.Initialized)
                {
                    Util.DebugLog("Initializing TrajectoriesVesselSettings module");
                    DescentProfile.Clear();
                    DescentProfile.Save(module);
                    TargetProfile.Clear();
                    TargetProfile.ManualText = "";
                    TargetProfile.Save(module);
                    module.Initialized = true;
                    Util.Log("New vessel, profiles created");
                }
                else
                {
                    Util.DebugLog("Reading profile settings...");
                    // descent profile
                    if (DescentProfile.Ready)
                    {
                        DescentProfile.RetrogradeEntry        = module.RetrogradeEntry;
                        DescentProfile.AtmosEntry.AngleRad    = module.EntryAngle;
                        DescentProfile.AtmosEntry.Horizon     = module.EntryHorizon;
                        DescentProfile.HighAltitude.AngleRad  = module.HighAngle;
                        DescentProfile.HighAltitude.Horizon   = module.HighHorizon;
                        DescentProfile.LowAltitude.AngleRad   = module.LowAngle;
                        DescentProfile.LowAltitude.Horizon    = module.LowHorizon;
                        DescentProfile.FinalApproach.AngleRad = module.GroundAngle;
                        DescentProfile.FinalApproach.Horizon  = module.GroundHorizon;
                        DescentProfile.RefreshGui();
                    }

                    // target profile
                    TargetProfile.SetFromLocalPos(FlightGlobals.Bodies.FirstOrDefault(b => b.name == module.TargetBody),
                                                  new Vector3d(module.TargetPosition_x, module.TargetPosition_y, module.TargetPosition_z));
                    TargetProfile.ManualText = module.ManualTargetTxt;
                    Util.Log("Profiles loaded");
                }
            }
        }
 internal Trajectory(Vessel vessel)
 {
     AttachedVessel = vessel;
     TargetProfile  = new TargetProfile(this);
     DescentProfile = new DescentProfile(this);
     FlightOverlay  = new FlightOverlay(this);
     MapOverlay     = new MapOverlay(this);
     NavBallOverlay = new NavBallOverlay(this);
     Util.DebugLog("Constructing");
 }
예제 #3
0
        private static void MainWindow(int id)
        {
            GUILayout.BeginHorizontal();

            Settings.DisplayTrajectories = GUILayout.Toggle(Settings.DisplayTrajectories, "Show trajectory", GUILayout.Width(125));

            Settings.DisplayTrajectoriesInFlight = GUILayout.Toggle(Settings.DisplayTrajectoriesInFlight, "In-Flight");

            // check that we have patched conics. If not, apologize to the user and return.
            if (Settings.DisplayTrajectories && !Util.IsPatchedConicsAvailable)
            {
                ScreenMessages.PostScreenMessage(
                    "Can't show trajectory because patched conics are not available." +
                    " Please update your tracking station facility.");
                Settings.DisplayTrajectories = false;
                return;
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            Settings.BodyFixedMode = GUILayout.Toggle(Settings.BodyFixedMode, "Body-fixed mode");

            if (Settings.DisplayTrajectories)
            {
                Settings.DisplayCompleteTrajectory = GUILayout.Toggle(Settings.DisplayCompleteTrajectory, "complete", GUILayout.Width(70));
            }

            GUILayout.EndHorizontal();

            GUILayout.Label("Max G-force: " + guistring_gForce);

            GUILayout.Label(guistring_impactVelocity);
            GUILayout.Space(10);


            if (Settings.DisplayTargetGUI = ToggleGroup(Settings.DisplayTargetGUI, "Target"))
            {
                GUI.enabled = TargetProfile.WorldPosition.HasValue;

                GUILayout.Label(guistring_targetDistance);

                if (GUILayout.Button("Unset target"))
                {
                    TargetProfile.Clear();
                }
                GUI.enabled = true;

                GUILayout.BeginHorizontal();
                Trajectory.Patch patch = Trajectory.Patches.LastOrDefault();
                GUI.enabled = (patch != null && patch.ImpactPosition.HasValue);
                if (GUILayout.Button("Set current impact", GUILayout.Width(150)))
                {
                    if (patch.ImpactPosition.HasValue)
                    {
                        TargetProfile.SetFromWorldPos(patch.StartingState.ReferenceBody, patch.ImpactPosition.Value);
                    }
                }
                GUI.enabled = true;
                if (GUILayout.Button("Set KSC", GUILayout.Width(70)))
                {
                    CelestialBody homebody = FlightGlobals.GetHomeBody();

                    double latitude  = SpaceCenter.Instance.Latitude;
                    double longitude = SpaceCenter.Instance.Longitude;

                    if (homebody != null)
                    {
                        TargetProfile.SetFromLatLonAlt(homebody, latitude, longitude);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                Vessel targetVessel = FlightGlobals.fetch.VesselTarget?.GetVessel();
                GUI.enabled = (patch != null && targetVessel != null && targetVessel.Landed
                               // && targetVessel.lastBody == patch.startingState.referenceBody
                               );
                if (GUILayout.Button("Target vessel"))
                {
                    TargetProfile.SetFromWorldPos(targetVessel.lastBody, targetVessel.GetWorldPos3D() - targetVessel.lastBody.position);
                    ScreenMessages.PostScreenMessage("Targeting vessel " + targetVessel.GetName());
                }

                FinePrint.Waypoint navigationWaypoint = Trajectories.AttachedVessel?.navigationWaypoint;
                GUI.enabled = (navigationWaypoint != null);
                if (GUILayout.Button("Active waypoint"))
                {
                    TargetProfile.SetFromLatLonAlt(navigationWaypoint.celestialBody,
                                                   navigationWaypoint.latitude, navigationWaypoint.longitude, navigationWaypoint.altitude);
                    ScreenMessages.PostScreenMessage("Targeting waypoint " + navigationWaypoint.name);
                }
                GUILayout.EndHorizontal();

                GUI.enabled = true;

                GUILayout.BeginHorizontal();
                coords = GUILayout.TextField(TargetProfile.ManualText, GUILayout.Width(170));
                if (coords != TargetProfile.ManualText)
                {
                    TargetProfile.ManualText = coords;
                    TargetProfile.Save();
                }
                if (GUILayout.Button(new GUIContent("Set",
                                                    "Enter target latitude and longitude, separated by a comma, in decimal format (with a dot for decimal separator)"),
                                     GUILayout.Width(50)))
                {
                    string[]      latLng = coords.Split(new char[] { ',', ';' });
                    CelestialBody body   = FlightGlobals.currentMainBody;
                    if (latLng.Length == 2 && body != null)
                    {
                        double lat;
                        double lng;
                        if (double.TryParse(latLng[0].Trim(), out lat) && double.TryParse(latLng[1].Trim(), out lng))
                        {
                            TargetProfile.SetFromLatLonAlt(body, lat, lng);
                        }
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(10);

            GUILayout.BeginHorizontal();
            bool descentProfileGroup = Settings.DisplayDescentProfileGUI = ToggleGroup(Settings.DisplayDescentProfileGUI, "Descent profile", 120);

            DescentProfile.DoQuickControlsGUI();
            GUILayout.EndHorizontal();
            if (descentProfileGroup)
            {
                DescentProfile.DoGUI();
            }
            GUILayout.Space(10);

            if (Settings.DisplaySettingsGUI = ToggleGroup(Settings.DisplaySettingsGUI, "Settings"))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Max patches", GUILayout.Width(100));
                Settings.MaxPatchCount = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)Settings.MaxPatchCount, 3, 10, GUILayout.Width(100)));
                GUILayout.Label(Settings.MaxPatchCount.ToString(), GUILayout.Width(15));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max frames per patch", GUILayout.Width(100));
                Settings.MaxFramesPerPatch = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)Settings.MaxFramesPerPatch, 1, 50, GUILayout.Width(100)));
                GUILayout.Label(Settings.MaxFramesPerPatch.ToString(), GUILayout.Width(15));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                Settings.UseCache = GUILayout.Toggle(Settings.UseCache, new GUIContent("Use Cache", "Toggle cache usage. Trajectory will be more precise when cache disabled, but computation time will be higher. It's not recommended to keep it unchecked, unless your CPU can handle the load."), GUILayout.Width(80));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                Settings.AutoUpdateAerodynamicModel = GUILayout.Toggle(Settings.AutoUpdateAerodynamicModel, new GUIContent("Auto update", "Auto-update of the aerodynamic model. For example if a part is decoupled, the model needs to be updated. This is independent from trajectory update."));
                if (GUILayout.Button("Update now"))
                {
                    Trajectory.InvalidateAerodynamicModel();
                }
                GUILayout.EndHorizontal();

                if (ToolbarManager.ToolbarAvailable)
                {
                    Settings.UseBlizzyToolbar = GUILayout.Toggle(Settings.UseBlizzyToolbar, new GUIContent("Use Blizzy's toolbar", "Will take effect after restart"));
                }

                if (Trajectories.IsVesselAttached)
                {
                    GUILayout.Label("Position:");
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("lat=" + guistring_Latitude, GUILayout.Width(110));
                    GUILayout.Label("lng=" + guistring_Longitude, GUILayout.Width(110));
                    GUILayout.EndHorizontal();
                }

                GUILayout.Label("Aerodynamic model: " + Trajectory.AerodynamicModelName);
                GUILayout.BeginHorizontal();
                GUILayout.Label(string.Format("Perf: {0,5:F1}ms ({1,4:F1})%",
                                              Trajectory.ComputationTime * 1000.0f,
                                              Trajectory.ComputationTime / Trajectory.GameFrameTime * 100.0f
                                              ), GUILayout.Width(130));
                GUILayout.Label(Trajectory.ErrorCount + " error(s)", GUILayout.Width(80));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Toggle(Settings.NewGui, new GUIContent("New Gui", "Swap to the New Gui")))
                {
                    Settings.NewGui         = true;
                    Settings.MainGUIEnabled = true;
                    Settings.GUIEnabled     = false;
                    InputLockManager.RemoveControlLock("TrajectoriesFlightLock");
                    clickThroughLocked = false;
                }
                else
                {
                    Settings.NewGui         = false;
                    Settings.MainGUIEnabled = false;
                    Settings.GUIEnabled     = true;
                }
                GUILayout.EndHorizontal();
            }

            tooltip = GUI.tooltip;

            GUI.DragWindow();
        }