Skip to content
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
1 change: 0 additions & 1 deletion RasterPropMonitor/Handlers/JSIOrbitDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ private static void DrawOrbitSegment(
double midTA = (startTA + endTA) / 2.0;
Vector3 midVertex = ScreenPositionFromOrbitAtTA(o, referenceBody, screenTransform, midTA, now);
Vector3 midStraight = (startVertex + endVertex) * 0.5f;
// Debug.Log($"startTA: {startTA}, endTA: {endTA}, startVertex: {startVertex}, endVertex: {endVertex}, midVertex: {midVertex}, midStraight: {midStraight}");

if (Math.Abs(startTA - endTA) < 0.01 || (midStraight - midVertex).sqrMagnitude < 16.0)
{
Expand Down
71 changes: 39 additions & 32 deletions RasterPropMonitor/Handlers/JSIPrimaryFlightDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
****************************************************************************/
using UnityEngine;
using System;
using KSP.UI.Screens.Flight;
using FinePrint;

namespace JSI
{
Expand Down Expand Up @@ -291,37 +291,8 @@ public bool RenderPFD(RenderTexture screen, float aspect)
markerManeuverMinus.visible = true;
}

/*
if (FinePrint.WaypointManager.navIsActive() == true)
{
// MOARdV: Code for the waypoint marker based on https://github.com/Ninenium/NavHud/blob/master/Source/WaypointMarker.cs
// However, in 1.1.2 (maybe earlier), the NavBall gameobject doesn't have children.
// And in 1.1.3, FinePrint.WaypointManager .navIsActive and .navWaypoint no longer exist...
try
{
GameObject navWaypointIndicator = GameObject.Find("NavBall").transform.FindChild("vectorsPivot").FindChild("NavWaypoint").gameObject;
Renderer markerRenderer = null;
markerNavWaypoint.GetComponentCached<Renderer>(ref markerRenderer);
Material material = navWaypointIndicator.GetComponent<Renderer>().sharedMaterial;
markerRenderer.material.mainTexture = material.mainTexture;
markerRenderer.material.mainTextureScale = Vector2.one;
markerRenderer.material.mainTextureOffset = Vector2.zero;
if (string.IsNullOrEmpty(waypointColor))
{
markerRenderer.material.SetVector("_Color", material.GetVector("_Color"));
}
DrawWaypoint(gymbal);

Vector3d waypointPosition = vessel.mainBody.GetWorldSurfacePosition(FinePrint.WaypointManager.navWaypoint.latitude, FinePrint.WaypointManager.navWaypoint.longitude, FinePrint.WaypointManager.navWaypoint.altitude);
Vector3 waypointDirection = (waypointPosition - vessel.CoM).normalized;
MoveMarker(markerNavWaypoint, waypointDirection, gymbal);
JUtil.ShowHide(true, markerNavWaypoint);
}
catch
{
// if something's borked, let's just silently do nothing
}
}
*/
ITargetable target = FlightGlobals.fetch.VesselTarget;
if (target != null)
{
Expand Down Expand Up @@ -469,6 +440,42 @@ private static void DrawMarker(Marker marker)
}
}

private void DrawWaypoint(Quaternion gymbal)
{
NavWaypoint waypoint = NavWaypoint.fetch;
if (waypoint == null || !waypoint.IsActive)
{
return;
}

if (waypoint.IsBlinking && Planetarium.GetUniversalTime() % 1.0 > 0.5)
{
return;
}

try
{
Material material = waypoint.Visual.GetComponent<Renderer>().sharedMaterial;
markerNavWaypoint.gameObject.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
markerNavWaypoint.material.mainTexture = material.GetTexture("_MainTexture");
markerNavWaypoint.material.mainTextureScale = Vector2.one;
markerNavWaypoint.material.mainTextureOffset = Vector2.zero;
if (string.IsNullOrEmpty(waypointColor))
{
markerNavWaypoint.material.SetVector("_Color", material.GetVector("_TintColor"));
}
}
catch (Exception e)
{
Debug.Log($"Waypoint material failure: {e}");
}

Vector3d waypointPosition = waypoint.Body.GetWorldSurfacePosition(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
Vector3 waypointDirection = (waypointPosition - vessel.CoM).normalized;
MoveMarker(markerNavWaypoint, waypointDirection, gymbal);
markerNavWaypoint.visible = true;
}

public void Start()
{
if (HighLogic.LoadedSceneIsEditor)
Expand Down Expand Up @@ -542,7 +549,7 @@ public void Start()
}

navBall.GetComponent<Renderer>().material.SetFloat("_Opacity", ballOpacity);

navBall.SetActive(false);

startupComplete = true;
Expand Down
119 changes: 103 additions & 16 deletions RasterPropMonitor/Handlers/JSITargetMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using FinePrint;
using UnityEngine;

namespace JSI
Expand Down Expand Up @@ -73,6 +74,7 @@ public class JSITargetMenu : InternalModule
private readonly TextMenu topMenu = new TextMenu();
private TextMenu activeMenu;
private TextMenu.Item clearTarget;
private TextMenu.Item clearWaypoint;
private TextMenu.Item removeNode;
private TextMenu.Item undockMenuItem;
private TextMenu.Item grappleMenuItem;
Expand All @@ -85,15 +87,18 @@ public class JSITargetMenu : InternalModule
private const string armGrappleText = "Arm Grapple";
private const string crewEvaText = "Crew EVA";
private const string removeNodeItemText = "Remove Node";
private const string clearWaypointText = "Clear Waypoint";
private readonly List<string> rootMenu = new List<string> {
"Celestials",
"Vessels",
"Space Objects",
"Reference part",
"Waypoints",
undockItemText,
armGrappleText,
"Filters",
clearTargetItemText,
clearWaypointText,
crewEvaText,
removeNodeItemText,
};
Expand Down Expand Up @@ -125,6 +130,7 @@ private enum MenuList
Undock,
Filters,
CrewEVA,
Waypoints
};

private enum SortMode
Expand All @@ -144,6 +150,7 @@ private enum SortMode
private readonly List<PartModule> undockablesList = new List<PartModule>();
private List<ModuleDockingNode> portsList = new List<ModuleDockingNode>();
private readonly List<PartModule> referencePoints = new List<PartModule>();
private readonly List<(Waypoint, double)> waypointsList = new List<(Waypoint, double)>();
private readonly List<uint> unavailablePorts = new List<uint>();
private int partCount;
private SortMode sortMode;
Expand Down Expand Up @@ -195,10 +202,12 @@ public string ShowMenu(int width, int height)
activeMenu.menuTitle = string.Format(fp, menuTitleFormatString, "Decouple ports");
break;
case MenuList.Root:
NavWaypoint waypoint = NavWaypoint.fetch;
activeMenu.menuTitle = MakeMenuTitle("Root menu");
grappleMenuItem.isDisabled = UpdateReferencePartAsClaw();
clearTarget.isDisabled = (currentTarget == null);
undockMenuItem.isDisabled = (undockablesList.Count == 0);
clearTarget.isDisabled = currentTarget == null;
clearWaypoint.isDisabled = waypoint != null && waypoint.IsActive;
undockMenuItem.isDisabled = undockablesList.Count == 0;
removeNode.isDisabled = vessel.patchedConicSolver == null || vessel.patchedConicSolver.maneuverNodes.Count == 0;
break;
case MenuList.Filters:
Expand All @@ -216,6 +225,9 @@ public string ShowMenu(int width, int height)
case MenuList.Reference:
activeMenu.menuTitle = string.Format(fp, menuTitleFormatString, "Select reference");
break;
case MenuList.Waypoints:
activeMenu.menuTitle = MakeMenuTitle("Waypoints");
break;
case MenuList.Ports:
// sanity check:
if (selectedVessel == null || !selectedVessel.loaded || portsList.Count == 0)
Expand Down Expand Up @@ -422,7 +434,6 @@ private void UpdateUndockablesList()

private void UpdateLists()
{

switch (currentMenu)
{
case MenuList.Undock:
Expand Down Expand Up @@ -460,7 +471,6 @@ private void UpdateLists()
foreach (Celestial body in celestialsList)
body.UpdateDistance(vessel.transform.position);

CelestialBody currentBody = celestialsList[activeMenu.GetCurrentIndex()].body;
switch (sortMode)
{
case SortMode.Alphabetic:
Expand Down Expand Up @@ -516,6 +526,36 @@ private void UpdateLists()
activeMenu.Add(tmi);
}
break;
case MenuList.Waypoints:
waypointsList.Clear();
foreach (Waypoint waypoint in WaypointManager.Instance().Waypoints)
{
if (waypoint.celestialBody == vessel.mainBody)
{
waypointsList.Add((waypoint, WaypointDistance(waypoint, vessel)));
}
}

if (sortMode == SortMode.Alphabetic)
{
waypointsList.Sort((a, b) => a.Item1.name.CompareTo(b.Item1.name));
}
else if (sortMode == SortMode.Distance)
{
waypointsList.Sort((a, b) => a.Item2.CompareTo(b.Item2));
}

activeMenu.Clear();
foreach ((Waypoint waypoint, double distance) in waypointsList)
{
TextMenu.Item tmi = new TextMenu.Item();
tmi.action = SelectWaypoint;
tmi.labelText = waypoint.name;
tmi.rightText = string.Format(fp, distanceFormatString.UnMangleConfigText(), distance);
tmi.isSelected = vessel.navigationWaypoint == waypoint;
activeMenu.Add(tmi);
}
break;
case MenuList.Vessels:
vesselsList.Clear();
foreach (Vessel thatVessel in FlightGlobals.fetch.vessels)
Expand Down Expand Up @@ -625,7 +665,6 @@ private void UpdateLists()
}
break;
}

}

