// Returns a specific Launchsite, keyed by site.name public static LaunchSite getLaunchSiteByName(string sSiteName, bool bRemember = false) { if (bRemember) { if (sBaseMem == sSiteName) { return(launchsitemem); } } List <LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site.name == sSiteName) { if (bRemember) { sBaseMem = sSiteName; launchsitemem = site; } return(site); } } return(null); }
// Get nearest base, either open or closed, and the range to it public static void getNearestBase(Vector3 position, out string sBase, out float flRange, out LaunchSite lSite) { SpaceCenter KSC = SpaceCenter.Instance; var smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); string sNearestBase = ""; LaunchSite lTargetSite = null; LaunchSite lKSC = null; List <LaunchSite> basesites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in basesites) { if (site.GameObject == null) { continue; } //if (site.recoveryfactor == 0) continue; var radialposition = site.GameObject.transform.position; var dist = Vector3.Distance(position, radialposition); if (site.name == "Runway" || site.name == "LaunchPad") { lKSC = site; } else { if ((float)dist < (float)smallestDist) { { sNearestBase = site.name; smallestDist = dist; lTargetSite = site; } } } } if (sNearestBase == "") { sNearestBase = "KSC"; lTargetSite = lKSC; } RangeNearestBase = (float)smallestDist; sBase = sNearestBase; flRange = RangeNearestBase; lSite = lTargetSite; }
// Pokes KSP to change the launchsite to use. There's near hackery here again that may get broken by Squad // This only works because they use multiple variables to store the same value, basically its black magic // Original author: medsouz public static void setLaunchSite(LaunchSite site) { if (site.facility != null) { if (EditorDriver.editorFacility.Equals(EditorFacility.SPH)) { site.facility.name = "Runway"; } else { site.facility.name = "LaunchPad"; } } EditorLogic.fetch.launchSiteName = site.name; }
public static float getDistanceToBase(Vector3 position, LaunchSite lTarget) { float flRange = 0f; List <LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site == lTarget) { var radialposition = site.GameObject.transform.position; var dist = Vector3.Distance(position, radialposition); flRange = dist; } } return(flRange); }
public static void setLaunchSite(LaunchSite site) { // Debug.Log("KK: EditorLogic.fetch.launchSiteName set to " + site.name); //Trick KSP to think that you launched from Runway or LaunchPad //I'm sure Squad will break this in the future //This only works because they use multiple variables to store the same value, basically its black magic. //--medsouz if (site.facility != null) { if (EditorDriver.editorFacility.Equals(EditorFacility.SPH)) { site.facility.name = "Runway"; } else { site.facility.name = "LaunchPad"; } } EditorLogic.fetch.launchSiteName = site.name; }
public void drawSelectorWindow(int id) { ButtonKK = new GUIStyle(GUI.skin.button); ButtonKK.padding.left = 0; ButtonKK.padding.right = 0; DeadButton = new GUIStyle(GUI.skin.button); DeadButton.normal.background = null; DeadButton.hover.background = null; DeadButton.active.background = null; DeadButton.focused.background = null; DeadButton.normal.textColor = Color.white; DeadButton.hover.textColor = Color.white; DeadButton.active.textColor = Color.white; DeadButton.focused.textColor = Color.white; DeadButton.fontSize = 14; DeadButton.fontStyle = FontStyle.Bold; DeadButtonRed = new GUIStyle(GUI.skin.button); DeadButtonRed.normal.background = null; DeadButtonRed.hover.background = null; DeadButtonRed.active.background = null; DeadButtonRed.focused.background = null; DeadButtonRed.normal.textColor = Color.red; DeadButtonRed.hover.textColor = Color.yellow; DeadButtonRed.active.textColor = Color.red; DeadButtonRed.focused.textColor = Color.red; DeadButtonRed.fontSize = 12; DeadButtonRed.fontStyle = FontStyle.Bold; BoxNoBorder = new GUIStyle(GUI.skin.box); BoxNoBorder.normal.background = null; BoxNoBorder.normal.textColor = Color.white; KKToolTip = new GUIStyle(GUI.skin.box); KKToolTip.normal.textColor = Color.white; KKToolTip.fontSize = 11; KKToolTip.fontStyle = FontStyle.Normal; string smessage = ""; GUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.Button("-KK-", DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUILayout.Button("Launchsite Selector", DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUI.enabled = true; if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(21))) { InputLockManager.RemoveControlLock("KKEditorLock"); InputLockManager.RemoveControlLock("KKEditorLock2"); KerbalKonstructs.instance.showSiteSelector = false; } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.BeginHorizontal(); { GUILayout.Space(5); if (MiscUtils.isCareerGame()) { if (bOpenOn) tHolder = tOpenBasesOn; else tHolder = tOpenBasesOff; if (GUILayout.Button(new GUIContent(tHolder, "Open"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { if (bOpenOn) { bOpenOn = false; bClosedOn = true; } else bOpenOn = true; } if (bClosedOn) tHolder = tClosedBasesOn; else tHolder = tClosedBasesOff; if (GUILayout.Button(new GUIContent(tHolder, "Closed"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { if (bClosedOn) { bClosedOn = false; bOpenOn = true; } else bClosedOn = true; } GUILayout.FlexibleSpace(); } if (bFavesOnly) tHolder = tFavesOn; else tHolder = tFavesOff; if (GUILayout.Button(new GUIContent(tHolder, "Only Favourites"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { if (bFavesOnly) { bFavesOnly = false; } else bFavesOnly = true; } GUILayout.FlexibleSpace(); if (editorType == SiteType.SPH) GUI.enabled = false; if (bRocketpadsOn) tHolder = tLaunchpadsOn; else tHolder = tLaunchpadsOff; if (GUILayout.Button(new GUIContent(tHolder, "Rocketpads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { bRocketpadsOn = true; bHelipadsOn = false; bRunwaysOn = false; bOtherOn = false; sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "RocketPad"); } GUI.enabled = true; GUILayout.Space(2); if (editorType == SiteType.VAB) GUI.enabled = false; if (bRunwaysOn) tHolder = tRunwaysOn; else tHolder = tRunwaysOff; if (GUILayout.Button(new GUIContent(tHolder, "Runways"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { bRunwaysOn = true; bHelipadsOn = false; bRocketpadsOn = false; bOtherOn = false; sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "Runway"); } GUI.enabled = true; GUILayout.Space(2); if (editorType == SiteType.VAB) GUI.enabled = false; if (bHelipadsOn) tHolder = tHelipadsOn; else tHolder = tHelipadsOff; if (GUILayout.Button(new GUIContent(tHolder, "Helipads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { bRocketpadsOn = false; bHelipadsOn = true; bRunwaysOn = false; bOtherOn = false; sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "Helipad"); } GUI.enabled = true; GUILayout.Space(2); if (bOtherOn) tHolder = tOtherOn; else tHolder = tOtherOff; if (GUILayout.Button(new GUIContent(tHolder, "Other"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32))) { bRocketpadsOn = false; bHelipadsOn = false; bRunwaysOn = false; bOtherOn = true; sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "Other"); } GUILayout.FlexibleSpace(); if (GUILayout.Button("ALL", GUILayout.Width(32), GUILayout.Height(32))) { bRocketpadsOn = true; bHelipadsOn = true; bRunwaysOn = true; bOtherOn = true; sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "ALL"); } } GUILayout.EndHorizontal(); GUILayout.Space(10); sitesScrollPosition = GUILayout.BeginScrollView(sitesScrollPosition); { if (sites == null) sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "ALL"); sites.Sort(delegate(LaunchSite a, LaunchSite b) { return (a.name).CompareTo(b.name); }); foreach (LaunchSite site in sites) { if (bFavesOnly) { if (site.favouritesite != "Yes") continue; } if (MiscUtils.isCareerGame()) { if (!bOpenOn) { if (site.openclosestate == "Open" || site.opencost == 0) continue; } if (!bClosedOn) { if (site.openclosestate == "Closed") continue; } GUILayout.BeginHorizontal(); if (site.openclosestate == "Open" || site.opencost == 0 && site.openclosestate != "OpenLocked" && site.openclosestate != "ClosedLocked") { site.openclosestate = "Open"; GUILayout.Label(tIconOpen, GUILayout.Height(30), GUILayout.Width(30)); } else GUILayout.Label(tIconClosed, GUILayout.Height(30), GUILayout.Width(30)); } GUI.enabled = !(selectedSite == site); string sButtonName = ""; sButtonName = site.name; if (site.name == "Runway") sButtonName = "KSC Runway"; if (site.name == "LaunchPad") sButtonName = "KSC LaunchPad"; if (GUILayout.Button(sButtonName, GUILayout.Height(30))) { selectedSite = site; if (!MiscUtils.isCareerGame()) { LaunchSiteManager.setLaunchSite(site); smessage = "Launchsite set to " + sButtonName; MiscUtils.HUDMessage(smessage, 10, 2); } } GUI.enabled = true; if (MiscUtils.isCareerGame()) { if (site.openclosestate == "Open" || site.opencost == 0 && site.openclosestate != "OpenLocked" && site.openclosestate != "ClosedLocked") { site.openclosestate = "Open"; GUILayout.Label(tIconOpen, GUILayout.Height(30), GUILayout.Width(30)); } else GUILayout.Label(tIconClosed, GUILayout.Height(30), GUILayout.Width(30)); GUILayout.EndHorizontal(); } } } GUILayout.EndScrollView(); GUILayout.Space(5); sCurrentSite = LaunchSiteManager.getCurrentLaunchSite(); if (sCurrentSite != null) { if (sCurrentSite == "Runway") GUILayout.Box("Current Launchsite: KSC Runway"); else if (sCurrentSite == "LaunchPad") GUILayout.Box("Current Launchsite: KSC LaunchPad"); else GUILayout.Box("Current Launchsite: " + sCurrentSite); } GUILayout.BeginHorizontal(); { if (editorType == SiteType.SPH) GUI.enabled = (KerbalKonstructs.instance.defaultSPHlaunchsite != sCurrentSite); if (editorType == SiteType.VAB) GUI.enabled = (KerbalKonstructs.instance.defaultVABlaunchsite != sCurrentSite); if (GUILayout.Button("Set as Default", GUILayout.Height(23))) { if (sCurrentSite != null) { if (editorType == SiteType.SPH) KerbalKonstructs.instance.defaultSPHlaunchsite = sCurrentSite; if (editorType == SiteType.VAB) KerbalKonstructs.instance.defaultVABlaunchsite = sCurrentSite; } } GUI.enabled = true; LaunchSite DefaultSite = null; if (GUILayout.Button("Use Default", GUILayout.Height(23))) { if (editorType == SiteType.SPH) { foreach (LaunchSite site in sites) { if (site.name == KerbalKonstructs.instance.defaultSPHlaunchsite) DefaultSite = site; } if (DefaultSite != null) { if (MiscUtils.isCareerGame()) { if (DefaultSite.openclosestate == "OpenLocked" || DefaultSite.openclosestate == "ClosedLocked" || (DefaultSite.openclosestate != "Open" && DefaultSite.opencost != 0)) { smessage = "Default site is closed."; MiscUtils.HUDMessage(smessage, 10, 0); } else LaunchSiteManager.setLaunchSite(DefaultSite); } else LaunchSiteManager.setLaunchSite(DefaultSite); } } if (editorType == SiteType.VAB) { foreach (LaunchSite site in sites) { if (site.name == KerbalKonstructs.instance.defaultVABlaunchsite) DefaultSite = site; } if (DefaultSite != null) { if (MiscUtils.isCareerGame()) { if (DefaultSite.openclosestate == "OpenLocked" || DefaultSite.openclosestate == "ClosedLocked" || (DefaultSite.openclosestate != "Open" && DefaultSite.opencost != 0)) { smessage = "Default site is closed."; MiscUtils.HUDMessage(smessage, 10, 0); } else LaunchSiteManager.setLaunchSite(DefaultSite); } else LaunchSiteManager.setLaunchSite(DefaultSite); } } if (DefaultSite != null) { smessage = DefaultSite.name + " has been set as the launchsite"; MiscUtils.HUDMessage(smessage, 10, 0); } else { smessage = "KK could not determine the default launchsite."; MiscUtils.HUDMessage(smessage, 10, 0); } } } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUI.enabled = true; if (selectedSite != null) { BaseManager.setSelectedSite(selectedSite); KerbalKonstructs.instance.showBaseManager = true; } else { if (LaunchSiteManager.getLaunchSites().Count > 0) { selectedSite = LaunchSiteManager.getLaunchSites(editorType)[0]; LaunchSiteManager.setLaunchSite(selectedSite); BaseManager.setSelectedSite(selectedSite); KerbalKonstructs.instance.showBaseManager = true; } else { Debug.LogError("KK: ERROR Launch Selector cannot find KSC Runway or Launch Pad! PANIC! Runaway! Hide!"); } } if (GUI.tooltip != "") { var labelSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(GUI.tooltip)); GUI.Box(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y + 20, labelSize.x + 5, labelSize.y + 6), GUI.tooltip, KKToolTip); } GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }
public void setEditorType(SiteType type) { editorType = (KerbalKonstructs.instance.launchFromAnySite) ? SiteType.Any : type; if (selectedSite != null) { if (selectedSite.type != editorType && selectedSite.type != SiteType.Any) { selectedSite = LaunchSiteManager.getLaunchSites(editorType)[0]; } // if (!isCareerGame()) LaunchSiteManager.setLaunchSite(selectedSite); } }
// Pokes KSP to change the launchsite to use. There's near hackery here again that may get broken by Squad // This only works because they use multiple variables to store the same value, basically its black magic // Original author: medsouz public static void setLaunchSite(LaunchSite site) { if (site.facility != null) { if (EditorDriver.editorFacility.Equals(EditorFacility.SPH)) { site.facility.name = "Runway"; } else { site.facility.name = "LaunchPad"; } } EditorLogic.fetch.launchSiteName = site.name; }
// Returns the nearest Launchsite to a position and range in m to the Launchsite, regardless of whether it is open or closed public static void getNearestBase(Vector3 position, out string sBase, out string sBase2, out float flRange, out LaunchSite lSite, out LaunchSite lSite2) { SpaceCenter KSC = SpaceCenter.Instance; var smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); var lastSmallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); string sNearestBase = ""; LaunchSite lTargetSite = null; LaunchSite lLastSite = null; LaunchSite lKSC = null; string sLastNearest = ""; List<LaunchSite> basesites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in basesites) { if (site.GameObject == null) continue; var radialposition = site.GameObject.transform.position; var dist = Vector3.Distance(position, radialposition); if (radialposition == position) continue; if (site.name == "Runway" || site.name == "LaunchPad") { lKSC = site; } else { if ((float)dist < (float)smallestDist) { sLastNearest = sNearestBase; lLastSite = lTargetSite; lastSmallestDist = smallestDist; sNearestBase = site.name; smallestDist = dist; lTargetSite = site; } else if (dist < lastSmallestDist) { sLastNearest = site.name; lastSmallestDist = dist; lLastSite = site; } } } if (sNearestBase == "") { sNearestBase = "KSC"; lTargetSite = lKSC; } if (sLastNearest == "") { sLastNearest = "KSC"; lLastSite = lKSC; } RangeNearestBase = (float)smallestDist; sBase = sNearestBase; sBase2 = sLastNearest; flRange = RangeNearestBase; lSite = lTargetSite; lSite2 = lLastSite; }
public void drawIcons() { displayingTooltip = false; MapObject target = PlanetariumCamera.fetch.target; if (target.type == MapObject.MapObjectType.CELESTIALBODY) { // Do tracking stations first foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics()) { bool display2 = false; if ((string)obj.getSetting("FacilityType") == "TrackingStation") { if (!isOccluded(obj.gameObject.transform.position, target.celestialBody)) { if (MiscUtils.isCareerGame()) { //PersistenceUtils.loadStaticPersistence(obj); string openclosed2 = (string)obj.getSetting("OpenCloseState"); // To do manage open and close state of tracking stations if (KerbalKonstructs.instance.mapShowOpenT) // && openclosed == "Open") display2 = true; if (!KerbalKonstructs.instance.mapShowClosed && openclosed2 == "Closed") display2 = false; if (!KerbalKonstructs.instance.mapShowOpen && openclosed2 == "Open") display2 = false; } else { // Not a career game } if (display2) { Vector3 pos = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position)); Rect screenRect2 = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16); Graphics.DrawTexture(screenRect2, TrackingStationIcon); if (screenRect2.Contains(Event.current.mousePosition) && !displayingTooltip) { 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); // TO DO Display Lat and Lon in tooltip too if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { //MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3); Debug.Log("KK: Selected station in map"); float sTrackAngle = (float)obj.getSetting("TrackingAngle"); Debug.Log("KK: Before save load " + sTrackAngle.ToString()); float sTrackRange = (float)obj.getSetting("TrackingShort"); Debug.Log("KK: Before save load " + sTrackRange.ToString()); //PersistenceUtils.saveStaticPersistence(obj); PersistenceUtils.loadStaticPersistence(obj); float sTrackAngle2 = (float)obj.getSetting("TrackingAngle"); Debug.Log("KK: After save load " + sTrackAngle2.ToString()); float sTrackRange2 = (float)obj.getSetting("TrackingShort"); Debug.Log("KK: After save load " + sTrackRange2.ToString()); selectedFacility = obj; FacilityManager.setSelectedFacility(obj); KerbalKonstructs.instance.showFacilityManager = true; //EditorGUI.setTargetSite(selectedSite); } } else { // Mouse is not over tooltip } } else { // Filter set to not display } } else { // is occluded } } else { // Not a tracking station } } //end foreach // Then do launchsites List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { bool display = false; PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name); if (facility != null) { PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name); if (sp != null) { if (facility.facilityPQS == target.celestialBody.pqsController) { if (!isOccluded(sp.GetSpawnPointTransform().position, target.celestialBody)) { Vector3 pos = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(sp.GetSpawnPointTransform().position)); Rect screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16); string openclosed = site.openclosestate; string category = site.category; if (KerbalKonstructs.instance.mapShowHelipads && category == "Helipad") display = true; if (KerbalKonstructs.instance.mapShowOther && category == "Other") display = true; if (KerbalKonstructs.instance.mapShowRocketbases && category == "RocketPad") display = true; if (KerbalKonstructs.instance.mapShowRunways && category == "Runway") display = true; if (display && MiscUtils.isCareerGame()) { if (!KerbalKonstructs.instance.mapShowOpen && openclosed == "Open") display = false; if (!KerbalKonstructs.instance.mapShowClosed && openclosed == "Closed") display = false; if (KerbalKonstructs.instance.disableDisplayClosed && openclosed == "Closed") display = false; } if (display) { if (site.icon != null) { Graphics.DrawTexture(screenRect, site.icon); } else { switch (site.type) { case SiteType.VAB: Graphics.DrawTexture(screenRect, VABIcon); break; case SiteType.SPH: Graphics.DrawTexture(screenRect, SPHIcon); break; default: Graphics.DrawTexture(screenRect, ANYIcon); break; } } // Tooltip if (screenRect.Contains(Event.current.mousePosition) && !displayingTooltip) { //Only display one tooltip at a time string sToolTip = ""; sToolTip = site.name; if (site.name == "Runway") sToolTip = "KSC Runway"; if (site.name == "LaunchPad") sToolTip = "KSC LaunchPad"; displayMapIconToolTip(sToolTip, pos); // Select a base by clicking on the icon if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3); BaseManager.setSelectedSite(site); selectedSite = site; NavGuidanceSystem.setTargetSite(selectedSite); KerbalKonstructs.instance.showBaseManager = true; } } } } } } } } } }
public void drawSelectorWindow(int id) { // ASH 28102014 Category filter handling added. // ASH 07112014 Disabling of restricted categories added. GUILayout.BeginArea(new Rect(10, 25, 370, 550)); GUILayout.BeginHorizontal(); if (editorType == SiteType.SPH) { GUI.enabled = false; } if (GUILayout.Button("RocketPads", GUILayout.Width(80))) { sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "RocketPad"); } GUI.enabled = true; GUILayout.Space(2); if (editorType == SiteType.VAB) { GUI.enabled = false; } if (GUILayout.Button("Runways", GUILayout.Width(73))) { sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "Runway"); } GUI.enabled = true; GUILayout.Space(2); if (editorType == SiteType.VAB) { GUI.enabled = false; } if (GUILayout.Button("Helipads", GUILayout.Width(73))) { sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "Helipad"); } GUI.enabled = true; GUILayout.Space(2); if (GUILayout.Button("Other", GUILayout.Width(65))) { sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "Other"); } GUILayout.Space(2); if (GUILayout.Button("ALL", GUILayout.Width(45))) { sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "ALL"); } GUILayout.EndHorizontal(); GUILayout.Space(10); sitesScrollPosition = GUILayout.BeginScrollView(sitesScrollPosition); // ASH 28102014 Category filter handling added if (sites == null) sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "ALL"); foreach (LaunchSite site in sites) { if (isCareerGame()) GUILayout.BeginHorizontal(); // Light icons in the launchsite list only shown in career so only need horizontal for two elements for that mode GUI.enabled = !(selectedSite == site); if (GUILayout.Button(site.name, GUILayout.Height(30))) { selectedSite = site; // ASH Career Mode Unlocking // In career the launchsite is not set by the launchsite list but rather in the launchsite description // panel on the right if (!isCareerGame()) LaunchSiteManager.setLaunchSite(site); } GUI.enabled = true; if (isCareerGame()) { // if site is closed show red light // if site is open show green light // If a site has an open cost of 0 it's always open if (site.openclosestate == "Open" || site.opencost == 0) { site.openclosestate = "Open"; GUILayout.Label(tIconOpen, GUILayout.Height(30), GUILayout.Width(30)); } else { GUILayout.Label(tIconClosed, GUILayout.Height(30), GUILayout.Width(30)); } // Light icons in the launchsite list only shown in career GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); GUILayout.EndArea(); GUI.enabled = true; if (selectedSite != null) { drawRightSelectorWindow(); } else { if (LaunchSiteManager.getLaunchSites().Count > 0) { selectedSite = LaunchSiteManager.getLaunchSites(editorType)[0]; // ASH Career Mode Unlocking // In career the launchsite is not set by the launchsite list but rather in the launchsite description // panel on the right // if (!isCareerGame()) LaunchSiteManager.setLaunchSite(selectedSite); // ASH 05112014 Fixes the selector centering issue on the right panel... probably drawRightSelectorWindow(); } else { Debug.Log("KK: ERROR Launch Selector cannot find KSC Runway or Launch Pad! PANIC! Runaway! Hide!"); } } }
public void setEditorType(SiteType type) { editorType = (KerbalKonstructs.instance.launchFromAnySite) ? SiteType.Any : type; if (selectedSite != null) { if (selectedSite.type != editorType && selectedSite.type != SiteType.Any) { selectedSite = LaunchSiteManager.getLaunchSites(editorType)[0]; } // ASH Career Mode Unlocking // In career the launchsite is not set by the launchsite list but rather in the launchsite description // panel on the right // if (!isCareerGame()) LaunchSiteManager.setLaunchSite(selectedSite); } }
public static void setTargetSite(LaunchSite lsTarget, string sName = "") { lTargetSite = lsTarget; }
public static void setTargetSite(LaunchSite lsTarget) { lTargetSite = lsTarget; }
// Returns the distance in m from a position to a specified Launchsite public static float getDistanceToBase(Vector3 position, LaunchSite lTarget) { float flRange = 0f; List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site == lTarget) { var radialposition = site.GameObject.transform.position; var dist = Vector3.Distance(position, radialposition); flRange = dist; } } return flRange; }
// Returns a specific Launchsite, keyed by site.name public static LaunchSite getLaunchSiteByName(string sSiteName, bool bRemember = false) { if (bRemember) { if (sBaseMem == sSiteName) return launchsitemem; } List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site.name == sSiteName) { if (bRemember) { sBaseMem = sSiteName; launchsitemem = site; } return site; } } return null; }
public void drawBaseManagerWindow(int windowID) { DeadButton = new GUIStyle(GUI.skin.button); DeadButton.normal.background = null; DeadButton.hover.background = null; DeadButton.active.background = null; DeadButton.focused.background = null; DeadButton.normal.textColor = Color.white; DeadButton.hover.textColor = Color.white; DeadButton.active.textColor = Color.white; DeadButton.focused.textColor = Color.white; DeadButton.fontSize = 14; DeadButton.fontStyle = FontStyle.Bold; DeadButtonRed = new GUIStyle(GUI.skin.button); DeadButtonRed.normal.background = null; DeadButtonRed.hover.background = null; DeadButtonRed.active.background = null; DeadButtonRed.focused.background = null; DeadButtonRed.normal.textColor = Color.red; DeadButtonRed.hover.textColor = Color.yellow; DeadButtonRed.active.textColor = Color.red; DeadButtonRed.focused.textColor = Color.red; DeadButtonRed.fontSize = 12; DeadButtonRed.fontStyle = FontStyle.Bold; Yellowtext = new GUIStyle(GUI.skin.box); Yellowtext.normal.textColor = Color.yellow; Yellowtext.normal.background = null; TextAreaNoBorder = new GUIStyle(GUI.skin.textArea); TextAreaNoBorder.normal.background = null; TextAreaNoBorder.normal.textColor = Color.white; TextAreaNoBorder.fontSize = 12; TextAreaNoBorder.padding.left = 1; TextAreaNoBorder.padding.right = 1; TextAreaNoBorder.padding.top = 4; BoxNoBorder = new GUIStyle(GUI.skin.box); BoxNoBorder.normal.background = null; BoxNoBorder.normal.textColor = Color.white; LabelWhite = new GUIStyle(GUI.skin.label); LabelWhite.normal.background = null; LabelWhite.normal.textColor = Color.white; LabelWhite.fontSize = 12; LabelWhite.padding.left = 1; LabelWhite.padding.right = 1; LabelWhite.padding.top = 4; LabelInfo = new GUIStyle(GUI.skin.label); LabelInfo.normal.background = null; LabelInfo.normal.textColor = Color.white; LabelInfo.fontSize = 13; LabelInfo.fontStyle = FontStyle.Bold; LabelInfo.padding.left = 3; LabelInfo.padding.top = 0; LabelInfo.padding.bottom = 0; KKWindowTitle = new GUIStyle(GUI.skin.box); KKWindowTitle.normal.background = null; KKWindowTitle.normal.textColor = Color.white; KKWindowTitle.fontSize = 14; KKWindowTitle.fontStyle = FontStyle.Bold; SmallButton = new GUIStyle(GUI.skin.button); SmallButton.normal.textColor = Color.red; SmallButton.hover.textColor = Color.white; SmallButton.padding.top = 1; SmallButton.padding.left = 1; SmallButton.padding.right = 1; SmallButton.padding.bottom = 4; SmallButton.normal.background = null; SmallButton.hover.background = null; SmallButton.fontSize = 12; if (!loadedPersistence && MiscUtils.isCareerGame()) { PersistenceFile<LaunchSite>.LoadList(LaunchSiteManager.AllLaunchSites, "LAUNCHSITES", "KK"); loadedPersistence = true; } string sButtonName = ""; sButtonName = selectedSite.name; if (selectedSite.name == "Runway") sButtonName = "KSC Runway"; if (selectedSite.name == "LaunchPad") sButtonName = "KSC LaunchPad"; GUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.Button("-KK-", DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUILayout.Button("Base Manager", DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUI.enabled = true; if (HighLogic.LoadedScene != GameScenes.EDITOR) { if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(21))) { InputLockManager.RemoveControlLock("KKEditorLock"); selectedSite = null; loadedPersistence = false; KerbalKonstructs.instance.showBaseManager = false; } } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); if (selectedSite.name == "Runway") GUILayout.Box("KSC Runway", Yellowtext); else if (selectedSite.name == "LaunchPad") GUILayout.Box("KSC LaunchPad", Yellowtext); else GUILayout.Box("" + selectedSite.name, Yellowtext); if (!foldedIn) { GUILayout.Space(5); GUILayout.BeginHorizontal(); { GUILayout.Space(2); GUILayout.Box(tVerticalSep, BoxNoBorder, GUILayout.Width(4), GUILayout.Height(135)); GUILayout.FlexibleSpace(); GUILayout.Box(selectedSite.logo, BoxNoBorder, GUILayout.Height(135), GUILayout.Width(135)); GUILayout.FlexibleSpace(); GUILayout.Box(tVerticalSep, BoxNoBorder, GUILayout.Width(4), GUILayout.Height(135)); GUILayout.Space(2); } GUILayout.EndHorizontal(); GUILayout.Space(3); descriptionScrollPosition = GUILayout.BeginScrollView(descriptionScrollPosition, GUILayout.Height(120)); { GUI.enabled = false; GUILayout.Label(selectedSite.description, LabelWhite); GUI.enabled = true; } GUILayout.EndScrollView(); } GUILayout.Space(1); isFavourite = (selectedSite.favouritesite == "Yes"); GUILayout.BeginHorizontal(); { GUI.enabled = (!displayStats); if(GUILayout.Button("Stats", GUILayout.Height(23))) { displayLog = false; displayStats = true; } GUI.enabled = true; GUI.enabled = (!displayLog); if(GUILayout.Button("Log", GUILayout.Height(23))) { displayLog = true; displayStats = false; } GUI.enabled = true; if (isFavourite) tFaveTemp = tIsFave; else tFaveTemp = tMakeFavourite; if (GUILayout.Button(tFaveTemp, GUILayout.Height(23), GUILayout.Width(23))) { if (isFavourite) selectedSite.favouritesite = "No"; else selectedSite.favouritesite = "Yes"; List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); PersistenceFile<LaunchSite>.SaveList(sites, "LAUNCHSITES", "KK"); } if (foldedIn) tFolded = tFoldOut; if (!foldedIn) tFolded = tFoldIn; if (GUILayout.Button(tFolded, GUILayout.Height(23), GUILayout.Width(23))) { if (foldedIn) foldedIn = false; else foldedIn = true; } } GUILayout.EndHorizontal(); GUILayout.Space(1); if (displayStats) { GUILayout.Label("Altitude: " + selectedSite.refalt.ToString("#0.0") + " m", LabelInfo); GUILayout.Label("Longitude: " + selectedSite.reflon.ToString("#0.000"), LabelInfo); GUILayout.Label("Latitude: " + selectedSite.reflat.ToString("#0.000"), LabelInfo); GUILayout.Space(3); GUILayout.Label("Length: " + selectedSite.sitelength.ToString("#0" + " m"), LabelInfo); GUILayout.Label("Width: " + selectedSite.sitewidth.ToString("#0" + " m"), LabelInfo); GUILayout.Label ("RemoteTech Enabled: " + selectedSite.RTEnabled.ToString ()); GUILayout.FlexibleSpace(); } iFundsOpen = selectedSite.opencost; iFundsClose = selectedSite.closevalue; bool isAlwaysOpen = false; bool cannotBeClosed = false; if (iFundsOpen == 0) isAlwaysOpen = true; if (iFundsClose == 0) cannotBeClosed = true; if (MiscUtils.isCareerGame()) { if (displayStats) { if (!KerbalKonstructs.instance.disableRemoteRecovery) { if (selectedSite.recoveryfactor > 0) { GUILayout.Label("Recovery Factor: " + selectedSite.recoveryfactor.ToString() + "%", LabelInfo); if (selectedSite.name != "Runway" && selectedSite.name != "LaunchPad") { if (selectedSite.recoveryrange > 0) rangekm = selectedSite.recoveryrange / 1000; else rangekm = 0; GUILayout.Label("Effective Range: " + rangekm.ToString() + " km", LabelInfo); } else GUILayout.Label("Effective Range: Unlimited", LabelInfo); } else GUILayout.Label("No Recovery Capability", LabelInfo); } GUILayout.FlexibleSpace(); GUILayout.Label("Launch Refund: " + selectedSite.launchrefund.ToString() + "%", LabelInfo); } if (displayLog) { logScrollPosition = GUILayout.BeginScrollView(logScrollPosition, GUILayout.Height(120)); { GUILayout.Box("Feature is WIP"); GUILayout.Box("Log Entry"); GUILayout.Box("Log Entry"); GUILayout.Box("Log Entry"); } GUILayout.EndScrollView(); GUILayout.FlexibleSpace(); } isOpen = (selectedSite.openclosestate == "Open"); GUI.enabled = !isOpen; List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); if (!isAlwaysOpen) { if (!KerbalKonstructs.instance.disableRemoteBaseOpening) { if (GUILayout.Button("Open Base for \n" + iFundsOpen + " funds", GUILayout.Height(40))) { double currentfunds = Funding.Instance.Funds; if (iFundsOpen > currentfunds) ScreenMessages.PostScreenMessage("Insufficient funds to open this base!", 10, ScreenMessageStyle.LOWER_CENTER); else { selectedSite.OpenLauchsite (); Funding.Instance.AddFunds(-iFundsOpen, TransactionReasons.Cheating); PersistenceFile<LaunchSite>.SaveList(sites, "LAUNCHSITES", "KK"); } } } } GUI.enabled = true; GUI.enabled = isOpen; if (!cannotBeClosed) { if (GUILayout.Button("Close Base for \n" + iFundsClose + " funds", GUILayout.Height(40))) { Funding.Instance.AddFunds(iFundsClose, TransactionReasons.Cheating); selectedSite.CloseLaunchSite (); PersistenceFile<LaunchSite>.SaveList(sites, "LAUNCHSITES", "KK"); } } GUI.enabled = true; GUILayout.FlexibleSpace(); if (HighLogic.LoadedScene == GameScenes.EDITOR) { GUILayout.BeginHorizontal(); { if (selectedSite.name == EditorLogic.fetch.launchSiteName) tStatusLaunchsite = tSetLaunchsite; else if (isOpen || isAlwaysOpen) tStatusLaunchsite = tOpenedLaunchsite; else tStatusLaunchsite = tClosedLaunchsite; GUILayout.Label(tStatusLaunchsite, GUILayout.Height(32), GUILayout.Width(32)); GUI.enabled = (isOpen || isAlwaysOpen) && !(selectedSite.name == EditorLogic.fetch.launchSiteName); if (GUILayout.Button("Set as \nLaunchsite", GUILayout.Height(40))) { LaunchSiteManager.setLaunchSite(selectedSite); string smessage = sButtonName + " has been set as the launchsite"; ScreenMessages.PostScreenMessage(smessage, 10, 0); } GUI.enabled = true; } GUILayout.EndHorizontal(); } } GUILayout.Space(3); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(1); GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }
// Returns the nearest open Launchsite to a position and range to the Launchsite in m // The basic ATC feature is in here for now public static void getNearestOpenBase(Vector3 position, out string sBase, out float flRange, out LaunchSite lNearest) { SpaceCenter KSC = SpaceCenter.Instance; var smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); string sNearestBase = ""; string sOpenCloseState = ""; LaunchSite lNearestBase = null; LaunchSite lKSC = null; List<LaunchSite> basesites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in basesites) { sOpenCloseState = site.openclosestate; if (!MiscUtils.isCareerGame()) sOpenCloseState = "Open"; if (sOpenCloseState == "Open") { var radialposition = site.GameObject.transform.position; var dist = Vector3.Distance(position, radialposition); if (site.name == "Runway") { if (lNearestBase == null) lNearestBase = site; lKSC = site; } else if (site.name != "LaunchPad") { if ((float)dist < (float)smallestDist) { { sNearestBase = site.name; lNearestBase = site; smallestDist = dist; } } } else { lKSC = site; } } } if (sNearestBase == "") { sNearestBase = "KSC"; lNearestBase = lKSC; } RangeNearestOpenBase = (float)smallestDist; // Air traffic control messaging if (KerbalKonstructs.instance.enableATC) { if (sNearestBase != NearestOpenBase) { if (RangeNearestOpenBase < 25000) { NearestOpenBase = sNearestBase; MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.BLUE; MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You have entered the airspace of " + sNearestBase + " ATC. Please keep this channel open and obey all signal lights. Thank you. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE); MessageSystem.Instance.AddMessage(m); } else if (NearestOpenBase != "") { // you have left ... MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.GREEN; MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You are now leaving the airspace of " + sNearestBase + ". Safe journey. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE); MessageSystem.Instance.AddMessage(m); NearestOpenBase = ""; } } } sBase = sNearestBase; flRange = RangeNearestOpenBase; lNearest = lNearestBase; }
public static void setSelectedSite(LaunchSite soSite) { selectedSite = soSite; }
public void drawIcons() { displayingTooltip = false; MapObject target = PlanetariumCamera.fetch.target; if (target.type == MapObject.MapObjectType.CELESTIALBODY) { List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name); if (facility != null) { PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name); if (sp != null) { if (facility.facilityPQS == target.celestialBody.pqsController) { if (!isOccluded(sp.GetSpawnPointTransform().position, target.celestialBody)) { Vector3 pos = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(sp.GetSpawnPointTransform().position)); Rect screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16); bool display = false; string openclosed = site.openclosestate; string category = site.category; if (showHelipads && category == "Helipad") display = true; if (showOther && category == "Other") display = true; if (showRocketPads && category == "RocketPad") display = true; if (showRunways && category == "Runway") display = true; if (display && isCareerGame()) { if (!showOpen && openclosed == "Open") display = false; if (!showClosed && openclosed == "Closed") display = false; } if (display) { if (site.icon != null) { Graphics.DrawTexture(screenRect, site.icon); } else { switch (site.type) { case SiteType.VAB: Graphics.DrawTexture(screenRect, VABIcon); break; case SiteType.SPH: Graphics.DrawTexture(screenRect, SPHIcon); break; default: Graphics.DrawTexture(screenRect, ANYIcon); break; } } //"Borrowed" from FinePrint //https://github.com/Arsonide/FinePrint/blob/master/Source/WaypointManager.cs#L53 if (screenRect.Contains(Event.current.mousePosition) && !displayingTooltip) { //Only display one tooltip at a time displayingTooltip = true; GUI.Label(new Rect((float)(pos.x) + 16, (float)(Screen.height - pos.y) - 8, 200, 20), site.name); if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { ScreenMessages.PostScreenMessage("Selected base is " + site.name + ".", 5f, ScreenMessageStyle.LOWER_CENTER); selectedSite = site; EditorGUI.setTargetSite(site); if (HighLogic.LoadedSceneIsFlight) { } } } } } } } } } } }
public void drawLaunchsites(MapObject target) { displayingTooltip = false; int iPulseRate = 180; iRadarCounter = iRadarCounter + 1; if (iRadarCounter > iPulseRate) iRadarCounter = 0; // Then do launchsites List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name); if (facility == null) continue; PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name); if (sp == null) continue; if (facility.facilityPQS != target.celestialBody.pqsController) continue; if (isOccluded(sp.GetSpawnPointTransform().position, target.celestialBody)) { if (KerbalKonstructs.instance.mapHideIconsBehindBody) continue; } Vector3 pos = MapView.MapCamera.GetComponent<Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(sp.GetSpawnPointTransform().position)); Rect screenRect = 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; float fRadarOffset = fRadarRadius / 2; string openclosed = site.openclosestate; string category = site.category; bool display = true; if (!KerbalKonstructs.instance.mapShowHelipads && category == "Helipad") display = false; if (!KerbalKonstructs.instance.mapShowOther && category == "Other") display = false; if (!KerbalKonstructs.instance.mapShowRocketbases && category == "RocketPad") display = false; if (!KerbalKonstructs.instance.mapShowRunways && category == "Runway") display = false; if (display && MiscUtils.isCareerGame()) { if (!KerbalKonstructs.instance.mapShowOpen && openclosed == "Open") display = false; if (!KerbalKonstructs.instance.mapShowClosed && openclosed == "Closed") display = false; if (KerbalKonstructs.instance.disableDisplayClosed && openclosed == "Closed") display = false; if (openclosed == "OpenLocked" || openclosed == "ClosedLocked") display = false; } if (!display) continue; if (KerbalKonstructs.instance.mapShowRadar) drawRadar(pos, category, openclosed); if (openclosed == "Open" && KerbalKonstructs.instance.mapShowGroundComms) { drawGroundComms(null, site); } if (site.icon != null) { if (fRadarRadius > 15) Graphics.DrawTexture(screenRect, site.icon); } else { if (fRadarRadius > 15) { switch (site.type) { case SiteType.VAB: Graphics.DrawTexture(screenRect, UIMain.VABIcon); break; case SiteType.SPH: Graphics.DrawTexture(screenRect, UIMain.SPHIcon); break; default: Graphics.DrawTexture(screenRect, UIMain.ANYIcon); break; } } } // Tooltip if (screenRect.Contains(Event.current.mousePosition) && !displayingTooltip) { //Only display one tooltip at a time string sToolTip = ""; sToolTip = site.name; if (site.name == "Runway") sToolTip = "KSC Runway"; if (site.name == "LaunchPad") sToolTip = "KSC LaunchPad"; displayMapIconToolTip(sToolTip, pos); // Select a base by clicking on the icon if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3); BaseManager.setSelectedSite(site); selectedSite = site; NavGuidanceSystem.setTargetSite(selectedSite); KerbalKonstructs.instance.showBaseManager = true; } } } }
// Get the nearest open base and range to it public static void getNearestOpenBase(Vector3 position, out string sBase, out float flRange, out LaunchSite lNearest) { SpaceCenter KSC = SpaceCenter.Instance; var smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); string sNearestBase = ""; string sOpenCloseState = ""; LaunchSite lNearestBase = null; LaunchSite lKSC = null; List <LaunchSite> basesites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in basesites) { sOpenCloseState = site.openclosestate; if (!MiscUtils.isCareerGame()) { sOpenCloseState = "Open"; } //if (site.recoveryfactor == 0) continue; if (sOpenCloseState == "Open") { var radialposition = site.GameObject.transform.position; var dist = Vector3.Distance(position, radialposition); if (site.name == "Runway") { if (lNearestBase == null) { lNearestBase = site; } lKSC = site; } else if (site.name != "LaunchPad") { if ((float)dist < (float)smallestDist) { { sNearestBase = site.name; lNearestBase = site; smallestDist = dist; } } } else { lKSC = site; } } } if (sNearestBase == "") { sNearestBase = "KSC"; lNearestBase = lKSC; } RangeNearestOpenBase = (float)smallestDist; // Air traffic control messaging if (KerbalKonstructs.instance.enableATC) { if (sNearestBase != NearestOpenBase) { if (RangeNearestOpenBase < 25000) { NearestOpenBase = sNearestBase; MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.BLUE; MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You have entered the airspace of " + sNearestBase + " ATC. Please keep this channel open and obey all signal lights. Thank you. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE); MessageSystem.Instance.AddMessage(m); } else if (NearestOpenBase != "") { // you have left ... MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.GREEN; MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You are now leaving the airspace of " + sNearestBase + ". Safe journey. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE); MessageSystem.Instance.AddMessage(m); NearestOpenBase = ""; } } } sBase = sNearestBase; flRange = RangeNearestOpenBase; lNearest = lNearestBase; }
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(); } }
public static void setLaunchSite(LaunchSite site) { // Debug.Log("KK: EditorLogic.fetch.launchSiteName set to " + site.name); //Trick KSP to think that you launched from Runway or LaunchPad //I'm sure Squad will break this in the future //This only works because they use multiple variables to store the same value, basically its black magic. //--medsouz if (site.facility != null) { if (EditorDriver.editorFacility.Equals(EditorFacility.SPH)) { site.facility.name = "Runway"; } else { site.facility.name = "LaunchPad"; } } EditorLogic.fetch.launchSiteName = site.name; }
public static void setTargetSite(LaunchSite lsTarget, string sName = "") { lTargetSite = lsTarget; /* if (sName != "") sOtherName = sName; else sOtherName = ""; */ }