diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/camera.svg b/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/camera.svg new file mode 100644 index 0000000000..7fa565d5b8 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/camera.svg @@ -0,0 +1,9 @@ + + + Camera + + + + + + \ No newline at end of file diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/debug.svg b/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/debug.svg new file mode 100644 index 0000000000..938e4e3342 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/debug.svg @@ -0,0 +1,7 @@ + + + debug + + + + \ No newline at end of file diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/resolution.svg b/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/resolution.svg new file mode 100644 index 0000000000..2434d6707d --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Images/Menu/resolution.svg @@ -0,0 +1,7 @@ + + + resolution + + + + \ No newline at end of file diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Images/resources.qrc b/Code/Framework/AzQtComponents/AzQtComponents/Images/resources.qrc index 7b0c6530ab..2487917f67 100644 --- a/Code/Framework/AzQtComponents/AzQtComponents/Images/resources.qrc +++ b/Code/Framework/AzQtComponents/AzQtComponents/Images/resources.qrc @@ -15,4 +15,9 @@ Notifications/download.svg Notifications/link.svg + + Menu/resolution.svg + Menu/debug.svg + Menu/camera.svg + diff --git a/Code/Sandbox/Editor/InfoBar.cpp b/Code/Sandbox/Editor/InfoBar.cpp deleted file mode 100644 index 14ef2e7f05..0000000000 --- a/Code/Sandbox/Editor/InfoBar.cpp +++ /dev/null @@ -1,394 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "InfoBar.h" - -// Editor -#include "MainWindow.h" -#include "DisplaySettings.h" -#include "GameEngine.h" -#include "Include/ITransformManipulator.h" -#include "ActionManager.h" -#include "Settings.h" -#include "Include/IObjectManager.h" -#include "MathConversion.h" - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -#include - -#include - -void BeautifyEulerAngles(Vec3& v) -{ - if (v.x + v.y + v.z >= 360.0f) - { - v.x = 180.0f - v.x; - v.y = 180.0f - v.y; - v.z = 180.0f - v.z; - } -} - -///////////////////////////////////////////////////////////////////////////// -// CInfoBar dialog -CInfoBar::CInfoBar(QWidget* parent) - : QWidget(parent) - , ui(new Ui::CInfoBar) -{ - ui->setupUi(this); - - m_bSelectionChanged = false; - m_bDragMode = false; - m_prevMoveSpeed = 0; - m_currValue = Vec3(-111, +222, -333); //this wasn't initialized. I don't know what a good value is - m_oldMainVolume = 1.0f; - - GetIEditor()->RegisterNotifyListener(this); - - //audio request setup - m_oMuteAudioRequest.pData = &m_oMuteAudioRequestData; - m_oUnmuteAudioRequest.pData = &m_oUnmuteAudioRequestData; - - OnInitDialog(); - - auto comboBoxTextChanged = static_cast(&QComboBox::currentTextChanged); - connect(ui->m_moveSpeed, comboBoxTextChanged, this, &CInfoBar::OnUpdateMoveSpeedText); - connect(ui->m_moveSpeed->lineEdit(), &QLineEdit::returnPressed, this, &CInfoBar::OnSpeedComboBoxEnter); - - // Hide some buttons from the expander menu - AzQtComponents::Style::addClass(ui->m_physDoStepBtn, "expanderMenu_hide"); - AzQtComponents::Style::addClass(ui->m_physSingleStepBtn, "expanderMenu_hide"); - - connect(ui->m_physicsBtn, &QToolButton::clicked, this, &CInfoBar::OnBnClickedPhysics); - connect(ui->m_physSingleStepBtn, &QToolButton::clicked, this, &CInfoBar::OnBnClickedSingleStepPhys); - connect(ui->m_physDoStepBtn, &QToolButton::clicked, this, &CInfoBar::OnBnClickedDoStepPhys); - connect(ui->m_syncPlayerBtn, &QToolButton::clicked, this, &CInfoBar::OnBnClickedSyncplayer); - connect(ui->m_gotoPos, &QToolButton::clicked, this, &CInfoBar::OnBnClickedGotoPosition); - connect(ui->m_muteBtn, &QToolButton::clicked, this, &CInfoBar::OnBnClickedMuteAudio); - connect(ui->m_vrBtn, &QToolButton::clicked, this, &CInfoBar::OnBnClickedEnableVR); - - connect(this, &CInfoBar::ActionTriggered, MainWindow::instance()->GetActionManager(), &ActionManager::ActionTriggered); - - connect(ui->m_physicsBtn, &QAbstractButton::toggled, ui->m_physicsBtn, [this](bool checked) { - ui->m_physicsBtn->setToolTip(checked ? tr("Stop Simulation (Ctrl+P)") : tr("Simulate (Ctrl+P)")); - }); - connect(ui->m_physSingleStepBtn, &QAbstractButton::toggled, ui->m_physSingleStepBtn, [this](bool checked) { - ui->m_physSingleStepBtn->setToolTip(checked ? tr("Disable Physics/AI Single-step Mode ('<' in Game Mode)") : tr("Enable Physics/AI Single-step Mode ('<' in Game Mode)")); - }); - connect(ui->m_syncPlayerBtn, &QAbstractButton::toggled, ui->m_syncPlayerBtn, [this](bool checked) { - ui->m_syncPlayerBtn->setToolTip(checked ? tr("Synchronize Player with Camera") : tr("Move Player and Camera Separately")); - }); - connect(ui->m_muteBtn, &QAbstractButton::toggled, ui->m_muteBtn, [this](bool checked) { - ui->m_muteBtn->setToolTip(checked ? tr("Un-mute Audio") : tr("Mute Audio")); - }); - connect(ui->m_vrBtn, &QAbstractButton::toggled, ui->m_vrBtn, [this](bool checked) { - ui->m_vrBtn->setToolTip(checked ? tr("Disable VR Preview") : tr("Enable VR Preview")); - }); - - ui->m_moveSpeed->setValidator(new QDoubleValidator(m_minSpeed, m_maxSpeed, m_numDecimals, ui->m_moveSpeed)); - - // Save off the move speed here since setting up the combo box can cause it to update values in the background. - float cameraMoveSpeed = gSettings.cameraMoveSpeed; - - // Populate the presets in the ComboBox - for (float presetValue : m_speedPresetValues) - { - ui->m_moveSpeed->addItem(QString().setNum(presetValue, 'f', m_numDecimals), presetValue); - } - - SetSpeedComboBox(cameraMoveSpeed); - - ui->m_moveSpeed->setInsertPolicy(QComboBox::NoInsert); - - using namespace AzToolsFramework::ComponentModeFramework; - EditorComponentModeNotificationBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId()); -} - -////////////////////////////////////////////////////////////////////////// -CInfoBar::~CInfoBar() -{ - using namespace AzToolsFramework::ComponentModeFramework; - EditorComponentModeNotificationBus::Handler::BusDisconnect(); - - GetIEditor()->UnregisterNotifyListener(this); - - AZ::VR::VREventBus::Handler::BusDisconnect(); -} - -////////////////////////////////////////////////////////////////////////// -void CInfoBar::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - if (event == eNotify_OnIdleUpdate) - { - IdleUpdate(); - } - else if (event == eNotify_OnBeginGameMode || event == eNotify_OnEndGameMode) - { - // Audio: determine muted state of audio - //m_bMuted = gEnv->pAudioSystem->GetMainVolume() == 0.f; - ui->m_muteBtn->setChecked(gSettings.bMuteAudio); - } - else if (event == eNotify_OnBeginLoad || event == eNotify_OnCloseScene) - { - // make sure AI/Physics is disabled on level load (CE-4229) - if (GetIEditor()->GetGameEngine()->GetSimulationMode()) - { - OnBnClickedPhysics(); - } - - ui->m_physicsBtn->setEnabled(false); - ui->m_physSingleStepBtn->setEnabled(false); - ui->m_physDoStepBtn->setEnabled(false); - } - else if (event == eNotify_OnEndLoad || event == eNotify_OnEndNewScene) - { - ui->m_physicsBtn->setEnabled(true); - ui->m_physSingleStepBtn->setEnabled(true); - ui->m_physDoStepBtn->setEnabled(true); - } - else if (event == eNotify_OnSelectionChange) - { - m_bSelectionChanged = true; - } -} - -void CInfoBar::IdleUpdate() -{ - if (!m_idleUpdateEnabled) - { - return; - } - - bool updateUI = false; - // Update Width/Height of selection rectangle. - AABB box; - GetIEditor()->GetSelectedRegion(box); - float width = box.max.x - box.min.x; - float height = box.max.y - box.min.y; - if (m_width != width || m_height != height) - { - m_width = width; - m_height = height; - updateUI = true; - } - - Vec3 marker = GetIEditor()->GetMarkerPosition(); - - int selectedEntitiesCount = 0; - AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult( - selectedEntitiesCount, &AzToolsFramework::ToolsApplicationRequests::GetSelectedEntitiesCount); - if (selectedEntitiesCount != m_numSelected) - { - m_numSelected = selectedEntitiesCount; - updateUI = true; - } - - QString str; - if (updateUI) - { - if (m_numSelected == 0) - { - str = tr("None Selected"); - } - else if (m_numSelected == 1) - { - str = tr("1 Object Selected"); - } - else - { - str = tr("%1 Objects Selected").arg(m_numSelected); - } - - ui->m_statusText->setText(str); - m_sLastText = str; - } - - if (gSettings.cameraMoveSpeed != m_prevMoveSpeed && - !ui->m_moveSpeed->lineEdit()->hasFocus()) - { - m_prevMoveSpeed = gSettings.cameraMoveSpeed; - SetSpeedComboBox(gSettings.cameraMoveSpeed); - } - - { - bool bPhysics = GetIEditor()->GetGameEngine()->GetSimulationMode(); - if ((ui->m_physicsBtn->isChecked() && !bPhysics) || - (!ui->m_physicsBtn->isChecked() && bPhysics)) - { - ui->m_physicsBtn->setChecked(bPhysics); - } - - // Unsupported for Phyics:: atm - bool bSingleStep = false; - if (ui->m_physSingleStepBtn->isChecked() != bSingleStep) - { - ui->m_physSingleStepBtn->setChecked(bSingleStep); - } - - bool bSyncPlayer = GetIEditor()->GetGameEngine()->IsSyncPlayerPosition(); - if ((!ui->m_syncPlayerBtn->isChecked() && !bSyncPlayer) || - (ui->m_syncPlayerBtn->isChecked() && bSyncPlayer)) - { - ui->m_syncPlayerBtn->setChecked(!bSyncPlayer); - } - } - - // if our selection changed, or if our display values are out of date - if (m_bSelectionChanged) - { - m_bSelectionChanged = false; - } -} - -inline double Round(double fVal, double fStep) -{ - if (fStep > 0.f) - { - fVal = int_round(fVal / fStep) * fStep; - } - return fVal; -} - -void CInfoBar::OnUpdateMoveSpeedText(const QString& text) -{ - gSettings.cameraMoveSpeed = aznumeric_cast(Round(text.toDouble(), m_speedStep)); -} - -void CInfoBar::OnSpeedComboBoxEnter() -{ - ui->m_moveSpeed->clearFocus(); -} - -void CInfoBar::OnInitDialog() -{ - QFontMetrics metrics({}); - int width = metrics.boundingRect("-9999.99").width() * m_fieldWidthMultiplier; - - ui->m_moveSpeed->setFixedWidth(width); - - ui->m_physicsBtn->setEnabled(false); - ui->m_physSingleStepBtn->setEnabled(false); - ui->m_physDoStepBtn->setEnabled(false); - - ui->m_muteBtn->setChecked(gSettings.bMuteAudio); - Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequest, gSettings.bMuteAudio ? m_oMuteAudioRequest : m_oUnmuteAudioRequest); - - //This is here just in case this class hasn't been created before - //a VR headset was initialized - ui->m_vrBtn->setEnabled(false); - if (AZ::VR::HMDDeviceRequestBus::GetTotalNumOfEventHandlers() != 0) - { - ui->m_vrBtn->setEnabled(true); - } - - AZ::VR::VREventBus::Handler::BusConnect(); -} - -void CInfoBar::OnHMDInitialized() -{ - ui->m_vrBtn->setEnabled(true); -} - -void CInfoBar::OnHMDShutdown() -{ - ui->m_vrBtn->setEnabled(false); -} - -void CInfoBar::OnBnClickedTerrainCollision() -{ - emit ActionTriggered(ID_TERRAIN_COLLISION); -} - -void CInfoBar::OnBnClickedPhysics() -{ - if (!ui->m_physicsBtn->isEnabled()) - { - return; - } - - bool bPhysics = GetIEditor()->GetGameEngine()->GetSimulationMode(); - ui->m_physicsBtn->setChecked(bPhysics); - emit ActionTriggered(ID_SWITCH_PHYSICS); - - if (bPhysics && ui->m_physSingleStepBtn->isChecked()) - { - OnBnClickedSingleStepPhys(); - } -} - -void CInfoBar::OnBnClickedSingleStepPhys() -{ -} - -void CInfoBar::OnBnClickedDoStepPhys() -{ -} - -////////////////////////////////////////////////////////////////////////// -void CInfoBar::OnBnClickedSyncplayer() -{ - emit ActionTriggered(ID_GAME_SYNCPLAYER); -} - -////////////////////////////////////////////////////////////////////////// -void CInfoBar::OnBnClickedGotoPosition() -{ - emit ActionTriggered(ID_DISPLAY_GOTOPOSITION); -} - -////////////////////////////////////////////////////////////////////////// -void CInfoBar::OnBnClickedMuteAudio() -{ - gSettings.bMuteAudio = !gSettings.bMuteAudio; - - Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequest, gSettings.bMuteAudio ? m_oMuteAudioRequest : m_oUnmuteAudioRequest); - - ui->m_muteBtn->setChecked(gSettings.bMuteAudio); -} - -void CInfoBar::OnBnClickedEnableVR() -{ - gSettings.bEnableGameModeVR = !gSettings.bEnableGameModeVR; - ui->m_vrBtn->setChecked(gSettings.bEnableGameModeVR); -} - -void CInfoBar::EnteredComponentMode(const AZStd::vector& /*componentModeTypes*/) -{ - ui->m_physicsBtn->setDisabled(true); -} - -void CInfoBar::LeftComponentMode(const AZStd::vector& /*componentModeTypes*/) -{ - ui->m_physicsBtn->setEnabled(true); -} - -void CInfoBar::SetSpeedComboBox(double value) -{ - value = AZStd::clamp(Round(value, m_speedStep), m_minSpeed, m_maxSpeed); - - int index = ui->m_moveSpeed->findData(value); - if (index != -1) - { - ui->m_moveSpeed->setCurrentIndex(index); - } - else - { - ui->m_moveSpeed->lineEdit()->setText(QString().setNum(value, 'f', m_numDecimals)); - } -} - -#include diff --git a/Code/Sandbox/Editor/InfoBar.h b/Code/Sandbox/Editor/InfoBar.h deleted file mode 100644 index 6e547d46c6..0000000000 --- a/Code/Sandbox/Editor/InfoBar.h +++ /dev/null @@ -1,121 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_INFOBAR_H -#define CRYINCLUDE_EDITOR_INFOBAR_H - -#pragma once -// InfoBar.h : header file -// - -#if !defined(Q_MOC_RUN) -#include -#include -#include -#endif - -///////////////////////////////////////////////////////////////////////////// -// CInfoBar dialog - -namespace Ui { - class CInfoBar; -} - -class CInfoBar - : public QWidget - , public IEditorNotifyListener - , public AZ::VR::VREventBus::Handler - , private AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler -{ - Q_OBJECT - - // Construction -public: - CInfoBar(QWidget* parent = nullptr); - ~CInfoBar(); - - // Toggle the mute audio button - void ToggleAudio() { OnBnClickedMuteAudio(); } - void SetSpeedComboBox(double value); - -Q_SIGNALS: - void ActionTriggered(int command); - - // Implementation -protected: - void IdleUpdate(); - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event); - - virtual void OnOK() {}; - virtual void OnCancel() {}; - - void OnBnClickedSyncplayer(); - void OnBnClickedGotoPosition(); - - void OnSpeedComboBoxEnter(); - void OnUpdateMoveSpeedText(const QString&); - void OnBnClickedTerrainCollision(); - void OnBnClickedPhysics(); - void OnBnClickedSingleStepPhys(); - void OnBnClickedDoStepPhys(); - void OnBnClickedMuteAudio(); - void OnBnClickedEnableVR(); - void OnInitDialog(); - - ////////////////////////////////////////////////////////////////////////// - /// VR Event Bus Implementation - ////////////////////////////////////////////////////////////////////////// - void OnHMDInitialized() override; - void OnHMDShutdown() override; - ////////////////////////////////////////////////////////////////////////// - - // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; - - float m_width, m_height; - //int m_heightMapX,m_heightMapY; - double m_fieldWidthMultiplier = 1.8; - - int m_numSelected; - float m_prevMoveSpeed; - - // Speed combobox/lineEdit settings - double m_minSpeed = 0.1; - double m_maxSpeed = 100.0; - double m_speedStep = 0.1; - int m_numDecimals = 1; - - // Speed presets - float m_speedPresetValues[3] = { 0.1f, 1.0f, 10.0f }; - - bool m_bSelectionChanged; - - bool m_bDragMode; - QString m_sLastText; - - Vec3 m_lastValue; - Vec3 m_currValue; - float m_oldMainVolume; - - Audio::SAudioRequest m_oMuteAudioRequest; - Audio::SAudioManagerRequestData m_oMuteAudioRequestData; - Audio::SAudioRequest m_oUnmuteAudioRequest; - Audio::SAudioManagerRequestData m_oUnmuteAudioRequestData; - - QScopedPointer ui; - - bool m_idleUpdateEnabled = true; -}; - -#endif // CRYINCLUDE_EDITOR_INFOBAR_H diff --git a/Code/Sandbox/Editor/InfoBar.ui b/Code/Sandbox/Editor/InfoBar.ui deleted file mode 100644 index 84207629df..0000000000 --- a/Code/Sandbox/Editor/InfoBar.ui +++ /dev/null @@ -1,333 +0,0 @@ - - - CInfoBar - - - - 0 - 0 - 1600 - 27 - - - - - 0 - 0 - - - - true - - - b - - - - 0 - - - QLayout::SetFixedSize - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - No Objects Selected - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Go to Position - - - Go to Position - - - - :/InfoBar/GotoLocation-default.svg:/InfoBar/GotoLocation-default.svg - - - - 22 - 18 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 1 - 18 - - - - - - - - Speed - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Camera Movement Speed - - - true - - - - - - - - 0 - 0 - - - - Synchronize Player with Camera - - - Synchronize Player with Camera - - - - :/InfoBar/NoPlayerSync-default.svg - :/InfoBar/NoPlayerSync-selected.svg - :/InfoBar/NoPlayerSync-default.svg - - - - 18 - 18 - - - - true - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 1 - 18 - - - - - - - - Simulate (Ctrl+P) - - - Simulate (Ctrl+P) - - - - :/InfoBar/PhysicsCol-default.svg:/InfoBar/PhysicsCol-default.svg - - - - 18 - 18 - - - - true - - - - - - - - 0 - 0 - - - - Enable Physics/AI Single-step Mode ('<' in Game Mode) - - - Enable Physics/AI Single-step Mode ('<' in Game Mode) - - - - :/InfoBar/Pause-default.svg:/InfoBar/Pause-default.svg - - - - 18 - 18 - - - - true - - - false - - - - - - - - 0 - 0 - - - - Perform a Single Physics/AI Simulation Step ('>' in Game Mode) - - - Perform a Single Physics/AI Simulation Step ('>' in Game Mode) - - - - :/InfoBar/PausePlay-default.svg:/InfoBar/PausePlay-default.svg - - - - 18 - 18 - - - - false - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 1 - 18 - - - - - - - - - 0 - 0 - - - - Mute Audio - - - Mute Audio - - - - :/InfoBar/Mute-default.svg:/InfoBar/Mute-default.svg - - - - 18 - 18 - - - - true - - - - - - - - 0 - 0 - - - - Enable VR Preview - - - Enable VR Preview - - - - :/InfoBar/VR-default.svg:/InfoBar/VR-default.svg - - - - 18 - 18 - - - - true - - - - - - - - - - diff --git a/Code/Sandbox/Editor/LayoutWnd.cpp b/Code/Sandbox/Editor/LayoutWnd.cpp index 54389f30c1..1de4d9584a 100644 --- a/Code/Sandbox/Editor/LayoutWnd.cpp +++ b/Code/Sandbox/Editor/LayoutWnd.cpp @@ -94,134 +94,12 @@ void CLayoutSplitter::CreateLayoutView(int row, int col, int id) viewPane->SetId(id); } -////////////////////////////////////////////////////////////////////////// -// InfoBarExpanderWatcher -////////////////////////////////////////////////////////////////////////// - -class InfoBarExpanderWatcher - : public QObject -{ -public: - InfoBarExpanderWatcher(QObject* parent = nullptr) - : QObject(parent) - { - } - - bool eventFilter(QObject* obj, QEvent* event) override - { - switch (event->type()) - { - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - { - if (qobject_cast(obj)) - { - auto mouseEvent = static_cast(event); - auto expansion = qobject_cast(obj); - - expansion->setPopupMode(QToolButton::InstantPopup); - auto menu = new QMenu(expansion); - - auto toolbar = qobject_cast(expansion->parentWidget()); - - auto toolWidgets = toolbar->findChildren(); - - if (toolWidgets.count() > 0) - { - for (auto toolWidget : toolWidgets) - { - if (AzQtComponents::Style::hasClass(toolWidget, "expanderMenu_hide")) - { - continue; - } - - if (auto toolButton = qobject_cast(toolWidget)) - { - if (!toolButton->isVisible()) - { - // Skip some empty buttons - if (toolButton->text().isEmpty()) - { - continue; - } - - QString plainText = QTextDocumentFragment::fromHtml(toolButton->text()).toPlainText(); - QAction* action = new QAction(plainText, menu); - - if (!toolButton->isEnabled()) - { - action->setEnabled(false); - } - - connect(action, &QAction::triggered, toolButton, &QToolButton::clicked); - - if (toolButton->isCheckable()) - { - action->setCheckable(true); - } - - action->setChecked(toolButton->isChecked()); - - menu->addAction(action); - } - } - else if (auto toolCombo = qobject_cast(toolWidget)) - { - // Add custom menu for Speed - if (toolCombo->objectName() == "m_moveSpeed") - { - double currentValue = toolCombo->lineEdit()->text().toDouble(); - - QMenu* newMenu = menu->addMenu(QString("Speed: %1").arg(currentValue)); - - double presets[] = { 0.1, 1.0, 10.0 }; - for (double preset : presets) - { - QAction* presetAction = new QAction(newMenu); - presetAction->setText(QString::number(preset)); - - connect(presetAction, &QAction::triggered, this, [preset, this]() { - if (m_infoBar) - { - m_infoBar->SetSpeedComboBox(preset); - } - }); - - newMenu->addAction(presetAction); - } - } - } - } - } - - menu->exec(mouseEvent->globalPos()); - return true; - } - - break; - } - } - - return QObject::eventFilter(obj, event); - } - - void SetInfoBar(CInfoBar* infoBar) - { - m_infoBar = infoBar; - } - -private: - CInfoBar* m_infoBar = nullptr; -}; - ////////////////////////////////////////////////////////////////////////// // CLayoutWnd ////////////////////////////////////////////////////////////////////////// CLayoutWnd::CLayoutWnd(QSettings* settings, QWidget* parent) : AzQtComponents::ToolBarArea(parent) , m_settings(settings) - , m_expanderWatcher(new InfoBarExpanderWatcher(this)) { m_bMaximized = false; m_maximizedView = 0; @@ -230,23 +108,8 @@ CLayoutWnd::CLayoutWnd(QSettings* settings, QWidget* parent) m_maximizedViewId = 0; m_infoBarSize = QSize(0, 0); - m_infoBar = new CInfoBar(this); connect(qApp, &QApplication::focusChanged, this, &CLayoutWnd::OnFocusChanged); - m_expanderWatcher->SetInfoBar(m_infoBar); - - m_infoToolBar = CreateToolBarFromWidget(m_infoBar, - Qt::BottomToolBarArea, - QStringLiteral("Info Panel")); - m_infoToolBar->setMovable(false); - m_infoToolBar->setObjectName("InfoBar"); - AzQtComponents::Style::addClass(m_infoToolBar, "DefaultSpacing"); - - if (QToolButton* expansion = AzQtComponents::ToolBar::getToolBarExpansionButton(m_infoToolBar)) - { - expansion->installEventFilter(m_expanderWatcher); - } - setContextMenuPolicy(Qt::NoContextMenu); } @@ -415,7 +278,6 @@ void CLayoutWnd::CreateLayout(EViewLayout layout, bool bBindViewports, EViewport } QRect rcView = rect(); - rcView.setBottom(rcView.bottom() - m_infoBar->height()); // Ensure we delete our old view immediately so it can relinquish its backing ViewportContext if (m_maximizedView) diff --git a/Code/Sandbox/Editor/LayoutWnd.h b/Code/Sandbox/Editor/LayoutWnd.h index 87240cbf76..2af56f907c 100644 --- a/Code/Sandbox/Editor/LayoutWnd.h +++ b/Code/Sandbox/Editor/LayoutWnd.h @@ -20,7 +20,6 @@ #if !defined(Q_MOC_RUN) #include "Viewport.h" -#include "InfoBar.h" #include #include @@ -77,8 +76,6 @@ private: friend class CLayoutWnd; }; -class InfoBarExpanderWatcher; - /** Main layout window. */ class CLayoutWnd @@ -116,8 +113,6 @@ public: //! Switch 2D viewports. void Cycle2DViewport(); - CInfoBar& GetInfoBar() { return *m_infoBar; } - public slots: void ResetLayout(); @@ -162,11 +157,8 @@ private: // Id of maximized view pane. int m_maximizedViewId; - CInfoBar* m_infoBar; - QToolBar* m_infoToolBar; QSize m_infoBarSize; QSettings* m_settings; - InfoBarExpanderWatcher* m_expanderWatcher; }; ///////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/MainWindow.cpp b/Code/Sandbox/Editor/MainWindow.cpp index 9e983c3593..31eac05824 100644 --- a/Code/Sandbox/Editor/MainWindow.cpp +++ b/Code/Sandbox/Editor/MainWindow.cpp @@ -297,68 +297,6 @@ namespace } } -class SnapToWidget - : public QWidget -{ -public: - typedef AZStd::function SetValueCallback; - typedef AZStd::function GetValueCallback; - - SnapToWidget(QAction* defaultAction, SetValueCallback setValueCallback, GetValueCallback getValueCallback) - : m_setValueCallback(setValueCallback) - , m_getValueCallback(getValueCallback) - { - QHBoxLayout* layout = new QHBoxLayout(); - setLayout(layout); - - m_toolButton = new QToolButton(); - m_toolButton->setAutoRaise(true); - m_toolButton->setCheckable(false); - m_toolButton->setDefaultAction(defaultAction); - - m_spinBox = new AzQtComponents::DoubleSpinBox(); - - layout->addWidget(m_toolButton); - layout->addWidget(m_spinBox); - - m_spinBox->setEnabled(defaultAction->isChecked()); - m_spinBox->setMinimum(1e-2f); - - { - QSignalBlocker signalBlocker(m_spinBox); - m_spinBox->setValue(m_getValueCallback()); - } - - QObject::connect(m_spinBox, QOverload::of(&AzQtComponents::DoubleSpinBox::valueChanged), this, &SnapToWidget::OnValueChanged); - QObject::connect(defaultAction, &QAction::changed, this, &SnapToWidget::OnActionChanged); - } - - void SetIcon(QIcon icon) - { - m_toolButton->setIcon(icon); - } - -protected: - - void OnValueChanged(double value) - { - m_setValueCallback(value); - } - - void OnActionChanged() - { - m_spinBox->setEnabled(m_toolButton->isChecked()); - } - -private: - - QToolButton* m_toolButton = nullptr; - AzQtComponents::DoubleSpinBox* m_spinBox = nullptr; - - SetValueCallback m_setValueCallback; - GetValueCallback m_getValueCallback; -}; - ///////////////////////////////////////////////////////////////////////////// // MainWindow ///////////////////////////////////////////////////////////////////////////// @@ -1274,36 +1212,6 @@ void UndoRedoToolButton::Update(int count) setEnabled(count > 0); } -QWidget* MainWindow::CreateSnapToGridWidget() -{ - SnapToWidget::SetValueCallback setCallback = [](double snapStep) - { - SandboxEditor::SetGridSnappingSize(snapStep); - }; - - SnapToWidget::GetValueCallback getCallback = []() - { - return SandboxEditor::GridSnappingSize(); - }; - - return new SnapToWidget(m_actionManager->GetAction(ID_SNAP_TO_GRID), setCallback, getCallback); -} - -QWidget* MainWindow::CreateSnapToAngleWidget() -{ - SnapToWidget::SetValueCallback setCallback = [](double snapAngle) - { - SandboxEditor::SetAngleSnappingSize(snapAngle); - }; - - SnapToWidget::GetValueCallback getCallback = []() - { - return SandboxEditor::AngleSnappingSize(); - }; - - return new SnapToWidget(m_actionManager->GetAction(ID_SNAPANGLE), setCallback, getCallback); -} - bool MainWindow::IsPreview() const { return GetIEditor()->IsInPreviewMode(); @@ -2016,12 +1924,6 @@ QWidget* MainWindow::CreateToolbarWidget(int actionId) case ID_TOOLBAR_WIDGET_REDO: w = CreateUndoRedoButton(ID_REDO); break; - case ID_TOOLBAR_WIDGET_SNAP_GRID: - w = CreateSnapToGridWidget(); - break; - case ID_TOOLBAR_WIDGET_SNAP_ANGLE: - w = CreateSnapToAngleWidget(); - break; case ID_TOOLBAR_WIDGET_SPACER_RIGHT: w = CreateSpacerRightWidget(); break; diff --git a/Code/Sandbox/Editor/MainWindow.h b/Code/Sandbox/Editor/MainWindow.h index ab60b0e0d4..43600b039e 100644 --- a/Code/Sandbox/Editor/MainWindow.h +++ b/Code/Sandbox/Editor/MainWindow.h @@ -202,8 +202,6 @@ private: // AzToolsFramework::SourceControlNotificationBus::Handler: void ConnectivityStateChanged(const AzToolsFramework::SourceControlState state) override; - QWidget* CreateSnapToGridWidget(); - QWidget* CreateSnapToAngleWidget(); QWidget* CreateSpacerRightWidget(); QToolButton* CreateUndoRedoButton(int command); diff --git a/Code/Sandbox/Editor/Style/Editor.qss b/Code/Sandbox/Editor/Style/Editor.qss index fa7d67dd43..2e96c73f35 100644 --- a/Code/Sandbox/Editor/Style/Editor.qss +++ b/Code/Sandbox/Editor/Style/Editor.qss @@ -144,20 +144,6 @@ EditorWindow QToolBar border-bottom: 2px solid #111111; } -/* InfoBar (Toolbar below the main viewport) */ - -QToolBar#InfoBar -{ - qproperty-iconSize: 22px 18px; -} - -QToolBar#InfoBar AzQtComponents--VectorElement[Coordinate="X"] QLabel, -QToolBar#InfoBar AzQtComponents--VectorElement[Coordinate="Y"] QLabel, -QToolBar#InfoBar AzQtComponents--VectorElement[Coordinate="Z"] QLabel -{ - background-color: #333333; -} - DockWidgetTitleBar #DockWidgetContextMenu { qproperty-icon: url(:/Cards/img/UI20/Cards/menu_ico.svg); diff --git a/Code/Sandbox/Editor/ToolbarManager.cpp b/Code/Sandbox/Editor/ToolbarManager.cpp index 391eabae33..241b969da7 100644 --- a/Code/Sandbox/Editor/ToolbarManager.cpp +++ b/Code/Sandbox/Editor/ToolbarManager.cpp @@ -582,19 +582,6 @@ AmazonToolbar ToolbarManager::GetEditModeToolbar() const { AmazonToolbar t = AmazonToolbar("EditMode", QObject::tr("Edit Mode Toolbar")); t.SetMainToolbar(true); - t.AddAction(ID_TOOLBAR_WIDGET_UNDO, ORIGINAL_TOOLBAR_VERSION); - t.AddAction(ID_TOOLBAR_WIDGET_REDO, ORIGINAL_TOOLBAR_VERSION); - - t.AddAction(ID_TOOLBAR_SEPARATOR, ORIGINAL_TOOLBAR_VERSION); - - t.AddAction(ID_EDITMODE_MOVE, ORIGINAL_TOOLBAR_VERSION); - t.AddAction(ID_EDITMODE_ROTATE, ORIGINAL_TOOLBAR_VERSION); - t.AddAction(ID_EDITMODE_SCALE, ORIGINAL_TOOLBAR_VERSION); - - t.AddAction(ID_TOOLBAR_SEPARATOR, ORIGINAL_TOOLBAR_VERSION); - t.AddAction(ID_TOOLBAR_WIDGET_SNAP_GRID, ORIGINAL_TOOLBAR_VERSION); - t.AddAction(ID_TOOLBAR_WIDGET_SNAP_ANGLE, ORIGINAL_TOOLBAR_VERSION); - return t; } diff --git a/Code/Sandbox/Editor/ViewportTitleDlg.cpp b/Code/Sandbox/Editor/ViewportTitleDlg.cpp index 5ccb83cd5b..f85aa1f06d 100644 --- a/Code/Sandbox/Editor/ViewportTitleDlg.cpp +++ b/Code/Sandbox/Editor/ViewportTitleDlg.cpp @@ -21,6 +21,8 @@ // Qt #include +#include + // CryCommon #include @@ -35,16 +37,20 @@ #include "Objects/SelectionGroup.h" #include "UsedResources.h" #include "Include/IObjectManager.h" +#include "ActionManager.h" +#include "MainWindow.h" +#include "GameEngine.h" +#include "MathConversion.h" +#include "EditorViewportSettings.h" -#include - +#include +#include AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING #include "ui_ViewportTitleDlg.h" AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING #endif //!defined(Q_MOC_RUN) - // CViewportTitleDlg dialog inline namespace Helpers @@ -103,7 +109,9 @@ CViewportTitleDlg::CViewportTitleDlg(QWidget* pParent) layout->addWidget(container); container->setObjectName("ViewportTitleDlgContainer"); - m_pViewPane = NULL; + m_prevMoveSpeed = 0; + + m_pViewPane = nullptr; GetIEditor()->RegisterNotifyListener(this); GetISystem()->GetISystemEventDispatcher()->RegisterListener(this); @@ -111,21 +119,176 @@ CViewportTitleDlg::CViewportTitleDlg(QWidget* pParent) LoadCustomPresets("AspectRatioPresets", "AspectRatioPreset", m_customAspectRatioPresets); LoadCustomPresets("ResPresets", "ResPreset", m_customResPresets); - OnInitDialog(); + // audio request setup + m_oMuteAudioRequest.pData = &m_oMuteAudioRequestData; + m_oUnmuteAudioRequest.pData = &m_oUnmuteAudioRequestData; - connect(m_ui->m_fovLabel, &QWidget::customContextMenuRequested, this, &CViewportTitleDlg::PopUpFOVMenu); - connect(m_ui->m_fovStaticCtrl, &QWidget::customContextMenuRequested, this, &CViewportTitleDlg::PopUpFOVMenu); - connect(m_ui->m_ratioStaticCtrl, &QWidget::customContextMenuRequested, this, &CViewportTitleDlg::PopUpAspectMenu); - connect(m_ui->m_ratioLabel, &QWidget::customContextMenuRequested, this, &CViewportTitleDlg::PopUpAspectMenu); - connect(m_ui->m_sizeStaticCtrl, &QWidget::customContextMenuRequested, this, &CViewportTitleDlg::PopUpResolutionMenu); + SetupCameraDropdownMenu(); + SetupResolutionDropdownMenu(); + SetupViewportInformationMenu(); + SetupOverflowMenu(); + + Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequest, gSettings.bMuteAudio ? m_oMuteAudioRequest : m_oUnmuteAudioRequest); + + connect(this, &CViewportTitleDlg::ActionTriggered, MainWindow::instance()->GetActionManager(), &ActionManager::ActionTriggered); + + AZ::VR::VREventBus::Handler::BusConnect(); + + OnInitDialog(); } CViewportTitleDlg::~CViewportTitleDlg() { + AZ::VR::VREventBus::Handler::BusDisconnect(); GetISystem()->GetISystemEventDispatcher()->RemoveListener(this); GetIEditor()->UnregisterNotifyListener(this); } +void CViewportTitleDlg::SetupCameraDropdownMenu() +{ + // Setup the camera dropdown menu + QMenu* cameraMenu = new QMenu(this); + cameraMenu->addMenu(GetFovMenu()); + m_ui->m_cameraMenu->setMenu(cameraMenu); + m_ui->m_cameraMenu->setPopupMode(QToolButton::InstantPopup); + QAction* gotoPositionAction = new QAction("Go to position", cameraMenu); + connect(gotoPositionAction, &QAction::triggered, this, &CViewportTitleDlg::OnBnClickedGotoPosition); + cameraMenu->addAction(gotoPositionAction); + m_syncPlayerToCameraAction = new QAction("Sync camera to player", cameraMenu); + m_syncPlayerToCameraAction->setCheckable(true); + connect(m_syncPlayerToCameraAction, &QAction::triggered, this, &CViewportTitleDlg::OnBnClickedSyncplayer); + cameraMenu->addAction(m_syncPlayerToCameraAction); + + cameraMenu->addSeparator(); + + auto cameraSpeedActionWidget = new QWidgetAction(cameraMenu); + auto cameraSpeedContainer = new QWidget(cameraMenu); + auto cameraSpeedLabel = new QLabel(tr("Camera Speed"), cameraMenu); + m_cameraSpeed = new QComboBox(cameraMenu); + m_cameraSpeed->setEditable(true); + m_cameraSpeed->setValidator(new QDoubleValidator(m_minSpeed, m_maxSpeed, m_numDecimals, m_cameraSpeed)); + + QHBoxLayout* cameraSpeedLayout = new QHBoxLayout; + cameraSpeedLayout->addWidget(cameraSpeedLabel); + cameraSpeedLayout->addWidget(m_cameraSpeed); + cameraSpeedContainer->setLayout(cameraSpeedLayout); + cameraSpeedActionWidget->setDefaultWidget(cameraSpeedContainer); + + // Save off the move speed here since setting up the combo box can cause it to update values in the background. + float cameraMoveSpeed = gSettings.cameraMoveSpeed; + + // Populate the presets in the ComboBox + for (float presetValue : m_speedPresetValues) + { + m_cameraSpeed->addItem(QString().setNum(presetValue, 'f', m_numDecimals), presetValue); + } + + auto comboBoxTextChanged = static_cast(&QComboBox::currentTextChanged); + + SetSpeedComboBox(cameraMoveSpeed); + m_cameraSpeed->setInsertPolicy(QComboBox::NoInsert); + connect(m_cameraSpeed, comboBoxTextChanged, this, &CViewportTitleDlg::OnUpdateMoveSpeedText); + connect(m_cameraSpeed->lineEdit(), &QLineEdit::returnPressed, this, &CViewportTitleDlg::OnSpeedComboBoxEnter); + + cameraMenu->addAction(cameraSpeedActionWidget); +} + +void CViewportTitleDlg::SetupResolutionDropdownMenu() +{ + // Setup the resolution dropdown menu + QMenu* resolutionMenu = new QMenu(this); + resolutionMenu->addMenu(GetAspectMenu()); + resolutionMenu->addMenu(GetResolutionMenu()); + m_ui->m_resolutionMenu->setMenu(resolutionMenu); + m_ui->m_resolutionMenu->setPopupMode(QToolButton::InstantPopup); +} + +void CViewportTitleDlg::SetupViewportInformationMenu() +{ + // Setup the debug information button + m_ui->m_debugInformationMenu->setMenu(GetViewportInformationMenu()); + connect(m_ui->m_debugInformationMenu, &QToolButton::clicked, this, &CViewportTitleDlg::OnToggleDisplayInfo); + m_ui->m_debugInformationMenu->setPopupMode(QToolButton::MenuButtonPopup); + +} + +void CViewportTitleDlg::SetupOverflowMenu() +{ + // Setup the overflow menu + QMenu* overFlowMenu = new QMenu(this); + m_debugHelpersAction = new QAction("Debug Helpers", overFlowMenu); + m_debugHelpersAction->setCheckable(true); + m_debugHelpersAction->setChecked(Helpers::IsHelpersShown()); + connect(m_debugHelpersAction, &QAction::triggered, this, &CViewportTitleDlg::OnToggleHelpers); + overFlowMenu->addAction(m_debugHelpersAction); + + m_audioMuteAction = new QAction("Mute Audio", overFlowMenu); + connect(m_audioMuteAction, &QAction::triggered, this, &CViewportTitleDlg::OnBnClickedMuteAudio); + overFlowMenu->addAction(m_audioMuteAction); + + m_enableVRAction = new QAction("Enable VR Preview", overFlowMenu); + connect(m_enableVRAction, &QAction::triggered, this, &CViewportTitleDlg::OnBnClickedEnableVR); + overFlowMenu->addAction(m_enableVRAction); + + overFlowMenu->addSeparator(); + + m_enableGridSnappingAction = new QAction("Enable Grid Snapping", overFlowMenu); + connect(m_enableGridSnappingAction, &QAction::triggered, this, &CViewportTitleDlg::OnGridSnappingToggled); + m_enableGridSnappingAction->setCheckable(true); + overFlowMenu->addAction(m_enableGridSnappingAction); + + m_gridSizeActionWidget = new QWidgetAction(overFlowMenu); + auto gridSizeContainer = new QWidget(overFlowMenu); + auto gridSizeLabel = new QLabel(tr("Grid Size"), overFlowMenu); + + m_gridSpinBox = new AzQtComponents::DoubleSpinBox(); + m_gridSpinBox->setValue(SandboxEditor::GridSnappingSize()); + m_gridSpinBox->setMinimum(1e-2f); + + QObject::connect( + m_gridSpinBox, QOverload::of(&AzQtComponents::DoubleSpinBox::valueChanged), this, &CViewportTitleDlg::OnGridSpinBoxChanged); + + QHBoxLayout* gridSizeLayout = new QHBoxLayout; + gridSizeLayout->addWidget(gridSizeLabel); + gridSizeLayout->addWidget(m_gridSpinBox); + gridSizeContainer->setLayout(gridSizeLayout); + m_gridSizeActionWidget->setDefaultWidget(gridSizeContainer); + overFlowMenu->addAction(m_gridSizeActionWidget); + + overFlowMenu->addSeparator(); + + m_enableAngleSnappingAction = new QAction("Enable Grid Snapping", overFlowMenu); + connect(m_enableAngleSnappingAction, &QAction::triggered, this, &CViewportTitleDlg::OnAngleSnappingToggled); + m_enableAngleSnappingAction->setCheckable(true); + overFlowMenu->addAction(m_enableAngleSnappingAction); + + m_angleSizeActionWidget = new QWidgetAction(overFlowMenu); + auto angleSizeContainer = new QWidget(overFlowMenu); + auto angleSizeLabel = new QLabel(tr("Angle Snapping"), overFlowMenu); + + m_angleSpinBox = new AzQtComponents::DoubleSpinBox(); + m_angleSpinBox->setValue(SandboxEditor::AngleSnappingSize()); + m_angleSpinBox->setMinimum(1e-2f); + + QObject::connect( + m_angleSpinBox, QOverload::of(&AzQtComponents::DoubleSpinBox::valueChanged), this, + &CViewportTitleDlg::OnAngleSpinBoxChanged); + + QHBoxLayout* angleSizeLayout = new QHBoxLayout; + angleSizeLayout->addWidget(angleSizeLabel); + angleSizeLayout->addWidget(m_angleSpinBox); + angleSizeContainer->setLayout(angleSizeLayout); + m_angleSizeActionWidget->setDefaultWidget(angleSizeContainer); + overFlowMenu->addAction(m_angleSizeActionWidget); + + m_ui->m_overflowBtn->setMenu(overFlowMenu); + m_ui->m_overflowBtn->setPopupMode(QToolButton::InstantPopup); + connect(overFlowMenu, &QMenu::aboutToShow, this, &CViewportTitleDlg::UpdateOverFlowMenuState); + + UpdateMuteActionText(); +} + + ////////////////////////////////////////////////////////////////////////// void CViewportTitleDlg::SetViewPane(CLayoutViewPane* pViewPane) { @@ -140,21 +303,27 @@ void CViewportTitleDlg::SetViewPane(CLayoutViewPane* pViewPane) void CViewportTitleDlg::OnInitDialog() { m_ui->m_titleBtn->setText(m_title); - m_ui->m_sizeStaticCtrl->setText(QString()); - - m_ui->m_toggleHelpersBtn->setChecked(GetIEditor()->GetDisplaySettings()->IsDisplayHelpers()); - // Add a child parented to us that listens for r_displayInfo changes. auto displayInfoHelper = new CViewportTitleDlgDisplayInfoHelper(this); connect(displayInfoHelper, &CViewportTitleDlgDisplayInfoHelper::ViewportInfoStatusUpdated, this, &CViewportTitleDlg::UpdateDisplayInfo); UpdateDisplayInfo(); - connect(m_ui->m_toggleHelpersBtn, &QToolButton::clicked, this, &CViewportTitleDlg::OnToggleHelpers); - connect(m_ui->m_toggleDisplayInfoBtn, &QToolButton::clicked, this, &CViewportTitleDlg::OnToggleDisplayInfo); + // This is here just in case this class hasn't been created before + // a VR headset was initialized + m_enableVRAction->setEnabled(false); + if (AZ::VR::HMDDeviceRequestBus::GetTotalNumOfEventHandlers() != 0) + { + m_enableVRAction->setEnabled(true); + } + + AZ::VR::VREventBus::Handler::BusConnect(); + + QFontMetrics metrics({}); + int width = metrics.boundingRect("-9999.99").width() * m_fieldWidthMultiplier; + + m_cameraSpeed->setFixedWidth(width); - m_ui->m_toggleHelpersBtn->setProperty("class", "big"); - m_ui->m_toggleDisplayInfoBtn->setProperty("class", "big"); } ////////////////////////////////////////////////////////////////////////// @@ -177,34 +346,93 @@ void CViewportTitleDlg::OnMaximize() void CViewportTitleDlg::OnToggleHelpers() { Helpers::ToggleHelpers(); + m_debugHelpersAction->setChecked(Helpers::IsHelpersShown()); +} + +void CViewportTitleDlg::SetNoViewportInfo() +{ + AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Broadcast( + &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::SetDisplayState, AZ::AtomBridge::ViewportInfoDisplayState::NoInfo); } +void CViewportTitleDlg::SetNormalViewportInfo() +{ + AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Broadcast( + &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::SetDisplayState, AZ::AtomBridge::ViewportInfoDisplayState::NormalInfo); +} + +void CViewportTitleDlg::SetFullViewportInfo() +{ + AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Broadcast( + &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::SetDisplayState, AZ::AtomBridge::ViewportInfoDisplayState::FullInfo); +} + +void CViewportTitleDlg::SetCompactViewportInfo() +{ + AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Broadcast( + &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::SetDisplayState, AZ::AtomBridge::ViewportInfoDisplayState::CompactInfo); +} + + ////////////////////////////////////////////////////////////////////////// -void CViewportTitleDlg::OnToggleDisplayInfo() +void CViewportTitleDlg::UpdateDisplayInfo() { + if (m_viewportInformationMenu == nullptr) + { + // Nothing to update, just return; + return; + } + AZ::AtomBridge::ViewportInfoDisplayState state = AZ::AtomBridge::ViewportInfoDisplayState::NoInfo; AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::BroadcastResult( state, &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::GetDisplayState ); - state = aznumeric_cast( - (aznumeric_cast(state)+1) % aznumeric_cast(AZ::AtomBridge::ViewportInfoDisplayState::Invalid)); - // SetDisplayState will fire OnViewportInfoDisplayStateChanged and notify us, no need to call UpdateDisplayInfo. - AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Broadcast( - &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::SetDisplayState, - state - ); + + m_noInformationAction->setChecked(false); + m_normalInformationAction->setChecked(false); + m_fullInformationAction->setChecked(false); + m_compactInformationAction->setChecked(false); + + switch (state) + { + case AZ::AtomBridge::ViewportInfoDisplayState::NormalInfo: + { + m_normalInformationAction->setChecked(true); + break; + } + case AZ::AtomBridge::ViewportInfoDisplayState::FullInfo: + { + m_fullInformationAction->setChecked(true); + break; + } + case AZ::AtomBridge::ViewportInfoDisplayState::CompactInfo: + { + m_compactInformationAction->setChecked(true); + break; + } + case AZ::AtomBridge::ViewportInfoDisplayState::NoInfo: + default: + { + m_noInformationAction->setChecked(true); + break; + } + } + + m_ui->m_debugInformationMenu->setChecked(state != AZ::AtomBridge::ViewportInfoDisplayState::NoInfo); } ////////////////////////////////////////////////////////////////////////// -void CViewportTitleDlg::UpdateDisplayInfo() +void CViewportTitleDlg::OnToggleDisplayInfo() { AZ::AtomBridge::ViewportInfoDisplayState state = AZ::AtomBridge::ViewportInfoDisplayState::NoInfo; AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::BroadcastResult( - state, - &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::GetDisplayState - ); - m_ui->m_toggleDisplayInfoBtn->setChecked(state != AZ::AtomBridge::ViewportInfoDisplayState::NoInfo); + state, &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::GetDisplayState); + state = aznumeric_cast( + (aznumeric_cast(state) + 1) % aznumeric_cast(AZ::AtomBridge::ViewportInfoDisplayState::Invalid)); + // SetDisplayState will fire OnViewportInfoDisplayStateChanged and notify us, no need to call UpdateDisplayInfo. + AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Broadcast( + &AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Events::SetDisplayState, state); } ////////////////////////////////////////////////////////////////////////// @@ -277,7 +505,7 @@ void CViewportTitleDlg::CreateFOVMenu() { if (!m_fovMenu) { - m_fovMenu = new QMenu(this); + m_fovMenu = new QMenu("FOV", this); } m_fovMenu->clear(); @@ -292,17 +520,6 @@ void CViewportTitleDlg::CreateFOVMenu() connect(action, &QAction::triggered, this, &CViewportTitleDlg::OnMenuFOVCustom); } -void CViewportTitleDlg::PopUpFOVMenu() -{ - if (m_pViewPane == NULL) - { - return; - } - - CreateFOVMenu(); - m_fovMenu->exec(QCursor::pos()); -} - QMenu* const CViewportTitleDlg::GetFovMenu() { CreateFOVMenu(); @@ -379,9 +596,9 @@ void CViewportTitleDlg::OnMenuAspectRatioCustom() ////////////////////////////////////////////////////////////////////////// void CViewportTitleDlg::CreateAspectMenu() { - if (!m_aspectMenu) + if (m_aspectMenu == nullptr) { - m_aspectMenu = new QMenu(this); + m_aspectMenu = new QMenu("Aspect Ratio"); } m_aspectMenu->clear(); @@ -396,21 +613,46 @@ void CViewportTitleDlg::CreateAspectMenu() connect(customAction, &QAction::triggered, this, &CViewportTitleDlg::OnMenuAspectRatioCustom); } -void CViewportTitleDlg::PopUpAspectMenu() +QMenu* const CViewportTitleDlg::GetAspectMenu() { - if (!m_pViewPane) - { - return; - } - CreateAspectMenu(); - m_aspectMenu->exec(QCursor::pos()); + return m_aspectMenu; } -QMenu* const CViewportTitleDlg::GetAspectMenu() +QMenu* const CViewportTitleDlg::GetViewportInformationMenu() { - CreateAspectMenu(); - return m_aspectMenu; + CreateViewportInformationMenu(); + return m_viewportInformationMenu; +} + +void CViewportTitleDlg::CreateViewportInformationMenu() +{ + if (m_viewportInformationMenu == nullptr) + { + m_viewportInformationMenu = new QMenu("Viewport Information"); + + m_noInformationAction = new QAction(tr("None"), m_viewportInformationMenu); + m_noInformationAction->setCheckable(true); + connect(m_noInformationAction, &QAction::triggered, this, &CViewportTitleDlg::SetNoViewportInfo); + m_viewportInformationMenu->addAction(m_noInformationAction); + + m_normalInformationAction = new QAction(tr("Normal"), m_viewportInformationMenu); + m_normalInformationAction->setCheckable(true); + connect(m_normalInformationAction, &QAction::triggered, this, &CViewportTitleDlg::SetNormalViewportInfo); + m_viewportInformationMenu->addAction(m_normalInformationAction); + + m_fullInformationAction = new QAction(tr("Full"), m_viewportInformationMenu); + m_fullInformationAction->setCheckable(true); + connect(m_fullInformationAction, &QAction::triggered, this, &CViewportTitleDlg::SetFullViewportInfo); + m_viewportInformationMenu->addAction(m_fullInformationAction); + + m_compactInformationAction = new QAction(tr("Compact"), m_viewportInformationMenu); + m_compactInformationAction->setCheckable(true); + connect(m_compactInformationAction, &QAction::triggered, this, &CViewportTitleDlg::SetCompactViewportInfo); + m_viewportInformationMenu->addAction(m_compactInformationAction); + + UpdateDisplayInfo(); + } } void CViewportTitleDlg::AddResolutionMenus(QMenu* menu, std::function callback, const QStringList& customPresets) @@ -479,7 +721,7 @@ void CViewportTitleDlg::CreateResolutionMenu() { if (!m_resolutionMenu) { - m_resolutionMenu = new QMenu(this); + m_resolutionMenu = new QMenu("Resolution"); } m_resolutionMenu->clear(); @@ -494,17 +736,6 @@ void CViewportTitleDlg::CreateResolutionMenu() connect(action, &QAction::triggered, this, &CViewportTitleDlg::OnMenuResolutionCustom); } -void CViewportTitleDlg::PopUpResolutionMenu() -{ - if (!m_pViewPane) - { - return; - } - - CreateResolutionMenu(); - m_resolutionMenu->exec(QCursor::pos()); -} - QMenu* const CViewportTitleDlg::GetResolutionMenu() { CreateResolutionMenu(); @@ -514,14 +745,14 @@ QMenu* const CViewportTitleDlg::GetResolutionMenu() ////////////////////////////////////////////////////////////////////////// void CViewportTitleDlg::OnViewportSizeChanged(int width, int height) { - m_ui->m_sizeStaticCtrl->setText(QString::fromLatin1("%1 x %2").arg(width).arg(height)); + m_resolutionMenu->setTitle(QString::fromLatin1("Resolution: %1 x %2").arg(width).arg(height)); if (width != 0 && height != 0) { // Calculate greatest common divider of width & height int whGCD = gcd(width, height); - m_ui->m_ratioStaticCtrl->setText(QString::fromLatin1("%1:%2").arg(width / whGCD).arg(height / whGCD)); + m_aspectMenu->setTitle(QString::fromLatin1("Ratio: %1:%2").arg(width / whGCD).arg(height / whGCD)); } } @@ -529,9 +760,9 @@ void CViewportTitleDlg::OnViewportSizeChanged(int width, int height) void CViewportTitleDlg::OnViewportFOVChanged(float fov) { const float degFOV = RAD2DEG(fov); - if (m_ui && m_ui->m_fovStaticCtrl) + if (m_fovMenu) { - m_ui->m_fovStaticCtrl->setText(QString::fromLatin1("%1%2").arg(qRound(degFOV)).arg(QString(QByteArray::fromPercentEncoding("%C2%B0")))); + m_fovMenu->setTitle(QString::fromLatin1("FOV: %1%2").arg(qRound(degFOV)).arg(QString(QByteArray::fromPercentEncoding("%C2%B0")))); } } @@ -541,7 +772,11 @@ void CViewportTitleDlg::OnEditorNotifyEvent(EEditorNotifyEvent event) switch (event) { case eNotify_OnDisplayRenderUpdate: - m_ui->m_toggleHelpersBtn->setChecked(GetIEditor()->GetDisplaySettings()->IsDisplayHelpers()); + m_debugHelpersAction->setChecked(Helpers::IsHelpersShown()); + break; + case eNotify_OnBeginGameMode: + case eNotify_OnEndGameMode: + UpdateMuteActionText(); break; } } @@ -615,6 +850,132 @@ bool CViewportTitleDlg::eventFilter(QObject* object, QEvent* event) return QWidget::eventFilter(object, event) || consumeEvent; } +void CViewportTitleDlg::OnBnClickedSyncplayer() +{ + emit ActionTriggered(ID_GAME_SYNCPLAYER); + + bool bSyncPlayer = GetIEditor()->GetGameEngine()->IsSyncPlayerPosition(); + m_syncPlayerToCameraAction->setChecked(!bSyncPlayer); +} + +void CViewportTitleDlg::OnBnClickedGotoPosition() +{ + emit ActionTriggered(ID_DISPLAY_GOTOPOSITION); +} + +void CViewportTitleDlg::OnBnClickedMuteAudio() +{ + gSettings.bMuteAudio = !gSettings.bMuteAudio; + + Audio::AudioSystemRequestBus::Broadcast( + &Audio::AudioSystemRequestBus::Events::PushRequest, gSettings.bMuteAudio ? m_oMuteAudioRequest : m_oUnmuteAudioRequest); + + UpdateMuteActionText(); +} + +void CViewportTitleDlg::UpdateMuteActionText() +{ + m_audioMuteAction->setText(gSettings.bMuteAudio ? tr("Un-mute Audio") : tr("Mute Audio")); +} + +void CViewportTitleDlg::OnHMDInitialized() +{ + m_enableVRAction->setEnabled(true); +} + +void CViewportTitleDlg::OnHMDShutdown() +{ + m_enableVRAction->setEnabled(false); +} + +void CViewportTitleDlg::OnBnClickedEnableVR() +{ + gSettings.bEnableGameModeVR = !gSettings.bEnableGameModeVR; + + m_enableVRAction->setText(gSettings.bEnableGameModeVR ? tr("Disable VR Preview") : tr("Enable VR Preview")); +} + +inline double Round(double fVal, double fStep) +{ + if (fStep > 0.f) + { + fVal = int_round(fVal / fStep) * fStep; + } + return fVal; +} + +void CViewportTitleDlg::SetSpeedComboBox(double value) +{ + value = AZStd::clamp(Round(value, m_speedStep), m_minSpeed, m_maxSpeed); + + int index = m_cameraSpeed->findData(value); + if (index != -1) + { + m_cameraSpeed->setCurrentIndex(index); + } + else + { + m_cameraSpeed->lineEdit()->setText(QString().setNum(value, 'f', m_numDecimals)); + } +} + +void CViewportTitleDlg::OnSpeedComboBoxEnter() +{ + m_cameraSpeed->clearFocus(); +} + +void CViewportTitleDlg::OnUpdateMoveSpeedText(const QString& text) +{ + gSettings.cameraMoveSpeed = aznumeric_cast(Round(text.toDouble(), m_speedStep)); +} + +void CViewportTitleDlg::CheckForCameraSpeedUpdate() +{ + if (gSettings.cameraMoveSpeed != m_prevMoveSpeed && !m_cameraSpeed->lineEdit()->hasFocus()) + { + m_prevMoveSpeed = gSettings.cameraMoveSpeed; + SetSpeedComboBox(gSettings.cameraMoveSpeed); + } +} + +void CViewportTitleDlg::OnGridSnappingToggled() +{ + m_gridSizeActionWidget->setEnabled(m_enableGridSnappingAction->isChecked()); + MainWindow::instance()->GetActionManager()->GetAction(ID_SNAP_TO_GRID)->trigger(); +} + +void CViewportTitleDlg::OnAngleSnappingToggled() +{ + m_angleSizeActionWidget->setEnabled(m_enableAngleSnappingAction->isChecked()); + MainWindow::instance()->GetActionManager()->GetAction(ID_SNAPANGLE)->trigger(); +} + +void CViewportTitleDlg::OnGridSpinBoxChanged(double value) +{ + SandboxEditor::SetGridSnappingSize(value); +} + +void CViewportTitleDlg::OnAngleSpinBoxChanged(double value) +{ + SandboxEditor::SetAngleSnappingSize(value); +} + +void CViewportTitleDlg::UpdateOverFlowMenuState() +{ + bool gridSnappingActive = MainWindow::instance()->GetActionManager()->GetAction(ID_SNAP_TO_GRID)->isChecked(); + { + QSignalBlocker signalBlocker(m_enableGridSnappingAction); + m_enableGridSnappingAction->setChecked(gridSnappingActive); + } + m_gridSizeActionWidget->setEnabled(gridSnappingActive); + + bool angleSnappingActive = MainWindow::instance()->GetActionManager()->GetAction(ID_SNAPANGLE)->isChecked(); + { + QSignalBlocker signalBlocker(m_enableAngleSnappingAction); + m_enableAngleSnappingAction->setChecked(angleSnappingActive); + } + m_angleSizeActionWidget->setEnabled(angleSnappingActive); +} namespace { diff --git a/Code/Sandbox/Editor/ViewportTitleDlg.h b/Code/Sandbox/Editor/ViewportTitleDlg.h index ce2f116d97..dd0816082a 100644 --- a/Code/Sandbox/Editor/ViewportTitleDlg.h +++ b/Code/Sandbox/Editor/ViewportTitleDlg.h @@ -19,8 +19,16 @@ #include "RenderViewport.h" #include +#include + #include #include +#include +#include + +#include + +#include #endif // CViewportTitleDlg dialog @@ -42,6 +50,7 @@ class CViewportTitleDlg : public QWidget , public IEditorNotifyListener , public ISystemEventListener + , public AZ::VR::VREventBus::Handler { Q_OBJECT public: @@ -63,10 +72,15 @@ public: bool eventFilter(QObject* object, QEvent* event) override; + void SetSpeedComboBox(double value); + QMenu* const GetFovMenu(); QMenu* const GetAspectMenu(); QMenu* const GetResolutionMenu(); +Q_SIGNALS: + void ActionTriggered(int command); + protected: virtual void OnInitDialog(); @@ -75,9 +89,20 @@ protected: void OnMaximize(); void OnToggleHelpers(); - void OnToggleDisplayInfo(); void UpdateDisplayInfo(); + ////////////////////////////////////////////////////////////////////////// + /// VR Event Bus Implementation + ////////////////////////////////////////////////////////////////////////// + void OnHMDInitialized() override; + void OnHMDShutdown() override; + ////////////////////////////////////////////////////////////////////////// + + void SetupCameraDropdownMenu(); + void SetupResolutionDropdownMenu(); + void SetupViewportInformationMenu(); + void SetupOverflowMenu(); + QString m_title; CLayoutViewPane* m_pViewPane; @@ -87,22 +112,84 @@ protected: QStringList m_customFOVPresets; QStringList m_customAspectRatioPresets; + float m_prevMoveSpeed; + + // Speed combobox/lineEdit settings + double m_minSpeed = 0.1; + double m_maxSpeed = 100.0; + double m_speedStep = 0.1; + int m_numDecimals = 1; + + // Speed presets + float m_speedPresetValues[3] = { 0.1f, 1.0f, 10.0f }; + + double m_fieldWidthMultiplier = 1.8; + + void OnMenuFOVCustom(); void CreateFOVMenu(); - void PopUpFOVMenu(); void OnMenuAspectRatioCustom(); void CreateAspectMenu(); - void PopUpAspectMenu(); void OnMenuResolutionCustom(); void CreateResolutionMenu(); - void PopUpResolutionMenu(); + + void CreateViewportInformationMenu(); + QMenu* const GetViewportInformationMenu(); + void SetNoViewportInfo(); + void SetNormalViewportInfo(); + void SetFullViewportInfo(); + void SetCompactViewportInfo(); + + void OnBnClickedSyncplayer(); + void OnBnClickedGotoPosition(); + void OnBnClickedMuteAudio(); + void OnBnClickedEnableVR(); + + void UpdateMuteActionText(); + + void OnToggleDisplayInfo(); + + void OnSpeedComboBoxEnter(); + void OnUpdateMoveSpeedText(const QString&); + + void CheckForCameraSpeedUpdate(); + + void OnGridSnappingToggled(); + void OnAngleSnappingToggled(); + + void OnGridSpinBoxChanged(double value); + void OnAngleSpinBoxChanged(double value); + + void UpdateOverFlowMenuState(); QMenu* m_fovMenu = nullptr; QMenu* m_aspectMenu = nullptr; QMenu* m_resolutionMenu = nullptr; + QMenu* m_viewportInformationMenu = nullptr; + QAction* m_noInformationAction = nullptr; + QAction* m_normalInformationAction = nullptr; + QAction* m_fullInformationAction = nullptr; + QAction* m_compactInformationAction = nullptr; + QAction* m_debugHelpersAction = nullptr; + QAction* m_syncPlayerToCameraAction = nullptr; + QAction* m_audioMuteAction = nullptr; + QAction* m_enableVRAction = nullptr; + QAction* m_enableGridSnappingAction = nullptr; + QAction* m_enableAngleSnappingAction = nullptr; + QComboBox* m_cameraSpeed = nullptr; + AzQtComponents::DoubleSpinBox* m_gridSpinBox = nullptr; + AzQtComponents::DoubleSpinBox* m_angleSpinBox = nullptr; + QWidgetAction* m_gridSizeActionWidget = nullptr; + QWidgetAction* m_angleSizeActionWidget = nullptr; + + Audio::SAudioRequest m_oMuteAudioRequest; + Audio::SAudioManagerRequestData m_oMuteAudioRequestData; + Audio::SAudioRequest m_oUnmuteAudioRequest; + Audio::SAudioManagerRequestData m_oUnmuteAudioRequestData; + QScopedPointer m_ui; }; diff --git a/Code/Sandbox/Editor/ViewportTitleDlg.ui b/Code/Sandbox/Editor/ViewportTitleDlg.ui index e7b5cce1ec..2d547bfa99 100644 --- a/Code/Sandbox/Editor/ViewportTitleDlg.ui +++ b/Code/Sandbox/Editor/ViewportTitleDlg.ui @@ -61,121 +61,43 @@ - - - Qt::CustomContextMenu - - - FOV: - - - - - - - - 0 - 0 - - - - Qt::CustomContextMenu - - - 120° - - - - - - - Qt::CustomContextMenu - - - Ratio: - - - - - - - - 0 - 0 - - - - - 40 - 0 - - - - Qt::CustomContextMenu - - - 000:000 - - - + + + + :/Menu/camera.svg:/Menu/camera.svg + + + + - - - - 0 - 0 - - - - - 60 - 0 - - - - Qt::CustomContextMenu - - - 0000 x 0000 - - - + + + + :/Menu/debug.svg:/Menu/debug.svg + + + + true + + + - + + + + :/Menu/resolution.svg:/Menu/resolution.svg + + + - - - Toggle display info - - - Toggle display info - - - - :/stylesheet/img/UI20/Info.svg:/stylesheet/img/UI20/Info.svg - - - true - - - - - - - Toggle display helpers - - - Toggle display helpers - - - - :/stylesheet/img/UI20/Helpers.svg:/stylesheet/img/UI20/Helpers.svg - - - true - - + + + + :/stylesheet/img/UI20/menu-centered.svg:/stylesheet/img/UI20/menu-centered.svg + + + @@ -187,6 +109,8 @@ 1 - - + + + + diff --git a/Code/Sandbox/Editor/editor_lib_files.cmake b/Code/Sandbox/Editor/editor_lib_files.cmake index ebd7f89cfb..dc9d794021 100644 --- a/Code/Sandbox/Editor/editor_lib_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_files.cmake @@ -424,10 +424,6 @@ set(FILES GotoPositionDlg.cpp GotoPositionDlg.h GotoPositionDlg.ui - InfoBar.cpp - InfoBar.qrc - InfoBar.h - InfoBar.ui LayoutConfigDialog.cpp LayoutConfigDialog.h LayoutConfigDialog.ui