diff --git a/Assets/SEE/Controls/Actions/ShowTree.cs b/Assets/SEE/Controls/Actions/ShowTree.cs
index f9de96fc3e..1808c06319 100644
--- a/Assets/SEE/Controls/Actions/ShowTree.cs
+++ b/Assets/SEE/Controls/Actions/ShowTree.cs
@@ -1,4 +1,6 @@
+using System.Collections;
using System.Collections.Generic;
+using System.Linq;
using Cysharp.Threading.Tasks;
using SEE.Game;
using SEE.Game.City;
@@ -76,14 +78,21 @@ async UniTaskVoid SetupManager()
///
/// Close all tree view windows.
+ /// It is assumed that this method is called from a toggle action.
///
private void HideCodeView()
{
+ // If none of the windows were actually closed, we should instead open them.
+ bool anyClosed = false;
foreach (string city in treeWindows.Keys)
{
- space.CloseWindow(treeWindows[city]);
+ anyClosed |= space.CloseWindow(treeWindows[city]);
}
treeWindows.Clear();
+ if (!anyClosed)
+ {
+ ShowCodeView();
+ }
}
private void Update()
diff --git a/Assets/SEE/Controls/WindowSpaceManager.cs b/Assets/SEE/Controls/WindowSpaceManager.cs
index cdbb6f75fe..1664232c94 100644
--- a/Assets/SEE/Controls/WindowSpaceManager.cs
+++ b/Assets/SEE/Controls/WindowSpaceManager.cs
@@ -116,7 +116,7 @@ public void UpdateSpaceFromValueObject(string playerName, WindowSpace.WindowSpac
}
// Close windows which are no longer open
- closedWindows.ForEach(windowSpaces[playerName].CloseWindow);
+ closedWindows.ForEach(x => windowSpaces[playerName].CloseWindow(x));
// Set active window if it changed
if (windowSpaces[playerName].ActiveWindow.Title != valueObject.ActiveWindow.Title)
diff --git a/Assets/SEE/UI/Window/WindowSpace.cs b/Assets/SEE/UI/Window/WindowSpace.cs
index 52bbb19351..b9ae1c4f4a 100644
--- a/Assets/SEE/UI/Window/WindowSpace.cs
+++ b/Assets/SEE/UI/Window/WindowSpace.cs
@@ -89,16 +89,14 @@ public void AddWindow(BaseWindow window)
///
/// The window which should be closed.
/// If the given is null.
- public void CloseWindow(BaseWindow window)
+ /// true if the window was closed, false otherwise.
+ public bool CloseWindow(BaseWindow window)
{
- if (window == null)
+ if (ReferenceEquals(window, null))
{
throw new ArgumentNullException(nameof(window));
}
- else if (windows.Contains(window))
- {
- windows.Remove(window);
- }
+ return windows.Remove(window);
}
///