ATOM-15486 Saving material editor user settings

https://jira.agscollab.com/browse/ATOM-15486
This commit is contained in:
guthadam
2021-05-05 23:31:17 -05:00
parent 724add6365
commit e80de63d55
25 changed files with 463 additions and 361 deletions
@@ -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 <Atom/Document/MaterialDocumentSettings.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace MaterialEditor
{
void MaterialDocumentSettings::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<MaterialDocumentSettings, AZ::UserSettings>()
->Version(1)
->Field("showReloadDocumentPrompt", &MaterialDocumentSettings::m_showReloadDocumentPrompt)
;
if (auto editContext = serializeContext->GetEditContext())
{
editContext->Class<MaterialDocumentSettings>(
"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<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<MaterialDocumentSettings>("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<const MaterialDocumentSettings&>()
->Property("showReloadDocumentPrompt", BehaviorValueProperty(&MaterialDocumentSettings::m_showReloadDocumentPrompt))
;
}
}
} // namespace MaterialEditor
@@ -14,6 +14,7 @@
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentSettings.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/RPI.Edit/Material/MaterialSourceData.h>
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
@@ -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<AZ::SerializeContext*>(context))
{
serialize->Class<MaterialDocumentSystemComponent, AZ::Component>()
@@ -132,6 +134,7 @@ namespace MaterialEditor
void MaterialDocumentSystemComponent::Activate()
{
m_documentMap.clear();
m_settings = AZ::UserSettings::CreateFind<MaterialDocumentSettings>(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);
}
}
@@ -18,10 +18,10 @@
#include <AzCore/Asset/AssetCommon.h>
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <Atom/Document/MaterialDocumentSettings.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/RPI.Public/WindowContext.h>
#include <Document/MaterialDocument.h>
#include <Document/MaterialEditorSettings.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QFileInfo>
@@ -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<MaterialDocumentSettings> m_settings;
AZStd::unordered_map<AZ::Uuid, AZStd::shared_ptr<MaterialDocument>> m_documentMap;
AZStd::unordered_set<AZ::Uuid> m_documentIdsToRebuild;
AZStd::unordered_set<AZ::Uuid> m_documentIdsToReopen;
AZStd::unique_ptr<MaterialEditorSettings> m_settings;
const size_t m_maxMessageBoxLineCount = 15;
};
}
} // namespace MaterialEditor
@@ -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 <Document/MaterialEditorSettings.h>
namespace MaterialEditor
{
MaterialEditorSettings::MaterialEditorSettings()
{
MaterialEditorSettingsRequestBus::Handler::BusConnect();
}
MaterialEditorSettings::~MaterialEditorSettings()
{
MaterialEditorSettingsRequestBus::Handler::BusDisconnect();
}
AZ::Outcome<AZStd::any> 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<AZStd::string> MaterialEditorSettings::GetStringProperty(AZStd::string_view name) const
{
AZ::Outcome<AZStd::any> outcome = GetProperty(name);
if (!outcome || !outcome.GetValue().is<AZStd::string>())
{
return AZ::Failure();
}
return AZ::Success(AZStd::any_cast<AZStd::string>(outcome.GetValue()));
}
AZ::Outcome<bool> MaterialEditorSettings::GetBoolProperty(AZStd::string_view name) const
{
AZ::Outcome<AZStd::any> outcome = GetProperty(name);
if (!outcome || !outcome.GetValue().is<bool>())
{
return AZ::Failure();
}
return AZ::Success(AZStd::any_cast<bool>(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));
}
}
@@ -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 <AzCore/RTTI/RTTI.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/any.h>
#include <Atom/Document/MaterialEditorSettingsBus.h>
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<AZStd::any> GetProperty(AZStd::string_view name) const override;
AZ::Outcome<AZStd::string> GetStringProperty(AZStd::string_view name) const override;
AZ::Outcome<bool> 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<AZStd::string, AZStd::any> m_propertyMap;
};
} // namespace MaterialEditor