Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
7 changes: 7 additions & 0 deletions RasterPropMonitor/Core/IPageElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace JSI
{
internal interface IPageElement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? There's already a lot of ways to customize page behaviors

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RasterPropMonitor contains the state of which orbital patch is selected instead of RPMVesselComputer, otherwise all screens show the same thing, even if you only change one. Currently there's no way to pass the RasterPropMonitor instance to the pages themselves.

There are two main ways I considered. Either add another config variable into the ConfigNode which exposes it publicly and makes it hard to change later since you don't know if downstream dependencies use it, or use an internal interface. I chose the latter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that scansat or vesselviewer page states are not shared between monitors in the same pod. Is there a way to use the same pattern?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those states are local to the page not the monitor. There are other cases like that e.g. the science and target menus. They are not local to the monitor itself. If I switch from one orbital patch on the map screen, on the orbit screen, it will still stay at the old value. Potentially, I could create a "composite" page that contains both pages, but that might require some modification to the page clicking code to allow pages to capture it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks. Let me think about it...

Another example is generic switches; they create persistent variables to track their state per prop. And maybe this state could be stored in the JSIOrbitDisplay? I'm not sure if that's instantiated per monitor or per pod.

Copy link
Author

@andymac-2 andymac-2 Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example is generic switches

You might have to provide an example, I'm not sure what you mean when you refer to a "generic switch"

Maybe this state could be stored in the JSIOrbitDisplay

We end up with a worse problem where we need to thread the state of the JSIOrbitDisplay everywhere it's needed. Even the text on the map display wouldn't sync up unless you passed it in.

{
void HandlePageCreate(RasterPropMonitor propMonitor);
}
}
33 changes: 30 additions & 3 deletions RasterPropMonitor/Core/MonitorPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MonitorPage
public readonly int pageNumber;
public readonly string name = string.Empty;
public readonly bool unlocker;
private const int INVALID_BUTTON = -1;
private string text;
private StringProcessorFormatter[] spf;
private string[] outputLines;
Expand Down Expand Up @@ -80,7 +81,8 @@ public enum BackgroundType
private readonly MonoBehaviour backgroundHandlerModule, pageHandlerModule;
private readonly List<string> techsRequired = new List<string>();
private readonly string fallbackPageName = string.Empty;

private readonly int buttonNextPatch = INVALID_BUTTON;
private readonly int buttonPrevPatch = INVALID_BUTTON;

private struct HandlerSupportMethods
{
Expand Down Expand Up @@ -136,7 +138,7 @@ public void UpdateText(RasterPropMonitorComputer rpmComp)
allTextConstant = true;
for (int i = 0; i < linesArray.Length; ++i)
{
spf[i] = new StringProcessorFormatter(linesArray[i], rpmComp);
spf[i] = new StringProcessorFormatter(linesArray[i], rpmComp, ourMonitor);

outputLines[i] = spf[i].cachedResult;

Expand Down Expand Up @@ -433,6 +435,16 @@ public MonitorPage(int idNum, ConfigNode node, RasterPropMonitor thatMonitor)
}
}

int intValue = INVALID_BUTTON;
if (node.TryGetValue("buttonNextPatch", ref intValue))
{
buttonNextPatch = intValue;
}

if (node.TryGetValue("buttonPrevPatch", ref intValue))
{
buttonPrevPatch = intValue;
}
}

private static MethodInfo InstantiateHandler(ConfigNode node, RasterPropMonitor ourMonitor, out MonoBehaviour moduleInstance, out HandlerSupportMethods support)
Expand Down Expand Up @@ -593,6 +605,11 @@ private static MethodInfo InstantiateHandler(ConfigNode node, RasterPropMonitor
}
}

if (thatModule is IPageElement pageElement)
{
pageElement.HandlePageCreate(ourMonitor);
}

moduleInstance = thatModule;
foreach (MethodInfo m in thatModule.GetType().GetMethods())
{
Expand Down Expand Up @@ -622,7 +639,7 @@ public void Active(bool state)
public bool GlobalButtonClick(int buttonID)
{
buttonID = redirectGlobals[buttonID] ?? buttonID;
if (buttonID == -1)
if (buttonID == INVALID_BUTTON)
{
return false;
}
Expand All @@ -637,6 +654,16 @@ public bool GlobalButtonClick(int buttonID)
backgroundHandlerS.buttonClick(buttonID);
actionTaken = true;
}
if (buttonID == buttonNextPatch)
{
ourMonitor.SelectNextPatch();
actionTaken = true;
}
if (buttonID == buttonPrevPatch)
{
ourMonitor.SelectPreviousPatch();
actionTaken = true;
}
return actionTaken;
}

Expand Down
27 changes: 3 additions & 24 deletions RasterPropMonitor/Core/OrbitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ public static Vector3d SwappedOrbitNormal(this Orbit o)
//occurs at a true anomaly that a does not actually ever attain
public static double TimeOfAscendingNode(this Orbit a, Orbit b, double UT)
{
if (a.eccentricity >= 1.0)
{
return UT;
}
else
{
return a.TimeOfTrueAnomaly(Orbit.AscendingNodeTrueAnomaly(a, b), UT);
}
return a.TimeOfTrueAnomaly(Orbit.AscendingNodeTrueAnomaly(a, b), UT);
}
//Returns the next time at which a will cross its descending node with b.
//For elliptical orbits this is a time between UT and UT + a.period.
Expand All @@ -62,14 +55,7 @@ public static double TimeOfAscendingNode(this Orbit a, Orbit b, double UT)
//occurs at a true anomaly that a does not actually ever attain
public static double TimeOfDescendingNode(this Orbit a, Orbit b, double UT)
{
if (a.eccentricity >= 1.0)
{
return UT;
}
else
{
return a.TimeOfTrueAnomaly(Orbit.DescendingNodeTrueAnomaly(a, b), UT);
}
return a.TimeOfTrueAnomaly(Orbit.DescendingNodeTrueAnomaly(a, b), UT);
}
//Returns the next time at which the orbiting object will cross the equator
//moving northward, if o is east-moving, or southward, if o is west-moving.
Expand All @@ -80,14 +66,7 @@ public static double TimeOfDescendingNode(this Orbit a, Orbit b, double UT)
//"ascending node" occurs at a true anomaly that o does not actually ever attain.
public static double TimeOfAscendingNodeEquatorial(this Orbit o, double UT)
{
if (o.eccentricity >= 1.0)
{
return UT;
}
else
{
return o.TimeOfTrueAnomaly(o.AscendingNodeEquatorialTrueAnomaly(), UT);
}
return o.TimeOfTrueAnomaly(o.AscendingNodeEquatorialTrueAnomaly(), UT);
}
//Returns the next time at which the orbiting object will cross the equator
//moving southward, if o is east-moving, or northward, if o is west-moving.
Expand Down
2 changes: 2 additions & 0 deletions RasterPropMonitor/Core/RPMCEvaluators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ internal NumericVariableEvaluator GetNumericEvaluator(string input, out Variable
}
return double.NaN;
};
case "ANYTARGETEXISTS":
return (RPMVesselComputer comp) => comp.target == null ? -1d : 1d;
case "TARGETEXISTS":
return (RPMVesselComputer comp) =>
{
Expand Down
Loading