Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to display Waypoint Coordinates. #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified GameData/WaypointManager/WaypointManager.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion source/WaypointManager/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum WaypointDisplay
public static bool hudTime = true;
public static bool hudHeading = false;
public static bool hudAngle = false;
public static bool hudCoordinates = false;

public static bool useStockToolbar = true;

Expand Down Expand Up @@ -80,7 +81,7 @@ public static void Save()
configNode.AddValue("hudAngle", hudAngle);
configNode.AddValue("useStockToolbar", useStockToolbar);
configNode.AddValue("opacity", opacity);

configNode.AddValue("hudCoordinates", hudCoordinates);
configNode.Save(ConfigFileName,
"Waypoint Manager Configuration File\r\n" +
"//\r\n" +
Expand Down Expand Up @@ -111,6 +112,7 @@ public static void Load()
hudDistance = Convert.ToBoolean(configNode.GetValue("hudDistance"));
hudTime = Convert.ToBoolean(configNode.GetValue("hudTime"));
hudHeading = Convert.ToBoolean(configNode.GetValue("hudHeading"));
hudCoordinates = Convert.ToBoolean(configNode.GetValue("hudCoordinates"));
hudAngle = configNode.HasValue("hudAngle") ? Convert.ToBoolean(configNode.GetValue("hudAngle")) : false;
opacity = configNode.HasValue("opacity") ? (float)Convert.ToDouble(configNode.GetValue("opacity")) : 1.0f;
if (configNode.HasValue("useStockToolbar"))
Expand Down
18 changes: 18 additions & 0 deletions source/WaypointManager/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,23 @@ public static void DrawWaypoint(CelestialBody targetBody, double latitude, doubl
Graphics.DrawTexture(iconRect, ContractDefs.textures[id], new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, SystemUtilities.RandomColor(seed, alpha));
}

/// <summary>
/// Converts decimal degrees to a string of DMS formatted degrees with N/S, E/W prefix
/// </summary>
/// <param name="decimalDegrees"></param>
/// <param name="latitude">boolean to determin latitude or longitude for compass prefix</param>
/// <returns></returns>
public static string DecimalDegreesToDMS(double decimalDegrees, bool latitude)
{
string dms = string.Empty;
string direction = latitude ? (decimalDegrees >= 0 ? "N" : "S") : (decimalDegrees >= 0 ? "E" : "W");
decimalDegrees = Math.Abs(decimalDegrees);
int d =(int)(decimalDegrees);
double decimalpart = decimalDegrees - d;
int m = (int)(decimalpart * 60);
double s = (decimalpart - m / 60f) * 3600;
dms = string.Format("{3} {0}\x00B0 {1}\' {2:F1}\"", d, m, s, direction);
return dms;
}
}
}
8 changes: 8 additions & 0 deletions source/WaypointManager/WaypointFlightRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ protected void DrawWaypoint(WaypointData wpd)
ybase += 18f;
}
}
if(Config.hudCoordinates&&v.mainBody==wpd.celestialBody)
{
ybase += 9;
GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 38f), "Coordinates of " + label + ":", nameStyle);
GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 38f),
v.state != Vessel.State.DEAD ? string.Format("{0}\r\n{1}", Util.DecimalDegreesToDMS(wpd.waypoint.latitude,true), Util.DecimalDegreesToDMS(wpd.waypoint.longitude,false)) : "N/A", valueStyle);
ybase += 18f;
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions source/WaypointManager/WaypointManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ protected void SettingsGUI(int windowID)
{
Config.hudAngle = !Config.hudAngle;
}
if (GUILayout.Toggle(Config.hudCoordinates, "Coordinates of target")!=Config.hudCoordinates)
{
Config.hudCoordinates = !Config.hudCoordinates;
}

// Toolbar
GUILayout.Label("Toolbar Display", headingStyle);
Expand Down