public void drawTrackingStations() { displayingTooltip2 = false; CelestialBody body = PlanetariumCamera.fetch.target.GetReferenceBody(); // Do tracking stations first foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics()) { if (!MiscUtils.isCareerGame()) { break; } bool display2 = false; string openclosed3 = "Closed"; if ((string)obj.getSetting("FacilityType") != "TrackingStation") { continue; } if (isOccluded(obj.gameObject.transform.position, body)) { if (KerbalKonstructs.instance.mapHideIconsBehindBody) { continue; } } openclosed3 = (string)obj.getSetting("OpenCloseState"); if ((float)obj.getSetting("OpenCost") == 0) { openclosed3 = "Open"; } if (KerbalKonstructs.instance.mapShowOpenT) { display2 = true; } if (!KerbalKonstructs.instance.mapShowClosed && openclosed3 == "Closed") { display2 = false; } if (!KerbalKonstructs.instance.mapShowOpen && openclosed3 == "Open") { display2 = false; } if (!display2) { continue; } Vector3 pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position)); Rect screenRect6 = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16); // Distance between camera and spawnpoint sort of float fPosZ = pos.z; float fRadarRadius = 12800 / fPosZ; if (fRadarRadius > 15) { GUI.DrawTexture(screenRect6, UIMain.TrackingStationIcon, ScaleMode.ScaleToFit, true); } string sTarget = (string)obj.getSetting("TargetID"); float fStRange = (float)obj.getSetting("TrackingShort"); float fStAngle = (float)obj.getSetting("TrackingAngle"); if (openclosed3 == "Open" && KerbalKonstructs.instance.mapShowGroundComms) { drawGroundComms(obj); } if ((string)obj.getSetting("TargetType") == "Craft" && sTarget != "None") { Vessel vTargetVessel = TrackingStationGUI.GetTargetVessel(sTarget); if (vTargetVessel == null) { } else { if (vTargetVessel.state == Vessel.State.DEAD) { } else { CelestialBody cbTStation = (CelestialBody)obj.getSetting("CelestialBody"); CelestialBody cbTCraft = vTargetVessel.mainBody; if (cbTStation == cbTCraft && openclosed3 == "Open" && KerbalKonstructs.instance.mapShowUplinks) { Vector3 vCraftPos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(vTargetVessel.gameObject.transform.position)); float fRangeToTarget = TrackingStationGUI.GetRangeToCraft(obj, vTargetVessel); int iUplink = TrackingStationGUI.GetUplinkQuality(fStRange, fRangeToTarget); float fUplink = (float)iUplink / 100; float fRed = 1f; float fGreen = 0f; float fBlue = fUplink; float fAlpha = 1f; if (iUplink > 45) { fRed = 1f; fGreen = 0.65f + (fUplink / 10); fBlue = 0f; } if (iUplink > 85) { fRed = 0f; fGreen = fUplink; fBlue = 0f; } float fStationLOS = TrackingStationGUI.StationHasLOS(obj, vTargetVessel); if (fStationLOS > fStAngle) { fRed = 1f; fGreen = 0f; fBlue = 0f; fAlpha = 0.5f; } NavUtils.CreateLineMaterial(3); GL.Begin(GL.LINES); NavUtils.lineMaterial3.SetPass(0); GL.Color(new Color(fRed, fGreen, fBlue, fAlpha)); GL.Vertex3(pos.x - Screen.width / 2, pos.y - Screen.height / 2, pos.z); GL.Vertex3(vCraftPos.x - Screen.width / 2, vCraftPos.y - Screen.height / 2, vCraftPos.z); GL.End(); } } } } if (screenRect6.Contains(Event.current.mousePosition) && !displayingTooltip2) { CelestialBody cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody"); var objectpos2 = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position); var dObjectLat2 = NavUtils.GetLatitude(objectpos2); var dObjectLon2 = NavUtils.GetLongitude(objectpos2); var disObjectLat2 = dObjectLat2 * 180 / Math.PI; var disObjectLon2 = dObjectLon2 * 180 / Math.PI; if (disObjectLon2 < 0) { disObjectLon2 = disObjectLon2 + 360; } //Only display one tooltip at a time displayMapIconToolTip("Tracking Station " + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos); if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { float sTrackAngle = (float)obj.getSetting("TrackingAngle"); float sTrackRange = (float)obj.getSetting("TrackingShort"); PersistenceUtils.loadStaticPersistence(obj); float sTrackAngle2 = (float)obj.getSetting("TrackingAngle"); float sTrackRange2 = (float)obj.getSetting("TrackingShort"); selectedFacility = obj; FacilityManager.setSelectedFacility(obj); WindowManager.instance.OpenWindow(KerbalKonstructs.instance.GUI_FacilityManager.drawFacilityManager); } } } }
public void drawGroundComms(StaticObject obj, LaunchSite lSite = null) { string Base = ""; string Base2 = ""; float Range = 0f; LaunchSite lBase = null; LaunchSite lBase2 = null; Vector3 pos = Vector3.zero; if (lSite != null) { GameObject golSite = lSite.GameObject; pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(golSite.transform.position)); LaunchSiteManager.getNearestBase(golSite.transform.position, out Base, out Base2, out Range, out lBase, out lBase2); } if (obj != null) { pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position)); LaunchSiteManager.getNearestBase(obj.gameObject.transform.position, out Base, out Base2, out Range, out lBase, out lBase2); } Vector3 vNeighbourPos = Vector3.zero; Vector3 vNeighbourPos2 = Vector3.zero; Vector3 vBasePos = Vector3.zero; Vector3 vBasePos2 = Vector3.zero; GameObject goNeighbour = null; GameObject goNeighbour2 = null; if (Base != "") { if (Base == "KSC") { goNeighbour = SpaceCenterManager.KSC.gameObject; } else { goNeighbour = LaunchSiteManager.getSiteGameObject(Base); } } if (Base2 != "") { if (Base2 == "KSC") { goNeighbour2 = SpaceCenterManager.KSC.gameObject; } else { goNeighbour2 = LaunchSiteManager.getSiteGameObject(Base2); } } if (goNeighbour != null) { vNeighbourPos = goNeighbour.transform.position; vBasePos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(vNeighbourPos)); } if (goNeighbour2 != null) { vNeighbourPos2 = goNeighbour2.transform.position; vBasePos2 = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(vNeighbourPos2)); } if (goNeighbour != null && vNeighbourPos != Vector3.zero && vBasePos != Vector3.zero) { NavUtils.CreateLineMaterial(1); GL.Begin(GL.LINES); NavUtils.lineMaterial1.SetPass(0); GL.Color(new Color(1f, 1f, 1f, 0.7f)); GL.Vertex3(pos.x - Screen.width / 2, pos.y - Screen.height / 2, pos.z); GL.Vertex3(vBasePos.x - Screen.width / 2, vBasePos.y - Screen.height / 2, vBasePos.z); GL.End(); } if (goNeighbour2 != null && vNeighbourPos2 != Vector3.zero && vBasePos2 != Vector3.zero) { NavUtils.CreateLineMaterial(2); GL.Begin(GL.LINES); NavUtils.lineMaterial2.SetPass(0); GL.Color(new Color(1f, 1f, 1f, 0.7f)); GL.Vertex3(pos.x - Screen.width / 2, pos.y - Screen.height / 2, pos.z); GL.Vertex3(vBasePos2.x - Screen.width / 2, vBasePos2.y - Screen.height / 2, vBasePos2.z); GL.End(); } }