diff --git a/HelixGaugeMover.cs b/HelixGaugeMover.cs new file mode 100644 index 0000000..d7df1d7 --- /dev/null +++ b/HelixGaugeMover.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace MakeItSmall +{ + class HelixGaugeMover : MonoBehaviour + { + private KSP.UI.Screens.HelixGauge deltaVGauge; + + public void Start() + { + deltaVGauge = this.GetComponent(); + } + + public void LateUpdate() + { + if (deltaVGauge != null) + { + Transform t = deltaVGauge.transform; + deltaVGauge.readoutStandoff = (GameSettings.UI_SCALE * 150f + 20f) * transform.lossyScale.x; + deltaVGauge.readoutField.position = t.position + + Quaternion.AngleAxis(deltaVGauge.currentAngle, -t.forward) * t.up * deltaVGauge.readoutStandoff; + } + } + + } +} diff --git a/MakeItSmall.cs b/MakeItSmall.cs index cf1b9a0..11ac22a 100644 --- a/MakeItSmall.cs +++ b/MakeItSmall.cs @@ -23,6 +23,7 @@ using KSP.IO; using KSP.UI; +using KSP.UI.Screens.Flight; using UnityEngine; namespace MakeItSmall @@ -33,6 +34,9 @@ public class MakeItSmall : MonoBehaviour [Persistent] private float navBallScale = 1; + [Persistent] + private float offset = 0; + [Persistent] private float altimeterScale = 1; @@ -72,6 +76,8 @@ public class MakeItSmall : MonoBehaviour //private InitialState initialUiModState = new InitialState(); private InitialState initialCrewState = new InitialState(); + private NavBallBurnVector navBallBurnVector; + private class InitialState { public Vector3 scale; @@ -90,50 +96,64 @@ public void Start() ConfigNode config = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "MakeItSmall.cfg")); ConfigNode.LoadObjectFromConfig(this, config); } + GameEvents.onLevelWasLoadedGUIReady.Add(OnLevelLoadedGUIReady); GameEvents.onGameStateSaved.Add(data => SaveConfig()); GameEvents.onGameSceneLoadRequested.Add(scene => SaveConfig()); } + public void OnDestroy() + { + GameEvents.onGameStateSaved.Remove(data => SaveConfig()); + GameEvents.onGameSceneLoadRequested.Remove(scene => SaveConfig()); + GameEvents.onLevelWasLoadedGUIReady.Remove(OnLevelLoadedGUIReady); + } - void SaveConfig() + private void SaveConfig() { ConfigNode node = new ConfigNode("MakeItSmall"); ConfigNode.CreateConfigFromObject(this, node); node.Save(IOUtils.GetFilePathFor(this.GetType(), "MakeItSmall.cfg")); } - - public void Update() + private void OnLevelLoadedGUIReady(GameScenes data) { - if (HighLogic.LoadedScene != GameScenes.FLIGHT || !FlightUIModeController.Instance) + if (HighLogic.LoadedScene != GameScenes.FLIGHT) return; + scale = GameSettings.UI_SCALE; + + SaveState(FlightUIModeController.Instance.navBall, initialNavBallState); + SaveState(FlightUIModeController.Instance.altimeterFrame, initialAltimeterState); + SaveState(FlightUIModeController.Instance.timeFrame, initialTimeState); + //SaveState(FlightUIModeController.Instance.MapOptionsQuadrant, initialMapOptionsState); + //SaveState(FlightUIModeController.Instance.stagingQuadrant, initialStagingState); + //SaveState(FlightUIModeController.Instance.dockingRotQuadrant, initialdockingRotState); + //SaveState(FlightUIModeController.Instance.dockingLinQuadrant, initialdockingLinState); + //SaveState(FlightUIModeController.Instance.uiModeFrame, initialUiModState); + SaveState(FlightUIModeController.Instance.crew, initialCrewState); + + //printRectInfo(FlightUIModeController.Instance.navBall, "navBall"); + //printRectInfo(FlightUIModeController.Instance.altimeterFrame,"altimeterFrame"); + //printRectInfo(FlightUIModeController.Instance.timeFrame,"timeFrame"); + //printRectInfo(FlightUIModeController.Instance.MapOptionsQuadrant,"MapOptionsQuadrant"); + //printRectInfo(FlightUIModeController.Instance.stagingQuadrant,"stagingQuadrant"); + //printRectInfo(FlightUIModeController.Instance.crew, "crew"); + + navBallBurnVector = GameObject.FindObjectOfType(); + + // The node remaining dv cursor is moved in LateUpdate + // So I need an new component that run after the stock one + // to move it in the right position + navBallBurnVector.deltaVGauge.gameObject.AddComponent(); + + initialSaved = true; + } - if (!initialSaved) - { - - scale = GameSettings.UI_SCALE; - - SaveState(FlightUIModeController.Instance.navBall, initialNavBallState); - SaveState(FlightUIModeController.Instance.altimeterFrame, initialAltimeterState); - SaveState(FlightUIModeController.Instance.timeFrame, initialTimeState); - //SaveState(FlightUIModeController.Instance.MapOptionsQuadrant, initialMapOptionsState); - //SaveState(FlightUIModeController.Instance.stagingQuadrant, initialStagingState); - //SaveState(FlightUIModeController.Instance.dockingRotQuadrant, initialdockingRotState); - //SaveState(FlightUIModeController.Instance.dockingLinQuadrant, initialdockingLinState); - //SaveState(FlightUIModeController.Instance.uiModeFrame, initialUiModState); - SaveState(FlightUIModeController.Instance.crew, initialCrewState); - - //printRectInfo(FlightUIModeController.Instance.navBall, "navBall"); - //printRectInfo(FlightUIModeController.Instance.altimeterFrame,"altimeterFrame"); - //printRectInfo(FlightUIModeController.Instance.timeFrame,"timeFrame"); - //printRectInfo(FlightUIModeController.Instance.MapOptionsQuadrant,"MapOptionsQuadrant"); - //printRectInfo(FlightUIModeController.Instance.stagingQuadrant,"stagingQuadrant"); - //printRectInfo(FlightUIModeController.Instance.crew, "crew"); - - initialSaved = true; - } - + public void Update() + { + if (!initialSaved || HighLogic.LoadedScene != GameScenes.FLIGHT || !FlightUIModeController.Instance || navBallBurnVector.deltaVGauge == null) + return; + SetScale(FlightUIModeController.Instance.navBall, initialNavBallState, navBallScale, ref activeNavBallScale); SetScale(FlightUIModeController.Instance.altimeterFrame, initialAltimeterState, altimeterScale, ref activeAltimeterScale); SetScale(FlightUIModeController.Instance.timeFrame, initialTimeState, timeScale, ref activeTimeScale); @@ -151,7 +171,6 @@ public void Update() GameSettings.SaveSettings(); } - if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(KeyCode.U)) { showUI = !showUI; @@ -180,7 +199,6 @@ private void SetScale(UIPanelTransition panel, InitialState initialState, float panel.states[i].position = initialState.states[i].position * newScale; } - //panel. = initialState.states[panel.StateIndex].position; panel.panelTransform.anchoredPosition = panel.states[panel.StateIndex].position; activeScale = newScale; @@ -210,6 +228,7 @@ public void WindowGUI(int windowID) ScaleUI("All" , ref scale); ScaleUI("NavBall" , ref navBallScale); + ScaleUI("NavBall Offset", ref offset, 10f, 0); ScaleUI("Altimeter", ref altimeterScale); ScaleUI("Time" , ref timeScale); //ScaleUI("Map" , ref mapOptionsScale); @@ -221,26 +240,26 @@ public void WindowGUI(int windowID) GUI.DragWindow(); } - private void ScaleUI(string V, ref float scale) + private void ScaleUI(string V, ref float scale, float step=0.05f, float def = 1f) { GUILayout.BeginHorizontal(); GUILayout.Label(V, GUILayout.MinWidth(60)); if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { - scale -= 0.05f; + scale -= step; } GUILayout.Label(scale.ToString("F2"), GUILayout.MinWidth(30)); if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { - scale += 0.05f; + scale += step; } if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false))) { - scale = 1; + scale = def; } GUILayout.EndHorizontal();