private static string GetPortName(ModuleDockingNode port)
Expand Down Expand Up @@ -728,17 +767,21 @@ public void Start()
FindReferencePoints();
UpdateUndockablesList();

var menuActions = new List<Action<int, TextMenu.Item>>();
menuActions.Add(ShowCelestialMenu);
menuActions.Add(ShowVesselMenu);
menuActions.Add(ShowSpaceObjectMenu);
menuActions.Add(ShowReferenceMenu);
menuActions.Add(ShowUndockMenu);
menuActions.Add(ArmGrapple);
menuActions.Add(ShowFiltersMenu);
menuActions.Add(ClearTarget);
menuActions.Add(ShowCrewEVA);
menuActions.Add(RemoveNode);
var menuActions = new List<Action<int, TextMenu.Item>>
{
ShowCelestialMenu,
ShowVesselMenu,
ShowSpaceObjectMenu,
ShowReferenceMenu,
ShowWaypointsMenu,
ShowUndockMenu,
ArmGrapple,
ShowFiltersMenu,
ClearTarget,
ClearWaypoint,
ShowCrewEVA,
RemoveNode
};

for (int i = 0; i < rootMenu.Count; ++i)
{
Expand All @@ -751,6 +794,9 @@ public void Start()
case clearTargetItemText:
clearTarget = topMenu[i];
break;
case clearWaypointText:
clearWaypoint = topMenu[i];
break;
case undockItemText:
undockMenuItem = topMenu[i];
break;
Expand Down Expand Up @@ -946,6 +992,22 @@ private void ShowReferenceMenu(int index, TextMenu.Item ti)
activeMenu.currentSelection = referencePoints.FindIndex(x => x.part == vessel.GetReferenceTransformPart());
}

