diff --git a/OpenDreamClient/Interface/Controls/ControlWindow.cs b/OpenDreamClient/Interface/Controls/ControlWindow.cs index 8de1e33614..67acc26742 100644 --- a/OpenDreamClient/Interface/Controls/ControlWindow.cs +++ b/OpenDreamClient/Interface/Controls/ControlWindow.cs @@ -7,6 +7,7 @@ namespace OpenDreamClient.Interface.Controls; public sealed class ControlWindow : InterfaceControl { + [Dependency] private readonly IClyde _clyde = default!; [Dependency] private readonly IUserInterfaceManager _uiMgr = default!; [Dependency] private readonly IDreamInterfaceManager _dreamInterface = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; @@ -25,7 +26,9 @@ public sealed class ControlWindow : InterfaceControl { private Control _menuContainer = default!; private LayoutContainer _canvas = default!; - private readonly List<(OSWindow? osWindow, IClydeWindow? clydeWindow)> _openWindows = new(); + + private (OSWindow? osWindow, IClydeWindow? clydeWindow) _myWindow; + public ControlWindow(WindowDescriptor windowDescriptor) : base(windowDescriptor, null) { IoCManager.InjectDependencies(this); @@ -42,9 +45,8 @@ protected override void UpdateElementDescriptor() { _menuContainer.Visible = false; } - foreach (var window in _openWindows) { - UpdateWindowAttributes(window); - } + if(!WindowDescriptor.IsPane) + UpdateWindowAttributes(_myWindow); if (WindowDescriptor.IsDefault) { Macro.SetActive(); @@ -53,7 +55,8 @@ protected override void UpdateElementDescriptor() { public OSWindow CreateWindow() { OSWindow window = new(); - + if(UIElement.Parent is not null) + UIElement.Orphan(); window.Children.Add(UIElement); window.SetWidth = ControlDescriptor.Size?.X ?? 640; window.SetHeight = ControlDescriptor.Size?.Y ?? 440; @@ -66,19 +69,21 @@ public OSWindow CreateWindow() { if (WindowDescriptor.OnClose != null && _entitySystemManager.TryGetEntitySystem(out DreamCommandSystem? commandSystem)) { commandSystem.RunCommand(WindowDescriptor.OnClose); } - - _openWindows.Remove((window, null)); + _myWindow = (null, _myWindow.clydeWindow); }; + window.StartupLocation = WindowStartupLocation.CenterOwner; + window.Owner = _clyde.MainWindow; - _openWindows.Add((window, null)); - UpdateWindowAttributes((window, null)); + _myWindow = (window, _myWindow.clydeWindow); + UpdateWindowAttributes(_myWindow); return window; } public void RegisterOnClydeWindow(IClydeWindow window) { // todo: listen for closed. - _openWindows.Add((null, window)); - UpdateWindowAttributes((null, window)); + + _myWindow = (_myWindow.osWindow, window); + UpdateWindowAttributes(_myWindow); } public void UpdateAnchors() { @@ -151,6 +156,18 @@ public void UpdateAnchors() { private void UpdateWindowAttributes((OSWindow? osWindow, IClydeWindow? clydeWindow) windowRoot) { // TODO: this would probably be cleaner if an OSWindow for MainWindow was available. var (osWindow, clydeWindow) = windowRoot; + //if our window is null or closed, and we are visible, we need to create a new one. Otherwise we need to update the existing one. + if(osWindow == null && clydeWindow == null) { + if (WindowDescriptor.IsVisible) { + CreateWindow(); + return; //we return because CreateWindow() calls UpdateWindowAttributes() again. + } + } + if(osWindow != null && !osWindow.IsOpen) { + if (WindowDescriptor.IsVisible) { + osWindow.Show(); + } + } var title = WindowDescriptor.Title ?? "OpenDream World"; if (osWindow != null) osWindow.Title = title; @@ -166,11 +183,11 @@ private void UpdateWindowAttributes((OSWindow? osWindow, IClydeWindow? clydeWind root.BackgroundColor = WindowDescriptor.BackgroundColor; } - if (osWindow != null) { - if (WindowDescriptor.IsVisible && !osWindow.IsOpen) - osWindow?.Show(); - else if (!WindowDescriptor.IsVisible && osWindow.IsOpen) - osWindow?.Close(); + if (osWindow != null && osWindow.ClydeWindow != null) { + osWindow.ClydeWindow.IsVisible = WindowDescriptor.IsVisible; + // + //else if (!WindowDescriptor.IsVisible && osWindow.IsOpen) + // osWindow?.Close(); } else if (clydeWindow != null) { clydeWindow.IsVisible = WindowDescriptor.IsVisible; } diff --git a/OpenDreamClient/Interface/DreamInterfaceManager.cs b/OpenDreamClient/Interface/DreamInterfaceManager.cs index 6569bad415..e554cf4ce7 100644 --- a/OpenDreamClient/Interface/DreamInterfaceManager.cs +++ b/OpenDreamClient/Interface/DreamInterfaceManager.cs @@ -642,21 +642,13 @@ private void LoadInterface(InterfaceDescriptor descriptor) { if (DefaultWindow == null) throw new Exception("Given DMF did not have a default window"); - DefaultWindow.RegisterOnClydeWindow(_clyde.MainWindow); + //DefaultWindow.RegisterOnClydeWindow(_clyde.MainWindow); DefaultWindow.UIElement.Name = "MainWindow"; + _clyde.MainWindow.IsVisible = false; + //LayoutContainer.SetAnchorRight(DefaultWindow.UIElement, 1); + //LayoutContainer.SetAnchorBottom(DefaultWindow.UIElement, 1); - LayoutContainer.SetAnchorRight(DefaultWindow.UIElement, 1); - LayoutContainer.SetAnchorBottom(DefaultWindow.UIElement, 1); - - _userInterfaceManager.StateRoot.AddChild(DefaultWindow.UIElement); - - foreach (ControlWindow window in Windows.Where(pair => !((WindowDescriptor)pair.Value.ElementDescriptor).IsPane).Select(pair => pair.Value)) { - if(window != DefaultWindow) { - OSWindow _window = window.CreateWindow(); - _window.StartupLocation = WindowStartupLocation.CenterOwner; - _window.Owner = _clyde.MainWindow; - } - } + //_userInterfaceManager.StateRoot.AddChild(DefaultWindow.UIElement); } private void LoadDescriptor(ElementDescriptor descriptor) { diff --git a/Resources/OpenDream/DefaultInterface.dmf b/Resources/OpenDream/DefaultInterface.dmf index c2572cbf3f..0065f94a5b 100644 --- a/Resources/OpenDream/DefaultInterface.dmf +++ b/Resources/OpenDream/DefaultInterface.dmf @@ -40,9 +40,13 @@ menu "menu" command = ".quit" category = "Menu" elem - name = "Popup test" + name = "Show Popup" command = ".winset \"testwindow.is-visible=true\"" category = "Menu" + elem + name = "Hide Popup" + command = ".winset \"testwindow.is-visible=false\"" + category = "Menu" window "mapwindow" elem "mapwindow" diff --git a/TestGame/code.dm b/TestGame/code.dm index 577f54569a..54ad75547b 100644 --- a/TestGame/code.dm +++ b/TestGame/code.dm @@ -185,6 +185,11 @@ spawn(50) src.client.images.Cut() + verb/test_hide_main_window() + winset(src, null, "mapwindow.is-visible=false") + spawn(50) + winset(src, null, "mapwindow.is-visible=true") + /mob/Stat() if (statpanel("Status")) stat("tick_usage", world.tick_usage)