public void addToWaypoints(SCANwaypoint w) { if (waypoints == null) { waypoints = new List <SCANwaypoint>() { w }; return; } if (waypoints.Any(a => a.LandingTarget)) { waypoints.RemoveAll(a => a.LandingTarget); } waypoints.Add(w); }
public void addToWaypoints(SCANwaypoint w) { if (waypoints == null) { waypoints = new List<SCANwaypoint>() { w }; return; } if (waypoints.Any(a => a.LandingTarget)) waypoints.RemoveAll(a => a.LandingTarget); waypoints.Add(w); }
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); }
private void DrawIcon(SCANwaypoint p, Color iconColor) { Rect pos = new Rect((float)(longitudeToPixels(p.Longitude, p.Latitude)), (float)(latitudeToPixels(p.Longitude, p.Latitude)), 16, 16); if (!p.LandingTarget) { pos.x -= 8; pos.y -= 16; SCANuiUtil.drawMapIconGL(pos, SCANskins.SCAN_WaypointIcon, iconColor, iconMaterial, iconColorShadowValue, true); } else { pos.x -= 8; pos.y -= 8; SCANuiUtil.drawMapIconGL(pos, SCANcontroller.controller.mechJebTargetSelection ? SCANskins.SCAN_MechJebIcon : SCANskins.SCAN_TargetIcon, iconColor, iconMaterial, iconColorShadowValue, true); } }
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(); } }
private double waypointRange(SCANwaypoint p) { double min = ContractDefs.Survey.MinimumTriggerRange; double max = ContractDefs.Survey.MaximumTriggerRange; switch (p.Band) { case FlightBand.GROUND: return min; case FlightBand.LOW: return (min + max) / 2; case FlightBand.HIGH: return max; default: return max; } }
private static void drawWaypointLabel(Rect maprect, SCANmap map, SCANwaypoint p, SCANdata data) { double lon = SCANUtil.fixLon(p.Longitude); double lat = SCANUtil.fixLat(p.Latitude); if (map != null) { lat = SCANUtil.fixLat(map.projectLatitude(p.Longitude, p.Latitude)); lon = SCANUtil.fixLon(map.projectLongitude(p.Longitude, p.Latitude)); lat = map.scaleLatitude(lat); lon = map.scaleLongitude(lon); if (lat < 0 || lon < 0 || lat > 180 || lon > 360) return; } lon = lon * maprect.width / 360f; lat = maprect.height - lat * maprect.height / 180f; Rect r = new Rect(maprect.x + (float)lon, maprect.y + (float)lat, 24, 24); r.x -= 12; if (!p.LandingTarget) { r.y -= 24; drawMapIcon(r, SCANskins.SCAN_WaypointIcon, true); } else { r.x += 1; r.y -= 13; drawMapIcon(r, SCANcontroller.controller.mechJebTargetSelection ? SCANskins.SCAN_MechJebIcon : SCANskins.SCAN_TargetIcon, true, SCANcontroller.controller.mechJebTargetSelection ? palette.red : palette.xkcd_PukeGreen, true); } }
private SCANwaypoint loadWaypoint(string s) { SCANwaypoint w = null; string[] a = s.Split(','); double lat = 0; double lon = 0; if (!double.TryParse(a[0], out lat)) return w; if (!double.TryParse(a[1], out lon)) return w; string name = mechJebTargetSelection ? "MechJeb Landing Target" : "Landing Target Site"; w = new SCANwaypoint(lat, lon, name); return w; }