Add F11 shortcut to maximize Game window during play-mode in Editor
This commit is contained in:
@@ -169,21 +169,30 @@ namespace FlaxEditor.GUI.Docking
|
||||
/// <param name="position">Window location.</param>
|
||||
public void ShowFloating(Vector2 size, WindowStartPosition position = WindowStartPosition.CenterParent)
|
||||
{
|
||||
// Undock
|
||||
ShowFloating(new Vector2(200, 200), size, position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the window in a floating state.
|
||||
/// </summary>
|
||||
/// <param name="location">Window location.</param>
|
||||
/// <param name="size">Window size, set Vector2.Zero to use default.</param>
|
||||
/// <param name="position">Window location.</param>
|
||||
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();
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace FlaxEditor.GUI.Docking
|
||||
public override DockState TryGetDockState(out float splitterValue)
|
||||
{
|
||||
splitterValue = 0.5f;
|
||||
return DockState.Unknown;
|
||||
return DockState.DockFill;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the viewport.
|
||||
@@ -52,6 +55,41 @@ namespace FlaxEditor.Windows
|
||||
set => _showDebugDraw = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether game window is maximized (only in play mode).
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
@@ -291,6 +329,13 @@ namespace FlaxEditor.Windows
|
||||
_gameStartTime = Time.UnscaledGameTime;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnPlayEnd()
|
||||
{
|
||||
IsMaximized = false;
|
||||
Cursor = CursorType.Default;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnShowContextMenu(ContextMenu menu)
|
||||
{
|
||||
@@ -442,15 +487,19 @@ 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;
|
||||
}
|
||||
break;
|
||||
else if (Editor.IsPlayMode)
|
||||
{
|
||||
// Maximized game window toggle
|
||||
IsMaximized = !IsMaximized;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Prevent closing the game window tab during a play session
|
||||
|
||||
Reference in New Issue
Block a user