From e80de63d55586dfc6ddf0bbd74b5fdfcc8c2c446 Mon Sep 17 00:00:00 2001 From: guthadam Date: Wed, 5 May 2021 23:31:17 -0500 Subject: [PATCH 1/5] ATOM-15486 Saving material editor user settings https://jira.agscollab.com/browse/ATOM-15486 --- .../Atom/Document/MaterialDocumentSettings.h | 34 ++++++++ .../Atom/Document/MaterialEditorSettingsBus.h | 49 ----------- .../MaterialViewportNotificationBus.h | 1 - .../Atom/Viewport/MaterialViewportSettings.h | 41 +++++++++ .../Window/MaterialEditorWindowSettings.h | 37 ++++++++ .../Document/MaterialDocumentSettings.cpp | 51 +++++++++++ .../MaterialDocumentSystemComponent.cpp | 59 +++++++------ .../MaterialDocumentSystemComponent.h | 8 +- .../Document/MaterialEditorSettings.cpp | 73 ---------------- .../Source/Document/MaterialEditorSettings.h | 45 ---------- .../Code/Source/MaterialEditorApplication.cpp | 5 +- .../Viewport/MaterialViewportComponent.cpp | 42 +++++---- .../Viewport/MaterialViewportComponent.h | 13 +-- .../Viewport/MaterialViewportRenderer.cpp | 18 ++-- .../Viewport/MaterialViewportSettings.cpp | 72 +++++++++++++++ .../Source/Window/MaterialEditorWindow.cpp | 25 ++++-- .../Window/MaterialEditorWindowComponent.cpp | 19 ++-- .../Window/MaterialEditorWindowSettings.cpp | 62 +++++++++++++ .../Window/ToolBar/MaterialEditorToolBar.cpp | 51 ++++++----- .../ViewportSettingsInspector.cpp | 87 ++++--------------- .../ViewportSettingsInspector.h | 20 +---- .../Code/materialeditor_files.cmake | 2 - .../Code/materialeditordocument_files.cmake | 6 +- .../Code/materialeditorviewport_files.cmake | 2 + .../Code/materialeditorwindow_files.cmake | 2 + 25 files changed, 463 insertions(+), 361 deletions(-) create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h delete mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp delete mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp delete mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.cpp create mode 100644 Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h new file mode 100644 index 0000000000..37d6a8c2d8 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h @@ -0,0 +1,34 @@ +/* +* 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 +#include +#endif + +namespace MaterialEditor +{ + struct MaterialDocumentSettings + : public AZ::UserSettings + { + AZ_RTTI(MaterialDocumentSettings, "{FA4F4BF3-BF39-4753-AAF7-AF383B868881}", AZ::UserSettings); + AZ_CLASS_ALLOCATOR(MaterialDocumentSettings, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + bool m_showReloadDocumentPrompt = true; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h deleted file mode 100644 index 3ddfdf44d4..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h +++ /dev/null @@ -1,49 +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. -* -*/ - -#pragma once - -#include -#include -#include - -namespace MaterialEditor -{ - class MaterialEditorSettingsRequests - : public AZ::EBusTraits - { - public: - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - - virtual AZ::Outcome GetProperty(AZStd::string_view name) const = 0; - virtual AZ::Outcome GetStringProperty(AZStd::string_view name) const = 0; - virtual AZ::Outcome GetBoolProperty(AZStd::string_view name) const = 0; - - virtual void SetProperty(AZStd::string_view name, const AZStd::any& value) = 0; - virtual void SetStringProperty(AZStd::string_view name, AZStd::string_view stringValue) = 0; - virtual void SetBoolProperty(AZStd::string_view name, bool boolValue) = 0; - }; - using MaterialEditorSettingsRequestBus = AZ::EBus; - - class MaterialEditorSettingsNotifications - : public AZ::EBusTraits - { - public: - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - - virtual void OnPropertyChanged(AZStd::string_view name, const AZStd::any& value) = 0; - }; - using MaterialEditorSettingsNotificationBus = AZ::EBus; - -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h index 0727547b13..af85dcc1db 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h new file mode 100644 index 0000000000..7af6b307df --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h @@ -0,0 +1,41 @@ +/* +* 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 +#include +#include +#endif + +namespace MaterialEditor +{ + struct MaterialViewportSettings + : public AZ::UserSettings + { + AZ_RTTI(MaterialViewportSettings, "{16150503-A314-4765-82A3-172670C9EA90}", AZ::UserSettings); + AZ_CLASS_ALLOCATOR(MaterialViewportSettings, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + bool m_enableGrid = true; + bool m_enableShadowCatcher = true; + bool m_enableAlternateSkybox = false; + float m_fieldOfView = 90.0f; + AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; + AZStd::string m_selectedModelPresetName = "Shader Ball"; + AZStd::string m_selectedLightingPresetName = "Neutral Urban"; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h new file mode 100644 index 0000000000..bf572b070a --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h @@ -0,0 +1,37 @@ +/* +* 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 +#include +#endif + +namespace MaterialEditor +{ + struct MaterialEditorWindowSettings + : public AZ::UserSettings + { + AZ_RTTI(MaterialEditorWindowSettings, "{BB9DEB77-B7BE-4DF5-9FDD-6D9F3136C4EA}", AZ::UserSettings); + AZ_CLASS_ALLOCATOR(MaterialEditorWindowSettings, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + bool m_enableGrid = true; + bool m_enableShadowCatcher = true; + bool m_enableAlternateSkybox = false; + float m_fieldOfView = 90.0f; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp new file mode 100644 index 0000000000..a64b6584c1 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp @@ -0,0 +1,51 @@ +/* +* 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 + +namespace MaterialEditor +{ + void MaterialDocumentSettings::Reflect(AZ::ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("showReloadDocumentPrompt", &MaterialDocumentSettings::m_showReloadDocumentPrompt) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "MaterialDocumentSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_showReloadDocumentPrompt, "Show Reload Document Prompt", "") + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class("MaterialDocumentSettings") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Constructor() + ->Constructor() + ->Property("showReloadDocumentPrompt", BehaviorValueProperty(&MaterialDocumentSettings::m_showReloadDocumentPrompt)) + ; + } + } +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp index dbb1d18e49..d0a904d522 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -40,12 +41,13 @@ AZ_POP_DISABLE_WARNING namespace MaterialEditor { MaterialDocumentSystemComponent::MaterialDocumentSystemComponent() - : m_settings(aznew MaterialEditorSettings) { } void MaterialDocumentSystemComponent::Reflect(AZ::ReflectContext* context) { + MaterialDocumentSettings::Reflect(context); + if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() @@ -132,6 +134,7 @@ namespace MaterialEditor void MaterialDocumentSystemComponent::Activate() { m_documentMap.clear(); + m_settings = AZ::UserSettings::CreateFind(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL); MaterialDocumentSystemRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); } @@ -188,22 +191,25 @@ namespace MaterialEditor AZStd::string documentPath; MaterialDocumentRequestBus::EventResult(documentPath, documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath); - if (QMessageBox::question(QApplication::activeWindow(), + if (m_settings->m_showReloadDocumentPrompt && + (QMessageBox::question(QApplication::activeWindow(), QString("Material document was externally modified"), QString("Would you like to reopen the document:\n%1?").arg(documentPath.c_str()), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)) { - AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + continue; + } - bool openResult = false; - MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, documentPath); - if (!openResult) - { - QMessageBox::critical( - QApplication::activeWindow(), QString("Material document could not be opened"), - QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); - MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); - } + AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + + bool openResult = false; + MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, documentPath); + if (!openResult) + { + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); + MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); } } @@ -212,22 +218,25 @@ namespace MaterialEditor AZStd::string documentPath; MaterialDocumentRequestBus::EventResult(documentPath, documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath); - if (QMessageBox::question(QApplication::activeWindow(), + if (m_settings->m_showReloadDocumentPrompt && + (QMessageBox::question(QApplication::activeWindow(), QString("Material document dependencies have changed"), QString("Would you like to update the document with these changes:\n%1?").arg(documentPath.c_str()), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)) { - AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + continue; + } - bool openResult = false; - MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Rebuild); - if (!openResult) - { - QMessageBox::critical( - QApplication::activeWindow(), QString("Material document could not be opened"), - QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); - MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); - } + AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + + bool openResult = false; + MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Rebuild); + if (!openResult) + { + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); + MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h index 4b0ee424a7..617937ad1a 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h @@ -18,10 +18,10 @@ #include #include +#include #include #include #include -#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include @@ -43,7 +43,7 @@ namespace MaterialEditor MaterialDocumentSystemComponent(); ~MaterialDocumentSystemComponent() = default; MaterialDocumentSystemComponent(const MaterialDocumentSystemComponent&) = delete; - MaterialDocumentSystemComponent& operator =(const MaterialDocumentSystemComponent&) = delete; + MaterialDocumentSystemComponent& operator=(const MaterialDocumentSystemComponent&) = delete; static void Reflect(AZ::ReflectContext* context); @@ -87,10 +87,10 @@ namespace MaterialEditor AZ::Uuid OpenDocumentImpl(AZStd::string_view sourcePath, bool checkIfAlreadyOpen); + AZStd::intrusive_ptr m_settings; AZStd::unordered_map> m_documentMap; AZStd::unordered_set m_documentIdsToRebuild; AZStd::unordered_set m_documentIdsToReopen; - AZStd::unique_ptr m_settings; const size_t m_maxMessageBoxLineCount = 15; }; -} +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp deleted file mode 100644 index fc0ed84bfa..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp +++ /dev/null @@ -1,73 +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. -* -*/ - -#include - -namespace MaterialEditor -{ - MaterialEditorSettings::MaterialEditorSettings() - { - MaterialEditorSettingsRequestBus::Handler::BusConnect(); - } - - MaterialEditorSettings::~MaterialEditorSettings() - { - MaterialEditorSettingsRequestBus::Handler::BusDisconnect(); - } - - AZ::Outcome MaterialEditorSettings::GetProperty(AZStd::string_view name) const - { - const auto it = m_propertyMap.find(name); - if (it != m_propertyMap.end()) - { - return AZ::Success(it->second); - } - AZ_Warning("MaterialEditorSettings", false, "Failed to find property [%s].", name.data()); - return AZ::Failure(); - } - - AZ::Outcome MaterialEditorSettings::GetStringProperty(AZStd::string_view name) const - { - AZ::Outcome outcome = GetProperty(name); - if (!outcome || !outcome.GetValue().is()) - { - return AZ::Failure(); - } - return AZ::Success(AZStd::any_cast(outcome.GetValue())); - } - - AZ::Outcome MaterialEditorSettings::GetBoolProperty(AZStd::string_view name) const - { - AZ::Outcome outcome = GetProperty(name); - if (!outcome || !outcome.GetValue().is()) - { - return AZ::Failure(); - } - return AZ::Success(AZStd::any_cast(outcome.GetValue())); - } - - void MaterialEditorSettings::SetProperty(AZStd::string_view name, const AZStd::any& value) - { - m_propertyMap[name] = value; - MaterialEditorSettingsNotificationBus::Broadcast(&MaterialEditorSettingsNotifications::OnPropertyChanged, name, value); - } - - void MaterialEditorSettings::SetStringProperty(AZStd::string_view name, AZStd::string_view stringValue) - { - SetProperty(name, AZStd::any(AZStd::string(stringValue))); - } - - void MaterialEditorSettings::SetBoolProperty(AZStd::string_view name, bool boolValue) - { - SetProperty(name, AZStd::any(boolValue)); - } -} diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h deleted file mode 100644 index f3a948ed80..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h +++ /dev/null @@ -1,45 +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. -* -*/ - -#pragma once - -#include -#include -#include - -#include - -namespace MaterialEditor -{ - class MaterialEditorSettings - : public MaterialEditorSettingsRequestBus::Handler - { - public: - AZ_RTTI(MaterialEditorSettings, "{9C6B6E20-A28E-45DD-85BE-68CA35E9305E}"); - AZ_CLASS_ALLOCATOR(MaterialEditorSettings, AZ::SystemAllocator, 0); - - MaterialEditorSettings(); - ~MaterialEditorSettings(); - - AZ::Outcome GetProperty(AZStd::string_view name) const override; - AZ::Outcome GetStringProperty(AZStd::string_view name) const override; - AZ::Outcome GetBoolProperty(AZStd::string_view name) const override; - - void SetProperty(AZStd::string_view name, const AZStd::any& value) override; - void SetStringProperty(AZStd::string_view name, AZStd::string_view stringValue) override; - void SetBoolProperty(AZStd::string_view name, bool boolValue) override; - - private: - AZStd::unordered_map m_propertyMap; - }; - -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 1f32c2a66b..55710efb66 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -284,7 +284,7 @@ namespace MaterialEditor AZ_Assert(context, "No serialize context"); char resolvedPath[AZ_MAX_PATH_LEN] = ""; - AZ::IO::FileIOBase::GetInstance()->ResolvePath("@user@/EditorUserSettings.xml", resolvedPath, AZ_ARRAY_SIZE(resolvedPath)); + AZ::IO::FileIOBase::GetInstance()->ResolvePath("@user@/MaterialEditorUserSettings.xml", resolvedPath, AZ_ARRAY_SIZE(resolvedPath)); m_localUserSettings.Save(resolvedPath, context); } } @@ -546,6 +546,9 @@ namespace MaterialEditor void MaterialEditorApplication::Stop() { + MaterialEditor::MaterialEditorWindowFactoryRequestBus::Broadcast( + &MaterialEditor::MaterialEditorWindowFactoryRequestBus::Handler::DestroyMaterialEditorWindow); + UnloadSettings(); AzFramework::Application::Stop(); } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp index abaf50804f..948a23d509 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -70,6 +71,8 @@ namespace MaterialEditor void MaterialViewportComponent::Reflect(AZ::ReflectContext* context) { + MaterialViewportSettings::Reflect(context); + if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() @@ -160,6 +163,9 @@ namespace MaterialEditor void MaterialViewportComponent::Activate() { + m_viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + m_lightingPresetPreviewImageDefault = QImage(180, 90, QImage::Format::Format_RGBA8888); m_lightingPresetPreviewImageDefault.fill(Qt::GlobalColor::black); @@ -192,13 +198,14 @@ namespace MaterialEditor MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnBeginReloadContent); - const AZStd::string prevLightingPresetSelectionName = m_lightingPresetSelection ? m_lightingPresetSelection->m_displayName : ""; - const AZStd::string prevModelPresetSelectionName = m_modelPresetSelection ? m_modelPresetSelection->m_displayName : ""; + const AZStd::string selectedLightingPresetNameOld = m_viewportSettings->m_selectedLightingPresetName; m_lightingPresetVector.clear(); m_lightingPresetLastSavePathMap.clear(); m_lightingPresetSelection.reset(); + const AZStd::string selectedModelPresetNameOld = m_viewportSettings->m_selectedModelPresetName; + m_modelPresetVector.clear(); m_modelPresetLastSavePathMap.clear(); m_modelPresetSelection.reset(); @@ -263,8 +270,8 @@ namespace MaterialEditor // If there was a prior selection, this will keep the same configuration selected. // Otherwise, these strings are empty and the operation will be ignored. - SelectLightingPresetByName(prevLightingPresetSelectionName); - SelectModelPresetByName(prevModelPresetSelectionName); + SelectLightingPresetByName(selectedLightingPresetNameOld); + SelectModelPresetByName(selectedModelPresetNameOld); MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnEndReloadContent); @@ -327,6 +334,7 @@ namespace MaterialEditor if (preset) { m_lightingPresetSelection = preset; + m_viewportSettings->m_selectedLightingPresetName = preset->m_displayName; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnLightingPresetSelected, m_lightingPresetSelection); } } @@ -422,6 +430,7 @@ namespace MaterialEditor if (preset) { m_modelPresetSelection = preset; + m_viewportSettings->m_selectedModelPresetName = preset->m_displayName; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnModelPresetSelected, m_modelPresetSelection); } } @@ -463,71 +472,66 @@ namespace MaterialEditor void MaterialViewportComponent::SetShadowCatcherEnabled(bool enable) { - m_shadowCatcherEnabled = enable; + m_viewportSettings->m_enableShadowCatcher = enable; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnShadowCatcherEnabledChanged, enable); } bool MaterialViewportComponent::GetShadowCatcherEnabled() const { - return m_shadowCatcherEnabled; + return m_viewportSettings->m_enableShadowCatcher; } void MaterialViewportComponent::SetGridEnabled(bool enable) { - m_gridEnabled = enable; + m_viewportSettings->m_enableGrid = enable; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnGridEnabledChanged, enable); } bool MaterialViewportComponent::GetGridEnabled() const { - return m_gridEnabled; + return m_viewportSettings->m_enableGrid; } void MaterialViewportComponent::SetAlternateSkyboxEnabled(bool enable) { - m_alternateSkyboxEnabled = enable; + m_viewportSettings->m_enableAlternateSkybox = enable; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnAlternateSkyboxEnabledChanged, enable); } bool MaterialViewportComponent::GetAlternateSkyboxEnabled() const { - return m_alternateSkyboxEnabled; + return m_viewportSettings->m_enableAlternateSkybox; } void MaterialViewportComponent::SetFieldOfView(float fieldOfView) { - m_fieldOfView = fieldOfView; + m_viewportSettings->m_fieldOfView = fieldOfView; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnFieldOfViewChanged, fieldOfView); } float MaterialViewportComponent::GetFieldOfView() const { - return m_fieldOfView; + return m_viewportSettings->m_fieldOfView; } void MaterialViewportComponent::SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) { - m_displayMapperOperationType = operationType; + m_viewportSettings->m_displayMapperOperationType = operationType; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnDisplayMapperOperationTypeChanged, operationType); } AZ::Render::DisplayMapperOperationType MaterialViewportComponent::GetDisplayMapperOperationType() const { - return m_displayMapperOperationType; + return m_viewportSettings->m_displayMapperOperationType; } void MaterialViewportComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile) { AZ::TickBus::QueueFunction([this]() { ReloadContent(); - - // Automatically select preferred default presets if they exist - // We will later data drive this with editor settings - SelectLightingPresetByName("Neutral Urban"); - SelectModelPresetByName("Shader Ball"); }); } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h index 8332cb862c..ad35a86cf2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h @@ -13,13 +13,12 @@ #pragma once #include - -#include -#include - #include #include #include +#include +#include +#include namespace MaterialEditor { @@ -111,10 +110,6 @@ namespace MaterialEditor mutable AZStd::map m_lightingPresetLastSavePathMap; mutable AZStd::map m_modelPresetLastSavePathMap; - bool m_shadowCatcherEnabled = true; - bool m_gridEnabled = true; - bool m_alternateSkyboxEnabled = false; - float m_fieldOfView = 90.0f; - AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; + AZStd::intrusive_ptr m_viewportSettings; }; } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp index 5939a40db6..f009cc1f9b 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -92,6 +93,7 @@ namespace MaterialEditor auto sceneSystem = AzFramework::SceneSystemInterface::Get(); AZ_Assert(sceneSystem, "MaterialViewportRenderer was unable to get the scene system during construction."); AZStd::shared_ptr mainScene = sceneSystem->GetScene(AzFramework::Scene::MainSceneName); + // This should never happen unless scene creation has changed. AZ_Assert(mainScene, "Main scenes missing during system component initialization"); mainScene->SetSubsystem(m_scene); @@ -138,7 +140,6 @@ namespace MaterialEditor m_renderPipeline->SetDefaultViewFromEntity(m_cameraEntity->GetId()); // Configure tone mapper - AzFramework::EntityContextRequestBus::EventResult(m_postProcessEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "postProcessEntity"); AZ_Assert(m_postProcessEntity != nullptr, "Failed to create post process entity."); @@ -154,13 +155,11 @@ namespace MaterialEditor m_displayMapperFeatureProcessor = m_scene->GetFeatureProcessor(); // Init Skybox - m_skyboxFeatureProcessor = m_scene->GetFeatureProcessor(); m_skyboxFeatureProcessor->Enable(true); m_skyboxFeatureProcessor->SetSkyboxMode(AZ::Render::SkyBoxMode::Cubemap); // Create IBL - AzFramework::EntityContextRequestBus::EventResult(m_iblEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "IblEntity"); AZ_Assert(m_iblEntity != nullptr, "Failed to create ibl entity."); @@ -176,8 +175,8 @@ namespace MaterialEditor m_modelEntity->CreateComponent(AZ::Render::MaterialComponentTypeId); m_modelEntity->CreateComponent(azrtti_typeid()); m_modelEntity->Activate(); - // Create shadow catcher + // Create shadow catcher AzFramework::EntityContextRequestBus::EventResult(m_shadowCatcherEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "ViewportShadowCatcher"); AZ_Assert(m_shadowCatcherEntity != nullptr, "Failed to create shadow catcher entity."); m_shadowCatcherEntity->CreateComponent(AZ::Render::MeshComponentTypeId); @@ -208,7 +207,6 @@ namespace MaterialEditor } // Create grid - AzFramework::EntityContextRequestBus::EventResult(m_gridEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "ViewportGrid"); AZ_Assert(m_gridEntity != nullptr, "Failed to create grid entity."); @@ -235,6 +233,16 @@ namespace MaterialEditor MaterialViewportRequestBus::BroadcastResult(modelPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection); OnModelPresetSelected(modelPreset); + // Apply user settinngs restored since last run + AZStd::intrusive_ptr viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + + OnGridEnabledChanged(viewportSettings->m_enableGrid); + OnShadowCatcherEnabledChanged(viewportSettings->m_enableShadowCatcher); + OnAlternateSkyboxEnabledChanged(viewportSettings->m_enableAlternateSkybox); + OnFieldOfViewChanged(viewportSettings->m_fieldOfView); + OnDisplayMapperOperationTypeChanged(viewportSettings->m_displayMapperOperationType); + MaterialDocumentNotificationBus::Handler::BusConnect(); MaterialViewportNotificationBus::Handler::BusConnect(); AZ::TickBus::Handler::BusConnect(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.cpp new file mode 100644 index 0000000000..fd64f3073d --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.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 +#include + +namespace MaterialEditor +{ + void MaterialViewportSettings::Reflect(AZ::ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("enableGrid", &MaterialViewportSettings::m_enableGrid) + ->Field("enableShadowCatcher", &MaterialViewportSettings::m_enableShadowCatcher) + ->Field("enableAlternateSkybox", &MaterialViewportSettings::m_enableAlternateSkybox) + ->Field("fieldOfView", &MaterialViewportSettings::m_fieldOfView) + ->Field("displayMapperOperationType", &MaterialViewportSettings::m_displayMapperOperationType) + ->Field("selectedModelPresetName", &MaterialViewportSettings::m_selectedModelPresetName) + ->Field("selectedLightingPresetName", &MaterialViewportSettings::m_selectedLightingPresetName) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "MaterialViewportSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialViewportSettings::m_enableGrid, "Enable Grid", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialViewportSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialViewportSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") + ->DataElement(AZ::Edit::UIHandlers::Slider, &MaterialViewportSettings::m_fieldOfView, "Field Of View", "") + ->Attribute(AZ::Edit::Attributes::Min, 60.0f) + ->Attribute(AZ::Edit::Attributes::Max, 120.0f) + ->DataElement(AZ::Edit::UIHandlers::ComboBox, &MaterialViewportSettings::m_displayMapperOperationType, "Display Mapper Type", "") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Aces, "Aces") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard") + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class("MaterialViewportSettings") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Constructor() + ->Constructor() + ->Property("enableGrid", BehaviorValueProperty(&MaterialViewportSettings::m_enableGrid)) + ->Property("enableShadowCatcher", BehaviorValueProperty(&MaterialViewportSettings::m_enableShadowCatcher)) + ->Property("enableAlternateSkybox", BehaviorValueProperty(&MaterialViewportSettings::m_enableAlternateSkybox)) + ->Property("fieldOfView", BehaviorValueProperty(&MaterialViewportSettings::m_fieldOfView)) + ->Property("displayMapperOperationType", BehaviorValueProperty(&MaterialViewportSettings::m_displayMapperOperationType)) + ; + } + } +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 6e47de189c..12e75f8fcf 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -10,14 +10,15 @@ * */ -#include #include -#include -#include -#include -#include +#include #include #include +#include +#include +#include +#include +#include #include @@ -121,10 +122,24 @@ namespace MaterialEditor MaterialEditorWindowRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); OnDocumentOpened(AZ::Uuid::CreateNull()); + + auto windowState = AZ::UserSettings::Find( + AZ::Crc32("MaterialEditorWindowState"), AZ::UserSettings::CT_GLOBAL); + if (windowState) + { + windowState->RestoreGeometry(this); + } } MaterialEditorWindow::~MaterialEditorWindow() { + auto windowState = AZ::UserSettings::CreateFind( + AZ::Crc32("MaterialEditorWindowState"), AZ::UserSettings::CT_GLOBAL); + if (windowState) + { + windowState->CaptureGeometry(this); + } + MaterialDocumentNotificationBus::Handler::BusDisconnect(); MaterialEditorWindowRequestBus::Handler::BusDisconnect(); } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp index 820cee30f9..3d796a21ad 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp @@ -10,25 +10,24 @@ * */ -#include -#include +#include +#include #include - -#include +#include +#include #include #include +#include #include - -#include -#include -#include -#include +#include +#include +#include namespace MaterialEditor { void MaterialEditorWindowComponent::Reflect(AZ::ReflectContext* context) { - GeneralViewportSettings::Reflect(context); + MaterialEditorWindowSettings::Reflect(context); if (AZ::SerializeContext* serialize = azrtti_cast(context)) { diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp new file mode 100644 index 0000000000..a9c928df10 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp @@ -0,0 +1,62 @@ +/* +* 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 + +namespace MaterialEditor +{ + void MaterialEditorWindowSettings::Reflect(AZ::ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("enableGrid", &MaterialEditorWindowSettings::m_enableGrid) + ->Field("enableShadowCatcher", &MaterialEditorWindowSettings::m_enableShadowCatcher) + ->Field("enableAlternateSkybox", &MaterialEditorWindowSettings::m_enableAlternateSkybox) + ->Field("fieldOfView", &MaterialEditorWindowSettings::m_fieldOfView) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "MaterialEditorWindowSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableGrid, "Enable Grid", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") + ->DataElement(AZ::Edit::UIHandlers::Slider, &MaterialEditorWindowSettings::m_fieldOfView, "Field Of View", "") + ->Attribute(AZ::Edit::Attributes::Min, 60.0f) + ->Attribute(AZ::Edit::Attributes::Max, 120.0f) + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class("MaterialEditorWindowSettings") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Constructor() + ->Constructor() + ->Property("enableGrid", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableGrid)) + ->Property("enableShadowCatcher", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableShadowCatcher)) + ->Property("enableAlternateSkybox", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableAlternateSkybox)) + ->Property("fieldOfView", BehaviorValueProperty(&MaterialEditorWindowSettings::m_fieldOfView)) + ; + } + } +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp index 2af73bf436..8da7c903a2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp @@ -10,13 +10,13 @@ * */ -#include #include #include +#include #include -#include -#include -#include +#include +#include +#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include @@ -33,15 +33,16 @@ namespace MaterialEditor { AzQtComponents::ToolBar::addMainToolBarStyle(this); + AZStd::intrusive_ptr viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + // Add toggle grid button m_toggleGrid = addAction(QIcon(":/Icons/grid.svg"), "Toggle Grid"); m_toggleGrid->setCheckable(true); connect(m_toggleGrid, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_toggleGrid->isChecked()); - }); - bool enableGrid = false; - MaterialViewportRequestBus::BroadcastResult(enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); - m_toggleGrid->setChecked(enableGrid); + }); + m_toggleGrid->setChecked(viewportSettings->m_enableGrid); // Add toggle shadow catcher button m_toggleShadowCatcher = addAction(QIcon(":/Icons/shadow.svg"), "Toggle Shadow Catcher"); @@ -49,34 +50,32 @@ namespace MaterialEditor connect(m_toggleShadowCatcher, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_toggleShadowCatcher->isChecked()); - }); - bool enableShadowCatcher = false; - MaterialViewportRequestBus::BroadcastResult(enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); - m_toggleShadowCatcher->setChecked(enableShadowCatcher); + }); + m_toggleShadowCatcher->setChecked(viewportSettings->m_enableShadowCatcher); // Add mapping selection button - + QToolButton* toneMappingButton = new QToolButton(this); QMenu* toneMappingMenu = new QMenu(toneMappingButton); - m_operationNames = - { - { AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard" }, - { AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB" }, - { AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough" }, - { AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut" }, - { AZ::Render::DisplayMapperOperationType::Aces, "Aces" } - }; + m_operationNames = { + {AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard"}, + {AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB"}, + {AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough"}, + {AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut"}, + {AZ::Render::DisplayMapperOperationType::Aces, "Aces"}}; + for (auto operationNamePair : m_operationNames) { m_operationActions[operationNamePair.first] = toneMappingMenu->addAction(operationNamePair.second, [operationNamePair]() { MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - operationNamePair.first); - }); + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, operationNamePair.first); + }); m_operationActions[operationNamePair.first]->setCheckable(true); + m_operationActions[operationNamePair.first]->setChecked( + operationNamePair.first == viewportSettings->m_displayMapperOperationType); } - m_operationActions[AZ::Render::DisplayMapperOperationType::Aces]->setChecked(true); + toneMappingButton->setMenu(toneMappingMenu); toneMappingButton->setText("Tone Mapping"); toneMappingButton->setIcon(QIcon(":/Icons/toneMapping.svg")); @@ -122,4 +121,4 @@ namespace MaterialEditor } // namespace MaterialEditor -#include +#include 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 fd50ace918..22e752dddd 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -26,61 +26,12 @@ namespace MaterialEditor { - void GeneralViewportSettings::Reflect(AZ::ReflectContext* context) - { - if (auto serializeContext = azrtti_cast(context)) - { - serializeContext->Class() - ->Version(1) - ->Field("enableGrid", &GeneralViewportSettings::m_enableGrid) - ->Field("enableShadowCatcher", &GeneralViewportSettings::m_enableShadowCatcher) - ->Field("enableAlternateSkybox", &GeneralViewportSettings::m_enableAlternateSkybox) - ->Field("fieldOfView", &GeneralViewportSettings::m_fieldOfView) - ->Field("displayMapperOperationType", &GeneralViewportSettings::m_displayMapperOperationType) - ; - - if (auto editContext = serializeContext->GetEditContext()) - { - editContext->Class( - "GeneralViewportSettings", "") - ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->DataElement(AZ::Edit::UIHandlers::Default, &GeneralViewportSettings::m_enableGrid, "Enable Grid", "") - ->DataElement(AZ::Edit::UIHandlers::Default, &GeneralViewportSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") - ->DataElement(AZ::Edit::UIHandlers::Default, &GeneralViewportSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") - ->DataElement(AZ::Edit::UIHandlers::Slider, &GeneralViewportSettings::m_fieldOfView, "Field Of View", "") - ->Attribute(AZ::Edit::Attributes::Min, 60.0f) - ->Attribute(AZ::Edit::Attributes::Max, 120.0f) - ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralViewportSettings::m_displayMapperOperationType, "Display Mapper Type", "") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Aces, "Aces") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard") - ; - } - } - - if (auto behaviorContext = azrtti_cast(context)) - { - behaviorContext->Class("GeneralViewportSettings") - ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) - ->Attribute(AZ::Script::Attributes::Category, "Editor") - ->Attribute(AZ::Script::Attributes::Module, "render") - ->Constructor() - ->Constructor() - ->Property("enableGrid", BehaviorValueProperty(&GeneralViewportSettings::m_enableGrid)) - ->Property("enableShadowCatcher", BehaviorValueProperty(&GeneralViewportSettings::m_enableShadowCatcher)) - ->Property("enableAlternateSkybox", BehaviorValueProperty(&GeneralViewportSettings::m_enableAlternateSkybox)) - ->Property("fieldOfView", BehaviorValueProperty(&GeneralViewportSettings::m_fieldOfView)) - ->Property("displayMapperOperationType", BehaviorValueProperty(&GeneralViewportSettings::m_displayMapperOperationType)) - ; - } - } - ViewportSettingsInspector::ViewportSettingsInspector(QWidget* parent) : AtomToolsFramework::InspectorWidget(parent) { + m_viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + MaterialViewportNotificationBus::Handler::BusConnect(); } @@ -109,7 +60,7 @@ namespace MaterialEditor AddGroup( groupNameId, groupDisplayName, groupDescription, - new AtomToolsFramework::InspectorPropertyGroupWidget(&m_generalSettings, nullptr, m_generalSettings.TYPEINFO_Uuid(), this)); + new AtomToolsFramework::InspectorPropertyGroupWidget(m_viewportSettings.get(), nullptr, m_viewportSettings->TYPEINFO_Uuid(), this)); } void ViewportSettingsInspector::AddModelGroup() @@ -300,13 +251,13 @@ namespace MaterialEditor m_lightingPreset.reset(); MaterialViewportRequestBus::BroadcastResult(m_lightingPreset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection); - MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); + MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); MaterialViewportRequestBus::BroadcastResult( - m_generalSettings.m_enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); + m_viewportSettings->m_enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); MaterialViewportRequestBus::BroadcastResult( - m_generalSettings.m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); - MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); - MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); + m_viewportSettings->m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); + MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); + MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); AtomToolsFramework::InspectorWidget::Reset(); @@ -330,31 +281,31 @@ namespace MaterialEditor void ViewportSettingsInspector::OnShadowCatcherEnabledChanged(bool enable) { - m_generalSettings.m_enableShadowCatcher = enable; + m_viewportSettings->m_enableShadowCatcher = enable; RefreshGroup("general"); } void ViewportSettingsInspector::OnGridEnabledChanged(bool enable) { - m_generalSettings.m_enableGrid = enable; + m_viewportSettings->m_enableGrid = enable; RefreshGroup("general"); } void ViewportSettingsInspector::OnAlternateSkyboxEnabledChanged(bool enable) { - m_generalSettings.m_enableAlternateSkybox = enable; + m_viewportSettings->m_enableAlternateSkybox = enable; RefreshGroup("general"); } void ViewportSettingsInspector::OnFieldOfViewChanged(float fieldOfView) { - m_generalSettings.m_fieldOfView = fieldOfView; + m_viewportSettings->m_fieldOfView = fieldOfView; RefreshGroup("general"); } void ViewportSettingsInspector::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) { - m_generalSettings.m_displayMapperOperationType = operationType; + m_viewportSettings->m_displayMapperOperationType = operationType; RefreshGroup("general"); } @@ -379,13 +330,13 @@ namespace MaterialEditor { MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnLightingPresetChanged, m_lightingPreset); MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnModelPresetChanged, m_modelPreset); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_generalSettings.m_enableGrid); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_viewportSettings->m_enableGrid); MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_generalSettings.m_enableShadowCatcher); + &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_viewportSettings->m_enableShadowCatcher); MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_generalSettings.m_enableAlternateSkybox); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_generalSettings.m_fieldOfView); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_generalSettings.m_displayMapperOperationType); + &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_viewportSettings->m_enableAlternateSkybox); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_viewportSettings->m_fieldOfView); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_viewportSettings->m_displayMapperOperationType); } AZStd::string ViewportSettingsInspector::GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const 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 c61acb2e4c..fdfdec1458 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h @@ -14,28 +14,16 @@ #if !defined(Q_MOC_RUN) #include -#include #include #include -#include +#include +#include #include +#include #endif namespace MaterialEditor { - struct GeneralViewportSettings - { - AZ_TYPE_INFO(GeneralViewportSettings, "{16150503-A314-4765-82A3-172670C9EA90}"); - AZ_CLASS_ALLOCATOR(GeneralViewportSettings, AZ::SystemAllocator, 0); - static void Reflect(AZ::ReflectContext* context); - - bool m_enableGrid = true; - bool m_enableShadowCatcher = true; - bool m_enableAlternateSkybox = false; - float m_fieldOfView = 90.0f; - AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; - }; - //! Provides controls for viewing and editing a material document settings. //! The settings can be divided into cards, with each one showing a subset of properties. class ViewportSettingsInspector @@ -90,7 +78,7 @@ namespace MaterialEditor AZStd::string GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const; - GeneralViewportSettings m_generalSettings; + AZStd::intrusive_ptr m_viewportSettings; AZ::Render::ModelPresetPtr m_modelPreset; AZ::Render::LightingPresetPtr m_lightingPreset; }; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake index 845ff70cd1..e85a028005 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake @@ -13,7 +13,5 @@ set(FILES Source/main.cpp Source/MaterialEditorApplication.cpp Source/MaterialEditorApplication.h - Include/Atom/Document/MaterialDocumentModule.h - Source/Document/MaterialDocumentModule.cpp tool_dependencies.cmake ) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake index ff781e6664..cf951cf0b2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake @@ -14,11 +14,11 @@ set(FILES Include/Atom/Document/MaterialDocumentSystemRequestBus.h Include/Atom/Document/MaterialDocumentNotificationBus.h Include/Atom/Document/MaterialDocumentRequestBus.h - Include/Atom/Document/MaterialEditorSettingsBus.h + Include/Atom/Document/MaterialDocumentSettings.h + Source/Document/MaterialDocumentModule.cpp Source/Document/MaterialDocumentSystemComponent.cpp Source/Document/MaterialDocumentSystemComponent.h Source/Document/MaterialDocument.cpp Source/Document/MaterialDocument.h - Source/Document/MaterialEditorSettings.cpp - Source/Document/MaterialEditorSettings.h + Source/Document/MaterialDocumentSettings.cpp ) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake index e8a65c8084..6ad602e167 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake @@ -12,6 +12,7 @@ set(FILES Include/Atom/Viewport/InputController/MaterialEditorViewportInputControllerBus.h Include/Atom/Viewport/MaterialViewportModule.h + Include/Atom/Viewport/MaterialViewportSettings.h Include/Atom/Viewport/MaterialViewportRequestBus.h Include/Atom/Viewport/MaterialViewportNotificationBus.h Include/Atom/Viewport/PerformanceMetrics.h @@ -35,6 +36,7 @@ set(FILES Source/Viewport/InputController/RotateModelBehavior.cpp Source/Viewport/InputController/RotateModelBehavior.h Source/Viewport/MaterialViewportModule.cpp + Source/Viewport/MaterialViewportSettings.cpp Source/Viewport/MaterialViewportComponent.cpp Source/Viewport/MaterialViewportComponent.h Source/Viewport/MaterialViewportWidget.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake index 1547dbf48f..52022e6e87 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake @@ -11,6 +11,7 @@ set(FILES Include/Atom/Window/MaterialEditorWindowModule.h + Include/Atom/Window/MaterialEditorWindowSettings.h Include/Atom/Window/MaterialEditorWindowNotificationBus.h Include/Atom/Window/MaterialEditorWindowRequestBus.h Include/Atom/Window/MaterialEditorWindowFactoryRequestBus.h @@ -19,6 +20,7 @@ set(FILES Source/Window/MaterialEditorWindow.h Source/Window/MaterialEditorWindow.cpp Source/Window/MaterialEditorWindowModule.cpp + Source/Window/MaterialEditorWindowSettings.cpp Source/Window/MaterialBrowserWidget.h Source/Window/MaterialBrowserWidget.cpp Source/Window/MaterialBrowserWidget.ui From e9165ed91116d98b507e050e99902a1510e59fb7 Mon Sep 17 00:00:00 2001 From: guthadam Date: Fri, 7 May 2021 20:16:05 -0500 Subject: [PATCH 2/5] Added save state keys to most of the RPEs in the material editor and component to save expand/collapse state Saving main window fancy docking state so all of the dock widgets save/restore visibly and positioning Added window decoration wrapper inside material editor main window for saving/restoring window position, size, state Added object names to several QT widgets so that their state could be captured and restored --- .../Inspector/InspectorPropertyGroupWidget.h | 1 + .../InspectorPropertyGroupWidget.cpp | 2 + .../Window/MaterialEditorWindowSettings.h | 5 +- .../Source/Window/MaterialEditorWindow.cpp | 117 +++++++++++------- .../Window/MaterialEditorWindowComponent.cpp | 1 - .../Window/MaterialEditorWindowSettings.cpp | 17 +-- .../MaterialInspector/MaterialInspector.cpp | 18 ++- .../MaterialInspector/MaterialInspector.h | 1 + .../ViewportSettingsInspector.cpp | 10 +- .../EditorMaterialComponentInspector.cpp | 12 +- 10 files changed, 111 insertions(+), 73 deletions(-) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h index 71ca975f58..60eae524a5 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h @@ -44,6 +44,7 @@ namespace AtomToolsFramework const AZ::Uuid& instanceClassId, AzToolsFramework::IPropertyEditorNotify* instanceNotificationHandler = {}, QWidget* parent = {}, + const AZ::u32 saveStateKey = {}, const AzToolsFramework::InstanceDataHierarchy::ValueComparisonFunction& valueComparisonFunction = {}); void Refresh() override; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorPropertyGroupWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorPropertyGroupWidget.cpp index c4d78d1acb..b850b4a488 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorPropertyGroupWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorPropertyGroupWidget.cpp @@ -22,6 +22,7 @@ namespace AtomToolsFramework const AZ::Uuid& instanceClassId, AzToolsFramework::IPropertyEditorNotify* instanceNotificationHandler, QWidget* parent, + const AZ::u32 saveStateKey, const AzToolsFramework::InstanceDataHierarchy::ValueComparisonFunction& valueComparisonFunction) : InspectorGroupWidget(parent) { @@ -37,6 +38,7 @@ namespace AtomToolsFramework m_propertyEditor->SetHideRootProperties(true); m_propertyEditor->SetAutoResizeLabels(true); m_propertyEditor->SetValueComparisonFunction(valueComparisonFunction); + m_propertyEditor->SetSavedStateKey(saveStateKey); m_propertyEditor->Setup(context, instanceNotificationHandler, false); m_propertyEditor->AddInstance(instance, instanceClassId, nullptr, instanceToCompare); m_propertyEditor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h index bf572b070a..b28d4d662b 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h @@ -29,9 +29,6 @@ namespace MaterialEditor static void Reflect(AZ::ReflectContext* context); - bool m_enableGrid = true; - bool m_enableShadowCatcher = true; - bool m_enableAlternateSkybox = false; - float m_fieldOfView = 90.0f; + AZStd::vector m_mainWindowState; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 12e75f8fcf..e62dae2986 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -10,46 +10,50 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - #include - #include #include #include #include #include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + #include -#include -#include -#include +#include #include #include +#include #include +#include #include -#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT +#include +#include #include -#include +#include #include -#include #include +#include +#include AZ_POP_DISABLE_WARNING namespace MaterialEditor @@ -57,6 +61,15 @@ namespace MaterialEditor MaterialEditorWindow::MaterialEditorWindow(QWidget* parent /* = 0 */) : AzQtComponents::DockMainWindow(parent) { + resize(1280, 1024); + + // Among other things, we need the window wrapper to save the main window size, position, and state + auto mainWindowWrapper = + new AzQtComponents::WindowDecorationWrapper(AzQtComponents::WindowDecorationWrapper::OptionAutoTitleBarButtons); + mainWindowWrapper->setGuest(this); + mainWindowWrapper->enableSaveRestoreGeometry("amazon", "MaterialEditor", "mainWindowGeometry"); + + // set the style sheet for RPE highlighting and other styling AzQtComponents::StyleManager::setStyleSheet(this, QStringLiteral(":/MaterialEditor.qss")); QApplication::setWindowIcon(QIcon(":/Icons/materialtype.svg")); @@ -75,6 +88,7 @@ namespace MaterialEditor m_advancedDockManager = new AzQtComponents::FancyDocking(this); + setObjectName("MaterialEditorWindow"); setDockNestingEnabled(true); setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); @@ -82,17 +96,21 @@ namespace MaterialEditor setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); m_menuBar = new QMenuBar(this); + m_menuBar->setObjectName("MenuBar"); setMenuBar(m_menuBar); m_toolBar = new MaterialEditorToolBar(this); + m_toolBar->setObjectName("ToolBar"); addToolBar(m_toolBar); m_centralWidget = new QWidget(this); m_tabWidget = new AzQtComponents::TabWidget(m_centralWidget); + m_tabWidget->setObjectName("TabWidget"); m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); m_tabWidget->setContentsMargins(0, 0, 0, 0); m_materialViewport = new MaterialViewportWidget(m_centralWidget); + m_materialViewport->setObjectName("Viewport"); m_materialViewport->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); QVBoxLayout* vl = new QVBoxLayout(m_centralWidget); @@ -104,7 +122,8 @@ namespace MaterialEditor setCentralWidget(m_centralWidget); m_statusBar = new StatusBarWidget(this); - this->statusBar()->addPermanentWidget(m_statusBar, 1); + m_statusBar->setObjectName("StatusBar"); + statusBar()->addPermanentWidget(m_statusBar, 1); SetupMenu(); SetupTabs(); @@ -119,27 +138,26 @@ namespace MaterialEditor SetDockWidgetVisible("Performance Monitor", false); SetDockWidgetVisible("Python Terminal", false); + // Restore geometry and show the window + mainWindowWrapper->showFromSettings(); + + // Restore additional state for docked windows + auto windowSettings = AZ::UserSettings::CreateFind( + AZ::Crc32("MaterialEditorwindowSettings"), AZ::UserSettings::CT_GLOBAL); + + if (!windowSettings->m_mainWindowState.empty()) + { + QByteArray windowState(windowSettings->m_mainWindowState.data(), windowSettings->m_mainWindowState.size()); + m_advancedDockManager->restoreState(windowState); + } + MaterialEditorWindowRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); OnDocumentOpened(AZ::Uuid::CreateNull()); - - auto windowState = AZ::UserSettings::Find( - AZ::Crc32("MaterialEditorWindowState"), AZ::UserSettings::CT_GLOBAL); - if (windowState) - { - windowState->RestoreGeometry(this); - } } MaterialEditorWindow::~MaterialEditorWindow() { - auto windowState = AZ::UserSettings::CreateFind( - AZ::Crc32("MaterialEditorWindowState"), AZ::UserSettings::CT_GLOBAL); - if (windowState) - { - windowState->CaptureGeometry(this); - } - MaterialDocumentNotificationBus::Handler::BusDisconnect(); MaterialEditorWindowRequestBus::Handler::BusDisconnect(); } @@ -159,8 +177,9 @@ namespace MaterialEditor } auto dockWidget = new AzQtComponents::StyledDockWidget(name.c_str()); - dockWidget->setObjectName(name.c_str()); + dockWidget->setObjectName(QString("%1_DockWidget").arg(name.c_str())); dockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); + widget->setObjectName(name.c_str()); widget->setParent(dockWidget); widget->setMinimumSize(QSize(300, 300)); dockWidget->setWidget(widget); @@ -218,15 +237,16 @@ namespace MaterialEditor QSize requestedWindowSize = size() + offset; resize(requestedWindowSize); - AZ_Assert(m_materialViewport->size() == requestedViewportSize, + AZ_Assert( + m_materialViewport->size() == requestedViewportSize, "Resizing the window did not give the expected viewport size. Requested %d x %d but got %d x %d.", - requestedViewportSize.width(), requestedViewportSize.height(), - m_materialViewport->size().width(), m_materialViewport->size().height()); + requestedViewportSize.width(), requestedViewportSize.height(), m_materialViewport->size().width(), + m_materialViewport->size().height()); QSize newDeviceSize = m_materialViewport->size(); - AZ_Warning("Material Editor", newDeviceSize.width() == width && newDeviceSize.height() == height, - "Resizing the window did not give the expected frame size. Requested %d x %d but got %d x %d.", - width, height, + AZ_Warning( + "Material Editor", newDeviceSize.width() == width && newDeviceSize.height() == height, + "Resizing the window did not give the expected frame size. Requested %d x %d but got %d x %d.", width, height, newDeviceSize.width(), newDeviceSize.height()); } @@ -250,6 +270,13 @@ namespace MaterialEditor return; } + // Capture docking state before shutdown + auto windowSettings = AZ::UserSettings::CreateFind( + AZ::Crc32("MaterialEditorwindowSettings"), AZ::UserSettings::CT_GLOBAL); + + QByteArray windowState = m_advancedDockManager->saveState(); + windowSettings->m_mainWindowState.assign(windowState.begin(), windowState.end()); + MaterialEditorWindowNotificationBus::Broadcast(&MaterialEditorWindowNotifications::OnMaterialEditorWindowClosing); } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp index 3d796a21ad..b0e8533ba4 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp @@ -101,7 +101,6 @@ namespace MaterialEditor m_materialEditorBrowserInteractions.reset(aznew MaterialEditorBrowserInteractions); m_window.reset(aznew MaterialEditorWindow); - m_window->show(); } void MaterialEditorWindowComponent::DestroyMaterialEditorWindow() diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp index a9c928df10..5ea23de8c6 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp @@ -22,11 +22,8 @@ namespace MaterialEditor { serializeContext->Class() ->Version(1) - ->Field("enableGrid", &MaterialEditorWindowSettings::m_enableGrid) - ->Field("enableShadowCatcher", &MaterialEditorWindowSettings::m_enableShadowCatcher) - ->Field("enableAlternateSkybox", &MaterialEditorWindowSettings::m_enableAlternateSkybox) - ->Field("fieldOfView", &MaterialEditorWindowSettings::m_fieldOfView) - ; + ->Field("mainWindowState", &MaterialEditorWindowSettings::m_mainWindowState) + ; if (auto editContext = serializeContext->GetEditContext()) { @@ -34,12 +31,6 @@ namespace MaterialEditor "MaterialEditorWindowSettings", "") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableGrid, "Enable Grid", "") - ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") - ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") - ->DataElement(AZ::Edit::UIHandlers::Slider, &MaterialEditorWindowSettings::m_fieldOfView, "Field Of View", "") - ->Attribute(AZ::Edit::Attributes::Min, 60.0f) - ->Attribute(AZ::Edit::Attributes::Max, 120.0f) ; } } @@ -52,10 +43,6 @@ namespace MaterialEditor ->Attribute(AZ::Script::Attributes::Module, "render") ->Constructor() ->Constructor() - ->Property("enableGrid", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableGrid)) - ->Property("enableShadowCatcher", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableShadowCatcher)) - ->Property("enableAlternateSkybox", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableAlternateSkybox)) - ->Property("fieldOfView", BehaviorValueProperty(&MaterialEditorWindowSettings::m_fieldOfView)) ; } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp index b066c3c7dd..dffbd43702 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp @@ -39,6 +39,7 @@ namespace MaterialEditor void MaterialInspector::Reset() { + m_documentPath.clear(); m_documentId = AZ::Uuid::CreateNull(); m_groups = {}; @@ -55,6 +56,8 @@ namespace MaterialEditor bool isOpen = false; MaterialDocumentRequestBus::EventResult(isOpen, m_documentId, &MaterialDocumentRequestBus::Events::IsOpen); + MaterialDocumentRequestBus::EventResult(m_documentPath, m_documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath); + if (!m_documentId.IsNull() && isOpen) { // Create the top group for displaying details about the material @@ -89,7 +92,10 @@ namespace MaterialEditor group.m_properties.push_back(property); // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this, + const AZ::Crc32 saveStateKey( + AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupDisplayName.c_str())); + auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( + &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { AZ_UNUSED(source); const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); @@ -121,7 +127,10 @@ namespace MaterialEditor } // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this, + const AZ::Crc32 saveStateKey( + AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupDisplayName.c_str())); + auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( + &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { AZ_UNUSED(source); const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); @@ -156,7 +165,10 @@ namespace MaterialEditor } // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this, + const AZ::Crc32 saveStateKey( + AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupDisplayName.c_str())); + auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( + &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { AZ_UNUSED(source); const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h index efe979e5ea..a7a4dddbaa 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h @@ -64,6 +64,7 @@ namespace MaterialEditor const AtomToolsFramework::DynamicProperty* m_activeProperty = nullptr; AZ::Uuid m_documentId = AZ::Uuid::CreateNull(); + AZStd::string m_documentPath; AZStd::unordered_map m_groups; }; } // 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 22e752dddd..384644f79c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -58,9 +58,11 @@ namespace MaterialEditor const AZStd::string groupDisplayName = "General"; const AZStd::string groupDescription = "General"; + const AZ::Crc32 saveStateKey(AZStd::string::format("ViewportSettingsInspector::GeneralGroup")); AddGroup( groupNameId, groupDisplayName, groupDescription, - new AtomToolsFramework::InspectorPropertyGroupWidget(m_viewportSettings.get(), nullptr, m_viewportSettings->TYPEINFO_Uuid(), this)); + new AtomToolsFramework::InspectorPropertyGroupWidget( + m_viewportSettings.get(), nullptr, m_viewportSettings->TYPEINFO_Uuid(), this, this, saveStateKey)); } void ViewportSettingsInspector::AddModelGroup() @@ -92,8 +94,9 @@ namespace MaterialEditor if (m_modelPreset) { + const AZ::Crc32 saveStateKey(AZStd::string::format("ViewportSettingsInspector::ModelGroup")); auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this, groupWidget); + m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this, groupWidget, saveStateKey); groupWidget->layout()->addWidget(inspectorWidget); } @@ -179,8 +182,9 @@ namespace MaterialEditor if (m_lightingPreset) { + const AZ::Crc32 saveStateKey(AZStd::string::format("ViewportSettingsInspector::LightingGroup")); auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this, groupWidget); + m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this, groupWidget, saveStateKey); groupWidget->layout()->addWidget(inspectorWidget); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp index 03533e142f..1ae0610169 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp @@ -213,7 +213,11 @@ namespace AZ } // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this, + const AZ::Crc32 saveStateKey(AZStd::string::format( + "MaterialPropertyInspector::PropertyGroup::%s::%s", m_materialAssetId.ToString().c_str(), + groupDisplayName.c_str())); + auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( + &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { AZ_UNUSED(source); const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); @@ -262,7 +266,11 @@ namespace AZ } // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this, + const AZ::Crc32 saveStateKey(AZStd::string::format( + "MaterialPropertyInspector::PropertyGroup::%s::%s", m_materialAssetId.ToString().c_str(), + groupDisplayName.c_str())); + auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( + &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { AZ_UNUSED(source); const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); From 1dda6dabe4db1f1b166b3fe0e656f15915efc2d9 Mon Sep 17 00:00:00 2001 From: guthadam Date: Sat, 8 May 2021 00:57:16 -0500 Subject: [PATCH 3/5] Added support for expanding/collapsing material inspector groups by name Saving/restoring material inspector group expansion state --- .../Inspector/InspectorGroupHeaderWidget.h | 4 +- .../Inspector/InspectorRequestBus.h | 9 ++ .../Inspector/InspectorWidget.h | 15 ++- .../Inspector/InspectorGroupHeaderWidget.cpp | 17 ++- .../Code/Source/Inspector/InspectorWidget.cpp | 102 +++++++++++++----- .../Window/MaterialEditorWindowSettings.h | 1 + .../Source/Window/MaterialEditorWindow.cpp | 4 +- .../Window/MaterialEditorWindowSettings.cpp | 1 + .../MaterialInspector/MaterialInspector.cpp | 68 +++++++----- .../MaterialInspector/MaterialInspector.h | 10 ++ .../EditorMaterialComponentInspector.cpp | 4 +- 11 files changed, 169 insertions(+), 66 deletions(-) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h index bba299187b..931f88d0eb 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorGroupHeaderWidget.h @@ -29,11 +29,13 @@ namespace AtomToolsFramework AZ_CLASS_ALLOCATOR(InspectorGroupHeaderWidget, AZ::SystemAllocator, 0); explicit InspectorGroupHeaderWidget(QWidget* parent = nullptr); - void SetExpanded(bool expanded); + void SetExpanded(bool expand); bool IsExpanded() const; Q_SIGNALS: void clicked(QMouseEvent* event); + void expanded(); + void collapsed(); protected: void mousePressEvent(QMouseEvent* event) override; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h index 81b512faf2..e76837137a 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorRequestBus.h @@ -56,6 +56,15 @@ namespace AtomToolsFramework //! Calls Rebuild for all InspectorGroupWidget, allowing for destructive UI changes virtual void RebuildAll() = 0; + //! Expands a specific group + virtual void ExpandGroup(const AZStd::string& groupNameId) = 0; + + //! Collapses a specific group + virtual void CollapseGroup(const AZStd::string& groupNameId) = 0; + + //! Checks the expansion state of a specific group + virtual bool IsGroupExpanded(const AZStd::string& groupNameId) const = 0; + //! Expands all groups and headers virtual void ExpandAll() = 0; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h index b0932b3b04..5fb0b731d6 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Inspector/InspectorWidget.h @@ -63,15 +63,22 @@ namespace AtomToolsFramework void RefreshAll() override; void RebuildAll() override; + void ExpandGroup(const AZStd::string& groupNameId) override; + void CollapseGroup(const AZStd::string& groupNameId) override; + bool IsGroupExpanded(const AZStd::string& groupNameId) const override; + void ExpandAll() override; void CollapseAll() override; - private: - void OnHeaderClicked(QMouseEvent* event, InspectorGroupHeaderWidget* groupHeader, QWidget* groupWidget); + protected: + virtual bool ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const; + virtual void OnGroupExpanded(const AZStd::string& groupNameId); + virtual void OnGroupCollapsed(const AZStd::string& groupNameId); + virtual void OnHeaderClicked(const AZStd::string& groupNameId, QMouseEvent* event); + private: QVBoxLayout* m_layout = nullptr; QScopedPointer m_ui; - AZStd::vector m_headers; - AZStd::vector m_groups; + AZStd::unordered_map> m_groups; }; } // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp index 41cc1e4a50..666f8f6c93 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorGroupHeaderWidget.cpp @@ -33,10 +33,21 @@ namespace AtomToolsFramework setMargin(0); } - void InspectorGroupHeaderWidget::SetExpanded(bool expanded) + void InspectorGroupHeaderWidget::SetExpanded(bool expand) { - m_expanded = expanded; - update(); + if (m_expanded != expand) + { + m_expanded = expand; + if (m_expanded) + { + emit expanded(); + } + else + { + emit collapsed(); + } + update(); + } } bool InspectorGroupHeaderWidget::IsExpanded() const diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp index ec5f9893bd..0259120d9b 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Inspector/InspectorWidget.cpp @@ -39,7 +39,6 @@ namespace AtomToolsFramework m_layout = new QVBoxLayout(m_ui->m_propertyContent); m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setSpacing(0); - m_headers.clear(); m_groups.clear(); } @@ -70,16 +69,27 @@ namespace AtomToolsFramework groupHeader->setText(groupDisplayName.c_str()); groupHeader->setToolTip(groupDescription.c_str()); m_layout->addWidget(groupHeader); - m_headers.push_back(groupHeader); groupWidget->setObjectName(groupNameId.c_str()); groupWidget->setParent(m_ui->m_propertyContent); m_layout->addWidget(groupWidget); - m_groups.push_back(groupWidget); - connect(groupHeader, &InspectorGroupHeaderWidget::clicked, this, [this, groupHeader, groupWidget](QMouseEvent* event) { - OnHeaderClicked(event, groupHeader, groupWidget); + m_groups[groupNameId] = AZStd::make_pair(groupHeader, groupWidget); + + connect(groupHeader, &InspectorGroupHeaderWidget::clicked, this, [this, groupNameId](QMouseEvent* event) { + OnHeaderClicked(groupNameId, event); }); + connect(groupHeader, &InspectorGroupHeaderWidget::expanded, this, [this, groupNameId]() { OnGroupExpanded(groupNameId); }); + connect(groupHeader, &InspectorGroupHeaderWidget::collapsed, this, [this, groupNameId]() { OnGroupCollapsed(groupNameId); }); + + if (ShouldGroupAutoExpanded(groupNameId)) + { + ExpandGroup(groupNameId); + } + else + { + CollapseGroup(groupNameId); + } } void InspectorWidget::RefreshGroup(const AZStd::string& groupNameId) @@ -114,50 +124,86 @@ namespace AtomToolsFramework } } + void InspectorWidget::ExpandGroup(const AZStd::string& groupNameId) + { + auto groupItr = m_groups.find(groupNameId); + if (groupItr != m_groups.end()) + { + groupItr->second.first->SetExpanded(true); + groupItr->second.second->setVisible(true); + } + } + + void InspectorWidget::CollapseGroup(const AZStd::string& groupNameId) + { + auto groupItr = m_groups.find(groupNameId); + if (groupItr != m_groups.end()) + { + groupItr->second.first->SetExpanded(false); + groupItr->second.second->setVisible(false); + } + } + + bool InspectorWidget::IsGroupExpanded(const AZStd::string& groupNameId) const + { + auto groupItr = m_groups.find(groupNameId); + return groupItr != m_groups.end() ? groupItr->second.first->IsExpanded() : false; + } + void InspectorWidget::ExpandAll() { - for (auto headerWidget : m_headers) + for (auto& groupPair : m_groups) { - headerWidget->SetExpanded(true); - } - for (auto groupWidget : m_groups) - { - groupWidget->setVisible(true); + groupPair.second.first->SetExpanded(true); + groupPair.second.second->setVisible(true); } } void InspectorWidget::CollapseAll() { - for (auto headerWidget : m_headers) + for (auto& groupPair : m_groups) { - headerWidget->SetExpanded(false); - } - for (auto groupWidget : m_groups) - { - groupWidget->setVisible(false); + groupPair.second.first->SetExpanded(false); + groupPair.second.second->setVisible(false); } } - void InspectorWidget::OnHeaderClicked(QMouseEvent* event, InspectorGroupHeaderWidget* groupHeader, QWidget* groupWidget) + bool InspectorWidget::ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const + { + AZ_UNUSED(groupNameId); + return true; + } + + void InspectorWidget::OnGroupExpanded(const AZStd::string& groupNameId) + { + AZ_UNUSED(groupNameId); + } + + void InspectorWidget::OnGroupCollapsed(const AZStd::string& groupNameId) + { + AZ_UNUSED(groupNameId); + } + + void InspectorWidget::OnHeaderClicked(const AZStd::string& groupNameId, QMouseEvent* event) { if (event->button() == Qt::MouseButton::LeftButton) { - groupHeader->SetExpanded(!groupHeader->IsExpanded()); - groupWidget->setVisible(groupHeader->IsExpanded()); + if (!IsGroupExpanded(groupNameId)) + { + ExpandGroup(groupNameId); + } + else + { + CollapseGroup(groupNameId); + } return; } if (event->button() == Qt::MouseButton::RightButton) { QMenu menu; - menu.addAction("Expand", [groupHeader, groupWidget]() { - groupHeader->SetExpanded(true); - groupWidget->setVisible(true); - })->setEnabled(!groupHeader->IsExpanded()); - menu.addAction("Collapse", [groupHeader, groupWidget]() { - groupHeader->SetExpanded(false); - groupWidget->setVisible(false); - })->setEnabled(groupHeader->IsExpanded()); + menu.addAction("Expand", [this, groupNameId]() { ExpandGroup(groupNameId); })->setEnabled(!IsGroupExpanded(groupNameId)); + menu.addAction("Collapse", [this, groupNameId]() { CollapseGroup(groupNameId); })->setEnabled(IsGroupExpanded(groupNameId)); menu.addAction("Expand All", [this]() { ExpandAll(); }); menu.addAction("Collapse All", [this]() { CollapseAll(); }); menu.exec(event->globalPos()); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h index b28d4d662b..9ff03038f7 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h @@ -30,5 +30,6 @@ namespace MaterialEditor static void Reflect(AZ::ReflectContext* context); AZStd::vector m_mainWindowState; + AZStd::unordered_set m_inspectorCollapsedGroups; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index e62dae2986..075a58c532 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -143,7 +143,7 @@ namespace MaterialEditor // Restore additional state for docked windows auto windowSettings = AZ::UserSettings::CreateFind( - AZ::Crc32("MaterialEditorwindowSettings"), AZ::UserSettings::CT_GLOBAL); + AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL); if (!windowSettings->m_mainWindowState.empty()) { @@ -272,7 +272,7 @@ namespace MaterialEditor // Capture docking state before shutdown auto windowSettings = AZ::UserSettings::CreateFind( - AZ::Crc32("MaterialEditorwindowSettings"), AZ::UserSettings::CT_GLOBAL); + AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL); QByteArray windowState = m_advancedDockManager->saveState(); windowSettings->m_mainWindowState.assign(windowState.begin(), windowState.end()); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp index 5ea23de8c6..da04e2ea20 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp @@ -23,6 +23,7 @@ namespace MaterialEditor serializeContext->Class() ->Version(1) ->Field("mainWindowState", &MaterialEditorWindowSettings::m_mainWindowState) + ->Field("inspectorCollapsedGroups", &MaterialEditorWindowSettings::m_inspectorCollapsedGroups) ; if (auto editContext = serializeContext->GetEditContext()) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp index dffbd43702..2c334ad3b7 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp @@ -21,13 +21,17 @@ #include #include -#include +#include +#include namespace MaterialEditor { MaterialInspector::MaterialInspector(QWidget* parent) : AtomToolsFramework::InspectorWidget(parent) { + m_windowSettings = AZ::UserSettings::CreateFind( + AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL); + MaterialDocumentNotificationBus::Handler::BusConnect(); } @@ -47,6 +51,22 @@ namespace MaterialEditor AtomToolsFramework::InspectorWidget::Reset(); } + bool MaterialInspector::ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const + { + auto stateItr = m_windowSettings->m_inspectorCollapsedGroups.find(GetGroupSaveStateKey(groupNameId)); + return stateItr == m_windowSettings->m_inspectorCollapsedGroups.end(); + } + + void MaterialInspector::OnGroupExpanded(const AZStd::string& groupNameId) + { + m_windowSettings->m_inspectorCollapsedGroups.erase(GetGroupSaveStateKey(groupNameId)); + } + + void MaterialInspector::OnGroupCollapsed(const AZStd::string& groupNameId) + { + m_windowSettings->m_inspectorCollapsedGroups.insert(GetGroupSaveStateKey(groupNameId)); + } + void MaterialInspector::OnDocumentOpened(const AZ::Uuid& documentId) { AddGroupsBegin(); @@ -73,6 +93,20 @@ namespace MaterialEditor AddGroupsEnd(); } + AZ::Crc32 MaterialInspector::GetGroupSaveStateKey(const AZStd::string& groupNameId) const + { + return AZ::Crc32( + AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupNameId.c_str())); + } + + bool MaterialInspector::CompareInstanceNodeProperties( + const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) const + { + AZ_UNUSED(source); + const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); + return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue); + } + void MaterialInspector::AddDetailsGroup() { const AZ::RPI::MaterialTypeSourceData* materialTypeSourceData = nullptr; @@ -92,15 +126,9 @@ namespace MaterialEditor group.m_properties.push_back(property); // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - const AZ::Crc32 saveStateKey( - AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupDisplayName.c_str())); auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, - [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { - AZ_UNUSED(source); - const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); - return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue); - }); + &group, &group, group.TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId), + [this](const auto source, const auto target) { return CompareInstanceNodeProperties(source, target); }); AddGroup(groupNameId, groupDisplayName, groupDescription, propertyGroupWidget); } @@ -127,15 +155,9 @@ namespace MaterialEditor } // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - const AZ::Crc32 saveStateKey( - AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupDisplayName.c_str())); auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, - [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { - AZ_UNUSED(source); - const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); - return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue); - }); + &group, &group, group.TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId), + [this](const auto source, const auto target) { return CompareInstanceNodeProperties(source, target); }); AddGroup(groupNameId, groupDisplayName, groupDescription, propertyGroupWidget); } @@ -165,15 +187,9 @@ namespace MaterialEditor } // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties - const AZ::Crc32 saveStateKey( - AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupDisplayName.c_str())); auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, - [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { - AZ_UNUSED(source); - const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target); - return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue); - }); + &group, &group, group.TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId), + [this](const auto source, const auto target) { return CompareInstanceNodeProperties(source, target); }); AddGroup(groupNameId, groupDisplayName, groupDescription, propertyGroupWidget); } } @@ -270,4 +286,4 @@ namespace MaterialEditor } } // namespace MaterialEditor -#include +#include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h index a7a4dddbaa..b2900b979c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h @@ -41,7 +41,16 @@ namespace MaterialEditor // AtomToolsFramework::InspectorRequestBus::Handler overrides... void Reset() override; + protected: + bool ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const override; + void OnGroupExpanded(const AZStd::string& groupNameId) override; + void OnGroupCollapsed(const AZStd::string& groupNameId) override; + private: + AZ::Crc32 GetGroupSaveStateKey(const AZStd::string& groupNameId) const; + bool CompareInstanceNodeProperties( + const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) const; + void AddDetailsGroup(); void AddUvNamesGroup(); void AddPropertiesGroup(); @@ -66,5 +75,6 @@ namespace MaterialEditor AZ::Uuid m_documentId = AZ::Uuid::CreateNull(); AZStd::string m_documentPath; AZStd::unordered_map m_groups; + AZStd::intrusive_ptr m_windowSettings; }; } // namespace MaterialEditor diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp index 1ae0610169..7f54e386fc 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentInspector.cpp @@ -215,7 +215,7 @@ namespace AZ // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties const AZ::Crc32 saveStateKey(AZStd::string::format( "MaterialPropertyInspector::PropertyGroup::%s::%s", m_materialAssetId.ToString().c_str(), - groupDisplayName.c_str())); + groupNameId.c_str())); auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { @@ -268,7 +268,7 @@ namespace AZ // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties const AZ::Crc32 saveStateKey(AZStd::string::format( "MaterialPropertyInspector::PropertyGroup::%s::%s", m_materialAssetId.ToString().c_str(), - groupDisplayName.c_str())); + groupNameId.c_str())); auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( &group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey, [this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) { From 543784339045b2b8b1ea53fe7312c8cdfd0e0dab Mon Sep 17 00:00:00 2001 From: guthadam Date: Sun, 9 May 2021 12:34:55 -0500 Subject: [PATCH 4/5] 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 From 9725c9beab757fbaeea629257b16ff24b10290f0 Mon Sep 17 00:00:00 2001 From: guthadam Date: Mon, 10 May 2021 12:05:15 -0500 Subject: [PATCH 5/5] Recording/restoring viewport settings group expansion --- .../MaterialInspector/MaterialInspector.cpp | 75 +++++++++------ .../MaterialInspector/MaterialInspector.h | 1 + .../ViewportSettingsInspector.cpp | 94 ++++++++++++------- .../ViewportSettingsInspector.h | 9 +- 4 files changed, 113 insertions(+), 66 deletions(-) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp index 2c334ad3b7..55e098962a 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.cpp @@ -1,14 +1,14 @@ /* -* 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. -* -*/ + * 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 @@ -21,7 +21,6 @@ #include #include -#include #include namespace MaterialEditor @@ -95,8 +94,7 @@ namespace MaterialEditor AZ::Crc32 MaterialInspector::GetGroupSaveStateKey(const AZStd::string& groupNameId) const { - return AZ::Crc32( - AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupNameId.c_str())); + return AZ::Crc32(AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupNameId.c_str())); } bool MaterialInspector::CompareInstanceNodeProperties( @@ -110,7 +108,8 @@ namespace MaterialEditor void MaterialInspector::AddDetailsGroup() { const AZ::RPI::MaterialTypeSourceData* materialTypeSourceData = nullptr; - MaterialDocumentRequestBus::EventResult(materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData); + MaterialDocumentRequestBus::EventResult( + materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData); const AZStd::string groupNameId = "details"; const AZStd::string groupDisplayName = "Details"; @@ -118,11 +117,13 @@ namespace MaterialEditor auto& group = m_groups[groupNameId]; AtomToolsFramework::DynamicProperty property; - MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.materialType")); + MaterialDocumentRequestBus::EventResult( + property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.materialType")); group.m_properties.push_back(property); property = {}; - MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.parentMaterial")); + MaterialDocumentRequestBus::EventResult( + property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.parentMaterial")); group.m_properties.push_back(property); // Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties @@ -148,7 +149,9 @@ namespace MaterialEditor for (const auto& uvNamePair : uvNameMap) { AtomToolsFramework::DynamicProperty property; - MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::RPI::MaterialPropertyId(groupNameId, uvNamePair.m_shaderInput.ToString()).GetFullName()); + MaterialDocumentRequestBus::EventResult( + property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, + AZ::RPI::MaterialPropertyId(groupNameId, uvNamePair.m_shaderInput.ToString()).GetFullName()); group.m_properties.push_back(property); property.SetValue(property.GetConfig().m_parentValue); @@ -164,13 +167,15 @@ namespace MaterialEditor void MaterialInspector::AddPropertiesGroup() { const AZ::RPI::MaterialTypeSourceData* materialTypeSourceData = nullptr; - MaterialDocumentRequestBus::EventResult(materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData); + MaterialDocumentRequestBus::EventResult( + materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData); for (const auto& groupDefinition : materialTypeSourceData->GetGroupDefinitionsInDisplayOrder()) { const AZStd::string& groupNameId = groupDefinition.m_nameId; const AZStd::string& groupDisplayName = !groupDefinition.m_displayName.empty() ? groupDefinition.m_displayName : groupNameId; - const AZStd::string& groupDescription = !groupDefinition.m_description.empty() ? groupDefinition.m_description : groupDisplayName; + const AZStd::string& groupDescription = + !groupDefinition.m_description.empty() ? groupDefinition.m_description : groupDisplayName; auto& group = m_groups[groupNameId]; const auto& propertyLayout = materialTypeSourceData->m_propertyLayout; @@ -181,7 +186,9 @@ namespace MaterialEditor for (const auto& propertyDefinition : propertyListItr->second) { AtomToolsFramework::DynamicProperty property; - MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName()); + MaterialDocumentRequestBus::EventResult( + property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, + AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName()); group.m_properties.push_back(property); } } @@ -205,7 +212,8 @@ namespace MaterialEditor if (!AtomToolsFramework::ArePropertyValuesEqual(reflectedProperty.GetValue(), property.GetValue())) { reflectedProperty.SetValue(property.GetValue()); - AtomToolsFramework::InspectorRequestBus::Event(documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first); + AtomToolsFramework::InspectorRequestBus::Event( + documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first); } return; } @@ -213,7 +221,8 @@ namespace MaterialEditor } } - void MaterialInspector::OnDocumentPropertyConfigModified(const AZ::Uuid& documentId, const AtomToolsFramework::DynamicProperty& property) + void MaterialInspector::OnDocumentPropertyConfigModified( + const AZ::Uuid& documentId, const AtomToolsFramework::DynamicProperty& property) { for (auto& groupPair : m_groups) { @@ -225,12 +234,14 @@ namespace MaterialEditor if (reflectedProperty.GetVisibility() != property.GetVisibility()) { reflectedProperty.SetConfig(property.GetConfig()); - AtomToolsFramework::InspectorRequestBus::Event(documentId, &AtomToolsFramework::InspectorRequestBus::Events::RebuildGroup, groupPair.first); + AtomToolsFramework::InspectorRequestBus::Event( + documentId, &AtomToolsFramework::InspectorRequestBus::Events::RebuildGroup, groupPair.first); } else { reflectedProperty.SetConfig(property.GetConfig()); - AtomToolsFramework::InspectorRequestBus::Event(documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first); + AtomToolsFramework::InspectorRequestBus::Event( + documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first); } return; } @@ -242,7 +253,8 @@ namespace MaterialEditor { // For some reason the reflected property editor notifications are not symmetrical // This function is called continuously anytime a property changes until the edit has completed - // Because of that, we have to track whether or not we are continuing to edit the same property to know when editing has started and ended + // Because of that, we have to track whether or not we are continuing to edit the same property to know when editing has started and + // ended const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(pNode); if (property) { @@ -261,23 +273,24 @@ namespace MaterialEditor { if (m_activeProperty == property) { - MaterialDocumentRequestBus::Event(m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue, - property->GetId(), property->GetValue()); + MaterialDocumentRequestBus::Event( + m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue, property->GetId(), property->GetValue()); } } } void MaterialInspector::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) { - // As above, there are symmetrical functions on the notification interface for when editing begins and ends and has been completed but they are not being called following that pattern. - // when this function executes the changes to the property are ready to be committed or reverted + // As above, there are symmetrical functions on the notification interface for when editing begins and ends and has been completed + // but they are not being called following that pattern. when this function executes the changes to the property are ready to be + // committed or reverted const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(pNode); if (property) { if (m_activeProperty == property) { - MaterialDocumentRequestBus::Event(m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue, - property->GetId(), property->GetValue()); + MaterialDocumentRequestBus::Event( + m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue, property->GetId(), property->GetValue()); MaterialDocumentRequestBus::Event(m_documentId, &MaterialDocumentRequestBus::Events::EndEdit); m_activeProperty = nullptr; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h index b2900b979c..f53e93a2f9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialInspector/MaterialInspector.h @@ -20,6 +20,7 @@ #include #include +#include #endif 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 49bd31ee31..ebce4849e0 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -1,27 +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. -* -*/ + * 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 #include #include +#include +#include #include +#include #include #include -#include -#include #include namespace MaterialEditor @@ -32,6 +32,9 @@ namespace MaterialEditor m_viewportSettings = AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + m_windowSettings = AZ::UserSettings::CreateFind( + AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL); + MaterialViewportNotificationBus::Handler::BusConnect(); } @@ -54,22 +57,21 @@ namespace MaterialEditor void ViewportSettingsInspector::AddGeneralGroup() { - const AZStd::string groupNameId = "general"; - const AZStd::string groupDisplayName = "General"; - const AZStd::string groupDescription = "General"; + const AZStd::string groupNameId = "generalSettings"; + const AZStd::string groupDisplayName = "General Settings"; + const AZStd::string groupDescription = "General Settings"; - const AZ::Crc32 saveStateKey(AZStd::string::format("ViewportSettingsInspector::GeneralGroup")); AddGroup( groupNameId, groupDisplayName, groupDescription, new AtomToolsFramework::InspectorPropertyGroupWidget( - m_viewportSettings.get(), nullptr, m_viewportSettings->TYPEINFO_Uuid(), this, this, saveStateKey)); + m_viewportSettings.get(), nullptr, m_viewportSettings->TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId))); } void ViewportSettingsInspector::AddModelGroup() { - const AZStd::string groupNameId = "model"; - const AZStd::string groupDisplayName = "Model"; - const AZStd::string groupDescription = "Model"; + const AZStd::string groupNameId = "modelSettings"; + const AZStd::string groupDisplayName = "Model Settings"; + const AZStd::string groupDescription = "Model Settings"; auto groupWidget = new QWidget(this); auto buttonGroupWidget = new QWidget(groupWidget); @@ -94,9 +96,8 @@ namespace MaterialEditor if (m_modelPreset) { - const AZ::Crc32 saveStateKey(AZStd::string::format("ViewportSettingsInspector::ModelGroup")); auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this, groupWidget, saveStateKey); + m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this, groupWidget, GetGroupSaveStateKey(groupNameId)); groupWidget->layout()->addWidget(inspectorWidget); } @@ -155,9 +156,9 @@ namespace MaterialEditor void ViewportSettingsInspector::AddLightingGroup() { - const AZStd::string groupNameId = "lighting"; - const AZStd::string groupDisplayName = "Lighting"; - const AZStd::string groupDescription = "Lighting"; + const AZStd::string groupNameId = "lightingSettings"; + const AZStd::string groupDisplayName = "Lighting Settings"; + const AZStd::string groupDescription = "Lighting Settings"; auto groupWidget = new QWidget(this); auto buttonGroupWidget = new QWidget(groupWidget); @@ -182,9 +183,9 @@ namespace MaterialEditor if (m_lightingPreset) { - const AZ::Crc32 saveStateKey(AZStd::string::format("ViewportSettingsInspector::LightingGroup")); auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget( - m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this, groupWidget, saveStateKey); + m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this, groupWidget, + GetGroupSaveStateKey(groupNameId)); groupWidget->layout()->addWidget(inspectorWidget); } @@ -202,8 +203,7 @@ namespace MaterialEditor AZ::Render::LightingPresetPtr preset; MaterialViewportRequestBus::BroadcastResult( preset, &MaterialViewportRequestBus::Events::AddLightingPreset, AZ::Render::LightingPreset()); - MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SaveLightingPreset, preset, savePath); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveLightingPreset, preset, savePath); MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectLightingPreset, preset); } } @@ -227,7 +227,8 @@ namespace MaterialEditor MaterialViewportRequestBus::BroadcastResult(preset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection); AZStd::string defaultPath; - MaterialViewportRequestBus::BroadcastResult(defaultPath, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset); + MaterialViewportRequestBus::BroadcastResult( + defaultPath, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset); if (defaultPath.empty()) { @@ -260,8 +261,10 @@ namespace MaterialEditor m_viewportSettings->m_enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); MaterialViewportRequestBus::BroadcastResult( m_viewportSettings->m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); - MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); - MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); + MaterialViewportRequestBus::BroadcastResult( + m_viewportSettings->m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); + MaterialViewportRequestBus::BroadcastResult( + m_viewportSettings->m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); AtomToolsFramework::InspectorWidget::Reset(); @@ -340,7 +343,8 @@ namespace MaterialEditor MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_viewportSettings->m_enableAlternateSkybox); MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_viewportSettings->m_fieldOfView); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_viewportSettings->m_displayMapperOperationType); + MaterialViewportRequestBus::Broadcast( + &MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_viewportSettings->m_displayMapperOperationType); } AZStd::string ViewportSettingsInspector::GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const @@ -353,6 +357,28 @@ namespace MaterialEditor savePath = AtomToolsFramework::GetUniqueFileInfo(savePath.c_str()).absoluteFilePath().toUtf8().constData(); return savePath; } + + AZ::Crc32 ViewportSettingsInspector::GetGroupSaveStateKey(const AZStd::string& groupNameId) const + { + return AZ::Crc32(AZStd::string::format("ViewportSettingsInspector::PropertyGroup::%s", groupNameId.c_str())); + } + + bool ViewportSettingsInspector::ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const + { + auto stateItr = m_windowSettings->m_inspectorCollapsedGroups.find(GetGroupSaveStateKey(groupNameId)); + return stateItr == m_windowSettings->m_inspectorCollapsedGroups.end(); + } + + void ViewportSettingsInspector::OnGroupExpanded(const AZStd::string& groupNameId) + { + m_windowSettings->m_inspectorCollapsedGroups.erase(GetGroupSaveStateKey(groupNameId)); + } + + void ViewportSettingsInspector::OnGroupCollapsed(const AZStd::string& groupNameId) + { + m_windowSettings->m_inspectorCollapsedGroups.insert(GetGroupSaveStateKey(groupNameId)); + } + } // namespace MaterialEditor #include 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 ac9927e069..23bad988f0 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #endif @@ -78,8 +79,14 @@ namespace MaterialEditor AZStd::string GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const; - AZStd::intrusive_ptr m_viewportSettings; + AZ::Crc32 GetGroupSaveStateKey(const AZStd::string& groupNameId) const; + bool ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const override; + void OnGroupExpanded(const AZStd::string& groupNameId) override; + void OnGroupCollapsed(const AZStd::string& groupNameId) override; + AZ::Render::ModelPresetPtr m_modelPreset; AZ::Render::LightingPresetPtr m_lightingPreset; + AZStd::intrusive_ptr m_viewportSettings; + AZStd::intrusive_ptr m_windowSettings; }; } // namespace MaterialEditor