diff --git a/Source/Editor/Modules/SimulationModule.cs b/Source/Editor/Modules/SimulationModule.cs
index 6f54ab10d..dd83d7553 100644
--- a/Source/Editor/Modules/SimulationModule.cs
+++ b/Source/Editor/Modules/SimulationModule.cs
@@ -2,6 +2,7 @@
using System;
using System.Threading;
+using FlaxEditor.GUI.Docking;
using FlaxEditor.States;
using FlaxEditor.Windows;
using FlaxEngine;
@@ -20,6 +21,7 @@ namespace FlaxEditor.Modules
private bool _updateOrFixedUpdateWasCalled;
private long _breakpointHangFlag;
private EditorWindow _enterPlayFocusedWindow;
+ private DockWindow _previousWindow;
private Guid[] _scenesToReload;
internal SimulationModule(Editor editor)
@@ -272,23 +274,46 @@ namespace FlaxEditor.Modules
// Show Game widow if hidden
if (gameWin != null)
{
- if (gameWin.FocusOnPlay)
- gameWin.FocusGameViewport();
+ switch (gameWin.FocusOnPlayOption)
+ {
+ case Options.InterfaceOptions.PlayModeFocus.None:
+ break;
+
+ case Options.InterfaceOptions.PlayModeFocus.GamePanel:
+ gameWin.FocusGameViewport();
+ break;
+
+ case Options.InterfaceOptions.PlayModeFocus.GamePanelThenBack:
+ _previousWindow = gameWin.ParentDockPanel.SelectedTab;
+ gameWin.FocusGameViewport();
+ break;
+ }
+
gameWin.SetWindowMode(Editor.Options.Options.Interface.DefaultGameWindowMode);
}
-
Editor.Log("[PlayMode] Enter");
}
///
public override void OnPlayEnd()
{
- // Restore focused window before play mode
- if (_enterPlayFocusedWindow != null)
+ var gameWin = Editor.Windows.GameWin;
+
+ switch (gameWin.FocusOnPlayOption)
{
- _enterPlayFocusedWindow.FocusOrShow();
- _enterPlayFocusedWindow = null;
+ case Options.InterfaceOptions.PlayModeFocus.None:
+ break;
+
+ case Options.InterfaceOptions.PlayModeFocus.GamePanel:
+ break;
+
+ case Options.InterfaceOptions.PlayModeFocus.GamePanelThenBack:
+ if (!Editor.Windows.GameWin.ParentDockPanel.ContainsTab(_previousWindow))
+ break;
+
+ _previousWindow.Focus();
+ break;
}
Editor.UI.UncheckPauseButton();
diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs
index d8493a70a..315853041 100644
--- a/Source/Editor/Options/InterfaceOptions.cs
+++ b/Source/Editor/Options/InterfaceOptions.cs
@@ -138,6 +138,27 @@ namespace FlaxEditor.Options
AutoUnit,
}
+ ///
+ /// Options for on play mode start panel focus.
+ ///
+ public enum PlayModeFocus
+ {
+ ///
+ /// Don't change any focus.
+ ///
+ None,
+
+ ///
+ /// Focus the Game panel.
+ ///
+ GamePanel,
+
+ ///
+ /// Focus the Game panel. On play mode end focus the previous panel again.
+ ///
+ GamePanelThenBack,
+ }
+
///
/// Gets or sets the Editor User Interface scale. Applied to all UI elements, windows and text. Can be used to scale the interface up on a bigger display. Editor restart required.
///
@@ -341,11 +362,11 @@ namespace FlaxEditor.Options
public bool OutputLogScrollToBottom { get; set; } = true;
///
- /// Gets or sets a value indicating whether auto-focus game window on play mode start.
+ /// Gets or sets a value indicating what panel should be focused when play mode start.
///
- [DefaultValue(true)]
- [EditorDisplay("Play In-Editor", "Focus Game Window On Play"), EditorOrder(500), Tooltip("Determines whether auto-focus game window on play mode start.")]
- public bool FocusGameWinOnPlay { get; set; } = true;
+ [DefaultValue(PlayModeFocus.GamePanel)]
+ [EditorDisplay("Play In-Editor", "Focus On Play"), EditorOrder(500), Tooltip("Set what panel to focus on play mode start.")]
+ public PlayModeFocus FocusOnPlayMode { get; set; } = PlayModeFocus.GamePanel;
///
/// Gets or sets a value indicating what action should be taken upon pressing the play button.
diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs
index 56e4c4380..a2e831576 100644
--- a/Source/Editor/Windows/GameWindow.cs
+++ b/Source/Editor/Windows/GameWindow.cs
@@ -39,6 +39,28 @@ namespace FlaxEditor.Windows
private bool _useAspect = false;
private bool _freeAspect = true;
+ private List _focusOptions = new List()
+ {
+ new PlayModeFocusOptions
+ {
+ Name = "None",
+ Tooltip = "Don't change focus.",
+ FocusOption = InterfaceOptions.PlayModeFocus.None,
+ },
+ new PlayModeFocusOptions
+ {
+ Name = "Game Panel",
+ Tooltip = "Focus the Game panel.",
+ FocusOption = InterfaceOptions.PlayModeFocus.GamePanel,
+ },
+ new PlayModeFocusOptions
+ {
+ Name = "Game Panel Then Back",
+ Tooltip = "Focus the Game panel. On play mode end focus the previous panel again.",
+ FocusOption = InterfaceOptions.PlayModeFocus.GamePanelThenBack,
+ },
+ };
+
///
/// Gets the viewport.
///
@@ -162,9 +184,9 @@ namespace FlaxEditor.Windows
public bool CenterMouseOnFocus { get; set; }
///
- /// Gets or sets a value indicating whether auto-focus game window on play mode start.
+ /// Gets or sets a value indicating what panel should be focused when play mode start.
///
- public bool FocusOnPlay { get; set; }
+ public InterfaceOptions.PlayModeFocus FocusOnPlayOption { get; set; }
private enum ViewportScaleType
{
@@ -195,6 +217,29 @@ namespace FlaxEditor.Windows
public bool Active;
}
+ private class PlayModeFocusOptions
+ {
+ ///
+ /// The name.
+ ///
+ public string Name;
+
+ ///
+ /// The tooltip.
+ ///
+ public string Tooltip;
+
+ ///
+ /// The type of focus.
+ ///
+ public InterfaceOptions.PlayModeFocus FocusOption;
+
+ ///
+ /// If the option is active.
+ ///
+ public bool Active;
+ }
+
///
/// Root control for game UI preview in Editor. Supports basic UI editing via .
///
@@ -430,7 +475,7 @@ namespace FlaxEditor.Windows
private void OnOptionsChanged(EditorOptions options)
{
CenterMouseOnFocus = options.Interface.CenterMouseOnGameWinFocus;
- FocusOnPlay = options.Interface.FocusGameWinOnPlay;
+ FocusOnPlayOption = options.Interface.FocusOnPlayMode;
}
private void PlayingStateOnSceneDuplicating()
@@ -488,6 +533,41 @@ namespace FlaxEditor.Windows
}
}
+ // TODO: Move this to other generate method
+ private void GenerateFocusOptionsContextMenu(ContextMenu pfMenu)
+ {
+ foreach (PlayModeFocusOptions f in _focusOptions)
+ {
+ f.Active = f.FocusOption == FocusOnPlayOption;
+
+ var button = pfMenu.AddButton(f.Name);
+ button.CloseMenuOnClick = false;
+ button.Tag = f;
+ button.TooltipText = f.Tooltip;
+ button.Icon = f.Active ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
+ button.Clicked += () =>
+ {
+ foreach (var child in pfMenu.Items)
+ {
+ if (child is ContextMenuButton cmb && cmb.Tag is PlayModeFocusOptions p)
+ {
+ if (cmb == button)
+ {
+ p.Active = true;
+ button.Icon = Style.Current.CheckBoxTick;
+ FocusOnPlayOption = p.FocusOption;
+ }
+ else if (p.Active)
+ {
+ cmb.Icon = SpriteHandle.Invalid;
+ p.Active = false;
+ }
+ }
+ }
+ };
+ }
+ }
+
///
public override void OnShowContextMenu(ContextMenu menu)
{
@@ -495,10 +575,9 @@ namespace FlaxEditor.Windows
// Focus on play
{
- var focus = menu.AddButton("Start Focused");
- focus.CloseMenuOnClick = false;
- var checkbox = new CheckBox(140, 2, FocusOnPlay) { Parent = focus };
- checkbox.StateChanged += state => FocusOnPlay = state.Checked;
+ var pfMenu = menu.AddChildMenu("Play Mode Focus Override").ContextMenu;
+
+ GenerateFocusOptionsContextMenu(pfMenu);
}
menu.AddSeparator();