expand play mode game panel focus options

This commit is contained in:
xxSeys1
2024-10-17 19:24:38 +02:00
parent b45f6c1321
commit 21083f8905
3 changed files with 143 additions and 18 deletions

View File

@@ -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");
}
/// <inheritdoc />
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();

View File

@@ -138,6 +138,27 @@ namespace FlaxEditor.Options
AutoUnit,
}
/// <summary>
/// Options for on play mode start panel focus.
/// </summary>
public enum PlayModeFocus
{
/// <summary>
/// Don't change any focus.
/// </summary>
None,
/// <summary>
/// Focus the Game panel.
/// </summary>
GamePanel,
/// <summary>
/// Focus the Game panel. On play mode end focus the previous panel again.
/// </summary>
GamePanelThenBack,
}
/// <summary>
/// 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.
/// </summary>
@@ -341,11 +362,11 @@ namespace FlaxEditor.Options
public bool OutputLogScrollToBottom { get; set; } = true;
/// <summary>
/// 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.
/// </summary>
[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;
/// <summary>
/// Gets or sets a value indicating what action should be taken upon pressing the play button.

View File

@@ -39,6 +39,28 @@ namespace FlaxEditor.Windows
private bool _useAspect = false;
private bool _freeAspect = true;
private List<PlayModeFocusOptions> _focusOptions = new List<PlayModeFocusOptions>()
{
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,
},
};
/// <summary>
/// Gets the viewport.
/// </summary>
@@ -162,9 +184,9 @@ namespace FlaxEditor.Windows
public bool CenterMouseOnFocus { get; set; }
/// <summary>
/// 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.
/// </summary>
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
{
/// <summary>
/// The name.
/// </summary>
public string Name;
/// <summary>
/// The tooltip.
/// </summary>
public string Tooltip;
/// <summary>
/// The type of focus.
/// </summary>
public InterfaceOptions.PlayModeFocus FocusOption;
/// <summary>
/// If the option is active.
/// </summary>
public bool Active;
}
/// <summary>
/// Root control for game UI preview in Editor. Supports basic UI editing via <see cref="UIEditorRoot"/>.
/// </summary>
@@ -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;
}
}
}
};
}
}
/// <inheritdoc />
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();