Merge branch 'development' of https://github.com/o3de/o3de into daimini/FocusMode/breadcrumbs
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option")
|
||||
AZ_POP_DISABLE_WARNING
|
||||
|
||||
AZ_CVAR(
|
||||
bool, ed_useNewAssetBrowserTableView, false, nullptr, AZ::ConsoleFunctorFlags::Null,
|
||||
bool, ed_useNewAssetBrowserTableView, true, nullptr, AZ::ConsoleFunctorFlags::Null,
|
||||
"Use the new AssetBrowser TableView for searching assets.");
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ AZ_PUSH_DISABLE_WARNING(4251 4244, "-Wunknown-warning-option") // disable warnin
|
||||
AZ_POP_DISABLE_WARNING
|
||||
|
||||
AZ_CVAR(
|
||||
bool, ed_hideAssetPickerPathColumn, false, nullptr, AZ::ConsoleFunctorFlags::Null,
|
||||
bool, ed_hideAssetPickerPathColumn, true, nullptr, AZ::ConsoleFunctorFlags::Null,
|
||||
"Hide AssetPicker path column for a clearer view.");
|
||||
AZ_CVAR_EXTERNED(bool, ed_useNewAssetBrowserTableView);
|
||||
|
||||
|
||||
+17
-2
@@ -8,8 +8,9 @@
|
||||
|
||||
#include "ComponentModeCollection.h"
|
||||
|
||||
#include <AzToolsFramework/Commands/ComponentModeCommand.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzToolsFramework/API/ViewportEditorModeTrackerInterface.h>
|
||||
#include <AzToolsFramework/Commands/ComponentModeCommand.h>
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace AzToolsFramework
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(ComponentModeCollection, AZ::SystemAllocator, 0)
|
||||
|
||||
static const char* const s_nextActiveComponentModeTitle = "Edit Next";
|
||||
static const char* const s_nextActiveComponentModeTitle = "Edit Next";
|
||||
static const char* const s_previousActiveComponentModeTitle = "Edit Previous";
|
||||
static const char* const s_nextActiveComponentModeDesc = "Move to the next component";
|
||||
static const char* const s_prevActiveComponentModeDesc = "Move to the previous component";
|
||||
@@ -119,6 +120,11 @@ namespace AzToolsFramework
|
||||
}
|
||||
};
|
||||
|
||||
ComponentModeCollection::ComponentModeCollection(ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
: m_viewportEditorModeTracker(viewportEditorModeTracker)
|
||||
{
|
||||
}
|
||||
|
||||
void ComponentModeCollection::AddComponentMode(
|
||||
const AZ::EntityComponentIdPair& entityComponentIdPair, const AZ::Uuid componentType,
|
||||
const ComponentModeFactoryFunction& componentModeBuilder)
|
||||
@@ -209,6 +215,11 @@ namespace AzToolsFramework
|
||||
GetEntityContextId(), &EditorComponentModeNotifications::EnteredComponentMode,
|
||||
m_activeComponentTypes);
|
||||
|
||||
// this call to activate the component mode editor state should eventually replace the bus call in
|
||||
// ComponentModeCollection::BeginComponentMode() to EditorComponentModeNotifications::EnteredComponentMode
|
||||
// such that all of the notifications for activating/deactivating the different editor modes are in a central location
|
||||
m_viewportEditorModeTracker->ActivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Component);
|
||||
|
||||
// enable actions for the first/primary ComponentMode
|
||||
// note: if multiple ComponentModes are activated at the same time, actions
|
||||
// are not available together, the 'active' mode will bind its actions one at a time
|
||||
@@ -282,6 +293,10 @@ namespace AzToolsFramework
|
||||
&EditorComponentModeNotifications::LeftComponentMode,
|
||||
m_activeComponentTypes);
|
||||
|
||||
// this call to deactivate the component mode editor state should eventually replace the bus call in
|
||||
// ComponentModeCollection::EndComponentMode() to EditorComponentModeNotifications::LeftComponentMode
|
||||
// such that all of the notifications for activating/deactivating the different editor modes are in a central location
|
||||
m_viewportEditorModeTracker->DeactivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Component);
|
||||
|
||||
// clear stored modes and builders for this ComponentMode
|
||||
// TLDR: avoid 'use after free' error
|
||||
|
||||
+3
-1
@@ -15,6 +15,7 @@
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class EditorMetricsEventsBusTraits;
|
||||
class ViewportEditorModeTrackerInterface;
|
||||
|
||||
namespace ComponentModeFramework
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace AzToolsFramework
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
|
||||
/// @cond
|
||||
ComponentModeCollection() = default;
|
||||
explicit ComponentModeCollection(ViewportEditorModeTrackerInterface* viewportEditorModeTracker);
|
||||
~ComponentModeCollection() = default;
|
||||
ComponentModeCollection(const ComponentModeCollection&) = delete;
|
||||
ComponentModeCollection& operator=(const ComponentModeCollection&) = delete;
|
||||
@@ -101,6 +102,7 @@ namespace AzToolsFramework
|
||||
size_t m_selectedComponentModeIndex = 0; ///< Index into the array of active ComponentModes, current index is 'selected' ComponentMode.
|
||||
bool m_adding = false; ///< Are we currently adding individual ComponentModes to the Editor wide ComponentMode.
|
||||
bool m_componentMode = false; ///< Editor (global) ComponentMode flag - is ComponentMode active or not.
|
||||
ViewportEditorModeTrackerInterface* m_viewportEditorModeTracker = nullptr; //!< Tracker for activating/deactivating viewport editor modes.
|
||||
};
|
||||
} // namespace ComponentModeFramework
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
+3
-2
@@ -119,11 +119,12 @@ namespace AzToolsFramework
|
||||
|
||||
// replace the default input handler with one specific for dealing with
|
||||
// entity selection in the viewport
|
||||
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Event(
|
||||
GetEntityContextId(), &EditorInteractionSystemViewportSelection::SetHandler,
|
||||
[](const EditorVisibleEntityDataCache* entityDataCache)
|
||||
[](const EditorVisibleEntityDataCache* entityDataCache, ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
{
|
||||
return AZStd::make_unique<EditorPickEntitySelection>(entityDataCache);
|
||||
return AZStd::make_unique<EditorPickEntitySelection>(entityDataCache, viewportEditorModeTracker);
|
||||
});
|
||||
|
||||
if (!pickModeEntityContextId.IsNull())
|
||||
|
||||
+4
-2
@@ -22,6 +22,7 @@
|
||||
#include <AZTestShared/Math/MathTestHelpers.h>
|
||||
#include <AZTestShared/Utils/Utils.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/API/ViewportEditorModeTrackerInterface.h>
|
||||
#include <AzToolsFramework/Application/ToolsApplication.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityTransformBus.h>
|
||||
#include <AzToolsFramework/ComponentMode/EditorComponentModeBus.h>
|
||||
@@ -166,11 +167,12 @@ namespace UnitTest
|
||||
m_editorActions.Connect();
|
||||
|
||||
const auto viewportHandlerBuilder =
|
||||
[this](const AzToolsFramework::EditorVisibleEntityDataCache* entityDataCache)
|
||||
[this](const AzToolsFramework::EditorVisibleEntityDataCache* entityDataCache,
|
||||
[[maybe_unused]] AzToolsFramework::ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
{
|
||||
// create the default viewport (handles ComponentMode)
|
||||
AZStd::unique_ptr<AzToolsFramework::EditorDefaultSelection> defaultSelection =
|
||||
AZStd::make_unique<AzToolsFramework::EditorDefaultSelection>(entityDataCache);
|
||||
AZStd::make_unique<AzToolsFramework::EditorDefaultSelection>(entityDataCache, viewportEditorModeTracker);
|
||||
|
||||
// override the phantom widget so we can use out custom test widget
|
||||
defaultSelection->SetOverridePhantomWidget(&m_editorActions.m_componentModeWidget);
|
||||
|
||||
+7
-1
@@ -9,6 +9,7 @@
|
||||
#include "EditorDefaultSelection.h"
|
||||
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzToolsFramework/API/ViewportEditorModeTrackerInterface.h>
|
||||
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
|
||||
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
@@ -19,21 +20,26 @@ namespace AzToolsFramework
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(EditorDefaultSelection, AZ::SystemAllocator, 0)
|
||||
|
||||
EditorDefaultSelection::EditorDefaultSelection(const EditorVisibleEntityDataCache* entityDataCache)
|
||||
EditorDefaultSelection::EditorDefaultSelection(
|
||||
const EditorVisibleEntityDataCache* entityDataCache, ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
: m_phantomWidget(nullptr)
|
||||
, m_entityDataCache(entityDataCache)
|
||||
, m_viewportEditorModeTracker(viewportEditorModeTracker)
|
||||
, m_componentModeCollection(viewportEditorModeTracker)
|
||||
{
|
||||
ActionOverrideRequestBus::Handler::BusConnect(GetEntityContextId());
|
||||
ComponentModeFramework::ComponentModeSystemRequestBus::Handler::BusConnect();
|
||||
|
||||
m_manipulatorManager = AZStd::make_shared<AzToolsFramework::ManipulatorManager>(AzToolsFramework::g_mainManipulatorManagerId);
|
||||
m_transformComponentSelection = AZStd::make_unique<EditorTransformComponentSelection>(entityDataCache);
|
||||
m_viewportEditorModeTracker->ActivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Default);
|
||||
}
|
||||
|
||||
EditorDefaultSelection::~EditorDefaultSelection()
|
||||
{
|
||||
ComponentModeFramework::ComponentModeSystemRequestBus::Handler::BusDisconnect();
|
||||
ActionOverrideRequestBus::Handler::BusDisconnect();
|
||||
m_viewportEditorModeTracker->DeactivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Default);
|
||||
}
|
||||
|
||||
void EditorDefaultSelection::SetOverridePhantomWidget(QWidget* phantomOverrideWidget)
|
||||
|
||||
+5
-1
@@ -15,6 +15,8 @@
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class ViewportEditorModeTrackerInterface;
|
||||
|
||||
//! The default selection/input handler for the editor (includes handling ComponentMode).
|
||||
class EditorDefaultSelection
|
||||
: public ViewportInteraction::InternalViewportSelectionRequests
|
||||
@@ -25,7 +27,7 @@ namespace AzToolsFramework
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
|
||||
//! @cond
|
||||
explicit EditorDefaultSelection(const EditorVisibleEntityDataCache* entityDataCache);
|
||||
EditorDefaultSelection(const EditorVisibleEntityDataCache* entityDataCache, ViewportEditorModeTrackerInterface* viewportEditorModeTracker);
|
||||
EditorDefaultSelection(const EditorDefaultSelection&) = delete;
|
||||
EditorDefaultSelection& operator=(const EditorDefaultSelection&) = delete;
|
||||
virtual ~EditorDefaultSelection();
|
||||
@@ -110,5 +112,7 @@ namespace AzToolsFramework
|
||||
|
||||
AZStd::shared_ptr<AzToolsFramework::ManipulatorManager> m_manipulatorManager; //!< The default manipulator manager.
|
||||
ViewportInteraction::MouseInteraction m_currentInteraction; //!< Current mouse interaction to be used for drawing manipulators.
|
||||
ViewportEditorModeTrackerInterface* m_viewportEditorModeTracker = nullptr; //!< Tracker for activating/deactivating viewport editor modes.
|
||||
|
||||
};
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
+20
-4
@@ -10,9 +10,24 @@
|
||||
|
||||
#include <AzToolsFramework/ViewportSelection/EditorDefaultSelection.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorVisibleEntityDataCache.h>
|
||||
#include <AzToolsFramework/ViewportSelection/ViewportEditorModeTracker.h>
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
EditorInteractionSystemComponent::EditorInteractionSystemComponent()
|
||||
: m_viewportEditorMode(AZStd::make_unique<ViewportEditorModeTracker>())
|
||||
{
|
||||
AZ_Assert(AZ::Interface<ViewportEditorModeTrackerInterface>::Get() == nullptr, "Unexpected registration of viewport editor mode tracker.")
|
||||
AZ::Interface<ViewportEditorModeTrackerInterface>::Register(m_viewportEditorMode.get());
|
||||
}
|
||||
|
||||
EditorInteractionSystemComponent::~EditorInteractionSystemComponent()
|
||||
{
|
||||
m_interactionRequests.reset();
|
||||
AZ_Assert(AZ::Interface<ViewportEditorModeTrackerInterface>::Get() != nullptr, "Unexpected unregistration of viewport editor mode tracker.")
|
||||
AZ::Interface<ViewportEditorModeTrackerInterface>::Unregister(m_viewportEditorMode.get());
|
||||
}
|
||||
|
||||
void EditorInteractionSystemComponent::Activate()
|
||||
{
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Handler::BusConnect(GetEntityContextId());
|
||||
@@ -41,7 +56,8 @@ namespace AzToolsFramework
|
||||
return m_interactionRequests->InternalHandleMouseManipulatorInteraction(mouseInteraction);
|
||||
}
|
||||
|
||||
void EditorInteractionSystemComponent::SetHandler(const ViewportSelectionRequestsBuilderFn& interactionRequestsBuilder)
|
||||
void EditorInteractionSystemComponent::SetHandler(
|
||||
const ViewportSelectionRequestsBuilderFn& interactionRequestsBuilder)
|
||||
{
|
||||
// when setting a handler, make sure we're connected to the ViewportDebugDisplayEventBus so we
|
||||
// can forward calls to the specific type implementing ViewportSelectionRequests
|
||||
@@ -59,7 +75,7 @@ namespace AzToolsFramework
|
||||
m_entityDataCache = AZStd::make_unique<EditorVisibleEntityDataCache>();
|
||||
m_interactionRequests.reset(); // BusConnect/Disconnect in constructor/destructor,
|
||||
// so have to reset before assigning the new one
|
||||
m_interactionRequests = interactionRequestsBuilder(m_entityDataCache.get());
|
||||
m_interactionRequests = interactionRequestsBuilder(m_entityDataCache.get(), m_viewportEditorMode.get());
|
||||
}
|
||||
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Handler::BusConnect(GetEntityContextId());
|
||||
@@ -68,9 +84,9 @@ namespace AzToolsFramework
|
||||
void EditorInteractionSystemComponent::SetDefaultHandler()
|
||||
{
|
||||
SetHandler(
|
||||
[](const EditorVisibleEntityDataCache* entityDataCache)
|
||||
[](const EditorVisibleEntityDataCache* entityDataCache, ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
{
|
||||
return AZStd::make_unique<EditorDefaultSelection>(entityDataCache);
|
||||
return AZStd::make_unique<EditorDefaultSelection>(entityDataCache, viewportEditorModeTracker);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -14,6 +14,8 @@
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class ViewportEditorModeTracker;
|
||||
|
||||
//! System Component to wrap active input handler.
|
||||
//! EditorInteractionSystemComponent is notified of viewport mouse events from RenderViewport
|
||||
//! and forwards them to a concrete implementation of ViewportSelectionRequests.
|
||||
@@ -26,6 +28,9 @@ namespace AzToolsFramework
|
||||
public:
|
||||
AZ_COMPONENT(EditorInteractionSystemComponent, "{146D0317-AF42-45AB-A953-F54198525DD5}")
|
||||
|
||||
EditorInteractionSystemComponent();
|
||||
~EditorInteractionSystemComponent();
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
// EditorInteractionSystemViewportSelectionRequestBus
|
||||
@@ -54,5 +59,7 @@ namespace AzToolsFramework
|
||||
AZStd::unique_ptr<InternalViewportSelectionRequests> m_interactionRequests; //!< Hold a concrete implementation of
|
||||
//!< ViewportSelectionRequests to handle viewport
|
||||
//!< input and drawing for the Editor.
|
||||
|
||||
AZStd::unique_ptr<ViewportEditorModeTracker> m_viewportEditorMode; //!< Editor mode tracker for each viewport.
|
||||
};
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class EditorVisibleEntityDataCache;
|
||||
class ViewportEditorModeTrackerInterface;
|
||||
|
||||
//! Bus to handle all mouse events originating from the viewport.
|
||||
//! Coordinated by the EditorInteractionSystemComponent
|
||||
@@ -32,8 +33,8 @@ namespace AzToolsFramework
|
||||
};
|
||||
|
||||
//! Alias for factory function to create a new type implementing the ViewportSelectionRequests interface.
|
||||
using ViewportSelectionRequestsBuilderFn =
|
||||
AZStd::function<AZStd::unique_ptr<ViewportInteraction::InternalViewportSelectionRequests>(const EditorVisibleEntityDataCache*)>;
|
||||
using ViewportSelectionRequestsBuilderFn = AZStd::function<AZStd::unique_ptr<ViewportInteraction::InternalViewportSelectionRequests>(
|
||||
const EditorVisibleEntityDataCache*, ViewportEditorModeTrackerInterface*)>;
|
||||
|
||||
//! Interface for system component implementing the ViewportSelectionRequests interface.
|
||||
//! This interface also includes a setter to set a custom handler also implementing
|
||||
|
||||
+7
-1
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "EditorPickEntitySelection.h"
|
||||
|
||||
#include <AzToolsFramework/API/ViewportEditorModeTrackerInterface.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
#include <QApplication>
|
||||
|
||||
@@ -15,9 +16,12 @@ namespace AzToolsFramework
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(EditorPickEntitySelection, AZ::SystemAllocator, 0)
|
||||
|
||||
EditorPickEntitySelection::EditorPickEntitySelection(const EditorVisibleEntityDataCache* entityDataCache)
|
||||
EditorPickEntitySelection::EditorPickEntitySelection(
|
||||
const EditorVisibleEntityDataCache* entityDataCache, ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
: m_editorHelpers(AZStd::make_unique<EditorHelpers>(entityDataCache))
|
||||
, m_viewportEditorModeTracker(viewportEditorModeTracker)
|
||||
{
|
||||
m_viewportEditorModeTracker->ActivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Pick);
|
||||
}
|
||||
|
||||
EditorPickEntitySelection::~EditorPickEntitySelection()
|
||||
@@ -26,6 +30,8 @@ namespace AzToolsFramework
|
||||
{
|
||||
ToolsApplicationRequestBus::Broadcast(&ToolsApplicationRequests::SetEntityHighlighted, m_hoveredEntityId, false);
|
||||
}
|
||||
|
||||
m_viewportEditorModeTracker->DeactivateMode({ /* DefaultViewportId */ }, ViewportEditorMode::Pick);
|
||||
}
|
||||
|
||||
// note: entityIdUnderCursor is the authoritative entityId we get each frame by querying
|
||||
|
||||
+5
-1
@@ -13,6 +13,8 @@
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class ViewportEditorModeTrackerInterface;
|
||||
|
||||
//! Viewport interaction that will handle assigning an entity in the viewport to
|
||||
//! an entity field in the entity inspector.
|
||||
class EditorPickEntitySelection : public ViewportInteraction::InternalViewportSelectionRequests
|
||||
@@ -20,7 +22,8 @@ namespace AzToolsFramework
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
|
||||
EditorPickEntitySelection(const EditorVisibleEntityDataCache* entityDataCache);
|
||||
EditorPickEntitySelection(
|
||||
const EditorVisibleEntityDataCache* entityDataCache, ViewportEditorModeTrackerInterface* viewportEditorModeTracker);
|
||||
~EditorPickEntitySelection();
|
||||
|
||||
private:
|
||||
@@ -32,5 +35,6 @@ namespace AzToolsFramework
|
||||
AZStd::unique_ptr<EditorHelpers> m_editorHelpers; //!< Editor visualization of entities (icons, shapes, debug visuals etc).
|
||||
AZ::EntityId m_hoveredEntityId; //!< What EntityId is the mouse currently hovering over (if any).
|
||||
AZ::EntityId m_cachedEntityIdUnderCursor; //!< Store the EntityId on each mouse move for use in Display.
|
||||
ViewportEditorModeTrackerInterface* m_viewportEditorModeTracker = nullptr; //!< Tracker for activating/deactivating viewport editor modes.
|
||||
};
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
-16
@@ -45,22 +45,6 @@ namespace AzToolsFramework
|
||||
return m_editorModes[static_cast<AZ::u32>(mode)];
|
||||
}
|
||||
|
||||
void ViewportEditorModeTracker::RegisterInterface()
|
||||
{
|
||||
if (AZ::Interface<ViewportEditorModeTrackerInterface>::Get() == nullptr)
|
||||
{
|
||||
AZ::Interface<ViewportEditorModeTrackerInterface>::Register(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportEditorModeTracker::UnregisterInterface()
|
||||
{
|
||||
if (AZ::Interface<ViewportEditorModeTrackerInterface>::Get() != nullptr)
|
||||
{
|
||||
AZ::Interface<ViewportEditorModeTrackerInterface>::Unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ViewportEditorModeTracker::ActivateMode(
|
||||
const ViewportEditorModeInfo& viewportEditorModeInfo, ViewportEditorMode mode)
|
||||
{
|
||||
|
||||
-6
@@ -41,12 +41,6 @@ namespace AzToolsFramework
|
||||
: public ViewportEditorModeTrackerInterface
|
||||
{
|
||||
public:
|
||||
//! Registers this object with the AZ::Interface.
|
||||
void RegisterInterface();
|
||||
|
||||
//! Unregisters this object with the AZ::Interface.
|
||||
void UnregisterInterface();
|
||||
|
||||
// ViewportEditorModeTrackerInterface overrides ...
|
||||
AZ::Outcome<void, AZStd::string> ActivateMode(const ViewportEditorModeInfo& viewportEditorModeInfo, ViewportEditorMode mode) override;
|
||||
AZ::Outcome<void, AZStd::string> DeactivateMode(const ViewportEditorModeInfo& viewportEditorModeInfo, ViewportEditorMode mode) override;
|
||||
|
||||
@@ -29,13 +29,29 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
void ButtonGroup::SetHighlightedButton(ButtonId buttonId)
|
||||
{
|
||||
if (buttonId == m_highlightedButtonId) // the requested button is highlighted, so do nothing.
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto buttonEntry = m_buttons.find(buttonId); buttonEntry != m_buttons.end())
|
||||
{
|
||||
for (auto& button : m_buttons)
|
||||
{
|
||||
button.second->m_state = Button::State::Deselected;
|
||||
}
|
||||
ClearHighlightedButton();
|
||||
buttonEntry->second->m_state = Button::State::Selected;
|
||||
m_highlightedButtonId = buttonId;
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonGroup::ClearHighlightedButton()
|
||||
{
|
||||
if (m_highlightedButtonId == InvalidButtonId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (auto buttonEntry = m_buttons.find(m_highlightedButtonId); buttonEntry != m_buttons.end())
|
||||
{
|
||||
buttonEntry->second->m_state = Button::State::Deselected;
|
||||
m_highlightedButtonId = InvalidButtonId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
~ButtonGroup() = default;
|
||||
|
||||
void SetHighlightedButton(ButtonId buttonId);
|
||||
void ClearHighlightedButton();
|
||||
|
||||
void SetViewportUiElementId(ViewportUiElementId id);
|
||||
ViewportUiElementId GetViewportUiElementId() const;
|
||||
@@ -40,5 +41,6 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
AZ::Event<ButtonId> m_buttonTriggeredEvent;
|
||||
ViewportUiElementId m_viewportUiId;
|
||||
AZStd::unordered_map<ButtonId, AZStd::unique_ptr<Button>> m_buttons;
|
||||
ButtonId m_highlightedButtonId = InvalidButtonId;
|
||||
};
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
@@ -50,6 +50,16 @@ namespace AzToolsFramework::ViewportUi
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::ClearClusterActiveButton(ClusterId clusterId)
|
||||
{
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
auto cluster = clusterIt->second;
|
||||
cluster->ClearHighlightedButton();
|
||||
UpdateButtonGroupUi(cluster.get());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetSwitcherActiveButton(const SwitcherId switcherId, const ButtonId buttonId)
|
||||
{
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace AzToolsFramework::ViewportUi
|
||||
const ClusterId CreateCluster(Alignment align) override;
|
||||
const SwitcherId CreateSwitcher(Alignment align) override;
|
||||
void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) override;
|
||||
void ClearClusterActiveButton(ClusterId clusterId) override;
|
||||
void SetSwitcherActiveButton(SwitcherId switcherId, ButtonId buttonId) override;
|
||||
void SetClusterButtonLocked(ClusterId clusterId, ButtonId buttonId, bool isLocked) override;
|
||||
void SetClusterButtonTooltip(ClusterId clusterId, ButtonId buttonId, const AZStd::string& tooltip) override;
|
||||
|
||||
@@ -59,6 +59,8 @@ namespace AzToolsFramework::ViewportUi
|
||||
virtual const SwitcherId CreateSwitcher(Alignment align) = 0;
|
||||
//! Sets the active button of the cluster. This is the button which will display as highlighted.
|
||||
virtual void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) = 0;
|
||||
//! Clears the active button of the cluster if one is active. The button will no longer display as highlighted.
|
||||
virtual void ClearClusterActiveButton(ClusterId clusterId) = 0;
|
||||
//! Sets the active button of the switcher. This is the button which has a text label.
|
||||
virtual void SetSwitcherActiveButton(SwitcherId clusterId, ButtonId buttonId) = 0;
|
||||
//! Adds a locked overlay to the cluster button's icon.
|
||||
|
||||
@@ -344,9 +344,10 @@ namespace UnitTest
|
||||
using AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus;
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Event(
|
||||
AzToolsFramework::GetEntityContextId(), &EditorInteractionSystemViewportSelectionRequestBus::Events::SetHandler,
|
||||
[](const AzToolsFramework::EditorVisibleEntityDataCache* entityDataCache)
|
||||
[](const AzToolsFramework::EditorVisibleEntityDataCache* entityDataCache,
|
||||
[[maybe_unused]] AzToolsFramework::ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
{
|
||||
return AZStd::make_unique<AzToolsFramework::EditorPickEntitySelection>(entityDataCache);
|
||||
return AZStd::make_unique<AzToolsFramework::EditorPickEntitySelection>(entityDataCache, viewportEditorModeTracker);
|
||||
});
|
||||
|
||||
// When
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
*/
|
||||
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzToolsFramework/ComponentMode/EditorComponentModeBus.h>
|
||||
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorPickEntitySelection.h>
|
||||
#include <AzToolsFramework/ViewportSelection/ViewportEditorModeTracker.h>
|
||||
|
||||
namespace UnitTest
|
||||
@@ -18,6 +20,7 @@ namespace UnitTest
|
||||
using ViewportEditorModeInfo = AzToolsFramework::ViewportEditorModeInfo;
|
||||
using ViewportId = ViewportEditorModeInfo::IdType;
|
||||
using ViewportEditorModesInterface = AzToolsFramework::ViewportEditorModesInterface;
|
||||
using ViewportEditorModeTrackerInterface = AzToolsFramework::ViewportEditorModeTrackerInterface;
|
||||
|
||||
void ActivateModeAndExpectSuccess(ViewportEditorModes& editorModeState, ViewportEditorMode mode)
|
||||
{
|
||||
@@ -47,6 +50,26 @@ namespace UnitTest
|
||||
}
|
||||
}
|
||||
|
||||
void ExpectOnlyModeActive(const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode)
|
||||
{
|
||||
for (auto modeIndex = 0; modeIndex < ViewportEditorModes::NumEditorModes; modeIndex++)
|
||||
{
|
||||
const auto currentMode = static_cast<ViewportEditorMode>(modeIndex);
|
||||
const bool expectedActive = (mode == currentMode);
|
||||
EXPECT_EQ(editorModeState.IsModeActive(currentMode), expectedActive);
|
||||
}
|
||||
}
|
||||
|
||||
void ExpectOnlyModeInactive(const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode)
|
||||
{
|
||||
for (auto modeIndex = 0; modeIndex < ViewportEditorModes::NumEditorModes; modeIndex++)
|
||||
{
|
||||
const auto currentMode = static_cast<ViewportEditorMode>(modeIndex);
|
||||
const bool expectedActive = (mode != currentMode);
|
||||
EXPECT_EQ(editorModeState.IsModeActive(currentMode), expectedActive);
|
||||
}
|
||||
}
|
||||
|
||||
// Fixture for testing editor mode states
|
||||
class ViewportEditorModesTestsFixture
|
||||
: public ::testing::Test
|
||||
@@ -116,7 +139,7 @@ namespace UnitTest
|
||||
m_editorModes[mode].m_onEnter = true;
|
||||
}
|
||||
|
||||
virtual void OnEditorModeDeactivated([[maybe_unused]] const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode) override
|
||||
void OnEditorModeDeactivated([[maybe_unused]] const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode) override
|
||||
{
|
||||
m_editorModes[mode].m_onExit = true;
|
||||
}
|
||||
@@ -152,6 +175,22 @@ namespace UnitTest
|
||||
AZStd::array<AZStd::unique_ptr<ViewportEditorModeNotificationsBusHandler>, ViewportEditorModes::NumEditorModes> m_editorModeHandlers;
|
||||
};
|
||||
|
||||
// Fixture for testing the integration of viewport editor mode state tracker
|
||||
class ViewportEditorModeTrackerIntegrationTestFixture
|
||||
: public ToolsApplicationFixture
|
||||
{
|
||||
public:
|
||||
void SetUpEditorFixtureImpl() override
|
||||
{
|
||||
m_viewportEditorModeTracker = AZ::Interface<ViewportEditorModeTrackerInterface>::Get();
|
||||
ASSERT_NE(m_viewportEditorModeTracker, nullptr);
|
||||
m_viewportEditorModes = m_viewportEditorModeTracker->GetViewportEditorModes({});
|
||||
}
|
||||
|
||||
ViewportEditorModeTrackerInterface* m_viewportEditorModeTracker = nullptr;
|
||||
const ViewportEditorModesInterface* m_viewportEditorModes = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(ViewportEditorModesTestsFixture, NumberOfEditorModesIsEqualTo4)
|
||||
{
|
||||
EXPECT_EQ(ViewportEditorModes::NumEditorModes, 4);
|
||||
@@ -168,38 +207,14 @@ namespace UnitTest
|
||||
TEST_P(ViewportEditorModesTestsFixtureWithParams, SettingModeActiveActivatesOnlyThatMode)
|
||||
{
|
||||
ActivateModeAndExpectSuccess(m_editorModes, m_selectedEditorMode);
|
||||
|
||||
for (auto mode = 0; mode < ViewportEditorModes::NumEditorModes; mode++)
|
||||
{
|
||||
const auto editorMode = static_cast<ViewportEditorMode>(mode);
|
||||
if (editorMode == m_selectedEditorMode)
|
||||
{
|
||||
EXPECT_TRUE(m_editorModes.IsModeActive(static_cast<ViewportEditorMode>(editorMode)));
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_FALSE(m_editorModes.IsModeActive(static_cast<ViewportEditorMode>(editorMode)));
|
||||
}
|
||||
}
|
||||
ExpectOnlyModeActive(m_editorModes, m_selectedEditorMode);
|
||||
}
|
||||
|
||||
TEST_P(ViewportEditorModesTestsFixtureWithParams, SettingModeInactiveInactivatesOnlyThatMode)
|
||||
{
|
||||
SetAllModesActive(m_editorModes);
|
||||
DeactivateModeAndExpectSuccess(m_editorModes, m_selectedEditorMode);
|
||||
|
||||
for (auto mode = 0; mode < ViewportEditorModes::NumEditorModes; mode++)
|
||||
{
|
||||
const auto editorMode = static_cast<ViewportEditorMode>(mode);
|
||||
if (editorMode == m_selectedEditorMode)
|
||||
{
|
||||
EXPECT_FALSE(m_editorModes.IsModeActive(editorMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_TRUE(m_editorModes.IsModeActive(editorMode));
|
||||
}
|
||||
}
|
||||
ExpectOnlyModeInactive(m_editorModes, m_selectedEditorMode);
|
||||
}
|
||||
|
||||
TEST_P(ViewportEditorModesTestsFixtureWithParams, SettingMultipleModesActiveActivatesAllThoseModesNonMutuallyExclusively)
|
||||
@@ -298,7 +313,7 @@ namespace UnitTest
|
||||
EXPECT_EQ(m_viewportEditorModeTracker.GetTrackedViewportCount(), 0);
|
||||
}
|
||||
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, RegisteringViewportEditorModeForNonExistentIdCreatesViewportEditorModesForThatId)
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, ActivatingViewportEditorModeForNonExistentIdCreatesViewportEditorModesForThatId)
|
||||
{
|
||||
// Given a viewport not currently being tracked
|
||||
const ViewportId viewportid = 0;
|
||||
@@ -318,7 +333,7 @@ namespace UnitTest
|
||||
EXPECT_TRUE(viewportEditorModeState->IsModeActive(editorMode));
|
||||
}
|
||||
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, UnregisteringViewportEditorModeForNonExistentIdCreatesViewportEditorModesForThatIdButReturnsError)
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, DeactivatingViewportEditorModeForNonExistentIdCreatesViewportEditorModesForThatIdButReturnsError)
|
||||
{
|
||||
// Given a viewport not currently being tracked
|
||||
const ViewportId viewportid = 0;
|
||||
@@ -351,7 +366,7 @@ namespace UnitTest
|
||||
EXPECT_EQ(m_viewportEditorModeTracker.GetViewportEditorModes({ viewportid }), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, RegisteringViewportEditorModesForExistingIdInThatStateReturnsError)
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, ActivatingViewportEditorModesForExistingIdInThatStateReturnsError)
|
||||
{
|
||||
// Given a viewport not currently tracked
|
||||
const ViewportId viewportid = 0;
|
||||
@@ -390,7 +405,7 @@ namespace UnitTest
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, UnregisteringViewportEditorModesForExistingIdNotInThatStateReturnssError)
|
||||
TEST_F(ViewportEditorModeTrackerTestFixture, DeactivatingViewportEditorModesForExistingIdNotInThatStateReturnssError)
|
||||
{
|
||||
// Given a viewport not currently tracked
|
||||
const ViewportId viewportid = 0;
|
||||
@@ -432,7 +447,7 @@ namespace UnitTest
|
||||
|
||||
TEST_F(
|
||||
ViewportEditorModePublisherTestFixture,
|
||||
RegisteringViewportEditorModesForExistingIdPublishesOnViewportEditorModeRegisterEventForAllSubscribers)
|
||||
ActivatingViewportEditorModesForExistingIdPublishesOnViewportEditorModeActivateEventForAllSubscribers)
|
||||
{
|
||||
// Given a set of subscribers tracking the editor modes for their exclusive viewport
|
||||
for (auto mode = 0; mode < ViewportEditorModes::NumEditorModes; mode++)
|
||||
@@ -465,7 +480,7 @@ namespace UnitTest
|
||||
|
||||
TEST_F(
|
||||
ViewportEditorModePublisherTestFixture,
|
||||
UnregisteringViewportEditorModesForExistingIdPublishesOnViewportEditorModeUnregisterEventForAllSubscribers)
|
||||
DeactivatingViewportEditorModesForExistingIdPublishesOnViewportEditorModeDeactivatingEventForAllSubscribers)
|
||||
{
|
||||
// Given a set of subscribers tracking the editor modes for their exclusive viewport
|
||||
for (auto mode = 0; mode < ViewportEditorModes::NumEditorModes; mode++)
|
||||
@@ -495,4 +510,54 @@ namespace UnitTest
|
||||
EXPECT_TRUE(expectedEditorModeSet->second.m_onExit);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ViewportEditorModeTrackerIntegrationTestFixture, InitialViewportEditorModeIsDefault)
|
||||
{
|
||||
ExpectOnlyModeActive(*m_viewportEditorModes, ViewportEditorMode::Default);
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
ViewportEditorModeTrackerIntegrationTestFixture, EnteringComponentModeAfterInitialStateHasViewportEditorModesDefaultAndComponentModeActive)
|
||||
{
|
||||
// When component mode is entered
|
||||
AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::Broadcast(
|
||||
&AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::BeginComponentMode,
|
||||
AZStd::vector<AzToolsFramework::ComponentModeFramework::EntityAndComponentModeBuilders>{});
|
||||
|
||||
bool inComponentMode = false;
|
||||
AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::BroadcastResult(
|
||||
inComponentMode, &AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::InComponentMode);
|
||||
|
||||
// Expect to be in component mode
|
||||
EXPECT_TRUE(inComponentMode);
|
||||
|
||||
// Expect the default and component viewport editor modes to be active
|
||||
EXPECT_TRUE(m_viewportEditorModes->IsModeActive(ViewportEditorMode::Default));
|
||||
EXPECT_TRUE(m_viewportEditorModes->IsModeActive(ViewportEditorMode::Component));
|
||||
|
||||
// Do not expect the pick and focus viewport editor modes to be active
|
||||
EXPECT_FALSE(m_viewportEditorModes->IsModeActive(ViewportEditorMode::Pick));
|
||||
EXPECT_FALSE(m_viewportEditorModes->IsModeActive(ViewportEditorMode::Focus));
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
ViewportEditorModeTrackerIntegrationTestFixture,
|
||||
EnteringEditorPickEntitySelectionAfterInitialStateHasOnlyViewportEditorModePickModeActive)
|
||||
{
|
||||
// When entering pick mode
|
||||
using AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus;
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Event(
|
||||
AzToolsFramework::GetEntityContextId(), &EditorInteractionSystemViewportSelectionRequestBus::Events::SetHandler,
|
||||
[](const AzToolsFramework::EditorVisibleEntityDataCache* entityDataCache,
|
||||
[[maybe_unused]] AzToolsFramework::ViewportEditorModeTrackerInterface* viewportEditorModeTracker)
|
||||
{
|
||||
return AZStd::make_unique<AzToolsFramework::EditorPickEntitySelection>(entityDataCache, viewportEditorModeTracker);
|
||||
});
|
||||
|
||||
// Expect only the pick viewport editor mode to be active
|
||||
ExpectOnlyModeActive(*m_viewportEditorModes, ViewportEditorMode::Pick);
|
||||
}
|
||||
|
||||
// FocusMode integration tests will follow (LYN-6995)
|
||||
|
||||
} // namespace UnitTest
|
||||
|
||||
@@ -127,6 +127,25 @@ namespace UnitTest
|
||||
EXPECT_TRUE(button->m_state == AzToolsFramework::ViewportUi::Internal::Button::State::Selected);
|
||||
}
|
||||
|
||||
TEST_F(ViewportUiManagerTestFixture, ClearClusterActiveButtonSetsButtonStateToDeselected)
|
||||
{
|
||||
// setup
|
||||
auto clusterId = m_viewportManagerWrapper.GetViewportManager()->CreateCluster(AzToolsFramework::ViewportUi::Alignment::TopLeft);
|
||||
auto buttonId = m_viewportManagerWrapper.GetViewportManager()->CreateClusterButton(clusterId, "");
|
||||
|
||||
auto clusterEntry = m_viewportManagerWrapper.GetViewportManager()->GetClusterMap().find(clusterId);
|
||||
auto button = clusterEntry->second->GetButton(buttonId);
|
||||
|
||||
// first set a button to active
|
||||
m_viewportManagerWrapper.GetViewportManager()->SetClusterActiveButton(clusterId, buttonId);
|
||||
EXPECT_TRUE(button->m_state == AzToolsFramework::ViewportUi::Internal::Button::State::Selected);
|
||||
|
||||
// clear the active button on the cluster
|
||||
m_viewportManagerWrapper.GetViewportManager()->ClearClusterActiveButton(clusterId);
|
||||
// the button should now be deselected
|
||||
EXPECT_TRUE(button->m_state == AzToolsFramework::ViewportUi::Internal::Button::State::Deselected);
|
||||
}
|
||||
|
||||
TEST_F(ViewportUiManagerTestFixture, RegisterClusterEventHandlerConnectsHandlerToClusterEvent)
|
||||
{
|
||||
auto clusterId = m_viewportManagerWrapper.GetViewportManager()->CreateCluster(AzToolsFramework::ViewportUi::Alignment::TopLeft);
|
||||
|
||||
Reference in New Issue
Block a user