EditorFocusModeSelectionFixture.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #pragma once
  9. #include <Tests/FocusMode/EditorFocusModeFixture.h>
  10. #include <AzCore/Component/TransformBus.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <AzFramework/Viewport/ViewportScreen.h>
  13. #include <AzManipulatorTestFramework/AzManipulatorTestFramework.h>
  14. #include <AzManipulatorTestFramework/AzManipulatorTestFrameworkTestHelpers.h>
  15. #include <AzManipulatorTestFramework/DirectManipulatorViewportInteraction.h>
  16. #include <AzManipulatorTestFramework/ImmediateModeActionDispatcher.h>
  17. #include <AzManipulatorTestFramework/IndirectManipulatorViewportInteraction.h>
  18. #include <AzToolsFramework/Component/EditorComponentAPIBus.h>
  19. #include <AzToolsFramework/Manipulators/LinearManipulator.h>
  20. #include <AzToolsFramework/Manipulators/ManipulatorManager.h>
  21. #include <AzToolsFramework/ViewportSelection/EditorVisibleEntityDataCache.h>
  22. #include <AzToolsFramework/Prefab/PrefabEditorPreferences.h>
  23. namespace UnitTest
  24. {
  25. class EditorFocusModeSelectionFixture : public IndirectCallManipulatorViewportInteractionFixtureMixin<EditorFocusModeFixture>
  26. {
  27. public:
  28. void SetUpEditorFixtureImpl() override
  29. {
  30. AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
  31. m_formerOutlinerOverrideSetting = AzToolsFramework::Prefab::IsOutlinerOverrideManagementEnabled();
  32. registry->Set("/O3DE/Autoexec/ConsoleCommands/ed_enableOutlinerOverrideManagement", true);
  33. IndirectCallManipulatorViewportInteractionFixtureMixin<EditorFocusModeFixture>::SetUpEditorFixtureImpl();
  34. m_viewportManipulatorInteraction->GetViewportInteraction().SetIconsVisible(false);
  35. }
  36. void TearDownEditorFixtureImpl() override
  37. {
  38. AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
  39. IndirectCallManipulatorViewportInteractionFixtureMixin<EditorFocusModeFixture>::TearDownEditorFixtureImpl();
  40. registry->Set("/O3DE/Autoexec/ConsoleCommands/ed_enableOutlinerOverrideManagement", m_formerOutlinerOverrideSetting);
  41. }
  42. void ClickAtWorldPositionOnViewport(const AZ::Vector3& worldPosition)
  43. {
  44. // Calculate the world position in screen space
  45. const auto carScreenPosition = AzFramework::WorldToScreen(worldPosition, m_cameraState);
  46. // Click the entity in the viewport
  47. m_actionDispatcher->CameraState(m_cameraState)->MousePosition(carScreenPosition)->MouseLButtonDown()->MouseLButtonUp();
  48. }
  49. void BoxSelectOnViewport()
  50. {
  51. // Calculate the position in screen space of where to begin and end the box select action
  52. const auto beginningPositionWorldBoxSelect = AzFramework::WorldToScreen(AZ::Vector3(-10.0f, 15.0f, 5.0f), m_cameraState);
  53. const auto endingPositionWorldBoxSelect = AzFramework::WorldToScreen(AZ::Vector3(10.0f, 15.0f, -5.0f), m_cameraState);
  54. // Perform a box select in the viewport
  55. m_actionDispatcher->SetStickySelect(true)
  56. ->CameraState(m_cameraState)
  57. ->MousePosition(beginningPositionWorldBoxSelect)
  58. ->MouseLButtonDown()
  59. ->MousePosition(endingPositionWorldBoxSelect)
  60. ->MouseLButtonUp();
  61. }
  62. protected:
  63. bool m_formerOutlinerOverrideSetting = false;
  64. };
  65. } // namespace UnitTest