Atom Tools: updated document and windows systems and buses to support multiple instances

• This change is partially to unblock physics tool prototyping. It introduces a tool ID that is passed down into systems and acts as a context for document, window, and other systems and buses.
• The document system component is no longer a component. It is just a system class that can be constructed with a tool ID. Internally, it will connect to its buses and be addressable by tool ID. More than one can be instantiated, each with a unique tool ID.
• These changes are still backward compatible because most of the buses were using broadcast for standalone applications. All of those calls have been updated but not all of the scripts, which should still work as is.
• Got rid of the window factory request bus in favor of just instantiating the main window or any other UI in the application layer.
• Fixed a couple of bugs that were discovered while making these changes.

Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
Guthrie Adams
2022-02-11 01:10:17 -06:00
parent 257f3cb1ce
commit c6ba1ef064
39 changed files with 554 additions and 602 deletions
@@ -14,8 +14,8 @@
namespace ShaderManagementConsole
{
ShaderManagementConsoleDocument::ShaderManagementConsoleDocument()
: AtomToolsFramework::AtomToolsDocument()
ShaderManagementConsoleDocument::ShaderManagementConsoleDocument(const AZ::Crc32& toolId)
: AtomToolsFramework::AtomToolsDocument(toolId)
{
ShaderManagementConsoleDocumentRequestBus::Handler::BusConnect(m_id);
}
@@ -37,8 +37,8 @@ namespace ShaderManagementConsole
AZ_Error("ShaderManagementConsoleDocument", false, "Could not load shader asset: %s.", shaderPath.c_str());
}
AtomToolsFramework::AtomToolsDocumentNotificationBus::Broadcast(
&AtomToolsFramework::AtomToolsDocumentNotificationBus::Events::OnDocumentModified, m_id);
AtomToolsFramework::AtomToolsDocumentNotificationBus::Event(
m_toolId, &AtomToolsFramework::AtomToolsDocumentNotificationBus::Events::OnDocumentModified, m_id);
}
const AZ::RPI::ShaderVariantListSourceData& ShaderManagementConsoleDocument::GetShaderVariantListSourceData() const
@@ -24,11 +24,11 @@ namespace ShaderManagementConsole
, public ShaderManagementConsoleDocumentRequestBus::Handler
{
public:
AZ_RTTI(ShaderManagementConsoleDocument, "{DBA269AE-892B-415C-8FA1-166B94B0E045}");
AZ_RTTI(ShaderManagementConsoleDocument, "{504A74BA-F5DD-49E0-BA5E-A381F61DD524}");
AZ_CLASS_ALLOCATOR(ShaderManagementConsoleDocument, AZ::SystemAllocator, 0);
AZ_DISABLE_COPY(ShaderManagementConsoleDocument);
AZ_DISABLE_COPY_MOVE(ShaderManagementConsoleDocument);
ShaderManagementConsoleDocument();
ShaderManagementConsoleDocument(const AZ::Crc32& toolId);
~ShaderManagementConsoleDocument();
// AtomToolsFramework::AtomToolsDocument overrides...
@@ -47,27 +47,29 @@ void InitShaderManagementConsoleResources()
namespace ShaderManagementConsole
{
static const char* GetBuildTargetName()
{
#if !defined(LY_CMAKE_TARGET)
#error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target"
#endif
return LY_CMAKE_TARGET;
}
ShaderManagementConsoleApplication::ShaderManagementConsoleApplication(int* argc, char*** argv)
: Base(argc, argv)
: Base(GetBuildTargetName(), argc, argv)
{
InitShaderManagementConsoleResources();
QApplication::setApplicationName("O3DE Shader Management Console");
// The settings registry has been created at this point, so add the CMake target
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization(
*AZ::SettingsRegistry::Get(), GetBuildTargetName());
ShaderManagementConsoleRequestBus::Handler::BusConnect();
AzToolsFramework::EditorWindowRequestBus::Handler::BusConnect();
AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Handler::BusConnect();
}
ShaderManagementConsoleApplication::~ShaderManagementConsoleApplication()
{
ShaderManagementConsoleRequestBus::Handler::BusDisconnect();
AzToolsFramework::EditorWindowRequestBus::Handler::BusDisconnect();
AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Handler::BusDisconnect();
m_window.reset();
}
@@ -115,40 +117,20 @@ namespace ShaderManagementConsole
{
Base::StartCommon(systemEntity);
AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(
&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Handler::RegisterDocumentType,
[]() { return aznew ShaderManagementConsoleDocument(); });
}
AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Event(
m_toolId, &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Handler::RegisterDocumentType,
[](const AZ::Crc32& toolId) { return aznew ShaderManagementConsoleDocument(toolId); });
AZStd::string ShaderManagementConsoleApplication::GetBuildTargetName() const
{
#if !defined(LY_CMAKE_TARGET)
#error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target"
#endif
//! Returns the build system target name of "ShaderManagementConsole"
return AZStd::string_view{ LY_CMAKE_TARGET };
}
m_window.reset(aznew ShaderManagementConsoleWindow(m_toolId));
AZStd::vector<AZStd::string> ShaderManagementConsoleApplication::GetCriticalAssetFilters() const
{
return AZStd::vector<AZStd::string>({ "passes/", "config/" });
}
QWidget* ShaderManagementConsoleApplication::GetAppMainWindow()
{
return m_window.get();
}
void ShaderManagementConsoleApplication::CreateMainWindow()
{
m_window.reset(aznew ShaderManagementConsoleWindow);
m_assetBrowserInteractions.reset(aznew AtomToolsFramework::AtomToolsAssetBrowserInteractions);
m_assetBrowserInteractions->RegisterContextMenuActions(
[](const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries)
{
return entries.front()->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Source;
},
[]([[maybe_unused]] QWidget* caller, QMenu* menu, const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries)
[this]([[maybe_unused]] QWidget* caller, QMenu* menu, const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries)
{
if (AzFramework::StringFunc::Path::IsExtension(
entries.front()->GetFullPath().c_str(), AZ::RPI::ShaderSourceData::Extension))
@@ -166,10 +148,10 @@ namespace ShaderManagementConsole
else if (AzFramework::StringFunc::Path::IsExtension(
entries.front()->GetFullPath().c_str(), AZ::RPI::ShaderVariantListSourceData::Extension))
{
menu->addAction(QObject::tr("Open"), [entries]()
menu->addAction(QObject::tr("Open"), [entries, this]()
{
AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(
&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument,
AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Event(
m_toolId, &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument,
entries.front()->GetFullPath());
});
}
@@ -183,9 +165,20 @@ namespace ShaderManagementConsole
});
}
void ShaderManagementConsoleApplication::DestroyMainWindow()
void ShaderManagementConsoleApplication::Destroy()
{
m_window.reset();
Base::Destroy();
}
AZStd::vector<AZStd::string> ShaderManagementConsoleApplication::GetCriticalAssetFilters() const
{
return AZStd::vector<AZStd::string>({ "passes/", "config/" });
}
QWidget* ShaderManagementConsoleApplication::GetAppMainWindow()
{
return m_window.get();
}
AZ::Data::AssetInfo ShaderManagementConsoleApplication::GetSourceAssetInfo(const AZStd::string& sourceAssetFileName)
@@ -11,7 +11,6 @@
#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
#include <AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowserInteractions.h>
#include <AtomToolsFramework/Document/AtomToolsDocumentApplication.h>
#include <AtomToolsFramework/Window/AtomToolsMainWindowFactoryRequestBus.h>
#include <AzToolsFramework/API/EditorWindowRequestBus.h>
#include <ShaderManagementConsoleRequestBus.h>
#include <Window/ShaderManagementConsoleWindow.h>
@@ -21,7 +20,6 @@ namespace ShaderManagementConsole
class ShaderManagementConsoleApplication
: public AtomToolsFramework::AtomToolsDocumentApplication
, private ShaderManagementConsoleRequestBus::Handler
, private AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Handler
, private AzToolsFramework::EditorWindowRequestBus::Handler
{
public:
@@ -36,18 +34,14 @@ namespace ShaderManagementConsole
void Reflect(AZ::ReflectContext* context) override;
const char* GetCurrentConfigurationName() const override;
void StartCommon(AZ::Entity* systemEntity) override;
void Destroy() override;
// AtomToolsFramework::AtomToolsApplication overrides...
AZStd::string GetBuildTargetName() const override;
AZStd::vector<AZStd::string> GetCriticalAssetFilters() const override;
// AzToolsFramework::EditorWindowRequests::Bus::Handler
QWidget* GetAppMainWindow() override;
// AtomToolsMainWindowFactoryRequestBus::Handler overrides...
void CreateMainWindow() override;
void DestroyMainWindow() override;
// ShaderManagementConsoleRequestBus::Handler overrides...
AZ::Data::AssetInfo GetSourceAssetInfo(const AZStd::string& sourceAssetFileName) override;
AZStd::vector<AZ::Data::AssetId> FindMaterialAssetsUsingShader(const AZStd::string& shaderFilePath) override;
@@ -26,11 +26,9 @@ AZ_POP_DISABLE_WARNING
namespace ShaderManagementConsole
{
ShaderManagementConsoleWindow::ShaderManagementConsoleWindow(QWidget* parent /* = 0 */)
: Base(parent)
ShaderManagementConsoleWindow::ShaderManagementConsoleWindow(const AZ::Crc32& toolId, QWidget* parent)
: Base(toolId, 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);
@@ -42,11 +40,11 @@ namespace ShaderManagementConsole
setObjectName("ShaderManagementConsoleWindow");
m_assetBrowser->SetFilterState("", AZ::RPI::ShaderAsset::Group, true);
m_assetBrowser->SetOpenHandler([](const AZStd::string& absolutePath) {
m_assetBrowser->SetOpenHandler([this](const AZStd::string& absolutePath) {
if (AzFramework::StringFunc::Path::IsExtension(absolutePath.c_str(), AZ::RPI::ShaderVariantListSourceData::Extension))
{
AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(
&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, absolutePath);
AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Event(
m_toolId, &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, absolutePath);
return;
}
@@ -31,7 +31,7 @@ namespace ShaderManagementConsole
using Base = AtomToolsFramework::AtomToolsDocumentMainWindow;
ShaderManagementConsoleWindow(QWidget* parent = 0);
ShaderManagementConsoleWindow(const AZ::Crc32& toolId, QWidget* parent = 0);
~ShaderManagementConsoleWindow() = default;
protected: