/******************************************************************************************** * Function Name: drawDestiationGUI * Parameters: void * Return: void * * Description: Draw GPS GUI's Destination window * *********************************************************************************************/ //static bool styleInitted = false; private void drawDestinationGUI() { #if false GUIStyle varTextStyle = new GUIStyle(GUI.skin.textField); GUIStyle varHemisphereStyle = new GUIStyle(GUI.skin.textField); GUIStyle varLabelStyle = new GUIStyle(GUI.skin.label); #endif #if false if (!styleInitted) { styleInitted = true; varTextStyle.alignment = TextAnchor.UpperCenter; varTextStyle.normal.textColor = varTextStyle.focused.textColor = Color.white; varTextStyle.hover.textColor = varTextStyle.active.textColor = Color.yellow; varTextStyle.padding = new RectOffset(0, 0, 0, 0); varTextStyle.fixedHeight = 16.0f; varTextStyle.fixedWidth = 35.0f; varHemisphereStyle.alignment = TextAnchor.UpperCenter; varHemisphereStyle.normal.textColor = varHemisphereStyle.focused.textColor = Color.white; varHemisphereStyle.hover.textColor = varHemisphereStyle.active.textColor = Color.yellow; varHemisphereStyle.padding = new RectOffset(0, 0, 0, 0); varHemisphereStyle.fixedHeight = 16.0f; varHemisphereStyle.fixedWidth = 20.0f; varLabelStyle.padding = new RectOffset(0, 0, 0, 7); } #endif GUILayout.Label("Distance: " + gsDistance); GUILayout.Label("Heading: " + gsHeading); GUILayout.BeginVertical(GUILayout.MaxHeight(20.0f)); GUILayout.BeginHorizontal(GUILayout.MinWidth(GPS_GUI_WIDTH - 5.0f)); GUILayout.Label("Lat:", varLabelStyle); GUILayout.FlexibleSpace(); gsLatDeg = GUILayout.TextArea(gsLatDeg, 3, varTextStyle); GUILayout.Label("°", varLabelStyle); gsLatMin = GUILayout.TextArea(gsLatMin, 4, varTextStyle); GUILayout.Label("'", varLabelStyle); if (!HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLatSec = GUILayout.TextArea(gsLatSec, 4, varTextStyle); GUILayout.Label("\"", varLabelStyle); } //gsLatNS = GUILayout.TextArea(gsLatNS, 1, varHemisphereStyle); if (GUILayout.Button(gsLatNS, varButtonStyle, GUILayout.Width(24))) { if (gsLatNS == "N") { gsLatNS = "S"; } else { gsLatNS = "N"; } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.MaxHeight(20.0f)); GUILayout.BeginHorizontal(GUILayout.MinWidth(GPS_GUI_WIDTH - 5.0f)); GUILayout.Label("Lon:", varLabelStyle); GUILayout.FlexibleSpace(); gsLonDeg = GUILayout.TextArea(gsLonDeg, 3, varTextStyle); GUILayout.Label("°", varLabelStyle); gsLonMin = GUILayout.TextArea(gsLonMin, 4, varTextStyle); GUILayout.Label("'", varLabelStyle); if (!HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLonSec = GUILayout.TextArea(gsLonSec, 4, varTextStyle); GUILayout.Label("\"", varLabelStyle); } //gsLonEW = GUILayout.TextArea(gsLonEW, 1, varHemisphereStyle); if (GUILayout.Button(gsLonEW, varButtonStyle, GUILayout.Width(24))) { if (gsLonEW == "W") { gsLonEW = "E"; } else { gsLonEW = "W"; } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); if ((gsLatDeg.Length != 0) && (gsLatMin.Length > 2) && (gsLatNS.Length != 0) && (gsLonDeg.Length != 0) && (gsLonMin.Length > 2) && (gsLonEW.Length != 0)) { gfDestLat = ParseNS() * (ParseNumericString(gsLatDeg) + ParseNumericString(gsLatMin) / 60.0f + ParseNumericString(gsLatSec) / 3600.0f); gfDestLon = ParseEW() * (ParseNumericString(gsLonDeg) + ParseNumericString(gsLonMin) / 60.0f + ParseNumericString(gsLonSec) / 3600.0f); if (gfDestLat > 90) { gfDestLat = 90.0f; } if (gfDestLat < -90) { gfDestLat = -90.0f; } if (gfDestLon > 180) { gfDestLon = 180.0f; } if (gfDestLon < -180) { gfDestLon = -180.0f; } gsLatDeg = Math.Floor(Math.Abs(gfDestLat)).ToString(); double min = (Math.Abs(gfDestLat) - Math.Floor(Math.Abs(gfDestLat))) * 60.0f; if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLatMin = min.ToString("#0.0"); } else { gsLatMin = Math.Floor(min).ToString(); double sec = min - Math.Floor(min); gsLatSec = sec.ToString("#0.0"); } gsLonDeg = Math.Floor(Math.Abs(gfDestLon)).ToString(); min = (Math.Abs(gfDestLon) - Math.Floor(Math.Abs(gfDestLon))) * 60.0f; if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLonMin = min.ToString("#0.0"); } else { gsLonMin = Math.Floor(min).ToString(); double sec = min - Math.Floor(min); gsLonSec = sec.ToString("#0.0"); } } else { if ((gsLatDeg.Length == 0) || (gsLatNS.Length == 0) || (gsLonDeg.Length == 0) || (gsLonEW.Length == 0)) { if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { if (gsLatMin.StartsWith(".")) { gsLatMin = "0" + gsLatMin; } if (gsLonMin.StartsWith(".")) { gsLonMin = "0" + gsLonMin; } if (gsLatMin.Length <= 2) { gsLatMin = gsLatMin + ".0"; } if (gsLonMin.Length <= 2) { gsLonMin = gsLonMin + ".0"; } } else { if (gsLatSec.StartsWith(".")) { gsLatSec = "0" + gsLatSec; } if (gsLonSec.StartsWith(".")) { gsLonSec = "0" + gsLonSec; } if (gsLatSec.Length <= 2) { gsLatSec = gsLatSec + ".0"; } if (gsLonSec.Length <= 2) { gsLonSec = gsLonSec + ".0"; } } } } if (GUILayout.Button("Set Destination Here", varButtonStyle)) { gsLatDeg = Math.Floor(Math.Abs(gfOrigLat)).ToString(); double min = (Math.Abs(gfOrigLat) - Math.Floor(Math.Abs(gfOrigLat))) * 60.0f; if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLatMin = min.ToString("#0.0"); } else { gsLatMin = Math.Floor(min).ToString(); double sec = min - Math.Floor(min); gsLatSec = sec.ToString("#0.0"); } if (gfOrigLon > 180.0f) { gfOrigLon -= 360.0f; } if (gfOrigLon < -180.0f) { gfOrigLon += 360.0f; } gsLonDeg = Math.Floor(Math.Abs(gfOrigLon)).ToString(); min = (Math.Abs(gfOrigLon) - Math.Floor(Math.Abs(gfOrigLon))) * 60.0f; if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLonMin = min.ToString("#0.0"); } else { gsLonMin = Math.Floor(min).ToString(); double sec = min - Math.Floor(min); gsLonSec = sec.ToString("#0.0"); } gsDestName = NONAME; } GUILayout.BeginHorizontal(); GUILayout.Label("Dest. name:"); gsDestName = GUILayout.TextField(gsDestName, GUILayout.Width(GPS_GUI_WIDTH / 2)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (gsDestName == NONAME) { GUI.enabled = false; } if (GUILayout.Button("Save", varButtonStyle)) { FileIO.GPS_Coordinates coordinates = new FileIO.GPS_Coordinates(gsDestName, gfDestLat, gfDestLon); if (FileIO.gdDestinations.ContainsKey(gsDestName)) { FileIO.gdDestinations[gsDestName].fDestLat = gfDestLat; FileIO.gdDestinations[gsDestName].fDestLon = gfDestLon; } else { FileIO.gdDestinations.Add(gsDestName, coordinates); } Log.Info("Save, x: " + KerbalGPS.Instance.varWindowPos.x + ", y: " + KerbalGPS.Instance.varWindowPos.y); Log.Info("Save, x: " + varWindowPos.x + ", y: " + varWindowPos.y); FileIO.SaveData(this); } GUI.enabled = true; if (GUILayout.Button("Load", varButtonStyle)) { loadDestination = true; } GUILayout.EndHorizontal(); }
private void DestWindowGUI(int windowID) { GUILayout.BeginVertical(); displayScrollVector = GUILayout.BeginScrollView(displayScrollVector); foreach (var entry in FileIO.gdDestinations) { if (entry.Value.sCelestialBodyName == FlightGlobals.ActiveVessel.mainBody.name) { GUILayout.BeginHorizontal(); b = (selectedCoordinate != null && selectedCoordinate.sDestName == entry.Key); if (GUILayout.Toggle(b, entry.Key)) { selectedCoordinate = entry.Value; } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); if (selectedCoordinate != null) { gsDestName = selectedCoordinate.sDestName; gfDestLat = selectedCoordinate.fDestLat; gfDestLon = selectedCoordinate.fDestLon; gsLatDeg = Math.Floor(Math.Abs(gfDestLat)).ToString(); double min = (Math.Abs(gfDestLat) - Math.Floor(Math.Abs(gfDestLat))) * 60.0f; if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLatMin = ((Math.Abs(gfDestLat) - Math.Floor(Math.Abs(gfDestLat))) * 60.0f).ToString("#0.0"); } else { gsLatMin = Math.Floor(min).ToString(); double sec = min - Math.Floor(min); gsLatSec = sec.ToString("#0.0"); } gsLonDeg = Math.Floor(Math.Abs(gfDestLon)).ToString(); min = (Math.Abs(gfDestLon) - Math.Floor(Math.Abs(gfDestLon))) * 60.0f; if (HighLogic.CurrentGame.Parameters.CustomParams <KerbalGPSSettings>().useDecimalMinutes) { gsLonMin = ((Math.Abs(gfDestLon) - Math.Floor(Math.Abs(gfDestLon))) * 60.0f).ToString("#0.0"); } else { gsLonMin = Math.Floor(min).ToString(); double sec = min - Math.Floor(min); gsLonSec = sec.ToString("#0.0"); } // loadDestination = false; } if (GUILayout.Button("Delete")) { FileIO.gdDestinations.Remove(selectedCoordinate.sDestName); FileIO.SaveData(this); } if (GUILayout.Button("Close")) { loadDestination = false; FileIO.SaveData(this); } GUILayout.EndVertical(); GUI.DragWindow(); }