Skip to content

Commit

Permalink
Save window position on scene change
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 29, 2018
1 parent 90dc0f9 commit f59a8fa
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Astrogator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void Start()
// Reset the view when we take off or land, etc.
GameEvents.onVesselSituationChange.Add(OnSituationChanged);

// Save window position before Unity pre-emptively destroys it
GameEvents.onGameSceneSwitchRequested.Add(BeforeSceneChange);

// This event fires on SOI change
if (FlightGlobals.ActiveVessel != null) {
VesselMode = true;
Expand Down Expand Up @@ -109,6 +112,9 @@ public void OnDisable()
// Reset the view when we take off or land, etc.
GameEvents.onVesselSituationChange.Remove(OnSituationChanged);

// Save window position before Unity pre-emptively destroys it
GameEvents.onGameSceneSwitchRequested.Remove(BeforeSceneChange);

// The launcher destroyed event doesn't always fire when we need it (?)
RemoveLauncher();

Expand Down Expand Up @@ -496,6 +502,18 @@ private void TrackingStationTargetChanged(MapObject target)
}
}

/// <summary>
/// Tear down the window (saves the position as a side effect).
///
/// When changing scenes, OnDisable happens too late; the dialog is destroyed before
/// we have a chance to save its position, and the infamous "Unity null override"
/// tells us our reference to it has become null.
/// </summary>
private void BeforeSceneChange(GameEvents.FromToAction<GameScenes, GameScenes> evt)
{
HideMainWindow(false);
}

private void CheckIfNodesDisappeared()
{
model?.CheckIfNodesDisappeared();
Expand Down

0 comments on commit f59a8fa

Please sign in to comment.