private void mouseOver(int id) { float mx = Event.current.mousePosition.x - TextureRect.x; float my = Event.current.mousePosition.y - TextureRect.y; bool in_map = false; double mlon = 0, mlat = 0; //Draw the re-size label in the corner Rect resizer = new Rect(WindowRect.width - 24, WindowRect.height - 26, 24, 24); GUI.Label(resizer, SCANskins.SCAN_ResizeIcon); //Handles mouse positioning and converting to lat/long coordinates if (mx >= 0 && my >= 0 && mx <= TextureRect.width && my <= TextureRect.height /*mx >= 0 && my >= 0 && mx < MapTexture.width && my < MapTexture.height*/) { double mlo = spotmap.Lon_Offset + (mx / spotmap.MapScale) - 180; double mla = spotmap.Lat_Offset + ((TextureRect.height - my) / spotmap.MapScale) - 90; mlon = spotmap.unprojectLongitude(mlo, mla); mlat = spotmap.unprojectLatitude(mlo, mla); if (mlon >= -180 && mlon <= 180 && mlat >= -90 && mlat <= 90) { in_map = true; if (SCANcontroller.controller.TargetSelecting) { SCANcontroller.controller.TargetSelectingActive = true; mjTarget.x = mlon; mjTarget.y = mlat; SCANcontroller.controller.LandingTargetCoords = mjTarget; Rect r = new Rect(mx + TextureRect.x - 11, my + TextureRect.y - 13, 24, 24); SCANuiUtil.drawMapIcon(r, SCANcontroller.controller.mechJebTargetSelection ? SCANskins.SCAN_MechJebIcon : SCANskins.SCAN_TargetIcon, true, palette.yellow, true); } } else if (SCANcontroller.controller.TargetSelecting) { SCANcontroller.controller.TargetSelectingActive = false; } if (mlat > 90) { mlon = (mlon + 360) % 360 - 180; mlat = 180 - mlat; } else if (mlat < -90) { mlon = (mlon + 360) % 360 - 180; mlat = -180 - mlat; } } else if (SCANcontroller.controller.TargetSelecting) { SCANcontroller.controller.TargetSelectingActive = false; } //Handles mouse click while inside map if (Event.current.isMouse) { if (Event.current.type == EventType.MouseUp) { //Generate waypoint for MechJeb target if (SCANcontroller.controller.TargetSelecting && SCANcontroller.controller.TargetSelectingActive && Event.current.button == 0 && in_map) { string s = SCANcontroller.controller.mechJebTargetSelection ? "MechJeb Landing Target" : "Landing Target Site"; SCANwaypoint w = new SCANwaypoint(mlat, mlon, s); SCANcontroller.controller.LandingTarget = w; data.addToWaypoints(); SCANcontroller.controller.TargetSelecting = false; SCANcontroller.controller.TargetSelectingActive = false; } //Middle click re-center else if (Event.current.button == 2 || (Event.current.button == 1 && GameSettings.MODIFIER_KEY.GetKey())) { if (in_map) { spotmap.centerAround(mlon, mlat); resetMap(); } } //Right click zoom in else if (Event.current.button == 1) { if (in_map) { spotmap.MapScale = spotmap.MapScale * 1.25f; spotmap.centerAround(mlon, mlat); resetMap(); } } //Left click zoom out else if (Event.current.button == 0) { if (in_map) { spotmap.MapScale = spotmap.MapScale / 1.25f; if (spotmap.MapScale < 2) { spotmap.MapScale = 2; } spotmap.centerAround(mlon, mlat); resetMap(); } } Event.current.Use(); } //Handle clicking inside the re-size button else if (Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.button == 0 && resizer.Contains(Event.current.mousePosition)) { IsResizing = true; dragStart.x = Input.mousePosition.x; dragStart.y = Input.mousePosition.y; resizeW = TextureRect.width; resizeH = TextureRect.height; Event.current.Use(); } } //Draw the actual mouse over info label below the map if (SCANcontroller.controller.TargetSelecting) { SCANuiUtil.readableLabel(SCANcontroller.controller.mechJebTargetSelection ? "MechJeb Landing Guidance Targeting..." : "Landing Site Targeting...", false); fillS(-10); SCANuiUtil.mouseOverInfoSimple(mlon, mlat, spotmap, data, spotmap.Body, in_map); } else if (showInfo) { SCANuiUtil.mouseOverInfoSimple(mlon, mlat, spotmap, data, spotmap.Body, in_map); } else { fillS(10); } }
protected override void LateUpdate() { if (shutdown) { return; } if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) { return; } if (SCANcontroller.controller == null) { way = null; return; } if (!SCANcontroller.controller.mechJebTargetSelection) { way = null; return; } v = FlightGlobals.ActiveVessel; if (v == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (v.mainBody != SCANcontroller.controller.LandingTargetBody) { SCANcontroller.controller.LandingTargetBody = v.mainBody; } data = SCANUtil.getData(v.mainBody); if (data == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (v.FindPartModulesImplementing <MechJebCore>().Count <= 0) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } core = v.GetMasterMechJeb(); if (core == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX) { if (guidanceModule == null) { guidanceModule = (DisplayModule)core.GetComputerModule("MechJebModuleLandingGuidance"); } if (guidanceModule == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (!guidanceModule.unlockChecked) { return; } if (guidanceModule.hidden) { SCANcontroller.controller.MechJebLoaded = false; shutdown = true; way = null; return; } } target = core.target; if (target == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (!SCANcontroller.controller.MechJebLoaded) { SCANcontroller.controller.MechJebLoaded = true; RenderingManager.AddToPostDrawQueue(1, drawTarget); } if (SCANcontroller.controller.LandingTarget != null) { way = SCANcontroller.controller.LandingTarget; } if (SCANcontroller.controller.TargetSelecting) { way = null; selectingTarget = true; if (SCANcontroller.controller.TargetSelectingActive) { selectingInMap = true; } else { selectingInMap = false; } coords = SCANcontroller.controller.LandingTargetCoords; return; } else if (selectingTarget) { selectingTarget = false; if (selectingInMap) { selectingInMap = false; coords = SCANcontroller.controller.LandingTargetCoords; way = new SCANwaypoint(coords.y, coords.x, siteName); target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude); } } selectingInMap = false; selectingTarget = false; if (target.Target == null) { way = null; return; } if (target.targetBody != v.mainBody) { way = null; return; } if (!(target.Target is PositionTarget)) { way = null; return; } coords.x = target.targetLongitude; coords.y = target.targetLatitude; if (way != null) { if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude)) { way = new SCANwaypoint(coords.y, coords.x, siteName); SCANcontroller.controller.LandingTarget = way; data.addToWaypoints(); } } else { way = new SCANwaypoint(coords.y, coords.x, siteName); SCANcontroller.controller.LandingTarget = way; data.addToWaypoints(); } }