From ff1ae0f5ed7b6d5618ad256312f6be4416a64b26 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Mon, 22 Nov 2021 17:07:57 +0100 Subject: [PATCH] Add `F11` shortcut to maximize Game window during play-mode in Editor --- Source/Editor/GUI/Docking/DockWindow.cs | 17 +++++-- Source/Editor/GUI/Docking/MasterDockPanel.cs | 2 +- Source/Editor/Windows/GameWindow.cs | 53 +++++++++++++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Source/Editor/GUI/Docking/DockWindow.cs b/Source/Editor/GUI/Docking/DockWindow.cs index 257518ecf..a847a7ff4 100644 --- a/Source/Editor/GUI/Docking/DockWindow.cs +++ b/Source/Editor/GUI/Docking/DockWindow.cs @@ -169,21 +169,30 @@ namespace FlaxEditor.GUI.Docking /// Window location. public void ShowFloating(Vector2 size, WindowStartPosition position = WindowStartPosition.CenterParent) { - // Undock + ShowFloating(new Vector2(200, 200), size, position); + } + + /// + /// Shows the window in a floating state. + /// + /// Window location. + /// Window size, set Vector2.Zero to use default. + /// Window location. + public void ShowFloating(Vector2 location, Vector2 size, WindowStartPosition position = WindowStartPosition.CenterParent) + { Undock(); // Create window var winSize = size.LengthSquared > 4 ? size : DefaultSize; - var window = FloatWindowDockPanel.CreateFloatWindow(_masterPanel.Root, new Vector2(200, 200), winSize, position, _title); + var window = FloatWindowDockPanel.CreateFloatWindow(_masterPanel.Root, location, winSize, position, _title); var windowGUI = window.GUI; // Create dock panel for the window var dockPanel = new FloatWindowDockPanel(_masterPanel, windowGUI); dockPanel.DockWindowInternal(DockState.DockFill, this); - Visible = true; - // Perform layout + Visible = true; windowGUI.UnlockChildrenRecursive(); windowGUI.PerformLayout(); diff --git a/Source/Editor/GUI/Docking/MasterDockPanel.cs b/Source/Editor/GUI/Docking/MasterDockPanel.cs index 0293ec0cc..b274b6aab 100644 --- a/Source/Editor/GUI/Docking/MasterDockPanel.cs +++ b/Source/Editor/GUI/Docking/MasterDockPanel.cs @@ -132,7 +132,7 @@ namespace FlaxEditor.GUI.Docking public override DockState TryGetDockState(out float splitterValue) { splitterValue = 0.5f; - return DockState.Unknown; + return DockState.DockFill; } } } diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs index 1e65c9b4a..91296d845 100644 --- a/Source/Editor/Windows/GameWindow.cs +++ b/Source/Editor/Windows/GameWindow.cs @@ -20,7 +20,10 @@ namespace FlaxEditor.Windows private readonly GameRoot _guiRoot; private bool _showGUI = true; private bool _showDebugDraw = false; + private bool _isMaximized = false; private float _gameStartTime; + private GUI.Docking.DockState _maximizeRestoreDockState; + private GUI.Docking.DockPanel _maximizeRestoreDockTo; /// /// Gets the viewport. @@ -52,6 +55,41 @@ namespace FlaxEditor.Windows set => _showDebugDraw = value; } + /// + /// Gets or sets a value indicating whether game window is maximized (only in play mode). + /// + private bool IsMaximized + { + get => _isMaximized; + set + { + if (_isMaximized == value) + return; + _isMaximized = value; + if (value) + { + // Maximize + _maximizeRestoreDockTo = _dockedTo; + _maximizeRestoreDockState = _dockedTo.TryGetDockState(out _); + if (_maximizeRestoreDockState != GUI.Docking.DockState.Float) + { + var monitorBounds = Platform.GetMonitorBounds(PointToScreen(Size * 0.5f)); + ShowFloating(monitorBounds.Location + new Vector2(200, 200), Vector2.Zero, WindowStartPosition.Manual); + } + if (!RootWindow.IsMaximized) + RootWindow.Maximize(); + } + else + { + // Restore + RootWindow.Restore(); + if (_maximizeRestoreDockTo != null && _maximizeRestoreDockTo.IsDisposing) + _maximizeRestoreDockTo = null; + Show(_maximizeRestoreDockState, _maximizeRestoreDockTo); + } + } + } + /// /// Gets or sets a value indicating whether center mouse position on window focus in play mode. Helps when working with games that lock mouse cursor. /// @@ -290,6 +328,13 @@ namespace FlaxEditor.Windows { _gameStartTime = Time.UnscaledGameTime; } + + /// + public override void OnPlayEnd() + { + IsMaximized = false; + Cursor = CursorType.Default; + } /// public override void OnShowContextMenu(ContextMenu menu) @@ -442,16 +487,20 @@ namespace FlaxEditor.Windows Screenshot.Capture(string.Empty); return true; case KeyboardKeys.F11: - { if (Root.GetKey(KeyboardKeys.Shift)) { // Unlock mouse in game mode UnlockMouseInPlay(); return true; } + else if (Editor.IsPlayMode) + { + // Maximized game window toggle + IsMaximized = !IsMaximized; + return true; + } break; } - } // Prevent closing the game window tab during a play session if (Editor.StateMachine.IsPlayMode && Editor.Options.Options.Input.CloseTab.Process(this, key))