AtomRenderOptionsActionHandler.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "AtomRenderOptionsActionHandler.h"
  9. #include "AtomRenderOptions.h"
  10. #include <Atom/RPI.Public/Base.h>
  11. #include <AzCore/Debug/Trace.h>
  12. #include <AzCore/Interface/Interface.h>
  13. #include <AzCore/std/containers/vector.h>
  14. #include <AzCore/std/string/string_view.h>
  15. #include <AzToolsFramework/ActionManager/Action/ActionManagerInterface.h>
  16. #include <AzToolsFramework/ActionManager/Menu/MenuManagerInterface.h>
  17. #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorContextIdentifiers.h>
  18. #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorMenuIdentifiers.h>
  19. namespace AZ::Render
  20. {
  21. constexpr AZStd::string_view RenderOptionsMenuIdentifier = "o3de.menu.editor.viewport.renderOptions";
  22. void AtomRenderOptionsActionHandler::Activate()
  23. {
  24. m_actionManagerInterface = AZ::Interface<AzToolsFramework::ActionManagerInterface>::Get();
  25. m_menuManagerInterface = AZ::Interface<AzToolsFramework::MenuManagerInterface>::Get();
  26. if (m_actionManagerInterface && m_menuManagerInterface)
  27. {
  28. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusConnect();
  29. }
  30. AzToolsFramework::EditorEventsBus::Handler::BusConnect();
  31. }
  32. void AtomRenderOptionsActionHandler::Deactivate()
  33. {
  34. AzToolsFramework::EditorEventsBus::Handler::BusDisconnect();
  35. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusDisconnect();
  36. }
  37. void AtomRenderOptionsActionHandler::OnMenuRegistrationHook()
  38. {
  39. AzToolsFramework::MenuProperties menuProperties;
  40. menuProperties.m_name = "Render Options";
  41. m_menuManagerInterface->RegisterMenu(RenderOptionsMenuIdentifier, menuProperties);
  42. }
  43. void AtomRenderOptionsActionHandler::OnActionRegistrationHook()
  44. {
  45. for (const auto& [passName, actionName] : m_passToActionNames)
  46. {
  47. AzToolsFramework::ActionProperties actionProperties;
  48. actionProperties.m_name = passName.GetCStr();
  49. m_actionManagerInterface->RegisterCheckableAction(
  50. EditorIdentifiers::MainWindowActionContextIdentifier,
  51. actionName,
  52. actionProperties,
  53. [passNameCpy = passName]
  54. {
  55. const auto pipeline = GetDefaultViewportPipelinePtr();
  56. if (pipeline)
  57. {
  58. EnablePass(*pipeline, passNameCpy, !IsPassEnabled(*pipeline, passNameCpy));
  59. }
  60. },
  61. [passNameCpy = passName]() -> bool
  62. {
  63. const auto pipeline = GetDefaultViewportPipelinePtr();
  64. return pipeline ? IsPassEnabled(*pipeline, passNameCpy) : false;
  65. });
  66. }
  67. }
  68. void AtomRenderOptionsActionHandler::OnMenuBindingHook()
  69. {
  70. int i = 0;
  71. for (const auto& [passName, actionName] : m_passToActionNames)
  72. {
  73. m_menuManagerInterface->AddActionToMenu(RenderOptionsMenuIdentifier, actionName, 100 + i++);
  74. }
  75. m_menuManagerInterface->AddSeparatorToMenu(EditorIdentifiers::ViewportOptionsMenuIdentifier, 801);
  76. m_menuManagerInterface->AddSubMenuToMenu(EditorIdentifiers::ViewportOptionsMenuIdentifier, RenderOptionsMenuIdentifier, 802);
  77. }
  78. void AtomRenderOptionsActionHandler::NotifyMainWindowInitialized([[maybe_unused]] QMainWindow* mainWindow)
  79. {
  80. const auto pipeline = GetDefaultViewportPipelinePtr();
  81. if (!pipeline)
  82. {
  83. AZ_Warning("AtomRenderOptions", false, "Failed to find default viewport pipeline. No render options will be visible");
  84. }
  85. AZStd::vector<AZ::Name> passNames;
  86. GetViewportOptionsPasses(*pipeline.get(), passNames);
  87. for (const AZ::Name& name : passNames)
  88. {
  89. m_passToActionNames[name] = AZStd::string::format("o3de.action.viewport.renderOptions.%s", name.GetCStr());
  90. }
  91. }
  92. } // namespace AZ::Render