1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
230 lines
7.7 KiB
C++
230 lines
7.7 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <qgraphicsitem.h>
|
|
|
|
#include <AzCore/Component/Entity.h>
|
|
|
|
#include <Components/BookmarkManagerComponent.h>
|
|
|
|
#include <GraphCanvas/Components/VisualBus.h>
|
|
#include <GraphCanvas/Components/SceneBus.h>
|
|
#include <GraphCanvas/Editor/AssetEditorBus.h>
|
|
#include <GraphCanvas/GraphCanvasBus.h>
|
|
|
|
namespace GraphCanvas
|
|
{
|
|
/////////////////////////////
|
|
// BookmarkManagerComponent
|
|
/////////////////////////////
|
|
|
|
void BookmarkManagerComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
|
|
|
if (serializeContext)
|
|
{
|
|
serializeContext->Class<BookmarkManagerComponent, AZ::Component>()
|
|
->Version(1)
|
|
->Field("QuickBookmarks", &BookmarkManagerComponent::m_shortcuts)
|
|
->Field("Bookmarks", &BookmarkManagerComponent::m_bookmarks)
|
|
;
|
|
}
|
|
}
|
|
|
|
BookmarkManagerComponent::BookmarkManagerComponent()
|
|
{
|
|
}
|
|
|
|
BookmarkManagerComponent::~BookmarkManagerComponent()
|
|
{
|
|
}
|
|
|
|
void BookmarkManagerComponent::Init()
|
|
{
|
|
m_shortcuts.resize(m_shortcuts.max_size());
|
|
}
|
|
|
|
void BookmarkManagerComponent::Activate()
|
|
{
|
|
BookmarkManagerRequestBus::Handler::BusConnect(GetEntityId());
|
|
}
|
|
|
|
void BookmarkManagerComponent::Deactivate()
|
|
{
|
|
BookmarkManagerRequestBus::Handler::BusDisconnect();
|
|
}
|
|
|
|
bool BookmarkManagerComponent::CreateBookmarkAnchor(const AZ::Vector2& position, int bookmarkShortcut)
|
|
{
|
|
AZ::Entity* bookmarkAnchorEntity = nullptr;
|
|
GraphCanvasRequestBus::BroadcastResult(bookmarkAnchorEntity, &GraphCanvasRequests::CreateBookmarkAnchorAndActivate);
|
|
|
|
if (bookmarkAnchorEntity)
|
|
{
|
|
AZ::EntityId bookmarkId = bookmarkAnchorEntity->GetId();
|
|
BookmarkRequestBus::Event(bookmarkId, &BookmarkRequests::SetShortcut, bookmarkShortcut);
|
|
|
|
SceneRequestBus::Event(GetEntityId(), &SceneRequests::AddBookmarkAnchor, bookmarkId, position);
|
|
}
|
|
|
|
return bookmarkAnchorEntity != nullptr;
|
|
}
|
|
|
|
void BookmarkManagerComponent::RegisterBookmark(const AZ::EntityId& bookmarkId)
|
|
{
|
|
auto resultPair = m_bookmarks.insert(bookmarkId);
|
|
|
|
if (resultPair.second)
|
|
{
|
|
int shortcut = k_unusedShortcut;
|
|
|
|
BookmarkRequestBus::EventResult(shortcut, bookmarkId, &BookmarkRequests::GetShortcut);
|
|
|
|
if (shortcut == k_findShortcut)
|
|
{
|
|
for (unsigned int i = 1; i < m_shortcuts.size(); ++i)
|
|
{
|
|
if (!m_shortcuts[i].IsValid())
|
|
{
|
|
shortcut = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (shortcut > 0)
|
|
{
|
|
RequestShortcut(bookmarkId, shortcut);
|
|
}
|
|
else
|
|
{
|
|
BookmarkRequestBus::Event(bookmarkId, &BookmarkRequests::SetShortcut, k_unusedShortcut);
|
|
}
|
|
|
|
BookmarkNotificationBus::MultiHandler::BusConnect(bookmarkId);
|
|
BookmarkManagerNotificationBus::Event(GetEntityId(), &BookmarkManagerNotifications::OnBookmarkAdded, bookmarkId);
|
|
}
|
|
}
|
|
|
|
void BookmarkManagerComponent::UnregisterBookmark(const AZ::EntityId& bookmarkId)
|
|
{
|
|
auto bookmarkIter = m_bookmarks.find(bookmarkId);
|
|
|
|
AZ_Warning("Graph Canvas", bookmarkIter != m_bookmarks.end(), "Trying to unregister a bookmark from a manager it is not registered to.");
|
|
if (bookmarkIter != m_bookmarks.end())
|
|
{
|
|
UnregisterShortcut(bookmarkId);
|
|
m_bookmarks.erase(bookmarkIter);
|
|
|
|
BookmarkNotificationBus::MultiHandler::BusDisconnect(bookmarkId);
|
|
BookmarkManagerNotificationBus::Event(GetEntityId(), &BookmarkManagerNotifications::OnBookmarkRemoved, bookmarkId);
|
|
}
|
|
}
|
|
|
|
bool BookmarkManagerComponent::IsBookmarkRegistered(const AZ::EntityId& bookmarkId) const
|
|
{
|
|
return m_bookmarks.count(bookmarkId) > 0;
|
|
}
|
|
|
|
AZ::EntityId BookmarkManagerComponent::FindBookmarkForShortcut(int shortcut) const
|
|
{
|
|
if (shortcut <= 0 || shortcut >= m_shortcuts.size())
|
|
{
|
|
return AZ::EntityId();
|
|
}
|
|
|
|
return m_shortcuts[shortcut];
|
|
}
|
|
|
|
bool BookmarkManagerComponent::RequestShortcut(const AZ::EntityId& bookmark, int shortcut)
|
|
{
|
|
if ((shortcut <= 0 && shortcut != k_unusedShortcut) || shortcut >= m_shortcuts.size())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
AZ::EntityId previousBookmark;
|
|
|
|
if (shortcut != k_unusedShortcut)
|
|
{
|
|
// If something else is already using these values. Remove the quick index from the old one
|
|
// And assign it to the new one.
|
|
if (m_shortcuts[shortcut].IsValid())
|
|
{
|
|
previousBookmark = m_shortcuts[shortcut];
|
|
BookmarkRequestBus::Event(m_shortcuts[shortcut], &BookmarkRequests::SetShortcut, k_unusedShortcut);
|
|
}
|
|
}
|
|
|
|
// Order here matters. Since when creating a new anchor, the index get's preset. We want to track the previous values
|
|
// so we can signal out updates correctly, so we want to unset the previous element first, then try to unset the bookmark's
|
|
// previous. This handles both cases, with minimal extra steps.
|
|
int previousIndex = k_unusedShortcut;
|
|
BookmarkRequestBus::EventResult(previousIndex, bookmark, &BookmarkRequests::GetShortcut);
|
|
|
|
UnregisterShortcut(bookmark);
|
|
|
|
if (shortcut != k_unusedShortcut)
|
|
{
|
|
m_shortcuts[shortcut] = bookmark;
|
|
}
|
|
|
|
BookmarkRequestBus::Event(bookmark, &BookmarkRequests::SetShortcut, shortcut);
|
|
BookmarkManagerNotificationBus::Event(GetEntityId(), &BookmarkManagerNotifications::OnShortcutChanged, shortcut, previousBookmark, bookmark);
|
|
return true;
|
|
}
|
|
|
|
void BookmarkManagerComponent::ActivateShortcut(int shortcut)
|
|
{
|
|
JumpToBookmark(FindBookmarkForShortcut(shortcut));
|
|
}
|
|
|
|
void BookmarkManagerComponent::JumpToBookmark(const AZ::EntityId& bookmark)
|
|
{
|
|
if (!bookmark.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
QRectF bookmarkTarget;
|
|
BookmarkRequestBus::EventResult(bookmarkTarget, bookmark, &BookmarkRequests::GetBookmarkTarget);
|
|
|
|
ViewId viewId;
|
|
SceneRequestBus::EventResult(viewId, GetEntityId(), &SceneRequests::GetViewId);
|
|
|
|
EditorId editorId;
|
|
SceneRequestBus::EventResult(editorId, GetEntityId(), &SceneRequests::GetEditorId);
|
|
|
|
bool enableViewportControl = false;
|
|
AssetEditorSettingsRequestBus::EventResult(enableViewportControl, editorId, &AssetEditorSettingsRequests::IsBookmarkViewportControlEnabled);
|
|
|
|
if (enableViewportControl)
|
|
{
|
|
ViewRequestBus::Event(viewId, &ViewRequests::DisplayArea, bookmarkTarget);
|
|
}
|
|
else
|
|
{
|
|
ViewRequestBus::Event(viewId, &ViewRequests::CenterOnArea, bookmarkTarget);
|
|
}
|
|
|
|
BookmarkNotificationBus::Event(bookmark, &BookmarkNotifications::OnBookmarkTriggered);
|
|
}
|
|
|
|
void BookmarkManagerComponent::UnregisterShortcut(const AZ::EntityId& bookmark)
|
|
{
|
|
int previousIndex = k_unusedShortcut;
|
|
BookmarkRequestBus::EventResult(previousIndex, bookmark, &BookmarkRequests::GetShortcut);
|
|
|
|
if (previousIndex >= 0 && previousIndex < m_shortcuts.size())
|
|
{
|
|
m_shortcuts[previousIndex].SetInvalid();
|
|
}
|
|
}
|
|
}
|