3
0

FocusedEntityState.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <Pass/State/FocusedEntityState.h>
  9. #include <AzToolsFramework/FocusMode/FocusModeInterface.h>
  10. #include <AzToolsFramework/Viewport/ViewportMessages.h>
  11. #include <AzToolsFramework/Viewport/ViewportSettings.h>
  12. #include <AzToolsFramework/ViewportSelection/EditorTransformComponentSelectionRequestBus.h>
  13. namespace AZ::Render
  14. {
  15. static PassNameList CreateFocusedEntityChildPasses()
  16. {
  17. // Effect chain for the non-focused entities.
  18. return PassNameList
  19. {
  20. // Black and white effect for unfocused entities (scaled by distance)
  21. AZ::Name("EditorModeDesaturationTemplate"),
  22. // Darkening effect for unfocused entities (scaled by distance)
  23. AZ::Name("EditorModeTintTemplate"),
  24. // Blurring effect for unfocused entities (scaled by distance)
  25. AZ::Name("EditorModeBlurParentTemplate")
  26. };
  27. }
  28. FocusedEntityState::FocusedEntityState()
  29. : EditorStateBase(EditorState::FocusMode, "FocusMode", CreateFocusedEntityChildPasses())
  30. {
  31. AzToolsFramework::ViewportEditorModeNotificationsBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId());
  32. SetEnabled(AzToolsFramework::PrefabEditModeEffectEnabled());
  33. }
  34. FocusedEntityState::~FocusedEntityState()
  35. {
  36. AzToolsFramework::ViewportEditorModeNotificationsBus::Handler::BusDisconnect();
  37. }
  38. void FocusedEntityState::OnEditorModeActivated(
  39. [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState,
  40. AzToolsFramework::ViewportEditorMode mode)
  41. {
  42. if (AzToolsFramework::ViewportEditorMode::Focus == mode)
  43. {
  44. m_inFocusMode = true;
  45. }
  46. }
  47. void FocusedEntityState::OnEditorModeDeactivated(
  48. [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode)
  49. {
  50. if (AzToolsFramework::ViewportEditorMode::Focus == mode)
  51. {
  52. m_inFocusMode = false;
  53. }
  54. }
  55. bool FocusedEntityState::IsEnabled() const
  56. {
  57. return EditorStateBase::IsEnabled() && m_inFocusMode;
  58. }
  59. AzToolsFramework::EntityIdList FocusedEntityState::GetMaskedEntities() const
  60. {
  61. const auto focusModeInterface = AZ::Interface<AzToolsFramework::FocusModeInterface>::Get();
  62. if (!focusModeInterface)
  63. {
  64. return {};
  65. }
  66. return focusModeInterface->GetFocusedEntities(AzToolsFramework::GetEntityContextId());
  67. }
  68. } // namespace AZ::Render