Merge branch 'play-mode-window-options' of https://github.com/MineBill/FlaxEngine into MineBill-play-mode-window-options

This commit is contained in:
Wojtek Figat
2024-03-04 19:26:31 +01:00
4 changed files with 137 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ namespace FlaxEditor.Windows
private bool _showGUI = true;
private bool _showDebugDraw = false;
private bool _isMaximized = false, _isUnlockingMouse = false;
private bool _isFloating = false, _isBorderless = false;
private bool _cursorVisible = true;
private float _gameStartTime;
private GUI.Docking.DockState _maximizeRestoreDockState;
@@ -68,7 +69,7 @@ namespace FlaxEditor.Windows
}
/// <summary>
/// Gets or sets a value indicating whether game window is maximized (only in play mode).
/// Gets or sets a value indicating whether the game window is maximized (only in play mode).
/// </summary>
private bool IsMaximized
{
@@ -78,20 +79,42 @@ namespace FlaxEditor.Windows
if (_isMaximized == value)
return;
_isMaximized = value;
if (value)
{
IsFloating = true;
var rootWindow = RootWindow;
rootWindow.Maximize();
}
else
{
IsFloating = false;
}
}
}
/// <summary>
/// Gets or sets a value indicating whether the game window is floating (popup, only in play mode).
/// </summary>
private bool IsFloating
{
get => _isFloating;
set
{
if (_isFloating == value)
return;
_isFloating = value;
var rootWindow = RootWindow;
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 Float2(200, 200), Float2.Zero, WindowStartPosition.Manual);
rootWindow = RootWindow;
var size = DefaultSize;
var location = monitorBounds.Location + monitorBounds.Size * 0.5f - size * 0.5f;
ShowFloating(location, size, WindowStartPosition.Manual);
}
if (rootWindow != null && !rootWindow.IsMaximized)
rootWindow.Maximize();
}
else
{
@@ -105,6 +128,33 @@ namespace FlaxEditor.Windows
}
}
/// <summary>
/// Gets or sets a value indicating whether the game window is borderless (only in play mode).
/// </summary>
private bool IsBorderless
{
get => _isBorderless;
set
{
if (_isBorderless == value)
return;
_isBorderless = value;
if (value)
{
IsFloating = true;
var rootWindow = RootWindow;
var monitorBounds = Platform.GetMonitorBounds(rootWindow.RootWindow.Window.ClientPosition);
rootWindow.Window.Position = monitorBounds.Location;
rootWindow.Window.SetBorderless(true);
rootWindow.Window.ClientSize = monitorBounds.Size;
}
else
{
IsFloating = false;
}
}
}
/// <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>
@@ -488,7 +538,9 @@ namespace FlaxEditor.Windows
/// <inheritdoc />
public override void OnPlayEnd()
{
IsFloating = false;
IsMaximized = false;
IsBorderless = false;
Cursor = CursorType.Default;
}
@@ -970,6 +1022,29 @@ namespace FlaxEditor.Windows
Focus();
}
/// <summary>
/// Apply the selected window mode to the game window.
/// </summary>
/// <param name="mode"></param>
public void SetWindowMode(InterfaceOptions.GameWindowMode mode)
{
switch (mode)
{
case InterfaceOptions.GameWindowMode.Docked:
break;
case InterfaceOptions.GameWindowMode.PopupWindow:
IsFloating = true;
break;
case InterfaceOptions.GameWindowMode.MaximizedWindow:
IsMaximized = true;
break;
case InterfaceOptions.GameWindowMode.BorderlessWindow:
IsBorderless = true;
break;
default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
}
}
/// <summary>
/// Takes the screenshot of the current viewport.
/// </summary>