Skip to content

Commit

Permalink
Hide Windows/Overlays when the GUI is hidden
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
Peppie84 committed Jan 4, 2015
1 parent 8e78359 commit 81ff813
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/RemoteTech/UI/AbstractWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public AbstractWindow(Guid id, String title, Rect position, WindowAlign align)
Position = position;
mInitialHeight = position.height + 15;
mInitialWidth = position.width + 15;

GameEvents.onHideUI.Add(OnHideUI);
GameEvents.onShowUI.Add(OnShowUI);
}

public Rect RequestPosition() { return Position; }
Expand All @@ -65,10 +68,22 @@ public virtual void Show()
Enabled = true;
}

private void OnHideUI()
{
Enabled = false;
}

private void OnShowUI()
{
Enabled = true;
}

public virtual void Hide()
{
Windows.Remove(mGuid);
Enabled = false;
GameEvents.onHideUI.Remove(OnHideUI);
GameEvents.onShowUI.Remove(OnShowUI);
}

private void WindowPre(int uid)
Expand All @@ -87,6 +102,7 @@ public virtual void Window(int uid)

public virtual void Draw()
{
if (!Enabled) return;
if (Event.current.type == EventType.Layout)
{
Position.width = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/RemoteTech/UI/FilterOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static Style()
private AntennaFragment mAntennaFragment = new AntennaFragment(null);
private TargetInfoWindow mTargetInfos;
private bool mEnabled;
private bool mShowOverlay = true;
private bool onTrackingStation { get { return (HighLogic.LoadedScene == GameScenes.TRACKSTATION); } }

private Rect Position
Expand Down Expand Up @@ -175,9 +176,21 @@ private GUIStyle StyleStatusButton
}
}

private void OnHideUI()
{
mShowOverlay = false;
}

private void OnShowUI()
{
mShowOverlay = true;
}

public FilterOverlay()
{
GameEvents.onPlanetariumTargetChanged.Add(OnChangeTarget);
GameEvents.onHideUI.Add(OnHideUI);
GameEvents.onShowUI.Add(OnShowUI);
MapView.OnEnterMapView += OnEnterMapView;
MapView.OnExitMapView += OnExitMapView;
/// Add the on mouse over event
Expand All @@ -201,6 +214,8 @@ public void Dispose()
mAntennaFragment.onMouseOverListEntry -= showTargetInfo;

GameEvents.onPlanetariumTargetChanged.Remove(OnChangeTarget);
GameEvents.onHideUI.Remove(OnHideUI);
GameEvents.onShowUI.Remove(OnShowUI);
MapView.OnEnterMapView -= OnEnterMapView;
MapView.OnExitMapView -= OnExitMapView;
mSatelliteFragment.Dispose();
Expand Down Expand Up @@ -251,6 +266,7 @@ public void showTargetInfo()

public void Draw()
{
if (!mShowOverlay) return;
GUI.depth = 0;
GUI.skin = HighLogic.Skin;

Expand Down
16 changes: 16 additions & 0 deletions src/RemoteTech/UI/FocusOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static Style()

private FocusFragment mFocus = new FocusFragment();
private bool mEnabled;
private bool mShowOverlay;

private Rect PositionButton
{
Expand Down Expand Up @@ -59,12 +60,16 @@ public FocusOverlay()
{
MapView.OnEnterMapView += OnEnterMapView;
MapView.OnExitMapView += OnExitMapView;
GameEvents.onHideUI.Add(OnHideUI);
GameEvents.onShowUI.Add(OnShowUI);
}

public void Dispose()
{
MapView.OnEnterMapView -= OnEnterMapView;
MapView.OnExitMapView -= OnExitMapView;
GameEvents.onHideUI.Remove(OnHideUI);
GameEvents.onShowUI.Remove(OnShowUI);
}

public void OnEnterMapView()
Expand All @@ -78,8 +83,19 @@ public void OnExitMapView()
RTCore.Instance.OnGuiUpdate -= Draw;
}

private void OnHideUI()
{
mShowOverlay = false;
}

private void OnShowUI()
{
mShowOverlay = true;
}

public void Draw()
{
if (!mShowOverlay) return;
GUI.depth = 0;
GUI.skin = HighLogic.Skin;

Expand Down

0 comments on commit 81ff813

Please sign in to comment.