From 543784339045b2b8b1ea53fe7312c8cdfd0e0dab Mon Sep 17 00:00:00 2001 From: guthadam Date: Sun, 9 May 2021 12:34:55 -0500 Subject: [PATCH] Created material editor settings dialog Activated settings menu option Moved viewport camera controller initialization before viewport settings restoration --- .../Atom/Document/MaterialDocumentSettings.h | 1 + .../Document/MaterialDocumentSettings.cpp | 3 + .../Viewport/MaterialViewportRenderer.cpp | 4 +- .../CreateMaterialDialog.cpp | 9 ++- .../Source/Window/MaterialEditorWindow.cpp | 13 ++-- .../Code/Source/Window/MaterialEditorWindow.h | 2 +- .../Window/SettingsDialog/SettingsDialog.cpp | 43 +++++++++++ .../Window/SettingsDialog/SettingsDialog.h | 27 +++++++ .../Window/SettingsDialog/SettingsWidget.cpp | 72 +++++++++++++++++++ .../Window/SettingsDialog/SettingsWidget.h | 54 ++++++++++++++ .../ViewportSettingsInspector.cpp | 6 +- .../ViewportSettingsInspector.h | 2 +- .../Code/materialeditorwindow_files.cmake | 4 ++ 13 files changed, 226 insertions(+), 14 deletions(-) create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.cpp create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.h create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h index 37d6a8c2d8..86c913d271 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h @@ -30,5 +30,6 @@ namespace MaterialEditor static void Reflect(AZ::ReflectContext* context); bool m_showReloadDocumentPrompt = true; + AZStd::string m_defaultMaterialTypeName = "StandardPBR"; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp index a64b6584c1..0dab7ea9f6 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp @@ -23,6 +23,7 @@ namespace MaterialEditor serializeContext->Class() ->Version(1) ->Field("showReloadDocumentPrompt", &MaterialDocumentSettings::m_showReloadDocumentPrompt) + ->Field("defaultMaterialTypeName", &MaterialDocumentSettings::m_defaultMaterialTypeName) ; if (auto editContext = serializeContext->GetEditContext()) @@ -32,6 +33,7 @@ namespace MaterialEditor ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_showReloadDocumentPrompt, "Show Reload Document Prompt", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_defaultMaterialTypeName, "Default Material Type Name", "") ; } } @@ -45,6 +47,7 @@ namespace MaterialEditor ->Constructor() ->Constructor() ->Property("showReloadDocumentPrompt", BehaviorValueProperty(&MaterialDocumentSettings::m_showReloadDocumentPrompt)) + ->Property("defaultMaterialTypeName", BehaviorValueProperty(&MaterialDocumentSettings::m_defaultMaterialTypeName)) ; } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp index f009cc1f9b..c7265e0039 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp @@ -233,6 +233,8 @@ namespace MaterialEditor MaterialViewportRequestBus::BroadcastResult(modelPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection); OnModelPresetSelected(modelPreset); + m_viewportController->Init(m_cameraEntity->GetId(), m_modelEntity->GetId(), m_iblEntity->GetId()); + // Apply user settinngs restored since last run AZStd::intrusive_ptr viewportSettings = AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); @@ -248,8 +250,6 @@ namespace MaterialEditor AZ::TickBus::Handler::BusConnect(); AZ::TransformNotificationBus::MultiHandler::BusConnect(m_cameraEntity->GetId()); AzFramework::WindowSystemRequestBus::Handler::BusConnect(); - - m_viewportController->Init(m_cameraEntity->GetId(), m_modelEntity->GetId(), m_iblEntity->GetId()); } MaterialViewportRenderer::~MaterialViewportRenderer() diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp index 6c30540392..6a4bb8c0f4 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include namespace MaterialEditor @@ -69,8 +71,11 @@ namespace MaterialEditor QObject::connect(m_ui->m_materialTypeComboBox, static_cast(&QComboBox::currentIndexChanged), this, [this]() { UpdateMaterialTypeSelection(); }); QObject::connect(m_ui->m_materialTypeComboBox, &QComboBox::currentTextChanged, this, [this]() { UpdateMaterialTypeSelection(); }); - // Select StandardPBR by default but we will later data drive this with editor settings - const int index = m_ui->m_materialTypeComboBox->findText("StandardPBR"); + // Select the default material type from settings + auto settings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL); + + const int index = m_ui->m_materialTypeComboBox->findText(settings->m_defaultMaterialTypeName.c_str()); if (index >= 0) { m_ui->m_materialTypeComboBox->setCurrentIndex(index); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 075a58c532..d0470c476f 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -314,7 +315,7 @@ namespace MaterialEditor m_actionUndo->setEnabled(canUndo); m_actionRedo->setEnabled(canRedo); - m_actionPreferences->setEnabled(false); + m_actionSettings->setEnabled(true); m_actionAssetBrowser->setEnabled(true); m_actionInspector->setEnabled(true); @@ -507,9 +508,11 @@ namespace MaterialEditor m_menuEdit->addSeparator(); - m_actionPreferences = m_menuEdit->addAction("&Preferences...", [this]() { + m_actionSettings = m_menuEdit->addAction("&Settings...", [this]() { + SettingsDialog dialog(this); + dialog.exec(); }, QKeySequence::Preferences); - m_actionPreferences->setEnabled(false); + m_actionSettings->setEnabled(true); m_menuView = m_menuBar->addMenu("&View"); @@ -554,8 +557,8 @@ namespace MaterialEditor m_menuHelp = m_menuBar->addMenu("&Help"); m_actionHelp = m_menuHelp->addAction("&Help...", [this]() { - HelpDialog dlg(this); - dlg.exec(); + HelpDialog dialog(this); + dialog.exec(); }); m_actionAbout = m_menuHelp->addAction("&About...", [this]() { diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h index 778e11275f..aa95e5ad8c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h @@ -119,7 +119,7 @@ namespace MaterialEditor QMenu* m_menuEdit = {}; QAction* m_actionUndo = {}; QAction* m_actionRedo = {}; - QAction* m_actionPreferences = {}; + QAction* m_actionSettings = {}; QMenu* m_menuView = {}; QAction* m_actionAssetBrowser = {}; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.cpp new file mode 100644 index 0000000000..75bc78db12 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.cpp @@ -0,0 +1,43 @@ +/* + * 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. + * + */ + +#include +#include + +#include +#include + +namespace MaterialEditor +{ + SettingsDialog::SettingsDialog(QWidget* parent) + : QDialog(parent) + { + setWindowTitle("Material Editor Settings"); + setFixedSize(600, 300); + setLayout(new QVBoxLayout(this)); + + auto settingsWidget = new SettingsWidget(this); + settingsWidget->Populate(); + layout()->addWidget(settingsWidget); + + // Create the bottom row of the dialog with action buttons + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, this); + layout()->addWidget(buttonBox); + + QObject::connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + QObject::connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + + setModal(true); + } +} // namespace MaterialEditor + +//#include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.h new file mode 100644 index 0000000000..a5ad35c4a3 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsDialog.h @@ -0,0 +1,27 @@ +/* + * 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. + * + */ + +#pragma once + +#include + +namespace MaterialEditor +{ + class SettingsDialog + : public QDialog + { + Q_OBJECT + public: + SettingsDialog(QWidget* parent = nullptr); + ~SettingsDialog() = default; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp new file mode 100644 index 0000000000..2cb07b6770 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp @@ -0,0 +1,72 @@ +/* +* 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. +* +*/ + +#include +#include + +namespace MaterialEditor +{ + SettingsWidget::SettingsWidget(QWidget* parent) + : AtomToolsFramework::InspectorWidget(parent) + { + m_documentSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL); + } + + SettingsWidget::~SettingsWidget() + { + AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); + } + + void SettingsWidget::Populate() + { + AddGroupsBegin(); + AddDocumentGroup(); + AddGroupsEnd(); + } + + void SettingsWidget::AddDocumentGroup() + { + const AZStd::string groupNameId = "documentSettings"; + const AZStd::string groupDisplayName = "Document Settings"; + const AZStd::string groupDescription = "Document Settings"; + + const AZ::Crc32 saveStateKey(AZStd::string::format("SettingsWidget::DocumentGroup")); + AddGroup( + groupNameId, groupDisplayName, groupDescription, + new AtomToolsFramework::InspectorPropertyGroupWidget( + m_documentSettings.get(), nullptr, m_documentSettings->TYPEINFO_Uuid(), this, this, saveStateKey)); + } + + void SettingsWidget::Reset() + { + AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); + AtomToolsFramework::InspectorWidget::Reset(); + } + + void SettingsWidget::BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) + { + AZ_UNUSED(pNode); + } + + void SettingsWidget::AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode) + { + AZ_UNUSED(pNode); + } + + void SettingsWidget::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) + { + AZ_UNUSED(pNode); + } +} // namespace MaterialEditor + +//#include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h new file mode 100644 index 0000000000..33d831f3d1 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h @@ -0,0 +1,54 @@ +/* +* 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. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#endif + +namespace MaterialEditor +{ + //! Provides controls for viewing and editing settings. + class SettingsWidget + : public AtomToolsFramework::InspectorWidget + , private AzToolsFramework::IPropertyEditorNotify + { + Q_OBJECT + public: + AZ_CLASS_ALLOCATOR(SettingsWidget, AZ::SystemAllocator, 0); + + explicit SettingsWidget(QWidget* parent = nullptr); + ~SettingsWidget() override; + + void Populate(); + + private: + void AddDocumentGroup(); + + // AtomToolsFramework::InspectorRequestBus::Handler overrides... + void Reset() override; + + // AzToolsFramework::IPropertyEditorNotify overrides... + void BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) override; + void AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode) override; + void SetPropertyEditingActive([[maybe_unused]] AzToolsFramework::InstanceDataNode* pNode) override {} + void SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) override; + void SealUndoStack() override {} + void RequestPropertyContextMenu(AzToolsFramework::InstanceDataNode*, const QPoint&) override {} + void PropertySelectionChanged(AzToolsFramework::InstanceDataNode*, bool) override {} + + AZStd::intrusive_ptr m_documentSettings; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp index 384644f79c..49bd31ee31 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -43,7 +43,7 @@ namespace MaterialEditor AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); } - void ViewportSettingsInspector::Popuate() + void ViewportSettingsInspector::Populate() { AddGroupsBegin(); AddGeneralGroup(); @@ -271,7 +271,7 @@ namespace MaterialEditor { if (m_lightingPreset != preset) { - Popuate(); + Populate(); } } @@ -279,7 +279,7 @@ namespace MaterialEditor { if (m_modelPreset != preset) { - Popuate(); + Populate(); } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h index fdfdec1458..ac9927e069 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h @@ -39,7 +39,7 @@ namespace MaterialEditor ~ViewportSettingsInspector() override; private: - void Popuate(); + void Populate(); void AddGeneralGroup(); void AddModelGroup(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake index 52022e6e87..7a1aa8c735 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake @@ -28,6 +28,10 @@ set(FILES Source/Window/MaterialEditor.qss Source/Window/MaterialEditorWindowComponent.h Source/Window/MaterialEditorWindowComponent.cpp + Source/Window/SettingsDialog/SettingsDialog.cpp + Source/Window/SettingsDialog/SettingsDialog.h + Source/Window/SettingsDialog/SettingsWidget.cpp + Source/Window/SettingsDialog/SettingsWidget.h Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp Source/Window/CreateMaterialDialog/CreateMaterialDialog.h Source/Window/CreateMaterialDialog/CreateMaterialDialog.ui