add game view to "View" menu, add keyboard new keyboard shortcuts to menu and extra options for view flags and view layers

This commit is contained in:
Saas
2025-09-20 16:12:04 +02:00
parent b130b81863
commit fd1e0a4e80
3 changed files with 46 additions and 23 deletions

View File

@@ -864,7 +864,9 @@ namespace FlaxEditor.Viewport
}
});
viewLayers.AddButton("Reset layers", () => Task.ViewLayersMask = LayersMask.Default).Icon = Editor.Instance.Icons.Rotate32;
viewLayers.AddButton("Disable layers", () => Task.ViewLayersMask = new LayersMask(0)).Icon = Editor.Instance.Icons.Rotate32;
viewLayers.AddSeparator();
viewLayers.AddButton("Enable all", () => Task.ViewLayersMask = new LayersMask(-1)).Icon = Editor.Instance.Icons.CheckBoxTick12;
viewLayers.AddButton("Disable all", () => Task.ViewLayersMask = new LayersMask(0)).Icon = Editor.Instance.Icons.Cross12;
viewLayers.AddSeparator();
var layers = LayersAndTagsSettings.GetCurrentLayers();
if (layers != null && layers.Length > 0)
@@ -905,7 +907,9 @@ namespace FlaxEditor.Viewport
}
});
viewFlags.AddButton("Reset flags", () => Task.ViewFlags = ViewFlags.DefaultEditor).Icon = Editor.Instance.Icons.Rotate32;
viewFlags.AddButton("Disable flags", () => Task.ViewFlags = ViewFlags.None).Icon = Editor.Instance.Icons.Rotate32;
viewFlags.AddSeparator();
viewFlags.AddButton("Enable all", () => Task.ViewFlags = ViewFlags.All).Icon = Editor.Instance.Icons.CheckBoxTick12;
viewFlags.AddButton("Disable all", () => Task.ViewFlags = ViewFlags.None).Icon = Editor.Instance.Icons.Cross12;
viewFlags.AddSeparator();
for (int i = 0; i < ViewFlagsValues.Length; i++)
{

View File

@@ -25,6 +25,7 @@ namespace FlaxEditor.Viewport
private readonly Editor _editor;
private readonly ContextMenuButton _showGridButton;
private readonly ContextMenuButton _showNavigationButton;
private readonly ContextMenuButton _toggleGameViewButton;
private SelectionOutline _customSelectionOutline;
/// <summary>
@@ -191,6 +192,7 @@ namespace FlaxEditor.Viewport
: base(Object.New<SceneRenderTask>(), editor.Undo, editor.Scene.Root)
{
_editor = editor;
var inputOptions = _editor.Options.Options.Input;
DragHandlers = new ViewportDragHandlers(this, this, ValidateDragItem, ValidateDragActorType, ValidateDragScriptItem);
// Prepare rendering task
@@ -238,9 +240,14 @@ namespace FlaxEditor.Viewport
_showGridButton.CloseMenuOnClick = false;
// Show navigation widget
_showNavigationButton = ViewWidgetShowMenu.AddButton("Navigation", () => ShowNavigation = !ShowNavigation);
_showNavigationButton = ViewWidgetShowMenu.AddButton("Navigation", inputOptions.ToggleNavMeshVisibility, () => ShowNavigation = !ShowNavigation);
_showNavigationButton.CloseMenuOnClick = false;
// Game View
ViewWidgetButtonMenu.AddSeparator();
_toggleGameViewButton = ViewWidgetButtonMenu.AddButton("Game View", inputOptions.ToggleGameView, ToggleGameView);
_toggleGameViewButton.CloseMenuOnClick = false;
// Create camera widget
ViewWidgetButtonMenu.AddSeparator();
ViewWidgetButtonMenu.AddButton("Create camera here", CreateCameraAtView);
@@ -268,26 +275,7 @@ namespace FlaxEditor.Viewport
InputActions.Add(options => options.ToggleNavMeshVisibility, () => ShowNavigation = !ShowNavigation);
// Game View
InputActions.Add(options => options.ToggleGameView, () =>
{
if (!_gameViewActive)
{
_preGameViewFlags = Task.ViewFlags;
_gameViewWasGridShown = ShowFpsCounter;
_gameViewWasFpsCounterShown = ShowNavigation;
_gameViewWasNagivationShown = Grid.Enabled;
}
Task.ViewFlags = _gameViewActive ? _preGameViewFlags : ViewFlags.GameView;
ShowFpsCounter = _gameViewActive ? _gameViewWasGridShown : false;
ShowNavigation = _gameViewActive ? _gameViewWasFpsCounterShown : false;
Grid.Enabled = _gameViewActive ? _gameViewWasNagivationShown : false;
_gameViewActive = !_gameViewActive;
TransformGizmo.Visible = !_gameViewActive;
SelectionOutline.ShowSelectionOutline = !_gameViewActive;
});
InputActions.Add(options => options.ToggleGameView, ToggleGameView);
}
/// <inheritdoc />
@@ -503,6 +491,32 @@ namespace FlaxEditor.Viewport
TransformGizmo.EndTransforming();
}
/// <summary>
/// Toggles game view view mode on or off.
/// </summary>
public void ToggleGameView()
{
if (!_gameViewActive)
{
_preGameViewFlags = Task.ViewFlags;
_gameViewWasGridShown = ShowFpsCounter;
_gameViewWasFpsCounterShown = ShowNavigation;
_gameViewWasNagivationShown = Grid.Enabled;
}
Task.ViewFlags = _gameViewActive ? _preGameViewFlags : ViewFlags.GameView;
ShowFpsCounter = _gameViewActive ? _gameViewWasGridShown : false;
ShowNavigation = _gameViewActive ? _gameViewWasFpsCounterShown : false;
Grid.Enabled = _gameViewActive ? _gameViewWasNagivationShown : false;
_gameViewActive = !_gameViewActive;
TransformGizmo.Visible = !_gameViewActive;
SelectionOutline.ShowSelectionOutline = !_gameViewActive;
_toggleGameViewButton.Icon = _gameViewActive ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
}
/// <inheritdoc />
public override void OnLostFocus()
{

View File

@@ -1087,6 +1087,11 @@ API_ENUM(Attributes="Flags") enum class ViewFlags : uint64
/// Default flags for game view.
/// </summary>
GameView = AntiAliasing | Shadows | Reflections | SSR | AO | GI | DirectionalLights | PointLights | SpotLights | SkyLights | Sky | Fog | SpecularLight | Decals | CustomPostProcess | Bloom | ToneMapping | EyeAdaptation | CameraArtifacts | LensFlares | MotionBlur | ContactShadows | DepthOfField,
/// <summary>
/// All flags enabled.
/// </summary>
All = None | DebugDraw | EditorSprites | Reflections | SSR | AO | GI | DirectionalLights | PointLights | SpotLights | SkyLights | Shadows | SpecularLight | AntiAliasing | CustomPostProcess | Bloom | ToneMapping | EyeAdaptation | CameraArtifacts | LensFlares | Decals | DepthOfField | PhysicsDebug | Fog | MotionBlur | ContactShadows | GlobalSDF | Sky | LightsDebug,
};
DECLARE_ENUM_OPERATORS(ViewFlags);