Files
o3de/Code/Editor/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h
T
Artur K 56904d1799 Cry Legacy: the Lessening (#5961)
* Generic Cleanup

Removals:

* Unused cvars,member variables and defines
* Windows media center edition support routines
* CSystem - removed debug_GetCallStackRaw/GetRootWindowMessageHandler/
UnloadDLL/ShutdownModuleLibraries

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Fix CryMessageBox return values in Windows build

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove named selection group and a few smaller unused functionalities

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove ObjectManager export functionality + 2 deprecated functions

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove object legacy freeze/hide support from ObjectManager

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove ObjectManager duplicate name dection, as well as object renaming

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove ObjectManager serialization and selection callbacks

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* ObjectManager - remove MoveObjects/HitTestObject/EndEditParams and related members/functions

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove a bunch of unused clone related functionality + misc

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* ObjectManager - misc removals

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* ObjectManager - more removals

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove unused object selection/retrieval in ObjectManager and LoadObjects in ObjectLoader

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject - remove unused material layers mask support

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More CBaseObject cleanups.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject - remove SubObj functions and IMouseCreateCallback

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove unused procedural floor management, helper scale and tags.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject - remove more unused methods.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Removals in multiple places.

CBaseObject - unused `OBJTYPE_DUMMY` flag removed, member `IsSameClass`
CObjectArchive removed unused methods/members
CObjectManager removed unused `Update` method

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More removals

IDisplayViewport - HitTestLine/GetGridStep/setHitcontext/
GetConstructionPlane
Unused Cry_Matrix44 template specializations.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* O3DE.exe Project-Centric "Open Editor" fix (#5852)

* The O3DE.exe Open Editor button now attempts to open the Editor in the
build directory of the project being opened.

If their is no Editor within the build directory of the Project, it uses
the Editor.exe in the current O3DE.exe executable directory if it exists

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Engine .gitignore now ignores the build directory if placed in the
AutomatedTesting project

Previously it was just ignoring a `[Bb]uild` directory if it was
directly within the engine root.
This change matches the behavior of the project templates.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Renamed the ProjectUtils GetEditorDirectory function to
GetEditorExecutablePath

Added a platform specific implementation for retrieving the path to the
Editor executable in the GetEditorExectuablePath function.

It first attempts to locate the Editor via checking the project build
directory for an Editor executable before falling back to checking the
binary directory of the currently running O3DE executable.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Correct the MacOS GetEditorExecutablePath to return the Editor path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Adding missing C++20 std::erase implementations (#5735)

There were already implementations for std::erase_if.
This adds the counterpart AZStd::erase versions

resolves #5734

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More removals and refactors

`ShowMessage` and `CryMessageBox` return void now
Simplify code in `CSystem::WarningV`
Remove unused `CryGetTicksPerSec`
Remove unused WinBase functionality
Replace `nanosleep` call in WinBase with `std::this_thread::sleep_for`
Remove unused Win32Wrapper routines
Remove unused IFunctorBase.h and IEntityObjectListener.h
Fix VectorAndArray.cpp compilation
Use QMessageBox instead of CryMessageBox in the editor.
Remove empty ArchiveVars platform specific files

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Fix test code.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove an unused  function

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject and undo description removals.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* A bunch of removals

* Remove IRenderNode
* Remove editor's KDTree
* Remove StatObjBus, InstanceStatObjEventBus::ReleaseData is redundant (
same functionality in the only available handler is triggered by
`OnCryEditorCloseScene`)
* Remove CExportManager::AddStatObj/AddMeshes/AddMesh,
IExportManager::ExportSingleStatObj
* Remove CIconManager/IIconManager::GetObject
* Remove CBaseObject::IntersectRayMesh
* Remove IIndexedMesh and related structs.
* Unused IUndoObject::GetDescription and all derived implementations.
* Unused CUndoBaseLibrary/CUndoBaseLibraryManager
* Unused Matrix34_tpl typedefs
* Legacy Xml classes cleanup

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove unused `Vec3ToVector3D` helper

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* fix - remove unused static variable

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-11-29 11:21:06 -07:00

354 lines
15 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
*
*/
#ifndef CRYINCLUDE_COMPONENTENTITYEDITORPLUGIN_SANDBOXINTEGRATION_H
#define CRYINCLUDE_COMPONENTENTITYEDITORPLUGIN_SANDBOXINTEGRATION_H
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Slice/SliceBus.h>
#include <AzCore/Slice/SliceComponent.h>
#include <AzCore/Math/Uuid.h>
#include <AzCore/std/string/conversions.h>
#include <AzFramework/Asset/AssetCatalogBus.h>
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
#include <AzFramework/Viewport/DisplayContextRequestBus.h>
#include <AzToolsFramework/API/EditorWindowRequestBus.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/Editor/EditorContextMenuBus.h>
#include <AzToolsFramework/ToolsComponents/EditorLayerComponentBus.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
#include <AzToolsFramework/UI/Layer/LayerUiHandler.h>
#include <AzToolsFramework/UI/Prefab/PrefabIntegrationManager.h>
#include <AzToolsFramework/UI/Slice/SliceOverridesNotificationWindowManager.hxx>
#include <AzToolsFramework/UI/Slice/SliceOverridesNotificationWindow.hxx>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/Entity/SliceEditorEntityOwnershipServiceBus.h>
#include <AzToolsFramework/Viewport/ViewportMessages.h>
// Sandbox imports.
#include "../Editor/ViewManager.h"
#include "../Editor/Viewport.h"
#include "../Editor/Undo/IUndoManagerListener.h"
#include "../Editor/Undo/IUndoObject.h"
#include <QApplication>
#include <QPointer>
/**
* Integration of ToolsApplication behavior and Cry undo/redo and selection systems
* with respect to component entity operations.
*
* Undo/Redo
* - CToolsApplicationUndoLink represents a component application undo operation within
* the Sandbox undo system. When an undo-able component operation is performed, we
* intercept ToolsApplicationEventBus::OnBeginUndo()/OnEndUndo() events, and in turn
* create and register a link instance.
* - When the user attempts to undo/redo a CToolsApplicationUndoLink event in Sandbox,
* CToolsApplicationUndoLink::Undo()/Redo() is invoked, and the request is passed
* to the component application via ToolsApplicationRequestBus::OnUndoPressed/OnRedoPressed,
* where restoration of the previous entity snapshot is handled.
*
* AzToolsFramework::ToolsApplication Extensions
* - Provides engine UI customizations, such as using the engine's built in asset browser
* when assigning asset references to component properties.
* - Handles component edit-time display requests (using the editor's drawing context).
* - Handles source control requests from AZ components or component-related UI.
*/
namespace AZ::Data
{
class AssetInfo;
}
class CToolsApplicationUndoLink;
class QMenu;
class QWidget;
class CComponentEntityObject;
class CHyperGraph;
namespace AzToolsFramework
{
class EditorEntityAPI;
class EditorEntityUiInterface;
namespace AssetBrowser
{
class AssetSelectionModel;
}
namespace Prefab
{
class PrefabIntegrationInterface;
}
}
//////////////////////////////////////////////////////////////////////////
class SandboxIntegrationManager
: private AzToolsFramework::ToolsApplicationEvents::Bus::Handler
, private AzToolsFramework::EditorRequests::Bus::Handler
, private AzToolsFramework::EditorContextMenuBus::Handler
, private AzToolsFramework::EditorWindowRequests::Bus::Handler
, private AzFramework::AssetCatalogEventBus::Handler
, private AzFramework::DisplayContextRequestBus::Handler
, private AzToolsFramework::EditorEntityContextNotificationBus::Handler
, private AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler
, private IUndoManagerListener
, private AzToolsFramework::Layers::EditorLayerComponentNotificationBus::Handler
{
public:
SandboxIntegrationManager();
~SandboxIntegrationManager();
void Setup();
void Teardown();
private:
//////////////////////////////////////////////////////////////////////////
// AssetCatalogEventBus::Handler
void OnCatalogAssetAdded(const AZ::Data::AssetId& assetId) override;
void OnCatalogAssetRemoved(const AZ::Data::AssetId& assetId, const AZ::Data::AssetInfo& assetInfo) override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// AzToolsFramework::ToolsApplicationEvents::Bus::Handler overrides
void OnBeginUndo(const char* label) override;
void OnEndUndo(const char* label, bool changed) override;
void EntityParentChanged(
AZ::EntityId entityId,
AZ::EntityId newParentId,
AZ::EntityId oldParentId) override;
void OnSaveLevel() override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorRequests::Bus::Handler overrides
void RegisterViewPane(const char* name, const char* category, const AzToolsFramework::ViewPaneOptions& viewOptions, const WidgetCreationFunc& widgetCreationFunc) override;
void RegisterCustomViewPane(const char* name, const char* category, const AzToolsFramework::ViewPaneOptions& viewOptions) override;
void UnregisterViewPane(const char* name) override;
QWidget* GetViewPaneWidget(const char* viewPaneName) override;
void OpenViewPane(const char* paneName) override;
QDockWidget* InstanceViewPane(const char* paneName) override;
void CloseViewPane(const char* paneName) override;
void BrowseForAssets(AzToolsFramework::AssetBrowser::AssetSelectionModel& selection) override;
void CreateEditorRepresentation(AZ::Entity* entity) override;
bool DestroyEditorRepresentation(AZ::EntityId entityId, bool deleteAZEntity) override;
void CloneSelection(bool& handled) override;
void DeleteSelectedEntities(bool includeDescendants) override;
AZ::EntityId CreateNewEntity(AZ::EntityId parentId = AZ::EntityId()) override;
AZ::EntityId CreateNewEntityAsChild(AZ::EntityId parentId) override;
AZ::EntityId CreateNewEntityAtPosition(const AZ::Vector3& /*pos*/, AZ::EntityId parentId = AZ::EntityId()) override;
AzFramework::EntityContextId GetEntityContextId() override;
QWidget* GetMainWindow() override;
IEditor* GetEditor() override;
bool GetUndoSliceOverrideSaveValue() override;
bool GetShowCircularDependencyError() override;
void SetShowCircularDependencyError(const bool& showCircularDependencyError) override;
void LaunchLuaEditor(const char* files) override;
bool IsLevelDocumentOpen() override;
AZStd::string GetLevelName() override;
void OpenPinnedInspector(const AzToolsFramework::EntityIdSet& entities) override;
void ClosePinnedInspector(AzToolsFramework::EntityPropertyEditor* editor) override;
void GoToSelectedOrHighlightedEntitiesInViewports() override;
void GoToSelectedEntitiesInViewports() override;
bool CanGoToSelectedEntitiesInViewports() override;
AZ::Vector3 GetWorldPositionAtViewportCenter() override;
void InstantiateSliceFromAssetId(const AZ::Data::AssetId& assetId) override;
void ClearRedoStack() override;
int GetIconTextureIdFromEntityIconPath(const AZStd::string& entityIconPath) override;
bool DisplayHelpersVisible() override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorWindowRequests::Bus::Handler
QWidget* GetAppMainWindow() override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorContextMenu::Bus::Handler overrides
void PopulateEditorGlobalContextMenu(QMenu* menu, const AZ::Vector2& point, int flags) override;
int GetMenuPosition() const override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorEntityContextNotificationBus::Handler
void OnContextReset() override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler
void OnSliceInstantiated(
const AZ::Data::AssetId& sliceAssetId,
AZ::SliceComponent::SliceInstanceAddress& sliceAddress,
const AzFramework::SliceInstantiationTicket& ticket) override;
//////////////////////////////////////////////////////////////////////////
// AzFramework::DisplayContextRequestBus (and @deprecated EntityDebugDisplayRequestBus)
// AzFramework::DisplayContextRequestBus
void SetDC(DisplayContext* dc) override;
DisplayContext* GetDC() override;
// Context menu handlers.
void ContextMenu_NewEntity();
AZ::EntityId ContextMenu_NewLayer();
void ContextMenu_SaveLayers(const AZStd::unordered_set<AZ::EntityId>& layers);
void ContextMenu_MakeSlice(AzToolsFramework::EntityIdList entities);
void ContextMenu_InheritSlice(AzToolsFramework::EntityIdList entities);
void ContextMenu_InstantiateSlice();
void ContextMenu_SelectSlice();
void ContextMenu_PushEntitiesToSlice(AzToolsFramework::EntityIdList entities,
AZ::SliceComponent::EntityAncestorList ancestors,
AZ::Data::AssetId targetAncestorId,
bool affectEntireHierarchy);
void ContextMenu_Duplicate();
void ContextMenu_DeleteSelected();
void ContextMenu_ResetToSliceDefaults(AzToolsFramework::EntityIdList entities);
void MakeSliceFromEntities(const AzToolsFramework::EntityIdList& entities, bool inheritSlices, bool setAsDynamic);
void GetSelectedEntities(AzToolsFramework::EntityIdList& entities);
void GetSelectedOrHighlightedEntities(AzToolsFramework::EntityIdList& entities);
AZStd::string GetDefaultComponentViewportIcon() override
{
return m_defaultComponentViewportIconLocation;
}
AZStd::string GetDefaultComponentEditorIcon() override
{
return m_defaultComponentIconLocation;
}
AZStd::string GetDefaultEntityIcon() override
{
return m_defaultEntityIconLocation;
}
AZStd::string GetComponentEditorIcon(const AZ::Uuid& componentType, AZ::Component* component) override;
AZStd::string GetComponentTypeEditorIcon(const AZ::Uuid& componentType) override;
AZStd::string GetComponentIconPath(const AZ::Uuid& componentType, AZ::Crc32 componentIconAttrib, AZ::Component* component) override;
//////////////////////////////////////////////////////////////////////////
// IUndoManagerListener
// Listens for Cry Undo System events.
void UndoStackFlushed() override;
// EditorLayerRequestBus...
void OnLayerComponentActivated(AZ::EntityId entityId) override;
void OnLayerComponentDeactivated(AZ::EntityId entityId) override;
private:
// Right click context menu when a layer is included in the selection.
void SetupLayerContextMenu(QMenu* menu);
void SetupSliceContextMenu(QMenu* menu);
void SetupSliceContextMenu_Modify(QMenu* menu, const AzToolsFramework::EntityIdList& selectedEntities, const AZ::u32 numEntitiesInSlices);
void SaveSlice(const bool& QuickPushToFirstLevel);
void GetEntitiesInSlices(const AzToolsFramework::EntityIdList& selectedEntities, AZ::u32& entitiesInSlices, AZStd::vector<AZ::SliceComponent::SliceInstanceAddress>& sliceInstances);
void GoToEntitiesInViewports(const AzToolsFramework::EntityIdList& entityIds);
bool CanGoToEntityOrChildren(const AZ::EntityId& entityId) const;
// This struct exists to help handle the error case where slice assets are
// accidentally deleted from disk but their instances are still in the editing level.
struct SliceAssetDeletionErrorInfo
{
SliceAssetDeletionErrorInfo() = default;
SliceAssetDeletionErrorInfo(AZ::Data::AssetId assetId, AZStd::vector<AZStd::pair<AZ::EntityId, AZ::SliceComponent::EntityRestoreInfo>>&& entityRestoreInfos)
: m_assetId(assetId)
, m_entityRestoreInfos(AZStd::move(entityRestoreInfos))
{ }
AZ::Data::AssetId m_assetId;
AZStd::vector<AZStd::pair<AZ::EntityId, AZ::SliceComponent::EntityRestoreInfo>> m_entityRestoreInfos;
};
private:
AZ::Vector2 m_contextMenuViewPoint;
short m_startedUndoRecordingNestingLevel; // used in OnBegin/EndUndo to ensure we only accept undo's we started recording
AzToolsFramework::SliceOverridesNotificationWindowManager* m_notificationWindowManager;
DisplayContext* m_dc;
AZStd::vector<SliceAssetDeletionErrorInfo> m_sliceAssetDeletionErrorRestoreInfos;
// Tracks new entities that have not yet been saved.
AZStd::unordered_set<AZ::EntityId> m_unsavedEntities;
const AZStd::string m_defaultComponentIconLocation = "Icons/Components/Component_Placeholder.svg";
const AZStd::string m_defaultComponentViewportIconLocation = "Icons/Components/Viewport/Component_Placeholder.svg";
const AZStd::string m_defaultEntityIconLocation = "Icons/Components/Viewport/Transform.svg";
AzToolsFramework::Prefab::PrefabIntegrationManager* m_prefabIntegrationManager = nullptr;
AzToolsFramework::EditorEntityUiInterface* m_editorEntityUiInterface = nullptr;
AzToolsFramework::Prefab::PrefabIntegrationInterface* m_prefabIntegrationInterface = nullptr;
AzToolsFramework::EditorEntityAPI* m_editorEntityAPI = nullptr;
// Overrides UI styling and behavior for Layer Entities
AzToolsFramework::LayerUiHandler m_layerUiOverrideHandler;
};
//////////////////////////////////////////////////////////////////////////
class CToolsApplicationUndoLink
: public IUndoObject
{
public:
CToolsApplicationUndoLink()
{
}
int GetSize() override
{
return 0;
}
void Undo(bool bUndo = true) override
{
// Always run the undo even if the flag was set to false, that just means that undo wasn't expressly desired, but can be used in cases of canceling the current super undo.
// Restore previous focus after applying the undo.
QPointer<QWidget> w = QApplication::focusWidget();
AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequestBus::Events::UndoPressed);
// Slice the redo stack if this wasn't due to explicit undo command
if (!bUndo)
{
AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequestBus::Events::FlushRedo);
}
if (!w.isNull())
{
w->setFocus(Qt::OtherFocusReason);
}
}
void Redo() override
{
// Restore previous focus after applying the undo.
QPointer<QWidget> w = QApplication::focusWidget();
AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequestBus::Events::RedoPressed);
if (!w.isNull())
{
w->setFocus(Qt::OtherFocusReason);
}
}
};
#endif // CRYINCLUDE_COMPONENTENTITYEDITORPLUGIN_SANDBOXINTEGRATION_H