Skip to content

Commit

Permalink
working but breaks menu?
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Oct 19, 2023
1 parent a1247cb commit 23e264c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
49 changes: 33 additions & 16 deletions OpenDreamClient/Interface/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
18 changes: 5 additions & 13 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion Resources/OpenDream/DefaultInterface.dmf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions TestGame/code.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 23e264c

Please sign in to comment.