AssetEditorRequestsHandler.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "AssetEditorRequestsHandler.h"
  10. // AzCore
  11. #include <AzCore/Asset/AssetManager.h>
  12. // Editor
  13. #include "AssetEditorWindow.h"
  14. #include "QtViewPaneManager.h"
  15. AssetEditorRequestsHandler::AssetEditorRequestsHandler()
  16. {
  17. AzToolsFramework::AssetEditor::AssetEditorRequestsBus::Handler::BusConnect();
  18. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  19. }
  20. AssetEditorRequestsHandler::~AssetEditorRequestsHandler()
  21. {
  22. AzToolsFramework::AssetEditor::AssetEditorRequestsBus::Handler::BusDisconnect();
  23. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  24. }
  25. void AssetEditorRequestsHandler::NotifyRegisterViews()
  26. {
  27. using namespace AzToolsFramework::AssetEditor;
  28. if (auto assetsWindowsToRestore = AZ::UserSettings::CreateFind<AssetEditorWindowSettings>(AZ::Crc32(AssetEditorWindowSettings::s_name), AZ::UserSettings::CT_GLOBAL))
  29. {
  30. //copy the current list and clear it since they will be re-added as we request to open them
  31. auto windowsToOpen = assetsWindowsToRestore->m_openAssets;
  32. assetsWindowsToRestore->m_openAssets.clear();
  33. for (auto&& assetRef : windowsToOpen)
  34. {
  35. AssetEditorWindow::RegisterViewClass(assetRef);
  36. }
  37. }
  38. }
  39. void AssetEditorRequestsHandler::CreateNewAsset(const AZ::Data::AssetType& assetType, const AZ::Uuid& observerId)
  40. {
  41. using namespace AzToolsFramework::AssetEditor;
  42. AzToolsFramework::OpenViewPane(LyViewPane::AssetEditor);
  43. AssetEditorWidgetRequestsBus::Broadcast(&AssetEditorWidgetRequests::CreateAsset, assetType, observerId);
  44. }
  45. void AssetEditorRequestsHandler::OpenAssetEditor(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
  46. {
  47. using namespace AzToolsFramework::AssetEditor;
  48. // Open the AssetEditor if it isn't open already.
  49. QtViewPaneManager::instance()->OpenPane(LyViewPane::AssetEditor, QtViewPane::OpenMode::RestoreLayout);
  50. AssetEditorWidgetRequestsBus::Broadcast(&AssetEditorWidgetRequests::OpenAsset, asset);
  51. }
  52. void AssetEditorRequestsHandler::OpenAssetEditorById(const AZ::Data::AssetId assetId)
  53. {
  54. AZ::Data::Asset<AZ::Data::AssetData> asset = AZ::Data::AssetManager::Instance().GetAsset<AZ::Data::AssetData>(assetId, AZ::Data::AssetLoadBehavior::NoLoad);
  55. OpenAssetEditor(asset);
  56. }