private void ShowWaypointsMenu(int index, TextMenu.Item ti)
{
currentMenu = MenuList.Waypoints;

activeMenu = new TextMenu();
activeMenu.rightColumnWidth = distanceColumnWidth;
activeMenu.labelColor = nameColorTag;
activeMenu.selectedColor = selectedColorTag;
activeMenu.disabledColor = unavailableColorTag;
activeMenu.rightTextColor = distanceColorTag;

UpdateLists();

activeMenu.currentSelection = waypointsList.FindIndex(waypoint => waypoint.Item1 == vessel.navigationWaypoint);
}

private void ShowUndockMenu(int index, TextMenu.Item ti)
{
currentMenu = MenuList.Undock;
Expand Down Expand Up @@ -1012,6 +1074,13 @@ private static void ClearTarget(int index, TextMenu.Item ti)
FlightGlobals.fetch.SetVesselTarget((ITargetable)null);
}

private static void ClearWaypoint(int index, TextMenu.Item ti)
{
NavWaypoint navWaypoint = NavWaypoint.fetch;
navWaypoint.Clear();
navWaypoint.Deactivate();
}

private void RemoveNode(int index, TextMenu.Item ti)
{
if (vessel.patchedConicSolver != null && vessel.patchedConicSolver.maneuverNodes.Count > 0)
Expand Down Expand Up @@ -1100,6 +1169,18 @@ private void TargetVessel(int index, TextMenu.Item ti)
activeMenu.SetSelected(index, true);
}
}

private void SelectWaypoint(int index, TextMenu.Item ti)
{
NavWaypoint navWaypoint = NavWaypoint.fetch;
navWaypoint.Clear();
navWaypoint.Deactivate();
navWaypoint.Setup(waypointsList[index].Item1);
navWaypoint.Activate();

activeMenu.SetSelected(index, true);
}

// Space Object Menu
private void TargetSpaceObject(int index, TextMenu.Item ti)
{
Expand Down Expand Up @@ -1228,6 +1309,12 @@ private static IEnumerable<PartModule> GetUndockableNodes(List<Part> parts)
}
}

private static double WaypointDistance(Waypoint waypoint, Vessel vessel)
{
Vector3d waypointPosition = waypoint.celestialBody.GetWorldSurfacePosition(waypoint.latitude, waypoint.longitude, waypoint.altitude);
return Vector3d.Distance(waypointPosition, vessel.CoM);
}

private class Celestial
{
public string name;
Expand Down
Loading