Наследование: IUpdatable, IUpdateRequest
 public override void Update()
 {
     RendezvousProcessor.RequestUpdate();
 }
Пример #2
0
        /// <summary>
        ///     Draws the target information when selected.
        /// </summary>
        private void DrawTarget(Unity.Flight.ISectionModule section)
        {
            ITargetable target = Flight.Readouts.Rendezvous.RendezvousProcessor.activeTarget;

            this.ResizeRequested = true;

            if (target != null)
            {
                if (HighLogic.LoadedSceneIsFlight)
                {
                    if (GUILayout.Button("Go Back to Target Selection", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
                    {
                        FlightGlobals.fetch.SetVesselTarget(null);
                    }
                }
                else
                {
                    if (RendezvousProcessor.TrackingStationSource != target)
                    {
                        if (GUILayout.Button("Use " + RendezvousProcessor.nameForTargetable(target) + " As Reference", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
                        {
                            RendezvousProcessor.TrackingStationSource = target;
                        }
                    }
                }

                if (HighLogic.LoadedSceneIsFlight)
                {
                    var act = FlightGlobals.ActiveVessel;

                    if (!(target is CelestialBody) && GUILayout.Button("Switch to Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
                    {
                        FlightEngineerCore.SwitchToVessel(target.GetVessel(), act);
                    }

                    bool focusable = (target is CelestialBody || target is global::Vessel);

                    if (focusable)
                    {
                        MapObject targMo = null;

                        if (target is global::Vessel)
                        {
                            targMo = ((global::Vessel)(target)).mapObject;
                        }
                        else
                        {
                            targMo = ((CelestialBody)(target)).MapObject;
                        }

                        bool shouldFocus = targMo != null && (targMo != PlanetariumCamera.fetch.target || !MapView.MapIsEnabled);

                        if (shouldFocus && GUILayout.Button("Focus Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
                        {
                            wasMapview = MapView.MapIsEnabled;
                            MapView.EnterMapView();
                            PlanetariumCamera.fetch.SetTarget(targMo);
                        }
                    }

                    bool switchBack = PlanetariumCamera.fetch.target != act.mapObject;

                    if (switchBack && MapView.MapIsEnabled && GUILayout.Button("Focus Vessel", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
                    {
                        if (!wasMapview)
                        {
                            MapView.ExitMapView();
                        }
                        PlanetariumCamera.fetch.SetTarget(act.mapObject);
                    }

                    if (FlightCamera.fetch.mode != FlightCamera.Modes.LOCKED && !MapView.MapIsEnabled && GUILayout.Button("Look at Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
                    {
                        var pcam = PlanetariumCamera.fetch;
                        var fcam = FlightCamera.fetch;

                        Vector3 from = new Vector3();

                        if (target is global::Vessel && ((global::Vessel)target).LandedOrSplashed)
                        {
                            from = ((global::Vessel)target).GetWorldPos3D();
                        }
                        else
                        {
                            //I don't think it's possible to target the sun so this should always work but who knows.
                            if (target.GetOrbit() != null)
                            {
                                from = target.GetOrbit().getTruePositionAtUT(Planetarium.GetUniversalTime());
                            }
                        }


                        Vector3 to = FlightGlobals.fetch.activeVessel.GetWorldPos3D();

                        //  float pdist = pcam.Distance;
                        float fdist = fcam.Distance;

                        Vector3 n = (from - to).normalized;

                        if (!n.IsInvalid())
                        {
                            //   pcam.SetCamCoordsFromPosition(n * -pdist); //this does weird stuff
                            fcam.SetCamCoordsFromPosition(n * -fdist);
                        }
                    }
                }

                GUILayout.Space(3f);

                this.DrawLine("Selected Target", RendezvousProcessor.nameForTargetable(target), section.IsHud);

                if (RendezvousProcessor.sourceDisplay != null)
                {
                    if (RendezvousProcessor.landedSamePlanet || RendezvousProcessor.overrideANDN)
                    {
                        this.DrawLine("Ref Orbit", "Landed on " + RendezvousProcessor.activeVessel.GetOrbit().referenceBody.GetName(), section.IsHud);
                    }
                    else
                    {
                        this.DrawLine("Ref Orbit", RendezvousProcessor.sourceDisplay, section.IsHud);
                    }
                }

                if (RendezvousProcessor.targetDisplay != null)
                {
                    if (RendezvousProcessor.landedSamePlanet || RendezvousProcessor.overrideANDNRev)
                    {
                        this.DrawLine("Target Orbit", "Landed on " + target.GetOrbit().referenceBody.GetName(), section.IsHud);
                    }
                    else
                    {
                        this.DrawLine("Target Orbit", RendezvousProcessor.targetDisplay, section.IsHud);
                    }
                }
            }
        }