-
Notifications
You must be signed in to change notification settings - Fork 17
Allow selecting patches #165
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
Changes from 2 commits
cccf21d
26c0290
5708fc7
21bba4d
63b9727
0f4b1ab
9024599
083973c
7b8e258
8591aac
1cab956
751cb68
99d77dc
382dea9
2ebebf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using System; | ||
|
|
||
| namespace JSI | ||
| { | ||
| public class GenericVariable : IVariable | ||
| { | ||
| private Func<object> Generator; | ||
|
|
||
| internal GenericVariable(Func<object> generator) | ||
| { | ||
| Generator = generator; | ||
| } | ||
|
|
||
| object IVariable.GetValue() | ||
| { | ||
| return Generator(); | ||
| } | ||
|
|
||
| bool IVariable.Changed(object oldValue) | ||
| { | ||
| return true; | ||
|
andymac-2 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| bool IVariable.IsConstant() | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace JSI | ||
| { | ||
| internal interface IPageElement | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There are two main ways I considered. Either add another config variable into the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You might have to provide an example, I'm not sure what you mean when you refer to a "generic switch"
We end up with a worse problem where we need to thread the state of the |
||
| { | ||
| void HandlePageCreate(RasterPropMonitor propMonitor); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace JSI | ||
| { | ||
| /// <summary> | ||
| /// This class exists to provide a base class that RasterPropMonitorComputer | ||
| /// manages for tracking various built-in plugin action handlers. | ||
| /// </summary> | ||
| internal interface IVariable | ||
| { | ||
| object GetValue(); | ||
| bool Changed(object oldValue); | ||
| bool IsConstant(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Text; | ||
| using UnityEngine; | ||
|
|
||
| namespace JSI | ||
|
|
@@ -80,7 +79,7 @@ public enum BackgroundType | |
| private readonly MonoBehaviour backgroundHandlerModule, pageHandlerModule; | ||
| private readonly List<string> techsRequired = new List<string>(); | ||
| private readonly string fallbackPageName = string.Empty; | ||
|
|
||
| private readonly PatchSelector patchSelector; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this stuff be moved to a page handler class somewhere?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did try this, but it ended with the same code duplicated a few times. Here's what I tried:
So this left me with a few options:
Let me know what you think, I can choose any of those other options whichever fits best in the codebase.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder...how horrible would it be if we just used per-pod variables to start, and then found a better way to do monitor-local ones?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since I'm using this for IVA play, I want to keep them monitor local for personal use and don't have much interest in making them pod local. If monitor local variables are a deal breaker, let me know and I'll leave this unmerged. |
||
|
|
||
| private struct HandlerSupportMethods | ||
| { | ||
|
|
@@ -136,7 +135,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; | ||
|
|
||
|
|
@@ -156,7 +155,7 @@ public void UpdateText(RasterPropMonitorComputer rpmComp) | |
| { | ||
| if (spf[i] != null) | ||
| { | ||
| outputLines[i] = StringProcessor.ProcessString(spf[i], rpmComp); | ||
| outputLines[i] = spf[i].GetFormattedString(); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -433,6 +432,13 @@ public MonitorPage(int idNum, ConfigNode node, RasterPropMonitor thatMonitor) | |
| } | ||
| } | ||
|
|
||
| if (node.HasNode("PATCHSELECTOR")) | ||
| { | ||
| foreach (ConfigNode patchSelectorNode in node.GetNodes("PATCHSELECTOR")) | ||
| { | ||
| patchSelector = new PatchSelector(ourMonitor, patchSelectorNode); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static MethodInfo InstantiateHandler(ConfigNode node, RasterPropMonitor ourMonitor, out MonoBehaviour moduleInstance, out HandlerSupportMethods support) | ||
|
|
@@ -593,6 +599,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()) | ||
| { | ||
|
|
@@ -626,17 +637,27 @@ public bool GlobalButtonClick(int buttonID) | |
| { | ||
| return false; | ||
| } | ||
|
|
||
| bool actionTaken = false; | ||
|
|
||
| if (pageHandlerS.buttonClick != null) | ||
| { | ||
| pageHandlerS.buttonClick(buttonID); | ||
| actionTaken = true; | ||
| } | ||
|
|
||
| if (backgroundHandlerS.buttonClick != null && pageHandlerS.buttonClick != backgroundHandlerS.buttonClick) | ||
| { | ||
| backgroundHandlerS.buttonClick(buttonID); | ||
| actionTaken = true; | ||
| } | ||
|
|
||
| if (patchSelector != null) | ||
| { | ||
| patchSelector.HandleButtonPress(buttonID); | ||
| actionTaken = true; | ||
| } | ||
|
|
||
| return actionTaken; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.