Skip to content

Commit

Permalink
Fix the node remaining dv cursor position
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Apr 23, 2016
1 parent e33c0dc commit 1bff62b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 35 deletions.
26 changes: 26 additions & 0 deletions 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<KSP.UI.Screens.HelixGauge>();
}

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;
}
}

}
}
89 changes: 54 additions & 35 deletions MakeItSmall.cs
Expand Up @@ -23,6 +23,7 @@

using KSP.IO;
using KSP.UI;
using KSP.UI.Screens.Flight;
using UnityEngine;

namespace MakeItSmall
Expand All @@ -33,6 +34,9 @@ public class MakeItSmall : MonoBehaviour
[Persistent]
private float navBallScale = 1;

[Persistent]
private float offset = 0;

[Persistent]
private float altimeterScale = 1;

Expand Down Expand Up @@ -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;
Expand All @@ -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<NavBallBurnVector>();

// 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<HelixGaugeMover>();

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);
Expand All @@ -151,7 +171,6 @@ public void Update()
GameSettings.SaveSettings();
}


if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(KeyCode.U))
{
showUI = !showUI;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 1bff62b

Please sign in to comment.