Skip to content

Commit

Permalink
New rendezvous functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbudda committed Mar 28, 2018
1 parent af793b2 commit b3488e7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 7 deletions.
Binary file modified Assets/Plugins/KerbalEngineer.Unity.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions Documents/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.1.4.4, 2018-03-28, KSP 1.4.1 #2089
When using the 'Switch To Target' button on the Rendezvous readout, the target ship's target will be set to the original ship (so you can switch back without digging through a menu or the map).
Added 'Focus Target' / 'Focus Vessel' buttons on the Rendezvous readout. Switches to the map and focuses your target if it's a vessel or celestial body. 'Focus Vessel' switches back to your ship ideally remembering if you were in the map or not.
Added 'Look At Target' button to the Rendezvous readout. Rotates the camera to look at the target. Flight mode only. No more searching the stars for that little green box.

1.1.4.3, 2018-03-23, KSP 1.4.1 #2089
Fix phantom stage when root part is stageable.
Handle decoupler stage detection in a more mod-friendly way.
Expand Down
2 changes: 1 addition & 1 deletion KerbalEngineer/EngineerGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class EngineerGlobals
/// <summary>
/// Current version of the Kerbal Engineer assembly.
/// </summary>
public const string ASSEMBLY_VERSION = "1.1.4.3";
public const string ASSEMBLY_VERSION = "1.1.4.4";

private static string assemblyFile;
private static string assemblyName;
Expand Down
15 changes: 14 additions & 1 deletion KerbalEngineer/Flight/FlightEngineerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public sealed class FlightEngineerCore : MonoBehaviour
private static bool isTrackingStationLimited = true;
private static bool switchVesselOnUpdate = false;
private static Vessel switchVesselTarget = null;
private static ITargetable switchVesselTargetTarget = null;

#endregion

Expand Down Expand Up @@ -209,10 +210,11 @@ public static bool IsTrackingStationLimited
/// <summary>
/// Switches the active vessel. This is delayed until the next Update call to avoid issues when called from OnGUI in KSP 1.2
/// </summary>
public static void SwitchToVessel(Vessel vessel)
public static void SwitchToVessel(Vessel vessel, ITargetable target = null)
{
switchVesselTarget = vessel;
switchVesselOnUpdate = true;
switchVesselTargetTarget = target;
}


Expand Down Expand Up @@ -375,11 +377,22 @@ private void Update()
switchVesselOnUpdate = false;

//bool doRestore = (tempVessel != null) && tempVessel.loaded;

if (switchVesselTargetTarget != null)
{ // you will switch or I will beat you.
tempVessel.protoVessel.targetInfo = new ProtoTargetInfo(switchVesselTargetTarget);
tempVessel.pTI = tempVessel.protoVessel.targetInfo;
tempVessel.targetObject = switchVesselTargetTarget;
}

FlightGlobals.SetActiveVessel(tempVessel);

//if (doRestore)
// FlightInputHandler.ResumeVesselCtrlState(tempVessel);
//else
// FlightInputHandler.SetNeutralControls();


}

if (FlightGlobals.ActiveVessel == null)
Expand Down
61 changes: 57 additions & 4 deletions KerbalEngineer/Flight/Readouts/Rendezvous/TargetSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,25 +198,78 @@ private void DrawSearch()
GUILayout.EndHorizontal();
}

private bool wasMapview;

/// <summary>
/// Draws the target information when selected.
/// </summary>
private void DrawTarget(SectionModule section)
{
var target = FlightGlobals.fetch.VesselTarget;
ITargetable target = FlightGlobals.fetch.VesselTarget;

this.ResizeRequested = true;

if (GUILayout.Button("Go Back to Target Selection", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
{
FlightGlobals.fetch.SetVesselTarget(null);
this.ResizeRequested = true;
}

if (target != null)
{
var act = FlightGlobals.ActiveVessel;

if (!(target is CelestialBody) && GUILayout.Button("Switch to Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
{
FlightEngineerCore.SwitchToVessel(target.GetVessel());
this.ResizeRequested = true;
FlightEngineerCore.SwitchToVessel(target.GetVessel(), act);
}

bool focusable = (target is CelestialBody || target is global::Vessel);

if (focusable)
{
MapObject targMo = null;

if (target is global::Vessel)
targMo = ((global::Vessel)(target)).mapObject;
else
targMo = ((CelestialBody)(target)).MapObject;

bool shouldFocus = targMo != null && (targMo != PlanetariumCamera.fetch.target || !MapView.MapIsEnabled);

if (shouldFocus && GUILayout.Button("Focus Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
{
wasMapview = MapView.MapIsEnabled;
MapView.EnterMapView();
PlanetariumCamera.fetch.SetTarget(targMo);
}
}

bool switchBack = PlanetariumCamera.fetch.target != act.mapObject;

if (switchBack && MapView.MapIsEnabled && GUILayout.Button("Focus Vessel", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
{
if (!wasMapview) MapView.ExitMapView();
PlanetariumCamera.fetch.SetTarget(act.mapObject);
}

if (FlightCamera.fetch.mode != FlightCamera.Modes.LOCKED && !MapView.MapIsEnabled && GUILayout.Button("Look at Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth)))
{
var pcam = PlanetariumCamera.fetch;
var fcam = FlightCamera.fetch;

Vector3 from = target.GetOrbit().getTruePositionAtUT(Planetarium.GetUniversalTime());
Vector3 to = FlightGlobals.fetch.activeVessel.GetWorldPos3D();
// float pdist = pcam.Distance;
float fdist = fcam.Distance;

Vector3 n = (from - to).normalized;

// pcam.SetCamCoordsFromPosition(n * -pdist); //this does weird stuff
fcam.SetCamCoordsFromPosition(n * -fdist);

Debug.Log(" target " + target.GetOrbit().getTruePositionAtUT(Planetarium.GetUniversalTime()));
Debug.Log(" vessel " + FlightGlobals.fetch.activeVessel.GetWorldPos3D());
Debug.Log(" distance " + fdist + " " + fcam.Distance);
}

GUILayout.Space(3f);
Expand Down
3 changes: 3 additions & 0 deletions KerbalEngineer/Flight/Sections/SectionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ public void Draw()
/// </summary>
private void DrawReadoutModules()
{
if (!HighLogic.LoadedSceneIsFlight)
return; //prevent null references and bad calculations during scene transition.

if (!this.IsHud)
{
GUILayout.BeginVertical(this.boxStyle);
Expand Down
Binary file modified Output/KerbalEngineer/KerbalEngineer.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Output/KerbalEngineer/KerbalEngineer.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"MAJOR":1,
"MINOR":1,
"PATCH":4,
"BUILD":3
"BUILD":4
},
"KSP_VERSION":
{
Expand Down

0 comments on commit b3488e7

Please sign in to comment.