Merge pull request #1306 from yuriy0/FullScreenGamePreview
Full screen game preview for Atom viewport
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <AzCore/Component/EntityId.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Math/VectorConversions.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Console/IConsole.h>
|
||||
|
||||
// AzFramework
|
||||
@@ -82,6 +83,8 @@
|
||||
#include "AnimationContext.h"
|
||||
#include "Objects/SelectionGroup.h"
|
||||
#include "Core/QtEditorApplication.h"
|
||||
#include "MainWindow.h"
|
||||
#include "LayoutWnd.h"
|
||||
|
||||
// ComponentEntityEditorPlugin
|
||||
#include <Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h>
|
||||
@@ -704,6 +707,11 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
}
|
||||
}
|
||||
SetCurrentCursor(STD_CURSOR_GAME);
|
||||
|
||||
if (ShouldPreviewFullscreen())
|
||||
{
|
||||
StartFullscreenPreview();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_renderViewport)
|
||||
@@ -722,6 +730,11 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
m_bInOrbitMode = false;
|
||||
m_bInZoomMode = false;
|
||||
|
||||
if (m_inFullscreenPreview)
|
||||
{
|
||||
StopFullscreenPreview();
|
||||
}
|
||||
|
||||
RestoreViewportAfterGameMode();
|
||||
}
|
||||
|
||||
@@ -1378,11 +1391,35 @@ void EditorViewportWidget::SetViewportId(int id)
|
||||
{
|
||||
CViewport::SetViewportId(id);
|
||||
|
||||
// Clear the cached debugdisplay pointer. we're about to delete that render viewport, and deleting the render
|
||||
// viewport invalidates the debugdisplay.
|
||||
m_debugDisplay = nullptr;
|
||||
|
||||
// First delete any existing layout
|
||||
// This also deletes any existing render viewport widget (since it will be added to the layout)
|
||||
// Below is the typical method of clearing a QLayout, see e.g. https://doc.qt.io/qt-5/qlayout.html#takeAt
|
||||
if (QLayout* thisLayout = layout())
|
||||
{
|
||||
QLayoutItem* item;
|
||||
while ((item = thisLayout->takeAt(0)) != nullptr)
|
||||
{
|
||||
if (QWidget* widget = item->widget())
|
||||
{
|
||||
delete widget;
|
||||
}
|
||||
thisLayout->removeItem(item);
|
||||
delete item;
|
||||
}
|
||||
delete thisLayout;
|
||||
}
|
||||
|
||||
// Now that we have an ID, we can initialize our viewport.
|
||||
m_renderViewport = new AtomToolsFramework::RenderViewportWidget(this, false);
|
||||
if (!m_renderViewport->InitializeViewportContext(id))
|
||||
{
|
||||
AZ_Warning("EditorViewportWidget", false, "Failed to initialize RenderViewportWidget's ViewportContext");
|
||||
delete m_renderViewport;
|
||||
m_renderViewport = nullptr;
|
||||
return;
|
||||
}
|
||||
auto viewportContext = m_renderViewport->GetViewportContext();
|
||||
@@ -3037,4 +3074,116 @@ float EditorViewportSettings::AngleStep() const
|
||||
return SandboxEditor::AngleSnappingSize();
|
||||
}
|
||||
|
||||
AZ_CVAR_EXTERNED(bool, ed_previewGameInFullscreen_once);
|
||||
|
||||
bool EditorViewportWidget::ShouldPreviewFullscreen() const
|
||||
{
|
||||
CLayoutWnd* layout = GetIEditor()->GetViewManager()->GetLayout();
|
||||
if (!layout)
|
||||
{
|
||||
AZ_Assert(false, "CRenderViewport: No View Manager layout");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Doesn't work with split layout
|
||||
if (layout->GetLayout() != EViewLayout::ET_Layout0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Not supported in VR
|
||||
if (gSettings.bEnableGameModeVR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If level not loaded, don't preview in fullscreen (preview shouldn't work at all without a level, but it does)
|
||||
if (auto ge = GetIEditor()->GetGameEngine())
|
||||
{
|
||||
if (!ge->IsLevelLoaded())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check 'ed_previewGameInFullscreen_once'
|
||||
if (ed_previewGameInFullscreen_once)
|
||||
{
|
||||
ed_previewGameInFullscreen_once = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorViewportWidget::StartFullscreenPreview()
|
||||
{
|
||||
AZ_Assert(!m_inFullscreenPreview, "EditorViewportWidget::StartFullscreenPreview called when already in full screen preview");
|
||||
m_inFullscreenPreview = true;
|
||||
|
||||
// Pick the screen on which the main window lies to use as the screen for the full screen preview
|
||||
const QScreen* screen = MainWindow::instance()->screen();
|
||||
const QRect screenGeometry = screen->geometry();
|
||||
|
||||
// Unparent this and show it, which turns it into a free floating window
|
||||
// Also set style to frameless and disable resizing by user
|
||||
setParent(nullptr);
|
||||
setWindowFlag(Qt::FramelessWindowHint, true);
|
||||
setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, true);
|
||||
setFixedSize(screenGeometry.size());
|
||||
move(QPoint(screenGeometry.x(), screenGeometry.y()));
|
||||
showMaximized();
|
||||
|
||||
// This must be done after unparenting this widget above
|
||||
MainWindow::instance()->hide();
|
||||
}
|
||||
|
||||
void EditorViewportWidget::StopFullscreenPreview()
|
||||
{
|
||||
AZ_Assert(m_inFullscreenPreview, "EditorViewportWidget::StartFullscreenPreview called when not in full screen preview");
|
||||
m_inFullscreenPreview = false;
|
||||
|
||||
// Unset frameless window flags
|
||||
setWindowFlag(Qt::FramelessWindowHint, false);
|
||||
setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, false);
|
||||
|
||||
// Unset fixed size (note that 50x50 is the minimum set in the constructor)
|
||||
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
setMinimumSize(50, 50);
|
||||
|
||||
// Attach this viewport to the primary view pane (whose index is 0).
|
||||
if (CLayoutWnd* layout = GetIEditor()->GetViewManager()->GetLayout())
|
||||
{
|
||||
if (CLayoutViewPane* viewPane = layout->GetViewPaneByIndex(0))
|
||||
{
|
||||
// Force-reattach this viewport to its view pane by first detaching
|
||||
viewPane->DetachViewport();
|
||||
viewPane->AttachViewport(this);
|
||||
|
||||
// Set the main widget of the layout, which causes this widgets size to be bound to the layout
|
||||
// and the viewport title bar to be displayed
|
||||
layout->SetMainWidget(viewPane);
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "CRenderViewport: No view pane with ID 0 (primary view pane)");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "CRenderViewport: No View Manager layout");
|
||||
}
|
||||
|
||||
// Set this as the selected viewport
|
||||
GetIEditor()->GetViewManager()->SelectViewport(this);
|
||||
|
||||
// Show this widget (setting flags may hide it)
|
||||
showNormal();
|
||||
|
||||
// Show the main window
|
||||
MainWindow::instance()->show();
|
||||
}
|
||||
|
||||
#include <moc_EditorViewportWidget.cpp>
|
||||
|
||||
Reference in New Issue
Block a user