Skip to content

Commit

Permalink
Merge pull request #41 from Peppie23/infinite_map_zoom
Browse files Browse the repository at this point in the history
Infinite map zoom
  • Loading branch information
Peppie84 committed Oct 8, 2014
2 parents d86f5da + 49ce539 commit c590f27
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
68 changes: 48 additions & 20 deletions src/RemoteTech/UI/FocusFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public void Draw()
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
foreach (VesselSatellite sat in RTCore.Instance.Satellites)
{
if (sat.parentVessel != null && !MapViewFiltering.CheckAgainstFilter(sat.parentVessel)) {
if ((sat.parentVessel != null && !MapViewFiltering.CheckAgainstFilter(sat.parentVessel)) || FlightGlobals.ActiveVessel == sat.parentVessel)
{
continue;
}

Expand All @@ -30,25 +31,22 @@ public void Draw()
mSelection = (s > 0) ? sat : null;
if (mSelection != null)
{
MapObject newTarget = PlanetariumCamera.fetch.targets.FirstOrDefault(t => t != null && t.gameObject.name == sat.Name);
if (newTarget == null)
{
Vessel vessel = sat.SignalProcessor.Vessel;
ScaledMovement scaledMovement = new GameObject().AddComponent<ScaledMovement>();
scaledMovement.tgtRef = vessel.transform;
scaledMovement.name = sat.Name;
scaledMovement.transform.parent = ScaledSpace.Instance.transform;
scaledMovement.vessel = vessel;
scaledMovement.type = MapObject.MapObjectType.VESSEL;
newTarget = scaledMovement;
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
PlanetariumCamera.fetch.targets.Remove(newTarget);
}
else
{
PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(newTarget));
}
Vessel vessel = sat.SignalProcessor.Vessel;
ScaledMovement scaledMovement = new GameObject().AddComponent<ScaledMovement>();
scaledMovement.tgtRef = vessel.transform;
scaledMovement.name = sat.Name;
scaledMovement.transform.parent = ScaledSpace.Instance.transform;
scaledMovement.vessel = vessel;
scaledMovement.type = MapObject.MapObjectType.VESSEL;
var success = PlanetariumCamera.fetch.SetTarget(PlanetariumCamera.fetch.AddTarget(scaledMovement));
PlanetariumCamera.fetch.targets.Remove(scaledMovement);
this.resetTarget();
}
else
{
// go back to the active vessel
PlanetariumCamera.fetch.SetTarget(this.resetTarget());
}
});
}
Expand All @@ -57,5 +55,35 @@ public void Draw()
}
GUILayout.EndScrollView();
}

/// <summary>
/// This method resets the current selected state button on the FocusFragment.
/// Should be called by enter map view.
/// </summary>
public void resetSelection()
{
// reset the selection set before
mSelection = null;
}

/// <summary>
/// Reset the current target object on the PlanetariumCamera to the Active vessel
/// or if there is no active vessel (tracking station), back to Kerbin
/// </summary>
/// <returns>Found target as MapObject. Can be the active vessel or kerbin</returns>
public MapObject resetTarget()
{
// try to get the active vessel
int target_id = PlanetariumCamera.fetch.GetTargetIndex("ActiveVesselScaled");
if (target_id == -1)
{
// there is no active vessel, go to target kerbin
target_id = PlanetariumCamera.fetch.GetTargetIndex("Kerbin");
}

MapObject activeVesselObj = PlanetariumCamera.fetch.GetTarget(target_id);
PlanetariumCamera.fetch.target = activeVesselObj;
return activeVesselObj;
}
}
}
1 change: 1 addition & 0 deletions src/RemoteTech/UI/FocusOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void Dispose()
public void OnEnterMapView()
{
RTCore.Instance.OnGuiUpdate += Draw;
mFocus.resetSelection();
}

public void OnExitMapView()
Expand Down

0 comments on commit c590f27

Please sign in to comment.