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>
|
/// <param name="position">Window location.</param>
|
||||||
public void ShowFloating(Vector2 size, WindowStartPosition position = WindowStartPosition.CenterParent)
|
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();
|
Undock();
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
var winSize = size.LengthSquared > 4 ? size : DefaultSize;
|
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;
|
var windowGUI = window.GUI;
|
||||||
|
|
||||||
// Create dock panel for the window
|
// Create dock panel for the window
|
||||||
var dockPanel = new FloatWindowDockPanel(_masterPanel, windowGUI);
|
var dockPanel = new FloatWindowDockPanel(_masterPanel, windowGUI);
|
||||||
dockPanel.DockWindowInternal(DockState.DockFill, this);
|
dockPanel.DockWindowInternal(DockState.DockFill, this);
|
||||||
|
|
||||||
Visible = true;
|
|
||||||
|
|
||||||
// Perform layout
|
// Perform layout
|
||||||
|
Visible = true;
|
||||||
windowGUI.UnlockChildrenRecursive();
|
windowGUI.UnlockChildrenRecursive();
|
||||||
windowGUI.PerformLayout();
|
windowGUI.PerformLayout();
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace FlaxEditor.GUI.Docking
|
|||||||
public override DockState TryGetDockState(out float splitterValue)
|
public override DockState TryGetDockState(out float splitterValue)
|
||||||
{
|
{
|
||||||
splitterValue = 0.5f;
|
splitterValue = 0.5f;
|
||||||
return DockState.Unknown;
|
return DockState.DockFill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ namespace FlaxEditor.Windows
|
|||||||
private readonly GameRoot _guiRoot;
|
private readonly GameRoot _guiRoot;
|
||||||
private bool _showGUI = true;
|
private bool _showGUI = true;
|
||||||
private bool _showDebugDraw = false;
|
private bool _showDebugDraw = false;
|
||||||
|
private bool _isMaximized = false;
|
||||||
private float _gameStartTime;
|
private float _gameStartTime;
|
||||||
|
private GUI.Docking.DockState _maximizeRestoreDockState;
|
||||||
|
private GUI.Docking.DockPanel _maximizeRestoreDockTo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the viewport.
|
/// Gets the viewport.
|
||||||
@@ -52,6 +55,41 @@ namespace FlaxEditor.Windows
|
|||||||
set => _showDebugDraw = value;
|
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>
|
/// <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.
|
/// 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>
|
/// </summary>
|
||||||
@@ -290,6 +328,13 @@ namespace FlaxEditor.Windows
|
|||||||
{
|
{
|
||||||
_gameStartTime = Time.UnscaledGameTime;
|
_gameStartTime = Time.UnscaledGameTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnPlayEnd()
|
||||||
|
{
|
||||||
|
IsMaximized = false;
|
||||||
|
Cursor = CursorType.Default;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnShowContextMenu(ContextMenu menu)
|
public override void OnShowContextMenu(ContextMenu menu)
|
||||||
@@ -442,16 +487,20 @@ namespace FlaxEditor.Windows
|
|||||||
Screenshot.Capture(string.Empty);
|
Screenshot.Capture(string.Empty);
|
||||||
return true;
|
return true;
|
||||||
case KeyboardKeys.F11:
|
case KeyboardKeys.F11:
|
||||||
{
|
|
||||||
if (Root.GetKey(KeyboardKeys.Shift))
|
if (Root.GetKey(KeyboardKeys.Shift))
|
||||||
{
|
{
|
||||||
// Unlock mouse in game mode
|
// Unlock mouse in game mode
|
||||||
UnlockMouseInPlay();
|
UnlockMouseInPlay();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (Editor.IsPlayMode)
|
||||||
|
{
|
||||||
|
// Maximized game window toggle
|
||||||
|
IsMaximized = !IsMaximized;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent closing the game window tab during a play session
|
// Prevent closing the game window tab during a play session
|
||||||
if (Editor.StateMachine.IsPlayMode && Editor.Options.Options.Input.CloseTab.Process(this, key))
|
if (Editor.StateMachine.IsPlayMode && Editor.Options.Options.Input.CloseTab.Process(this, key))
|
||||||
|
|||||||
Reference in New Issue
Block a user