Example #1
0
        private void HandlePositionPicking()
        {
            if (!MapView.MapIsEnabled || !this.vessel.isActiveVessel)
            {
                // No longer in map mode.
                StopPickingVirtualTarget(keepTarget: false);
                return;
            }

            CelestialBody pickingBody       = this.m_virtualTarget.Location.Body;
            MapObject     planetariumTarget = PlanetariumCamera.fetch.target;

            if (planetariumTarget.celestialBody != pickingBody || this.CurrentBody != pickingBody)
            {
                StopPickingVirtualTarget(keepTarget: false);
                return;
            }

            Coordinates?mouseCoords = pickingBody.GetMouseCoordinates();

            if (mouseCoords == null)
            {
                Screen.showCursor             = true;
                this.m_isMouseOverPickingBody = false;
                return;
            }

            // Position to pick.
            Screen.showCursor             = false;
            this.m_isMouseOverPickingBody = true;

            // ReSharper disable once PossibleNullReferenceException
            this.m_virtualTarget.SetLocation(new GlobalLocation(pickingBody, mouseCoords.Value));

            // IMPORTANT: Don't cancel on right click as the right mouse button is used
            //   to rotate the camera.
            // IMPORTANT: We need to use "ButtonDown" here (instead of "ButtonUp"). Otherwise
            //   "ButtonUp" would immediately be true after start picking (because this is triggered
            //   by "ButtonUp" in the same frame).
            if (Input.GetMouseButtonDown(MouseButtons.Left))
            {
                StopPickingVirtualTarget(keepTarget: true);
            }
        }
Example #2
0
        public void OnGUI()
        {
            bool paused = false;

            if (HighLogic.LoadedSceneIsFlight)
            {
                try
                {
                    paused = PauseMenu.isOpen || FlightResultsDialog.isDisplaying;
                }
                catch (Exception)
                {
                    // ignore the error and assume the pause menu is not open
                }
            }
            if (_targetBody != FlightGlobals.ActiveVessel.mainBody || paused || !showTooltip)
            //dont show tooltips on different bodys or ORS lags
            {
                return;
            }
            if (show && _targetBody != null)
            {
                if (Event.current.type == EventType.Layout)
                {
                    try
                    {
                        _mouseCoords = _targetBody.GetMouseCoordinates();
                        _mouse       = Event.current.mousePosition;
                        if (useScansat && _scanSat.Active() && _mouseCoords != null &&
                            !OverlayProvider.IsCoveredAt(_mouseCoords.Longitude, _mouseCoords.Latitude, _targetBody))
                        {
                            _mouseCoords = null;
                        }
                    }
                    catch (NullReferenceException e)
                    {
                        this.Log("layout nullref" + e);
                    }
                }
                if (_mouseCoords != null)
                {
                    _toolTipId = 0;
                    var overlayTooltip = OverlayProvider.TooltipContent(_mouseCoords.Latitude, _mouseCoords.Longitude,
                                                                        _targetBody);
                    if (Math.Abs(overlayTooltip.Size.x) < 0.01 && Math.Abs(overlayTooltip.Size.y) < 0.01)
                    {
                        overlayTooltip.Size = new Vector2(200f, 55f);
                    }
                    var style = new GUIStyle(GUI.skin.label)
                    {
                        wordWrap = true
                    };
                    GUI.Window(_toolTipId,
                               new Rect(_mouse.x + 10, _mouse.y + 10, overlayTooltip.Size.x, overlayTooltip.Size.y), i =>
                    {
                        GUI.Label(new Rect(5, 10, 190, 20),
                                  "Long: " + _mouseCoords.Longitude.ToString("###.##") + " Lat: " +
                                  _mouseCoords.Latitude.ToString("####.##"));
                        GUI.Label(new Rect(5, 30, overlayTooltip.Size.x - 10, overlayTooltip.Size.y - 35),
                                  overlayTooltip.Content, style);
                    },
                               overlayTooltip.Title);
                }
            }
        }