Merge branch 'main' into non-uniform-scale-mesh
This commit is contained in:
@@ -341,6 +341,16 @@ namespace AZ
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<ComponentApplicationBus>("ComponentApplicationBus")
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "Components")
|
||||
|
||||
->Event("GetEntityName", &ComponentApplicationBus::Events::GetEntityName)
|
||||
->Event("SetEntityName", &ComponentApplicationBus::Events::SetEntityName);
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
@@ -1050,6 +1060,20 @@ namespace AZ
|
||||
return AZStd::string();
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// SetEntityName
|
||||
//=========================================================================
|
||||
bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string_view name)
|
||||
{
|
||||
Entity* entity = FindEntity(id);
|
||||
if (entity)
|
||||
{
|
||||
entity->SetName(name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// EnumerateEntities
|
||||
//=========================================================================
|
||||
|
||||
@@ -209,6 +209,7 @@ namespace AZ
|
||||
bool DeleteEntity(const EntityId& id) override;
|
||||
Entity* FindEntity(const EntityId& id) override;
|
||||
AZStd::string GetEntityName(const EntityId& id) override;
|
||||
bool SetEntityName(const EntityId& id, const AZStd::string_view name) override;
|
||||
void EnumerateEntities(const ComponentApplicationRequests::EntityCallback& callback) override;
|
||||
ComponentApplication* GetApplication() override { return this; }
|
||||
/// Returns the serialize context that has been registered with the app, if there is one.
|
||||
|
||||
@@ -130,7 +130,13 @@ namespace AZ
|
||||
//! @param entity A reference to the entity whose name you are seeking.
|
||||
//! @return The name of the entity with the specified entity ID.
|
||||
//! If no entity is found for the specified ID, it returns an empty string.
|
||||
virtual AZStd::string GetEntityName(const EntityId& id) { (void)id; return AZStd::string(); };
|
||||
virtual AZStd::string GetEntityName(const EntityId& id) { (void)id; return AZStd::string(); }
|
||||
|
||||
//! Sets the name of the entity that has the specified entity ID.
|
||||
//! Entity names are not enforced to be unique.
|
||||
//! @param entityId A reference to the entity whose name you want to change.
|
||||
//! @return True if the name was changed successfully, false if it wasn't.
|
||||
virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string_view name) { return false; }
|
||||
|
||||
//! The type that AZ::ComponentApplicationRequests::EnumerateEntities uses to
|
||||
//! pass entity callbacks to the application for enumeration.
|
||||
|
||||
@@ -258,7 +258,8 @@ namespace AZ
|
||||
Method("CreateFromMatrix3x3", &Quaternion::CreateFromMatrix3x3)->
|
||||
Method("CreateFromMatrix4x4", &Quaternion::CreateFromMatrix4x4)->
|
||||
Method("CreateFromAxisAngle", &Quaternion::CreateFromAxisAngle)->
|
||||
Method("CreateShortestArc", &Quaternion::CreateShortestArc)
|
||||
Method("CreateShortestArc", &Quaternion::CreateShortestArc)->
|
||||
Method("CreateFromEulerAnglesDegrees", &Quaternion::CreateFromEulerAnglesDegrees)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,6 +250,7 @@ namespace AZ
|
||||
Attribute(Script::Attributes::ExcludeFrom, Script::Attributes::ExcludeFlags::All)->
|
||||
Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::Value)->
|
||||
Attribute(Script::Attributes::GenericConstructorOverride, &Internal::TransformDefaultConstructor)->
|
||||
Constructor<const Vector3&, const Quaternion&, const Vector3&>()->
|
||||
Method("GetBasis", &Transform::GetBasis)->
|
||||
Method("GetBasisX", &Transform::GetBasisX)->
|
||||
Method("GetBasisY", &Transform::GetBasisY)->
|
||||
|
||||
@@ -40,14 +40,13 @@ ly_add_target(
|
||||
${common_dir}
|
||||
${AZ_CORE_RADTELEMETRY_INCLUDE_DIRECTORIES}
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
3rdParty::zlib
|
||||
3rdParty::zstd
|
||||
3rdParty::cityhash
|
||||
PUBLIC
|
||||
3rdParty::Lua
|
||||
3rdParty::RapidJSON
|
||||
3rdParty::RapidXML
|
||||
3rdParty::zlib
|
||||
3rdParty::zstd
|
||||
3rdParty::cityhash
|
||||
${AZ_CORE_RADTELEMETRY_BUILD_DEPENDENCIES}
|
||||
)
|
||||
ly_add_source_properties(
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace AzFramework
|
||||
|
||||
// ViewportControllerInterface ...
|
||||
bool HandleInputChannelEvent(const ViewportControllerInputEvent& event) override;
|
||||
void ResetInputChannels() override;
|
||||
void UpdateViewport(const ViewportControllerUpdateEvent& event) override;
|
||||
void RegisterViewportContext(ViewportId viewport) override;
|
||||
void UnregisterViewportContext(ViewportId viewport) override;
|
||||
@@ -58,6 +59,7 @@ namespace AzFramework
|
||||
ViewportId GetViewportId() const { return m_viewportId; }
|
||||
|
||||
virtual bool HandleInputChannelEvent([[maybe_unused]]const ViewportControllerInputEvent& event) { return false; }
|
||||
virtual void ResetInputChannels() {}
|
||||
virtual void UpdateViewport([[maybe_unused]]const ViewportControllerUpdateEvent& event) {}
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,6 +30,15 @@ namespace AzFramework
|
||||
return instanceIt->second->HandleInputChannelEvent(event);
|
||||
}
|
||||
|
||||
template <class TViewportControllerInstance, ViewportControllerPriority Priority>
|
||||
void MultiViewportController<TViewportControllerInstance, Priority>::ResetInputChannels()
|
||||
{
|
||||
for (auto instanceIt = m_instances.begin(); instanceIt != m_instances.end(); ++instanceIt)
|
||||
{
|
||||
instanceIt->second->ResetInputChannels();
|
||||
}
|
||||
}
|
||||
|
||||
template <class TViewportControllerInstance, ViewportControllerPriority Priority>
|
||||
void MultiViewportController<TViewportControllerInstance, Priority>::UpdateViewport(const ViewportControllerUpdateEvent& event)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,11 @@ namespace AzFramework
|
||||
|
||||
bool ViewportControllerList::HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If our event priority is "custom", we should dispatch at all priority levels in order
|
||||
using AzFramework::ViewportControllerPriority;
|
||||
if (event.m_priority == AzFramework::ViewportControllerPriority::DispatchToAllPriorities)
|
||||
@@ -76,6 +81,23 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportControllerList::ResetInputChannels()
|
||||
{
|
||||
// We don't need to send this while we're disabled, we're guaranteed to call ResetInputChannels after being re-enabled.
|
||||
if (!IsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& controllerList : m_controllers)
|
||||
{
|
||||
for (const auto& controller : controllerList.second)
|
||||
{
|
||||
controller->ResetInputChannels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewportControllerList::DispatchInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event)
|
||||
{
|
||||
if (auto priorityListIt = m_controllers.find(event.m_priority); priorityListIt != m_controllers.end())
|
||||
@@ -106,6 +128,11 @@ namespace AzFramework
|
||||
|
||||
void ViewportControllerList::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If our event priority is "custom", we should dispatch at all priority levels in reverse order
|
||||
// Reverse order lets high priority controllers get the last say in viewport update operations
|
||||
using AzFramework::ViewportControllerPriority;
|
||||
@@ -174,4 +201,22 @@ namespace AzFramework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewportControllerList::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void ViewportControllerList::SetEnabled(bool enabled)
|
||||
{
|
||||
if (m_enabled != enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
// If we've been re-enabled, reset our input channels as they may have missed state changes.
|
||||
if (m_enabled)
|
||||
{
|
||||
ResetInputChannels();
|
||||
}
|
||||
}
|
||||
}
|
||||
} //namespace AzFramework
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace AzFramework
|
||||
//! either a controller returns true to consume the event in OnInputChannelEvent or the controller list is exhausted.
|
||||
//! InputChannelEvents are sent to controllers in priority order (from the lowest priority value to the highest).
|
||||
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
|
||||
//! Dispatches a ResetInputChannels call to all controllers registered to this list.
|
||||
//! Calls to controllers are made in an undefined order.
|
||||
void ResetInputChannels() override;
|
||||
//! Dispatches an update tick to all controllers registered to this list.
|
||||
//! This occurs in *reverse* priority order (i.e. from the highest priority value to the lowest) so that
|
||||
//! controllers with the highest registration priority may override the transforms of the controllers with the
|
||||
@@ -50,6 +53,12 @@ namespace AzFramework
|
||||
//! All ViewportControllerLists have a priority of Custom to ensure
|
||||
//! that they receive events at all priorities from any parent controllers.
|
||||
AzFramework::ViewportControllerPriority GetPriority() const { return ViewportControllerPriority::DispatchToAllPriorities; }
|
||||
//! Returns true if this controller list is enabled, i.e.
|
||||
//! it is accepting and forwarding input and update events to its children.
|
||||
bool IsEnabled() const;
|
||||
//! Set this controller list's enabled state.
|
||||
//! If a controller list is disabled, it will ignore all input and update events rather than dispatching them to its children.
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
void SortControllers();
|
||||
@@ -58,5 +67,6 @@ namespace AzFramework
|
||||
|
||||
AZStd::unordered_map<AzFramework::ViewportControllerPriority, AZStd::vector<ViewportControllerPtr>> m_controllers;
|
||||
AZStd::unordered_set<ViewportId> m_viewports;
|
||||
bool m_enabled = true;
|
||||
};
|
||||
} //namespace AzFramework
|
||||
|
||||
@@ -33,12 +33,12 @@ ly_add_target(
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
AZ::AzCore
|
||||
PUBLIC
|
||||
AZ::GridMate
|
||||
3rdParty::md5
|
||||
3rdParty::zlib
|
||||
3rdParty::zstd
|
||||
3rdParty::lz4
|
||||
PUBLIC
|
||||
AZ::GridMate
|
||||
)
|
||||
|
||||
if(LY_ENABLE_STATISTICAL_PROFILING)
|
||||
|
||||
@@ -170,6 +170,15 @@ namespace AzToolsFramework
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
QSharedPointer<CompositeFilter> SearchWidget::GetStringFilter() const
|
||||
{
|
||||
return m_stringFilter;
|
||||
}
|
||||
|
||||
QSharedPointer<CompositeFilter> SearchWidget::GetTypesFilter() const
|
||||
{
|
||||
return m_typesFilter;
|
||||
}
|
||||
} // namespace AssetBrowser
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace AzToolsFramework
|
||||
|
||||
QSharedPointer<CompositeFilter> GetFilter() const;
|
||||
|
||||
QSharedPointer<CompositeFilter> GetStringFilter() const;
|
||||
|
||||
QSharedPointer<CompositeFilter> GetTypesFilter() const;
|
||||
|
||||
QString GetFilterString() const { return textFilter(); }
|
||||
void ClearStringFilter() { ClearTextFilter(); }
|
||||
|
||||
|
||||
+20
-7
@@ -94,6 +94,7 @@ namespace AzToolsFramework
|
||||
m_prefabSystemComponent->RemoveTemplate(templateId);
|
||||
}
|
||||
m_rootInstance->Reset();
|
||||
m_rootInstance->SetContainerEntityName("Level");
|
||||
|
||||
AzFramework::EntityOwnershipServiceNotificationBus::Event(
|
||||
m_entityContextId, &AzFramework::EntityOwnershipServiceNotificationBus::Events::OnEntityOwnershipServiceReset);
|
||||
@@ -198,6 +199,7 @@ namespace AzToolsFramework
|
||||
|
||||
m_rootInstance->SetTemplateId(templateId);
|
||||
m_rootInstance->SetTemplateSourcePath(m_loaderInterface->GetRelativePathToProject(filename));
|
||||
m_rootInstance->SetContainerEntityName("Level");
|
||||
m_prefabSystemComponent->PropagateTemplateChanges(templateId);
|
||||
|
||||
return true;
|
||||
@@ -279,18 +281,29 @@ namespace AzToolsFramework
|
||||
AZStd::unique_ptr<Prefab::Instance> createdPrefabInstance =
|
||||
m_prefabSystemComponent->CreatePrefab(entities, AZStd::move(nestedPrefabInstances), filePath);
|
||||
|
||||
if (!instanceToParentUnder)
|
||||
{
|
||||
instanceToParentUnder = *m_rootInstance;
|
||||
}
|
||||
|
||||
if (createdPrefabInstance)
|
||||
{
|
||||
if (!instanceToParentUnder)
|
||||
{
|
||||
instanceToParentUnder = *m_rootInstance;
|
||||
}
|
||||
|
||||
Prefab::Instance& addedInstance = instanceToParentUnder->get().AddInstance(AZStd::move(createdPrefabInstance));
|
||||
HandleEntitiesAdded({addedInstance.m_containerEntity.get()});
|
||||
AZ::Entity* containerEntity = addedInstance.m_containerEntity.get();
|
||||
containerEntity->AddComponent(aznew Prefab::EditorPrefabComponent());
|
||||
HandleEntitiesAdded({containerEntity});
|
||||
HandleEntitiesAdded(entities);
|
||||
|
||||
// Update the template of the instance since we modified the entities of the instance by calling HandleEntitiesAdded.
|
||||
Prefab::PrefabDom serializedInstance;
|
||||
if (Prefab::PrefabDomUtils::StoreInstanceInPrefabDom(addedInstance, serializedInstance))
|
||||
{
|
||||
m_prefabSystemComponent->UpdatePrefabTemplate(addedInstance.GetTemplateId(), serializedInstance);
|
||||
}
|
||||
|
||||
return addedInstance;
|
||||
}
|
||||
HandleEntitiesAdded(entities);
|
||||
|
||||
return AZStd::nullopt;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ namespace AzToolsFramework
|
||||
PlayInEditorData m_playInEditorData;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PrefabSystemComponentInterface interface implementation
|
||||
// PrefabEditorEntityOwnershipInterface implementation
|
||||
Prefab::InstanceOptionalReference CreatePrefab(
|
||||
const AZStd::vector<AZ::Entity*>& entities, AZStd::vector<AZStd::unique_ptr<Prefab::Instance>>&& nestedPrefabInstances,
|
||||
AZ::IO::PathView filePath, Prefab::InstanceOptionalReference instanceToParentUnder) override;
|
||||
|
||||
@@ -123,7 +123,11 @@ namespace AzToolsFramework
|
||||
void Instance::SetTemplateSourcePath(AZ::IO::PathView sourcePath)
|
||||
{
|
||||
m_templateSourcePath = sourcePath;
|
||||
m_containerEntity->SetName(sourcePath.Filename().Native());
|
||||
}
|
||||
|
||||
void Instance::SetContainerEntityName(AZStd::string_view containerName)
|
||||
{
|
||||
m_containerEntity->SetName(containerName);
|
||||
}
|
||||
|
||||
bool Instance::AddEntity(AZ::Entity& entity)
|
||||
@@ -563,7 +567,7 @@ namespace AzToolsFramework
|
||||
|
||||
AZ::EntityId Instance::GetContainerEntityId() const
|
||||
{
|
||||
return m_containerEntity->GetId();
|
||||
return m_containerEntity ? m_containerEntity->GetId() : AZ::EntityId();
|
||||
}
|
||||
|
||||
bool Instance::HasContainerEntity() const
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace AzToolsFramework
|
||||
|
||||
const AZ::IO::Path& GetTemplateSourcePath() const;
|
||||
void SetTemplateSourcePath(AZ::IO::PathView sourcePath);
|
||||
void SetContainerEntityName(AZStd::string_view containerName);
|
||||
|
||||
bool AddEntity(AZ::Entity& entity);
|
||||
bool AddEntity(AZ::Entity& entity, EntityAlias entityAlias);
|
||||
|
||||
+25
-1
@@ -15,6 +15,7 @@
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/Instance.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/TemplateInstanceMapperInterface.h>
|
||||
@@ -116,10 +117,24 @@ namespace AzToolsFramework
|
||||
"Could not find Template using Id '%llu'. Unable to update Instance.",
|
||||
currentTemplateId);
|
||||
|
||||
// Remove the instance from update queue if its corresponding template couldn't be found
|
||||
isUpdateSuccessful = false;
|
||||
m_instancesUpdateQueue.pop();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
auto findInstancesResult = m_templateInstanceMapperInterface->FindInstancesOwnedByTemplate(instanceTemplateId)->get();
|
||||
|
||||
if (findInstancesResult.find(instanceToUpdate) == findInstancesResult.end())
|
||||
{
|
||||
// Since nested instances get reconstructed during propagation, remove any nested instance that no longer
|
||||
// maps to a template.
|
||||
isUpdateSuccessful = false;
|
||||
m_instancesUpdateQueue.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
Template& currentTemplate = currentTemplateReference->get();
|
||||
Instance::EntityList newEntities;
|
||||
if (PrefabDomUtils::LoadInstanceFromPrefabDom(*instanceToUpdate, newEntities, currentTemplate.GetPrefabDom()))
|
||||
@@ -139,9 +154,18 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
m_instancesUpdateQueue.pop();
|
||||
|
||||
}
|
||||
|
||||
for (auto entityIdIterator = selectedEntityIds.begin(); entityIdIterator != selectedEntityIds.end(); entityIdIterator++)
|
||||
{
|
||||
// Since entities get recreated during propagation, we need to check whether the entities correspoding to the list
|
||||
// of selected entity ids are present or not.
|
||||
AZ::Entity* entity = GetEntityById(*entityIdIterator);
|
||||
if (entity == nullptr)
|
||||
{
|
||||
selectedEntityIds.erase(entityIdIterator--);
|
||||
}
|
||||
}
|
||||
ToolsApplicationRequestBus::Broadcast(&ToolsApplicationRequests::SetSelectedEntities, selectedEntityIds);
|
||||
|
||||
// Enable the Outliner
|
||||
|
||||
@@ -15,15 +15,16 @@
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Utils/TypeHash.h>
|
||||
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
|
||||
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
|
||||
#include <AzToolsFramework/Prefab/EditorPrefabComponent.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/Instance.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/InstanceEntityIdMapper.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/InstanceToTemplateInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabDomUtils.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabLoaderInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabUndo.h>
|
||||
@@ -37,12 +38,14 @@ namespace AzToolsFramework
|
||||
void PrefabPublicHandler::RegisterPrefabPublicHandlerInterface()
|
||||
{
|
||||
m_instanceEntityMapperInterface = AZ::Interface<InstanceEntityMapperInterface>::Get();
|
||||
AZ_Assert(
|
||||
m_instanceEntityMapperInterface, "PrefabPublicHandler - Could not retrieve instance of InstanceEntityMapperInterface");
|
||||
AZ_Assert(m_instanceEntityMapperInterface, "PrefabPublicHandler - Could not retrieve instance of InstanceEntityMapperInterface");
|
||||
|
||||
m_instanceToTemplateInterface = AZ::Interface<InstanceToTemplateInterface>::Get();
|
||||
AZ_Assert(m_instanceToTemplateInterface, "PrefabPublicHandler - Could not retrieve instance of InstanceToTemplateInterface");
|
||||
|
||||
m_prefabLoaderInterface = AZ::Interface<PrefabLoaderInterface>::Get();
|
||||
AZ_Assert(m_prefabLoaderInterface, "Could not get PrefabLoaderInterface on PrefabPublicHandler construction.");
|
||||
|
||||
m_prefabSystemComponentInterface = AZ::Interface<PrefabSystemComponentInterface>::Get();
|
||||
AZ_Assert(m_prefabSystemComponentInterface, "Could not get PrefabSystemComponentInterface on PrefabPublicHandler construction.");
|
||||
|
||||
@@ -59,91 +62,160 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
PrefabOperationResult PrefabPublicHandler::CreatePrefab(const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath)
|
||||
{
|
||||
EntityList inputEntityList, topLevelEntities;
|
||||
AZ::EntityId commonRootEntityId;
|
||||
InstanceOptionalReference commonRootEntityOwningInstance;
|
||||
PrefabOperationResult findCommonRootOutcome = FindCommonRootOwningInstance(
|
||||
entityIds, inputEntityList, topLevelEntities, commonRootEntityId, commonRootEntityOwningInstance);
|
||||
if (!findCommonRootOutcome.IsSuccess())
|
||||
{
|
||||
return findCommonRootOutcome;
|
||||
}
|
||||
|
||||
InstanceOptionalReference instanceToCreate;
|
||||
{
|
||||
// Initialize Undo Batch object
|
||||
ScopedUndoBatch undoBatch("Create Prefab");
|
||||
|
||||
PrefabDom commonRootInstanceDomBeforeCreate;
|
||||
m_instanceToTemplateInterface->GenerateDomForInstance(
|
||||
commonRootInstanceDomBeforeCreate, commonRootEntityOwningInstance->get());
|
||||
|
||||
AZStd::vector<AZ::Entity*> entities;
|
||||
AZStd::vector<AZStd::unique_ptr<Instance>> instances;
|
||||
|
||||
// Retrieve all entities affected and identify Instances
|
||||
if (!RetrieveAndSortPrefabEntitiesAndInstances(inputEntityList, commonRootEntityOwningInstance->get(), entities, instances))
|
||||
{
|
||||
return AZ::Failure(
|
||||
AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root."));
|
||||
}
|
||||
|
||||
// When we create a prefab with other prefab instances, we have to remove the existing links between the source and
|
||||
// target templates of the other instances.
|
||||
for (auto& nestedInstance : instances)
|
||||
{
|
||||
PrefabUndoHelpers::RemoveLink(
|
||||
nestedInstance->GetTemplateId(), commonRootEntityOwningInstance->get().GetTemplateId(),
|
||||
nestedInstance->GetInstanceAlias(), nestedInstance->GetLinkId(), undoBatch.GetUndoBatch());
|
||||
}
|
||||
|
||||
auto prefabEditorEntityOwnershipInterface = AZ::Interface<PrefabEditorEntityOwnershipInterface>::Get();
|
||||
if (!prefabEditorEntityOwnershipInterface)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error "
|
||||
"(PrefabEditorEntityOwnershipInterface unavailable)."));
|
||||
}
|
||||
|
||||
// Create the Prefab
|
||||
instanceToCreate = prefabEditorEntityOwnershipInterface->CreatePrefab(
|
||||
entities, AZStd::move(instances), filePath, commonRootEntityOwningInstance);
|
||||
|
||||
if (!instanceToCreate)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error "
|
||||
"(A null instance is returned)."));
|
||||
}
|
||||
|
||||
PrefabUndoHelpers::UpdatePrefabInstance(
|
||||
commonRootEntityOwningInstance->get(), "Update prefab instance", commonRootInstanceDomBeforeCreate, undoBatch.GetUndoBatch());
|
||||
|
||||
CreateLink(
|
||||
topLevelEntities, instanceToCreate->get(), commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch(),
|
||||
commonRootEntityId);
|
||||
AZ::EntityId containerEntityId = instanceToCreate->get().GetContainerEntityId();
|
||||
|
||||
// Change top level entities to be parented to the container entity
|
||||
// Mark them as dirty so this change is correctly applied to the template
|
||||
for (AZ::Entity* topLevelEntity : topLevelEntities)
|
||||
{
|
||||
m_prefabUndoCache.UpdateCache(topLevelEntity->GetId());
|
||||
undoBatch.MarkEntityDirty(topLevelEntity->GetId());
|
||||
AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId);
|
||||
}
|
||||
|
||||
// Select Container Entity
|
||||
{
|
||||
auto selectionUndo = aznew SelectionCommand({containerEntityId}, "Select Prefab Container Entity");
|
||||
selectionUndo->SetParent(undoBatch.GetUndoBatch());
|
||||
ToolsApplicationRequestBus::Broadcast(&ToolsApplicationRequestBus::Events::RunRedoSeparately, selectionUndo);
|
||||
}
|
||||
}
|
||||
|
||||
// Save Template to file
|
||||
m_prefabLoaderInterface->SaveTemplate(instanceToCreate->get().GetTemplateId());
|
||||
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
PrefabOperationResult PrefabPublicHandler::FindCommonRootOwningInstance(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, EntityList& inputEntityList, EntityList& topLevelEntities,
|
||||
AZ::EntityId& commonRootEntityId, InstanceOptionalReference& commonRootEntityOwningInstance)
|
||||
{
|
||||
// Retrieve entityList from entityIds
|
||||
EntityList inputEntityList = EntityIdListToEntityList(entityIds);
|
||||
inputEntityList = EntityIdListToEntityList(entityIds);
|
||||
|
||||
// Find common root and top level entities
|
||||
bool entitiesHaveCommonRoot = false;
|
||||
AZ::EntityId commonRootEntityId;
|
||||
EntityList topLevelEntities;
|
||||
|
||||
AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(
|
||||
entitiesHaveCommonRoot,
|
||||
&AzToolsFramework::ToolsApplicationRequests::FindCommonRootInactive,
|
||||
inputEntityList,
|
||||
commonRootEntityId,
|
||||
&topLevelEntities
|
||||
);
|
||||
entitiesHaveCommonRoot, &AzToolsFramework::ToolsApplicationRequests::FindCommonRootInactive, inputEntityList,
|
||||
commonRootEntityId, &topLevelEntities);
|
||||
|
||||
// Bail if entities don't share a common root
|
||||
if (!entitiesHaveCommonRoot)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root."));
|
||||
}
|
||||
|
||||
AZ::Entity* commonRootEntity = nullptr;
|
||||
if (commonRootEntityId.IsValid())
|
||||
{
|
||||
commonRootEntity = GetEntityById(commonRootEntityId);
|
||||
return AZ::Failure(AZStd::string("Failed to create a prefab: Provided entities do not share a common root."));
|
||||
}
|
||||
|
||||
// Retrieve the owning instance of the common root entity, which will be our new instance's parent instance.
|
||||
InstanceOptionalReference commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId);
|
||||
AZ_Assert(commonRootEntityOwningInstance.has_value(), "Failed to create prefab : "
|
||||
"Couldn't get a valid owning instance for the common root entity of the enities provided");
|
||||
|
||||
AZStd::vector<AZ::Entity*> entities;
|
||||
AZStd::vector<AZStd::unique_ptr<Instance>> instances;
|
||||
|
||||
// Retrieve all entities affected and identify Instances
|
||||
if (!RetrieveAndSortPrefabEntitiesAndInstances(inputEntityList, commonRootEntityOwningInstance->get(), entities, instances))
|
||||
commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId);
|
||||
if (!commonRootEntityOwningInstance)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - entities do not share a common root."));
|
||||
AZ_Assert(
|
||||
false,
|
||||
"Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided");
|
||||
return AZ::Failure(AZStd::string(
|
||||
"Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided"));
|
||||
}
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
auto prefabEditorEntityOwnershipInterface = AZ::Interface<PrefabEditorEntityOwnershipInterface>::Get();
|
||||
if (!prefabEditorEntityOwnershipInterface)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error "
|
||||
"(PrefabEditorEntityOwnershipInterface unavailable)."));
|
||||
}
|
||||
void PrefabPublicHandler::CreateLink(
|
||||
const EntityList& topLevelEntities, Instance& sourceInstance, TemplateId targetTemplateId,
|
||||
UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId)
|
||||
{
|
||||
AZ::EntityId containerEntityId = sourceInstance.GetContainerEntityId();
|
||||
AZ::Entity* containerEntity = GetEntityById(containerEntityId);
|
||||
Prefab::PrefabDom containerEntityDomBefore;
|
||||
m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomBefore, *containerEntity);
|
||||
|
||||
InstanceOptionalReference instance = prefabEditorEntityOwnershipInterface->CreatePrefab(
|
||||
entities, AZStd::move(instances), filePath, commonRootEntityOwningInstance);
|
||||
|
||||
if (!instance)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not create a new prefab out of the entities provided - internal error "
|
||||
"(A null instance is returned)."));
|
||||
}
|
||||
|
||||
AZ::EntityId containerEntityId = instance->get().GetContainerEntityId();
|
||||
AZ::Vector3 containerEntityTranslation(AZ::Vector3::CreateZero());
|
||||
AZ::Quaternion containerEntityRotation(AZ::Quaternion::CreateZero());
|
||||
|
||||
// Set the transform (translation, rotation) of the container entity
|
||||
GenerateContainerEntityTransform(topLevelEntities, containerEntityTranslation, containerEntityRotation);
|
||||
|
||||
// Set container entity to be child of common root
|
||||
AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, commonRootEntityId);
|
||||
|
||||
AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalTranslation, containerEntityTranslation);
|
||||
AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion, containerEntityRotation);
|
||||
|
||||
// Set container entity to be child of common root
|
||||
AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, commonRootEntityId);
|
||||
|
||||
// Assign the EditorPrefabComponent to the instance container
|
||||
EntityCompositionRequests::AddComponentsOutcome outcome;
|
||||
EntityCompositionRequestBus::BroadcastResult(
|
||||
outcome, &EntityCompositionRequests::AddComponentsToEntities, EntityIdList{containerEntityId},
|
||||
AZ::ComponentTypeList{azrtti_typeid<AzToolsFramework::Prefab::EditorPrefabComponent>()});
|
||||
|
||||
// Change top level entities to be parented to the container entity
|
||||
for (AZ::Entity* topLevelEntity : topLevelEntities)
|
||||
{
|
||||
AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId);
|
||||
}
|
||||
|
||||
return AZ::Success();
|
||||
PrefabDom containerEntityDomAfter;
|
||||
m_instanceToTemplateInterface->GenerateDomForEntity(containerEntityDomAfter, *containerEntity);
|
||||
|
||||
PrefabDom patch;
|
||||
m_instanceToTemplateInterface->GeneratePatch(patch, containerEntityDomBefore, containerEntityDomAfter);
|
||||
m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, containerEntityId);
|
||||
|
||||
PrefabUndoHelpers::CreateLink(
|
||||
sourceInstance.GetTemplateId(), targetTemplateId, patch, sourceInstance.GetInstanceAlias(),
|
||||
undoBatch);
|
||||
|
||||
// Update the cache - this prevents these changes from being stored in the regular undo/redo nodes
|
||||
m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter));
|
||||
}
|
||||
|
||||
PrefabOperationResult PrefabPublicHandler::InstantiatePrefab(AZStd::string_view /*filePath*/, AZ::EntityId /*parent*/, AZ::Vector3 /*position*/)
|
||||
@@ -173,14 +245,7 @@ namespace AzToolsFramework
|
||||
AZStd::string("SavePrefab - Path error. Path could be invalid, or the prefab may not be loaded in this level."));
|
||||
}
|
||||
|
||||
auto prefabLoaderInterface = AZ::Interface<PrefabLoaderInterface>::Get();
|
||||
if (prefabLoaderInterface == nullptr)
|
||||
{
|
||||
return AZ::Failure(AZStd::string(
|
||||
"Could not save prefab - internal error (PrefabLoaderInterface unavailable)."));
|
||||
}
|
||||
|
||||
if (!prefabLoaderInterface->SaveTemplate(templateId))
|
||||
if (!m_prefabLoaderInterface->SaveTemplate(templateId))
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not save prefab - internal error (Json write operation failure)."));
|
||||
}
|
||||
@@ -261,13 +326,13 @@ namespace AzToolsFramework
|
||||
|
||||
if (instanceOptionalReference.has_value())
|
||||
{
|
||||
PrefabDom beforeState;
|
||||
m_prefabUndoCache.Retrieve(entityId, beforeState);
|
||||
|
||||
PrefabDom afterState;
|
||||
AZ::Entity* entity = GetEntityById(entityId);
|
||||
if (entity)
|
||||
{
|
||||
PrefabDom beforeState;
|
||||
m_prefabUndoCache.Retrieve(entityId, beforeState);
|
||||
|
||||
m_instanceToTemplateInterface->GenerateDomForEntity(afterState, *entity);
|
||||
|
||||
PrefabDom patch;
|
||||
@@ -286,7 +351,10 @@ namespace AzToolsFramework
|
||||
// Update the cache
|
||||
m_prefabUndoCache.Store(entityId, AZStd::move(afterState));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
m_prefabUndoCache.PurgeCache(entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,7 +721,7 @@ namespace AzToolsFramework
|
||||
InstanceOptionalReference owningInstance = m_instanceEntityMapperInterface->FindOwningInstance(entity->GetId());
|
||||
AZ_Assert(
|
||||
owningInstance.has_value(),
|
||||
"An error occored while retrieving entities and prefab instances : "
|
||||
"An error occurred while retrieving entities and prefab instances : "
|
||||
"Owning instance of entity with id '%llu' couldn't be found",
|
||||
entity->GetId());
|
||||
|
||||
@@ -737,7 +805,7 @@ namespace AzToolsFramework
|
||||
{
|
||||
AZ_Assert(
|
||||
false,
|
||||
"An error occored in function EntitiesBelongToSameInstance: "
|
||||
"An error occurred in function EntitiesBelongToSameInstance: "
|
||||
"Owning instance of entity with id '%llu' couldn't be found",
|
||||
entityId);
|
||||
return false;
|
||||
|
||||
@@ -27,8 +27,10 @@ namespace AzToolsFramework
|
||||
namespace Prefab
|
||||
{
|
||||
class Instance;
|
||||
|
||||
class InstanceEntityMapperInterface;
|
||||
class InstanceToTemplateInterface;
|
||||
class PrefabLoaderInterface;
|
||||
class PrefabSystemComponentInterface;
|
||||
|
||||
class PrefabPublicHandler final
|
||||
@@ -67,12 +69,40 @@ namespace AzToolsFramework
|
||||
InstanceOptionalReference GetOwnerInstanceByEntityId(AZ::EntityId entityId) const;
|
||||
bool EntitiesBelongToSameInstance(const EntityIdList& entityIds) const;
|
||||
|
||||
/**
|
||||
* Creates a link between the templates of an instance and its parent.
|
||||
*
|
||||
* \param topLevelEntities The list of entities that are immediate children to the container entity of the instance.
|
||||
* \param sourceInstance The instance that corresponds to the source template of the link.
|
||||
* \param targetInstance The id of the target template.
|
||||
* \param undoBatch The undo batch to set as parent for this create link action.
|
||||
* \param commonRootEntityId The id of the entity that the source instance should be parented under.
|
||||
*/
|
||||
void CreateLink(
|
||||
const EntityList& topLevelEntities, Instance& sourceInstance, TemplateId targetTemplateId,
|
||||
UndoSystem::URSequencePoint* undoBatch, AZ::EntityId commonRootEntityId);
|
||||
|
||||
/**
|
||||
* Given a list of entityIds, finds the prefab instance that owns the common root entity of the entityIds.
|
||||
*
|
||||
* \param entityIds The list of entity ids.
|
||||
* \param inputEntityList The list of entities corresponding to the entity ids.
|
||||
* \param topLevelEntities The list of entities that are immediate children of the common root entity.
|
||||
* \param commonRootEntityId The entity id of the common root entity of all the entityIds.
|
||||
* \param commonRootEntityOwningInstance The owning instance of the common root entity.
|
||||
* \return PrefabOperationResult indicating whether the action was successful or not.
|
||||
*/
|
||||
PrefabOperationResult FindCommonRootOwningInstance(
|
||||
const AZStd::vector<AZ::EntityId>& entityIds, EntityList& inputEntityList, EntityList& topLevelEntities,
|
||||
AZ::EntityId& commonRootEntityId, InstanceOptionalReference& commonRootEntityOwningInstance);
|
||||
|
||||
static Instance* GetParentInstance(Instance* instance);
|
||||
static Instance* GetAncestorOfInstanceThatIsChildOfRoot(const Instance* ancestor, Instance* descendant);
|
||||
static void GenerateContainerEntityTransform(const EntityList& topLevelEntities, AZ::Vector3& translation, AZ::Quaternion& rotation);
|
||||
|
||||
InstanceEntityMapperInterface* m_instanceEntityMapperInterface = nullptr;
|
||||
InstanceToTemplateInterface* m_instanceToTemplateInterface = nullptr;
|
||||
PrefabLoaderInterface* m_prefabLoaderInterface = nullptr;
|
||||
PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr;
|
||||
|
||||
// Caches entity states for undo/redo purposes
|
||||
|
||||
@@ -104,7 +104,6 @@ namespace AzToolsFramework
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
AZStd::unique_ptr<Instance> newInstance = AZStd::make_unique<Instance>(AZStd::move(containerEntity));
|
||||
|
||||
for (AZ::Entity* entity : entities)
|
||||
@@ -122,6 +121,7 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
newInstance->SetTemplateSourcePath(relativeFilePath);
|
||||
newInstance->SetContainerEntityName(relativeFilePath.Stem().Native());
|
||||
|
||||
TemplateId newTemplateId = CreateTemplateFromInstance(*newInstance);
|
||||
if (newTemplateId == InvalidTemplateId)
|
||||
@@ -142,7 +142,6 @@ namespace AzToolsFramework
|
||||
|
||||
void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId)
|
||||
{
|
||||
UpdatePrefabInstances(templateId);
|
||||
auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId);
|
||||
if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end())
|
||||
{
|
||||
@@ -153,15 +152,24 @@ namespace AzToolsFramework
|
||||
templateIdToLinkIdsIterator->second.end()));
|
||||
UpdateLinkedInstances(linkIdsToUpdateQueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdatePrefabInstances(templateId);
|
||||
}
|
||||
}
|
||||
|
||||
void PrefabSystemComponent::UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom)
|
||||
{
|
||||
PrefabDom& templateDomToUpdate = FindTemplateDom(templateId);
|
||||
if (AZ::JsonSerialization::Compare(templateDomToUpdate, updatedDom) != AZ::JsonSerializerCompareResult::Equal)
|
||||
auto templateToUpdate = FindTemplate(templateId);
|
||||
if (templateToUpdate)
|
||||
{
|
||||
templateDomToUpdate.CopyFrom(updatedDom, templateDomToUpdate.GetAllocator());
|
||||
PropagateTemplateChanges(templateId);
|
||||
PrefabDom& templateDomToUpdate = templateToUpdate->get().GetPrefabDom();
|
||||
if (AZ::JsonSerialization::Compare(templateDomToUpdate, updatedDom) != AZ::JsonSerializerCompareResult::Equal)
|
||||
{
|
||||
templateDomToUpdate.CopyFrom(updatedDom, templateDomToUpdate.GetAllocator());
|
||||
templateToUpdate->get().MarkAsDirty(true);
|
||||
PropagateTemplateChanges(templateId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,7 +623,12 @@ namespace AzToolsFramework
|
||||
instancesValue = memberFound->value;
|
||||
}
|
||||
|
||||
instancesValue->get().AddMember(rapidjson::StringRef(instanceAlias.c_str()), PrefabDomValue(), targetTemplateDom.GetAllocator());
|
||||
// Only add the instance if it's not there already
|
||||
if (instancesValue->get().FindMember(rapidjson::StringRef(instanceAlias.c_str())) == instancesValue->get().MemberEnd())
|
||||
{
|
||||
instancesValue->get().AddMember(
|
||||
rapidjson::StringRef(instanceAlias.c_str()), PrefabDomValue(), targetTemplateDom.GetAllocator());
|
||||
}
|
||||
|
||||
Template& sourceTemplate = sourceTemplateRef->get();
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace AzToolsFramework
|
||||
const TemplateId& targetId,
|
||||
const TemplateId& sourceId,
|
||||
const InstanceAlias& instanceAlias,
|
||||
const PrefabDomReference linkDom,
|
||||
PrefabDomReference linkDom,
|
||||
const LinkId linkId)
|
||||
{
|
||||
m_targetId = targetId;
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace AzToolsFramework
|
||||
const TemplateId& targetId,
|
||||
const TemplateId& sourceId,
|
||||
const InstanceAlias& instanceAlias,
|
||||
const PrefabDomReference linkDom = PrefabDomReference(),
|
||||
PrefabDomReference linkDom = PrefabDomReference(),
|
||||
const LinkId linkId = InvalidLinkId);
|
||||
|
||||
void Undo() override;
|
||||
|
||||
@@ -32,6 +32,28 @@ namespace AzToolsFramework
|
||||
state->SetParent(undoBatch);
|
||||
state->Redo();
|
||||
}
|
||||
|
||||
void CreateLink(
|
||||
TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch,
|
||||
const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch)
|
||||
{
|
||||
auto linkAddUndo = aznew PrefabUndoInstanceLink("Create Link");
|
||||
linkAddUndo->Capture(targetTemplateId, sourceTemplateId, instanceAlias, patch, InvalidLinkId);
|
||||
linkAddUndo->SetParent(undoBatch);
|
||||
linkAddUndo->Redo();
|
||||
}
|
||||
|
||||
void RemoveLink(
|
||||
TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias,
|
||||
LinkId linkId, UndoSystem::URSequencePoint* undoBatch)
|
||||
{
|
||||
auto linkRemoveUndo = aznew PrefabUndoInstanceLink("Remove Link");
|
||||
PrefabDom emptyLinkDom;
|
||||
linkRemoveUndo->Capture(
|
||||
targetTemplateId, sourceTemplateId, instanceAlias, emptyLinkDom, linkId);
|
||||
linkRemoveUndo->SetParent(undoBatch);
|
||||
linkRemoveUndo->Redo();
|
||||
}
|
||||
}
|
||||
} // namespace Prefab
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace AzToolsFramework
|
||||
void UpdatePrefabInstance(
|
||||
const Instance& instance, AZStd::string_view undoMessage, const PrefabDom& instanceDomBeforeUpdate,
|
||||
UndoSystem::URSequencePoint* undoBatch);
|
||||
void CreateLink(
|
||||
TemplateId sourceTemplateId, TemplateId targetTemplateId, PrefabDomReference patch,
|
||||
const InstanceAlias& instanceAlias, UndoSystem::URSequencePoint* undoBatch);
|
||||
void RemoveLink(
|
||||
TemplateId sourceTemplateId, TemplateId targetTemplateId, const InstanceAlias& instanceAlias,
|
||||
LinkId linkId, UndoSystem::URSequencePoint* undoBatch);
|
||||
}
|
||||
} // namespace Prefab
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
@@ -79,7 +79,9 @@ namespace AzToolsFramework
|
||||
int realHeight = qMin(aznumeric_cast<int>(originalWidth /aspectRatio), originalHeight);
|
||||
int realWidth = aznumeric_cast<int>(realHeight * aspectRatio);
|
||||
int x = (originalWidth - realWidth) / 2;
|
||||
painter.drawPixmap(QRect(x, 0, realHeight, realWidth), pixmap);
|
||||
// pixmap needs to be manually scaled to produce smoother result and avoid looking pixelated
|
||||
// using painter.setRenderHint(QPainter::SmoothPixmapTransform); does not seem to work
|
||||
painter.drawPixmap(QPoint(x, 0), pixmap.scaled(realWidth, realHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
QWidget::paintEvent(event);
|
||||
}
|
||||
|
||||
+5
@@ -61,6 +61,11 @@ namespace AzToolsFramework
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorEntityUiHandlerBase::CanRename(AZ::EntityId /*entityId*/) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorEntityUiHandlerBase::PaintItemBackground(QPainter* /*painter*/, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
|
||||
{
|
||||
}
|
||||
|
||||
+2
@@ -47,6 +47,8 @@ namespace AzToolsFramework
|
||||
virtual QPixmap GenerateItemIcon(AZ::EntityId entityId) const;
|
||||
//! Returns whether the element's lock and visibility state should be accessible in the Outliner
|
||||
virtual bool CanToggleLockVisibility(AZ::EntityId entityId) const;
|
||||
//! Returns whether the element's name should be editable
|
||||
virtual bool CanRename(AZ::EntityId entityId) const;
|
||||
|
||||
//! Paints the background of the item in the Outliner.
|
||||
virtual void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
|
||||
+22
-22
@@ -945,6 +945,12 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable reparenting to the root level
|
||||
if (!newParentId.IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ignore entities not owned by the editor context. It is assumed that all entities belong
|
||||
// to the same context since multiple selection doesn't span across views.
|
||||
for (const AZ::EntityId& entityId : selectedEntityIds)
|
||||
@@ -974,39 +980,33 @@ namespace AzToolsFramework
|
||||
}
|
||||
}
|
||||
|
||||
if (newParentId.IsValid())
|
||||
bool isLayerEntity = false;
|
||||
Layers::EditorLayerComponentRequestBus::EventResult(
|
||||
isLayerEntity,
|
||||
entityId,
|
||||
&Layers::EditorLayerComponentRequestBus::Events::HasLayer);
|
||||
// Layers can only have other layers as parents, or have no parent.
|
||||
if (isLayerEntity)
|
||||
{
|
||||
bool isLayerEntity = false;
|
||||
bool newParentIsLayer = false;
|
||||
Layers::EditorLayerComponentRequestBus::EventResult(
|
||||
isLayerEntity,
|
||||
entityId,
|
||||
newParentIsLayer,
|
||||
newParentId,
|
||||
&Layers::EditorLayerComponentRequestBus::Events::HasLayer);
|
||||
// Layers can only have other layers as parents, or have no parent.
|
||||
if (isLayerEntity)
|
||||
if (!newParentIsLayer)
|
||||
{
|
||||
bool newParentIsLayer = false;
|
||||
Layers::EditorLayerComponentRequestBus::EventResult(
|
||||
newParentIsLayer,
|
||||
newParentId,
|
||||
&Layers::EditorLayerComponentRequestBus::Events::HasLayer);
|
||||
if (!newParentIsLayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Only check the entity pointer if the entity id is valid because
|
||||
//we want to allow dragging items to unoccupied parts of the tree to un-parent them
|
||||
if (newParentId.IsValid())
|
||||
AZ::Entity* newParentEntity = nullptr;
|
||||
AZ::ComponentApplicationBus::BroadcastResult(newParentEntity, &AZ::ComponentApplicationRequests::FindEntity, newParentId);
|
||||
if (!newParentEntity)
|
||||
{
|
||||
AZ::Entity* newParentEntity = nullptr;
|
||||
AZ::ComponentApplicationBus::BroadcastResult(newParentEntity, &AZ::ComponentApplicationRequests::FindEntity, newParentId);
|
||||
if (!newParentEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//reject dragging on to yourself or your children
|
||||
|
||||
+24
-5
@@ -30,6 +30,7 @@
|
||||
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
|
||||
#include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx>
|
||||
#include <AzToolsFramework/UI/EditorEntityUi/EditorEntityUiHandlerBase.h>
|
||||
#include <AzToolsFramework/UI/Outliner/EntityOutlinerDisplayOptionsMenu.h>
|
||||
#include <AzToolsFramework/UI/Outliner/EntityOutlinerListModel.hxx>
|
||||
#include <AzToolsFramework/UI/Outliner/EntityOutlinerSortFilterProxyModel.hxx>
|
||||
@@ -271,6 +272,12 @@ namespace AzToolsFramework
|
||||
|
||||
m_listModel->Initialize();
|
||||
|
||||
m_editorEntityUiInterface = AZ::Interface<AzToolsFramework::EditorEntityUiInterface>::Get();
|
||||
|
||||
AZ_Assert(
|
||||
m_editorEntityUiInterface != nullptr,
|
||||
"EntityOutlinerWidget requires a EditorEntityUiInterface instance on Initialize.");
|
||||
|
||||
EditorPickModeNotificationBus::Handler::BusConnect(GetEntityContextId());
|
||||
EntityHighlightMessages::Bus::Handler::BusConnect();
|
||||
EntityOutlinerModelNotificationBus::Handler::BusConnect();
|
||||
@@ -562,7 +569,13 @@ namespace AzToolsFramework
|
||||
|
||||
if (m_selectedEntityIds.size() == 1)
|
||||
{
|
||||
contextMenu->addAction(m_actionToRenameSelection);
|
||||
auto entityId = m_selectedEntityIds.front();
|
||||
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
|
||||
|
||||
if (!entityUiHandler || entityUiHandler->CanRename(entityId))
|
||||
{
|
||||
contextMenu->addAction(m_actionToRenameSelection);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_selectedEntityIds.size() == 1)
|
||||
@@ -688,11 +701,17 @@ namespace AzToolsFramework
|
||||
|
||||
if (m_selectedEntityIds.size() == 1)
|
||||
{
|
||||
const QModelIndex proxyIndex = GetIndexFromEntityId(m_selectedEntityIds.front());
|
||||
if (proxyIndex.isValid())
|
||||
auto entityId = m_selectedEntityIds.front();
|
||||
auto entityUiHandler = m_editorEntityUiInterface->GetHandler(entityId);
|
||||
|
||||
if (!entityUiHandler || entityUiHandler->CanRename(entityId))
|
||||
{
|
||||
m_gui->m_objectTree->setCurrentIndex(proxyIndex);
|
||||
m_gui->m_objectTree->QTreeView::edit(proxyIndex);
|
||||
const QModelIndex proxyIndex = GetIndexFromEntityId(entityId);
|
||||
if (proxyIndex.isValid())
|
||||
{
|
||||
m_gui->m_objectTree->setCurrentIndex(proxyIndex);
|
||||
m_gui->m_objectTree->QTreeView::edit(proxyIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace Ui
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class EditorEntityUiInterface;
|
||||
class EntityOutlinerListModel;
|
||||
class EntityOutlinerSortFilterProxyModel;
|
||||
|
||||
@@ -193,6 +194,8 @@ namespace AzToolsFramework
|
||||
EntityIdSet m_entitiesToSort;
|
||||
EntityOutliner::DisplaySortMode m_sortMode;
|
||||
bool m_sortContentQueued;
|
||||
|
||||
EditorEntityUiInterface* m_editorEntityUiInterface = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -50,11 +50,31 @@ namespace AzToolsFramework
|
||||
return QPixmap(m_levelRootIconPath);
|
||||
}
|
||||
|
||||
QString LevelRootUiHandler::GenerateItemInfoString(AZ::EntityId entityId) const
|
||||
{
|
||||
QString infoString;
|
||||
|
||||
AZ::IO::Path path = m_prefabPublicInterface->GetOwningInstancePrefabPath(entityId);
|
||||
|
||||
if (!path.empty())
|
||||
{
|
||||
infoString =
|
||||
QObject::tr("<span style=\"font-style: italic; font-weight: 400;\">(%1)</span>").arg(path.Filename().Native().data());
|
||||
}
|
||||
|
||||
return infoString;
|
||||
}
|
||||
|
||||
bool LevelRootUiHandler::CanToggleLockVisibility(AZ::EntityId /*entityId*/) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LevelRootUiHandler::CanRename(AZ::EntityId /*entityId*/) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void LevelRootUiHandler::PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& /*index*/) const
|
||||
{
|
||||
if (!painter)
|
||||
|
||||
@@ -34,7 +34,9 @@ namespace AzToolsFramework
|
||||
|
||||
// EditorEntityUiHandler...
|
||||
QPixmap GenerateItemIcon(AZ::EntityId entityId) const override;
|
||||
QString GenerateItemInfoString(AZ::EntityId entityId) const override;
|
||||
bool CanToggleLockVisibility(AZ::EntityId entityId) const override;
|
||||
bool CanRename(AZ::EntityId entityId) const override;
|
||||
void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
|
||||
private:
|
||||
|
||||
+47
-10
@@ -310,6 +310,9 @@ namespace AzToolsFramework
|
||||
{
|
||||
initEntityPropertyEditorResources();
|
||||
|
||||
m_prefabPublicInterface = AZ::Interface<Prefab::PrefabPublicInterface>::Get();
|
||||
AZ_Assert(m_prefabPublicInterface != nullptr, "EntityPropertyEditor requires a PrefabPublicInterface instance on Initialize.");
|
||||
|
||||
setObjectName("EntityPropertyEditor");
|
||||
setAcceptDrops(true);
|
||||
|
||||
@@ -405,8 +408,6 @@ namespace AzToolsFramework
|
||||
CreateActions();
|
||||
UpdateContents();
|
||||
|
||||
m_prefabPublicInterface = AZ::Interface<Prefab::PrefabPublicInterface>::Get();
|
||||
|
||||
EditorEntityContextNotificationBus::Handler::BusConnect();
|
||||
|
||||
//forced to register global event filter with application for selection
|
||||
@@ -693,11 +694,38 @@ namespace AzToolsFramework
|
||||
m_gui->m_entityIcon->repaint();
|
||||
}
|
||||
|
||||
EntityPropertyEditor::InspectorLayout EntityPropertyEditor::GetCurrentInspectorLayout() const
|
||||
{
|
||||
if (!m_prefabsAreEnabled)
|
||||
{
|
||||
return m_isLevelEntityEditor ? InspectorLayout::LEVEL : InspectorLayout::ENTITY;
|
||||
}
|
||||
|
||||
AZ::EntityId levelContainerEntityId = m_prefabPublicInterface->GetLevelInstanceContainerEntityId();
|
||||
if (AZStd::find(m_selectedEntityIds.begin(), m_selectedEntityIds.end(), levelContainerEntityId) != m_selectedEntityIds.end())
|
||||
{
|
||||
if (m_selectedEntityIds.size() > 1)
|
||||
{
|
||||
return InspectorLayout::INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return InspectorLayout::LEVEL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return InspectorLayout::ENTITY;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityPropertyEditor::UpdateEntityDisplay()
|
||||
{
|
||||
UpdateStatusComboBox();
|
||||
|
||||
if (m_isLevelEntityEditor)
|
||||
InspectorLayout layout = GetCurrentInspectorLayout();
|
||||
|
||||
if (layout == InspectorLayout::LEVEL)
|
||||
{
|
||||
AZStd::string levelName;
|
||||
AzToolsFramework::EditorRequestBus::BroadcastResult(levelName, &AzToolsFramework::EditorRequests::GetLevelName);
|
||||
@@ -737,13 +765,20 @@ namespace AzToolsFramework
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework);
|
||||
SelectionEntityTypeInfo result = SelectionEntityTypeInfo::None;
|
||||
|
||||
if (m_isLevelEntityEditor)
|
||||
InspectorLayout layout = GetCurrentInspectorLayout();
|
||||
|
||||
if (layout == InspectorLayout::LEVEL)
|
||||
{
|
||||
// The Level Inspector should only have a list of selectable components after the
|
||||
// level entity itself is valid (i.e. "selected").
|
||||
return selection.empty() ? SelectionEntityTypeInfo::None : SelectionEntityTypeInfo::LevelEntity;
|
||||
}
|
||||
|
||||
if (layout == InspectorLayout::INVALID)
|
||||
{
|
||||
return SelectionEntityTypeInfo::Mixed;
|
||||
}
|
||||
|
||||
for (AZ::EntityId selectedEntityId : selection)
|
||||
{
|
||||
bool isLayerEntity = false;
|
||||
@@ -909,16 +944,18 @@ namespace AzToolsFramework
|
||||
}
|
||||
}
|
||||
|
||||
bool isLevelLayout = GetCurrentInspectorLayout() == InspectorLayout::LEVEL;
|
||||
|
||||
m_gui->m_entityDetailsLabel->setText(entityDetailsLabelText);
|
||||
m_gui->m_entityDetailsLabel->setVisible(entityDetailsVisible);
|
||||
m_gui->m_entityNameEditor->setVisible(hasEntitiesDisplayed);
|
||||
m_gui->m_entityNameLabel->setVisible(hasEntitiesDisplayed);
|
||||
m_gui->m_entityIcon->setVisible(hasEntitiesDisplayed);
|
||||
m_gui->m_pinButton->setVisible(m_overrideSelectedEntityIds.empty() && hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor);
|
||||
m_gui->m_statusLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor);
|
||||
m_gui->m_statusComboBox->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor);
|
||||
m_gui->m_entityIdLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor);
|
||||
m_gui->m_entityIdText->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !m_isLevelEntityEditor);
|
||||
m_gui->m_pinButton->setVisible(m_overrideSelectedEntityIds.empty() && hasEntitiesDisplayed && !m_isSystemEntityEditor);
|
||||
m_gui->m_statusLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout);
|
||||
m_gui->m_statusComboBox->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout);
|
||||
m_gui->m_entityIdLabel->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout);
|
||||
m_gui->m_entityIdText->setVisible(hasEntitiesDisplayed && !m_isSystemEntityEditor && !isLevelLayout);
|
||||
|
||||
bool displayComponentSearchBox = hasEntitiesDisplayed;
|
||||
if (hasEntitiesDisplayed)
|
||||
@@ -941,7 +978,7 @@ namespace AzToolsFramework
|
||||
UpdateEntityDisplay();
|
||||
}
|
||||
|
||||
m_gui->m_darkBox->setVisible(displayComponentSearchBox && !m_isSystemEntityEditor && !m_isLevelEntityEditor);
|
||||
m_gui->m_darkBox->setVisible(displayComponentSearchBox && !m_isSystemEntityEditor && !isLevelLayout);
|
||||
m_gui->m_entitySearchBox->setVisible(displayComponentSearchBox);
|
||||
|
||||
bool displayAddComponentMenu = CanAddComponentsToSelection(selectionEntityTypeInfo);
|
||||
|
||||
+9
@@ -521,6 +521,15 @@ namespace AzToolsFramework
|
||||
bool m_isSystemEntityEditor;
|
||||
bool m_isLevelEntityEditor = false;
|
||||
|
||||
enum class InspectorLayout
|
||||
{
|
||||
ENTITY = 0, // All selected entities are regular entities
|
||||
LEVEL, // The selected entity is the level prefab container entity
|
||||
INVALID // Other entities are selected alongside the level prefab container entity
|
||||
};
|
||||
|
||||
InspectorLayout GetCurrentInspectorLayout() const;
|
||||
|
||||
// the spacer's job is to make sure that its always at the end of the list of components.
|
||||
QSpacerItem* m_spacer;
|
||||
bool m_isAlreadyQueuedRefresh;
|
||||
|
||||
@@ -28,8 +28,9 @@ ly_add_target(
|
||||
${pal_dir}
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
3rdParty::OpenSSL
|
||||
AZ::AzCore
|
||||
PUBLIC
|
||||
3rdParty::OpenSSL
|
||||
)
|
||||
|
||||
ly_add_source_properties(
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "AlignTool.h"
|
||||
|
||||
// Editor
|
||||
#include "Objects/BaseObject.h"
|
||||
#include "Objects/SelectionGroup.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CAlignPickCallback::m_bActive = false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//! Called when object picked.
|
||||
void CAlignPickCallback::OnPick(CBaseObject* picked)
|
||||
{
|
||||
Matrix34 pickedTM(picked->GetWorldTM());
|
||||
|
||||
AABB pickedAABB;
|
||||
picked->GetBoundBox(pickedAABB);
|
||||
pickedAABB.Move(-pickedTM.GetTranslation());
|
||||
Vec3 pickedPivot = pickedAABB.GetCenter();
|
||||
|
||||
AABB pickedLocalAABB;
|
||||
picked->GetLocalBounds(pickedLocalAABB);
|
||||
|
||||
const Quat& pickedRot = picked->GetRotation();
|
||||
const Vec3& pickedScale = picked->GetScale();
|
||||
const Vec3& pickedPos = picked->GetPos();
|
||||
|
||||
bool bKeepScale = CheckVirtualKey(Qt::Key_Shift);
|
||||
bool bKeepRotation = CheckVirtualKey(Qt::Key_Alt);
|
||||
bool bAlignToBoundBox = CheckVirtualKey(Qt::Key_Control);
|
||||
bool bApplyTransform = !bKeepScale && !bKeepRotation && !bAlignToBoundBox;
|
||||
|
||||
{
|
||||
bool bUndo = !CUndo::IsRecording();
|
||||
if (bUndo)
|
||||
{
|
||||
GetIEditor()->BeginUndo();
|
||||
}
|
||||
|
||||
CSelectionGroup* selGroup = GetIEditor()->GetSelection();
|
||||
selGroup->FilterParents();
|
||||
|
||||
for (int i = 0; i < selGroup->GetFilteredCount(); i++)
|
||||
{
|
||||
CBaseObject* pMovedObj = selGroup->GetFilteredObject(i);
|
||||
|
||||
if (bKeepScale || bKeepRotation || bApplyTransform)
|
||||
{
|
||||
if (bKeepScale && bKeepRotation) // Keep scale and rotation of a moved object
|
||||
{
|
||||
pMovedObj->SetWorldTM(Matrix34::Create(pMovedObj->GetScale(), pMovedObj->GetRotation(), pickedPos), eObjectUpdateFlags_UserInput);
|
||||
}
|
||||
else if (bKeepScale) // Keep only scale of a moved object
|
||||
{
|
||||
pMovedObj->SetWorldTM(Matrix34::Create(pMovedObj->GetScale(), pickedRot, pickedPos), eObjectUpdateFlags_UserInput);
|
||||
}
|
||||
else if (bKeepRotation) // Keep only rotation of a moved object
|
||||
{
|
||||
pMovedObj->SetWorldTM(Matrix34::Create(pickedScale, pMovedObj->GetRotation(), pickedPos), eObjectUpdateFlags_UserInput);
|
||||
}
|
||||
else // Scale, Rotation and Position of a picked object are applied to a moved object.
|
||||
{
|
||||
pMovedObj->SetWorldTM(pickedTM, eObjectUpdateFlags_UserInput);
|
||||
}
|
||||
}
|
||||
else if (bAlignToBoundBox) // align to the bounding box.
|
||||
{
|
||||
if (pickedLocalAABB.GetVolume() == 0.0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AABB movedLocalAABB;
|
||||
pMovedObj->GetLocalBounds(movedLocalAABB);
|
||||
if (fabs(movedLocalAABB.max.x - movedLocalAABB.min.x) < VEC_EPSILON &&
|
||||
fabs(movedLocalAABB.max.y - movedLocalAABB.min.y) < VEC_EPSILON &&
|
||||
fabs(movedLocalAABB.max.z - movedLocalAABB.min.z) < VEC_EPSILON)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const Vec3& movedScale(pMovedObj->GetScale());
|
||||
Matrix34 movedScaleTM = Matrix34::CreateScale(movedScale);
|
||||
AABB movedLocalScaledAABB;
|
||||
movedLocalScaledAABB.min = movedScaleTM.TransformVector(movedLocalAABB.min);
|
||||
movedLocalScaledAABB.max = movedScaleTM.TransformVector(movedLocalAABB.max);
|
||||
|
||||
float fMovedWidth = movedLocalScaledAABB.max.x - movedLocalScaledAABB.min.x;
|
||||
float fMovedHeight = movedLocalScaledAABB.max.z - movedLocalScaledAABB.min.z;
|
||||
float fMovedLength = movedLocalScaledAABB.max.y - movedLocalScaledAABB.min.y;
|
||||
|
||||
Matrix34 pickedScaleTM = Matrix34::CreateScale(picked->GetScale());
|
||||
AABB pickedLocalScaledAABB;
|
||||
pickedLocalScaledAABB.min = pickedScaleTM.TransformVector(pickedLocalAABB.min);
|
||||
pickedLocalScaledAABB.max = pickedScaleTM.TransformVector(pickedLocalAABB.max);
|
||||
float fScaledPickedtWidth = pickedLocalScaledAABB.max.x - pickedLocalScaledAABB.min.x;
|
||||
float fScaledPickedHeight = pickedLocalScaledAABB.max.z - pickedLocalScaledAABB.min.z;
|
||||
float fScaledPickedLength = pickedLocalScaledAABB.max.y - pickedLocalScaledAABB.min.y;
|
||||
|
||||
Vec3 scale((fScaledPickedtWidth / fMovedWidth) * movedScale.x, (fScaledPickedLength / fMovedLength) * movedScale.y, (fScaledPickedHeight / fMovedHeight) * movedScale.z);
|
||||
Matrix34 scaleRotTM = Matrix34::Create(scale, pickedRot, Vec3(0, 0, 0));
|
||||
Vec3 movedPivot = scaleRotTM.TransformVector(movedLocalAABB.GetCenter());
|
||||
|
||||
pMovedObj->SetWorldTM(Matrix34::Create(scale, pickedRot, Vec3(pickedPos + (pickedPivot - movedPivot))), eObjectUpdateFlags_UserInput);
|
||||
}
|
||||
}
|
||||
m_bActive = false;
|
||||
if (bUndo)
|
||||
{
|
||||
GetIEditor()->AcceptUndo("Align To Object");
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
//! Called when pick mode cancelled.
|
||||
void CAlignPickCallback::OnCancelPick()
|
||||
{
|
||||
m_bActive = false;
|
||||
delete this;
|
||||
}
|
||||
|
||||
//! Return true if specified object is pickable.
|
||||
bool CAlignPickCallback::OnPickFilter([[maybe_unused]] CBaseObject* filterObject)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_ALIGNTOOL_H
|
||||
#define CRYINCLUDE_EDITOR_ALIGNTOOL_H
|
||||
|
||||
#pragma once
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CAlignPickCallback
|
||||
: public IPickObjectCallback
|
||||
{
|
||||
public:
|
||||
CAlignPickCallback() { m_bActive = true; };
|
||||
//! Called when object picked.
|
||||
virtual void OnPick(CBaseObject* picked);
|
||||
//! Called when pick mode cancelled.
|
||||
virtual void OnCancelPick();
|
||||
//! Return true if specified object is pickable.
|
||||
virtual bool OnPickFilter(CBaseObject* filterObject);
|
||||
|
||||
static bool IsActive() { return m_bActive; }
|
||||
|
||||
virtual bool IsNeedSpecificBehaviorForSpaceAcce() { return true; }
|
||||
private:
|
||||
static bool m_bActive;
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_ALIGNTOOL_H
|
||||
@@ -580,7 +580,6 @@ void LevelEditorMenuHandler::PopulateEditMenu(ActionManager::MenuWrapper& editMe
|
||||
|
||||
auto alignMenu = modifyMenu.AddMenu(tr("Align"));
|
||||
alignMenu.AddAction(ID_OBJECTMODIFY_ALIGNTOGRID);
|
||||
alignMenu.AddAction(ID_OBJECTMODIFY_ALIGN);
|
||||
alignMenu.AddAction(ID_MODIFY_ALIGNOBJTOSURF);
|
||||
|
||||
auto constrainMenu = modifyMenu.AddMenu(tr("Constrain"));
|
||||
|
||||
@@ -95,8 +95,6 @@ AZ_POP_DISABLE_WARNING
|
||||
|
||||
#include "Core/QtEditorApplication.h"
|
||||
#include "StringDlg.h"
|
||||
#include "LinkTool.h"
|
||||
#include "AlignTool.h"
|
||||
#include "VoxelAligningTool.h"
|
||||
#include "NewLevelDialog.h"
|
||||
#include "GridSettingsDialog.h"
|
||||
@@ -400,8 +398,6 @@ void CCryEditApp::RegisterActionHandlers()
|
||||
ON_COMMAND(ID_EDITMODE_MOVE, OnEditmodeMove)
|
||||
ON_COMMAND(ID_EDITMODE_ROTATE, OnEditmodeRotate)
|
||||
ON_COMMAND(ID_EDITMODE_SCALE, OnEditmodeScale)
|
||||
ON_COMMAND(ID_EDITTOOL_LINK, OnEditToolLink)
|
||||
ON_COMMAND(ID_EDITTOOL_UNLINK, OnEditToolUnlink)
|
||||
ON_COMMAND(ID_EDITMODE_SELECT, OnEditmodeSelect)
|
||||
ON_COMMAND(ID_EDIT_ESCAPE, OnEditEscape)
|
||||
ON_COMMAND(ID_OBJECTMODIFY_SETAREA, OnObjectSetArea)
|
||||
@@ -421,7 +417,6 @@ void CCryEditApp::RegisterActionHandlers()
|
||||
ON_COMMAND(ID_SELECTION_SAVE, OnSelectionSave)
|
||||
ON_COMMAND(ID_IMPORT_ASSET, OnOpenAssetImporter)
|
||||
ON_COMMAND(ID_SELECTION_LOAD, OnSelectionLoad)
|
||||
ON_COMMAND(ID_OBJECTMODIFY_ALIGN, OnAlignObject)
|
||||
ON_COMMAND(ID_MODIFY_ALIGNOBJTOSURF, OnAlignToVoxel)
|
||||
ON_COMMAND(ID_OBJECTMODIFY_ALIGNTOGRID, OnAlignToGrid)
|
||||
ON_COMMAND(ID_LOCK_SELECTION, OnLockSelection)
|
||||
@@ -2896,51 +2891,6 @@ void CCryEditApp::OnEditmodeScale()
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnEditToolLink()
|
||||
{
|
||||
// TODO: Add your command handler code here
|
||||
if (qobject_cast<CLinkTool*>(GetIEditor()->GetEditTool()))
|
||||
{
|
||||
GetIEditor()->SetEditTool(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetIEditor()->SetEditTool(new CLinkTool());
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnUpdateEditToolLink(QAction* action)
|
||||
{
|
||||
if (!GetIEditor()->GetDocument())
|
||||
{
|
||||
action->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
action->setEnabled(GetIEditor()->GetDocument()->IsDocumentReady());
|
||||
CEditTool* pEditTool = GetIEditor()->GetEditTool();
|
||||
action->setChecked(qobject_cast<CLinkTool*>(pEditTool) != nullptr);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnEditToolUnlink()
|
||||
{
|
||||
CUndo undo("Unlink Object(s)");
|
||||
CSelectionGroup* pSelection = GetIEditor()->GetObjectManager()->GetSelection();
|
||||
for (int i = 0; i < pSelection->GetCount(); i++)
|
||||
{
|
||||
CBaseObject* pBaseObj = pSelection->GetObject(i);
|
||||
pBaseObj->DetachThis();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnUpdateEditToolUnlink(QAction* action)
|
||||
{
|
||||
action->setEnabled(false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnEditmodeSelect()
|
||||
{
|
||||
@@ -3510,14 +3460,6 @@ void CCryEditApp::OnUpdateSelected(QAction* action)
|
||||
action->setEnabled(!GetIEditor()->GetSelection()->IsEmpty());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnAlignObject()
|
||||
{
|
||||
// Align pick callback will release itself.
|
||||
CAlignPickCallback* alignCallback = new CAlignPickCallback;
|
||||
GetIEditor()->PickObject(alignCallback, 0, "Align to Object");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnAlignToGrid()
|
||||
{
|
||||
@@ -3538,15 +3480,6 @@ void CCryEditApp::OnAlignToGrid()
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnUpdateAlignObject(QAction* action)
|
||||
{
|
||||
Q_ASSERT(action->isCheckable());
|
||||
action->setChecked(CAlignPickCallback::IsActive());
|
||||
|
||||
action->setEnabled(!GetIEditor()->GetSelection()->IsEmpty());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CCryEditApp::OnAlignToVoxel()
|
||||
{
|
||||
|
||||
@@ -224,10 +224,6 @@ public:
|
||||
void OnEditmodeMove();
|
||||
void OnEditmodeRotate();
|
||||
void OnEditmodeScale();
|
||||
void OnEditToolLink();
|
||||
void OnUpdateEditToolLink(QAction* action);
|
||||
void OnEditToolUnlink();
|
||||
void OnUpdateEditToolUnlink(QAction* action);
|
||||
void OnEditmodeSelect();
|
||||
void OnEditEscape();
|
||||
void OnObjectSetArea();
|
||||
@@ -256,10 +252,8 @@ public:
|
||||
void OnOpenAssetImporter();
|
||||
void OnSelectionLoad();
|
||||
void OnUpdateSelected(QAction* action);
|
||||
void OnAlignObject();
|
||||
void OnAlignToVoxel();
|
||||
void OnAlignToGrid();
|
||||
void OnUpdateAlignObject(QAction* action);
|
||||
void OnUpdateAlignToVoxel(QAction* action);
|
||||
void OnLockSelection();
|
||||
void OnEditLevelData();
|
||||
|
||||
@@ -276,9 +276,6 @@ void EditorViewportWidget::paintEvent([[maybe_unused]] QPaintEvent* event)
|
||||
if ((ge && ge->IsLevelLoaded()) || (GetType() != ET_ViewportCamera))
|
||||
{
|
||||
setRenderOverlayVisible(true);
|
||||
m_isOnPaint = true;
|
||||
Update();
|
||||
m_isOnPaint = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -682,6 +679,11 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
}
|
||||
SetCurrentCursor(STD_CURSOR_GAME);
|
||||
}
|
||||
|
||||
if (m_renderViewport)
|
||||
{
|
||||
m_renderViewport->GetControllerList()->SetEnabled(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -700,6 +702,11 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
|
||||
RestoreViewportAfterGameMode();
|
||||
}
|
||||
|
||||
if (m_renderViewport)
|
||||
{
|
||||
m_renderViewport->GetControllerList()->SetEnabled(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case eNotify_OnCloseScene:
|
||||
@@ -730,6 +737,8 @@ void EditorViewportWidget::OnEditorNotifyEvent(EEditorNotifyEvent event)
|
||||
// meters above the terrain (default terrain height is 32)
|
||||
viewTM.SetTranslation(Vec3(sx * 0.5f, sy * 0.5f, 34.0f));
|
||||
SetViewTM(viewTM);
|
||||
|
||||
UpdateScene();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -809,6 +818,10 @@ void EditorViewportWidget::OnBeginPrepareRender()
|
||||
return;
|
||||
}
|
||||
|
||||
m_isOnPaint = true;
|
||||
Update();
|
||||
m_isOnPaint = false;
|
||||
|
||||
float fNearZ = GetIEditor()->GetConsoleVar("cl_DefaultNearPlane");
|
||||
float fFarZ = m_Camera.GetFarPlane();
|
||||
|
||||
@@ -880,6 +893,11 @@ void EditorViewportWidget::OnBeginPrepareRender()
|
||||
|
||||
GetIEditor()->GetSystem()->SetViewCamera(m_Camera);
|
||||
|
||||
if (GetIEditor()->IsInGameMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PreWidgetRendering();
|
||||
|
||||
RenderAll();
|
||||
@@ -905,11 +923,6 @@ void EditorViewportWidget::OnBeginPrepareRender()
|
||||
m_debugDisplay->DepthTestOn();
|
||||
|
||||
PostWidgetRendering();
|
||||
|
||||
if (!m_renderer->IsStereoEnabled())
|
||||
{
|
||||
GetIEditor()->GetSystem()->RenderStatistics();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -391,21 +391,6 @@ enum EModifiedModule
|
||||
eModifiedAll = -1
|
||||
};
|
||||
|
||||
//! Callback class passed to PickObject.
|
||||
struct IPickObjectCallback
|
||||
{
|
||||
virtual ~IPickObjectCallback() = default;
|
||||
|
||||
//! Called when object picked.
|
||||
virtual void OnPick(CBaseObject* picked) = 0;
|
||||
//! Called when pick mode cancelled.
|
||||
virtual void OnCancelPick() = 0;
|
||||
//! Return true if specified object is pickable.
|
||||
virtual bool OnPickFilter([[maybe_unused]] CBaseObject* filterObject) { return true; };
|
||||
//! If need a specific behavior when holding space, return true or if not, return false.
|
||||
virtual bool IsNeedSpecificBehaviorForSpaceAcce() { return false; }
|
||||
};
|
||||
|
||||
//! Class provided by editor for various registration functions.
|
||||
struct CRegistrationContext
|
||||
{
|
||||
@@ -570,20 +555,6 @@ struct IEditor
|
||||
//! Get access to object manager.
|
||||
virtual struct IObjectManager* GetObjectManager() = 0;
|
||||
virtual CSettingsManager* GetSettingsManager() = 0;
|
||||
//! Set pick object mode.
|
||||
//! When object picked callback will be called, with OnPick
|
||||
//! If pick operation is canceled Cancel will be called
|
||||
//! @param targetClass specifies objects of which class are supposed to be picked
|
||||
//! @param bMultipick if true pick tool will pick multiple object
|
||||
virtual void PickObject(
|
||||
IPickObjectCallback* callback,
|
||||
const QMetaObject* targetClass = 0,
|
||||
const char* statusText = 0,
|
||||
bool bMultipick = false) = 0;
|
||||
//! Cancel current pick operation
|
||||
virtual void CancelPick() = 0;
|
||||
//! Return true if editor now in object picking mode
|
||||
virtual bool IsPicking() = 0;
|
||||
//! Get DB manager that own items of specified type.
|
||||
virtual IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType) = 0;
|
||||
//! Get Manager of Materials.
|
||||
|
||||
@@ -65,7 +65,6 @@ AZ_POP_DISABLE_WARNING
|
||||
#include "UIEnumsDatabase.h"
|
||||
#include "Util/Ruler.h"
|
||||
#include "RenderHelpers/AxisHelper.h"
|
||||
#include "PickObjectTool.h"
|
||||
#include "Settings.h"
|
||||
#include "Include/IObjectManager.h"
|
||||
#include "Include/ISourceControl.h"
|
||||
@@ -170,7 +169,6 @@ CEditorImpl::CEditorImpl()
|
||||
, m_pShaderEnum(nullptr)
|
||||
, m_pIconManager(nullptr)
|
||||
, m_bSelectionLocked(true)
|
||||
, m_pPickTool(nullptr)
|
||||
, m_pAxisGizmo(nullptr)
|
||||
, m_pGameEngine(nullptr)
|
||||
, m_pAnimationContext(nullptr)
|
||||
@@ -794,11 +792,6 @@ void CEditorImpl::SetEditTool(CEditTool* tool, bool bStopCurrentTool)
|
||||
m_pEditTool->BeginEditParams(this, 0);
|
||||
}
|
||||
|
||||
// Make sure pick is aborted.
|
||||
if (tool != m_pPickTool)
|
||||
{
|
||||
m_pPickTool = nullptr;
|
||||
}
|
||||
Notify(eNotify_OnEditToolChange);
|
||||
}
|
||||
|
||||
@@ -1069,34 +1062,6 @@ bool CEditorImpl::IsSelectionLocked()
|
||||
return m_bSelectionLocked;
|
||||
}
|
||||
|
||||
void CEditorImpl::PickObject(IPickObjectCallback* callback, const QMetaObject* targetClass, const char* statusText, bool bMultipick)
|
||||
{
|
||||
m_pPickTool = new CPickObjectTool(callback, targetClass);
|
||||
|
||||
static_cast<CPickObjectTool*>(m_pPickTool.get())->SetMultiplePicks(bMultipick);
|
||||
if (statusText)
|
||||
{
|
||||
m_pPickTool.get()->SetStatusText(statusText);
|
||||
}
|
||||
|
||||
SetEditTool(m_pPickTool);
|
||||
}
|
||||
|
||||
void CEditorImpl::CancelPick()
|
||||
{
|
||||
SetEditTool(0);
|
||||
m_pPickTool = 0;
|
||||
}
|
||||
|
||||
bool CEditorImpl::IsPicking()
|
||||
{
|
||||
if (GetEditTool() == m_pPickTool && m_pPickTool != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CViewManager* CEditorImpl::GetViewManager()
|
||||
{
|
||||
return m_pViewManager;
|
||||
|
||||
@@ -181,10 +181,7 @@ public:
|
||||
void SelectObject(CBaseObject* obj);
|
||||
void LockSelection(bool bLock);
|
||||
bool IsSelectionLocked();
|
||||
void PickObject(IPickObjectCallback* callback, const QMetaObject* targetClass = 0, const char* statusText = 0, bool bMultipick = false);
|
||||
|
||||
void CancelPick();
|
||||
bool IsPicking();
|
||||
IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType);
|
||||
CMaterialManager* GetMaterialManager() { return m_pMaterialManager; }
|
||||
CMusicManager* GetMusicManager() { return m_pMusicManager; };
|
||||
@@ -409,7 +406,6 @@ protected:
|
||||
QString m_primaryCDFolder;
|
||||
QString m_userFolder;
|
||||
bool m_bSelectionLocked;
|
||||
_smart_ptr<CEditTool> m_pPickTool;
|
||||
class CAxisGizmo* m_pAxisGizmo;
|
||||
CGameEngine* m_pGameEngine;
|
||||
CAnimationContext* m_pAnimationContext;
|
||||
|
||||
@@ -418,8 +418,11 @@ void CLayoutWnd::CreateLayout(EViewLayout layout, bool bBindViewports, EViewport
|
||||
QRect rcView = rect();
|
||||
rcView.setBottom(rcView.bottom() - m_infoBar->height());
|
||||
|
||||
// Ensure we delete our old view immediately so it can relinquish its backing ViewportContext
|
||||
if (m_maximizedView)
|
||||
m_maximizedView->deleteLater();
|
||||
{
|
||||
delete m_maximizedView;
|
||||
}
|
||||
|
||||
m_maximizedView = new CLayoutViewPane(this);
|
||||
m_maximizedView->SetId(0);
|
||||
|
||||
@@ -408,6 +408,13 @@ bool LegacyViewportCameraControllerInstance::HandleInputChannelEvent(const AzFra
|
||||
}
|
||||
}
|
||||
|
||||
UpdateCursorCapture(shouldCaptureCursor);
|
||||
|
||||
return shouldConsumeEvent;
|
||||
}
|
||||
|
||||
void LegacyViewportCameraControllerInstance::UpdateCursorCapture(bool shouldCaptureCursor)
|
||||
{
|
||||
if (m_capturingCursor != shouldCaptureCursor)
|
||||
{
|
||||
if (shouldCaptureCursor)
|
||||
@@ -427,8 +434,14 @@ bool LegacyViewportCameraControllerInstance::HandleInputChannelEvent(const AzFra
|
||||
|
||||
m_capturingCursor = shouldCaptureCursor;
|
||||
}
|
||||
}
|
||||
|
||||
return shouldConsumeEvent;
|
||||
void LegacyViewportCameraControllerInstance::ResetInputChannels()
|
||||
{
|
||||
m_modifiers = 0;
|
||||
m_pressedKeys.clear();
|
||||
UpdateCursorCapture(false);
|
||||
m_inRotateMode = m_inMoveMode = m_inOrbitMode = m_inZoomMode = false;
|
||||
}
|
||||
|
||||
void LegacyViewportCameraControllerInstance::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event)
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace SandboxEditor
|
||||
explicit LegacyViewportCameraControllerInstance(AzFramework::ViewportId viewport);
|
||||
|
||||
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
|
||||
void ResetInputChannels() override;
|
||||
void UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) override;
|
||||
|
||||
private:
|
||||
@@ -53,6 +54,7 @@ namespace SandboxEditor
|
||||
bool HandleMouseMove(const AzFramework::ScreenPoint& currentMousePos, const AzFramework::ScreenPoint& previousMousePos);
|
||||
bool HandleMouseWheel(float zDelta);
|
||||
bool IsKeyDown(Qt::Key key) const;
|
||||
void UpdateCursorCapture(bool shouldCaptureCursor);
|
||||
|
||||
bool m_inRotateMode = false;
|
||||
bool m_inMoveMode = false;
|
||||
|
||||
@@ -90,9 +90,6 @@ public:
|
||||
MOCK_METHOD0(IsSelectionLocked, bool());
|
||||
MOCK_METHOD0(GetObjectManager, struct IObjectManager* ());
|
||||
MOCK_METHOD0(GetSettingsManager, CSettingsManager* ());
|
||||
MOCK_METHOD4(PickObject, void(IPickObjectCallback*,const QMetaObject*,const char* ,bool bMultipick));
|
||||
MOCK_METHOD0(CancelPick, void());
|
||||
MOCK_METHOD0(IsPicking, bool());
|
||||
MOCK_METHOD1(GetDBItemManager, IDataBaseManager* (EDataBaseItemType));
|
||||
MOCK_METHOD0(GetMaterialManager, CMaterialManager* ());
|
||||
MOCK_METHOD0(GetMaterialManagerLibrary, IBaseLibraryManager* ());
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "LinkTool.h"
|
||||
|
||||
// Editor
|
||||
#include "Viewport.h"
|
||||
#include "Objects/EntityObject.h"
|
||||
#include "Objects/SelectionGroup.h"
|
||||
#include <Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h>
|
||||
|
||||
// AzCore
|
||||
#include <AzCore/Component/Entity.h>
|
||||
|
||||
#ifdef LoadCursor
|
||||
#undef LoadCursor
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
const float kGeomCacheNodePivotSizeScale = 0.0025f;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CLinkTool::CLinkTool()
|
||||
: m_nodeName(nullptr)
|
||||
, m_pGeomCacheRenderNode(nullptr)
|
||||
{
|
||||
m_pChild = NULL;
|
||||
SetStatusText("Click on object and drag a link to a new parent");
|
||||
|
||||
m_hLinkCursor = CMFCUtils::LoadCursor(IDC_POINTER_LINK);
|
||||
m_hLinkNowCursor = CMFCUtils::LoadCursor(IDC_POINTER_LINKNOW);
|
||||
m_hCurrCursor = &m_hLinkCursor;
|
||||
AZ::EntitySystemBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CLinkTool::~CLinkTool()
|
||||
{
|
||||
AZ::EntitySystemBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CLinkTool::LinkObject(CBaseObject* pChild, CBaseObject* pParent)
|
||||
{
|
||||
if (pChild == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ChildIsValid(pParent, pChild))
|
||||
{
|
||||
CUndo undo("Link Object");
|
||||
|
||||
if (qobject_cast<CEntityObject*>(pChild))
|
||||
{
|
||||
static_cast<CEntityObject*>(pChild)->SetAttachTarget("");
|
||||
static_cast<CEntityObject*>(pChild)->SetAttachType(CEntityObject::eAT_Pivot);
|
||||
}
|
||||
|
||||
pParent->AttachChild(pChild, true);
|
||||
|
||||
QString str;
|
||||
str = tr("%1 attached to %2").arg(pChild->GetName(), pParent->GetName());
|
||||
SetStatusText(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetStatusText("Error: Cyclic linking or already linked.");
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CLinkTool::LinkSelectedToParent(CBaseObject* pParent)
|
||||
{
|
||||
if (pParent)
|
||||
{
|
||||
if (IsRelevant(pParent))
|
||||
{
|
||||
CSelectionGroup* pSel = GetIEditor()->GetSelection();
|
||||
if (!pSel->GetCount())
|
||||
{
|
||||
return;
|
||||
}
|
||||
CUndo undo("Link Object(s)");
|
||||
for (int i = 0; i < pSel->GetCount(); i++)
|
||||
{
|
||||
CBaseObject* pChild = pSel->GetObject(i);
|
||||
if (pChild == pParent)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
LinkObject(pChild, pParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CLinkTool::MouseCallback(CViewport* view, EMouseEvent event, QPoint& point, [[maybe_unused]] int flags)
|
||||
{
|
||||
view->SetCursorString("");
|
||||
|
||||
m_hCurrCursor = &m_hLinkCursor;
|
||||
if (event == eMouseLDown)
|
||||
{
|
||||
HitContext hitInfo;
|
||||
view->HitTest(point, hitInfo);
|
||||
CBaseObject* obj = hitInfo.object;
|
||||
if (obj)
|
||||
{
|
||||
if (IsRelevant(obj))
|
||||
{
|
||||
m_StartDrag = obj->GetWorldPos();
|
||||
m_pChild = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event == eMouseLUp)
|
||||
{
|
||||
HitContext hitInfo;
|
||||
view->HitTest(point, hitInfo);
|
||||
CBaseObject* obj = hitInfo.object;
|
||||
if (obj)
|
||||
{
|
||||
if (IsRelevant(obj))
|
||||
{
|
||||
CSelectionGroup* pSelectionGroup = GetIEditor()->GetSelection();
|
||||
int nGroupCount = pSelectionGroup->GetCount();
|
||||
if (pSelectionGroup && nGroupCount > 1)
|
||||
{
|
||||
LinkSelectedToParent(obj);
|
||||
}
|
||||
if (!pSelectionGroup || nGroupCount <= 1 || !pSelectionGroup->IsContainObject(m_pChild))
|
||||
{
|
||||
LinkObject(m_pChild, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_pChild = NULL;
|
||||
}
|
||||
else if (event == eMouseMove)
|
||||
{
|
||||
m_EndDrag = view->ViewToWorld(point);
|
||||
m_nodeName = nullptr;
|
||||
m_pGeomCacheRenderNode = nullptr;
|
||||
|
||||
HitContext hitInfo;
|
||||
if (view->HitTest(point, hitInfo))
|
||||
{
|
||||
m_EndDrag = hitInfo.raySrc + hitInfo.rayDir * hitInfo.dist;
|
||||
}
|
||||
|
||||
CBaseObject* obj = hitInfo.object;
|
||||
if (obj)
|
||||
{
|
||||
if (IsRelevant(obj))
|
||||
{
|
||||
QString name = obj->GetName();
|
||||
if (hitInfo.name)
|
||||
{
|
||||
name += QString("\n ") + hitInfo.name;
|
||||
}
|
||||
|
||||
// Set Cursors.
|
||||
view->SetCursorString(name);
|
||||
if (m_pChild)
|
||||
{
|
||||
if (ChildIsValid(obj, m_pChild))
|
||||
{
|
||||
m_hCurrCursor = &m_hLinkNowCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CLinkTool::OnKeyDown([[maybe_unused]] CViewport* view, uint32 nChar, [[maybe_unused]] uint32 nRepCnt, [[maybe_unused]] uint32 nFlags)
|
||||
{
|
||||
if (nChar == VK_ESCAPE)
|
||||
{
|
||||
// Cancel selection.
|
||||
GetIEditor()->SetEditTool(nullptr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CLinkTool::Display(DisplayContext& dc)
|
||||
{
|
||||
if (m_pChild && m_EndDrag != Vec3(ZERO))
|
||||
{
|
||||
ColorF lineColor = (m_hCurrCursor == &m_hLinkNowCursor) ? ColorF(0, 1, 0) : ColorF(1, 0, 0);
|
||||
dc.DrawLine(m_StartDrag, m_EndDrag, lineColor, lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CLinkTool::OnEntityDestruction(const AZ::EntityId& entityId)
|
||||
{
|
||||
if (m_pChild && (m_pChild->GetType() == OBJTYPE_AZENTITY))
|
||||
{
|
||||
CComponentEntityObject* childComponentEntity = static_cast<CComponentEntityObject*>(m_pChild);
|
||||
AZ::EntityId childEntityId = childComponentEntity->GetAssociatedEntityId();
|
||||
if(entityId == childEntityId)
|
||||
{
|
||||
GetIEditor()->SetEditTool(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CLinkTool::ChildIsValid(CBaseObject* pParent, CBaseObject* pChild, int nDir)
|
||||
{
|
||||
if (!pParent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!pChild)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (pParent == pChild)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Legacy entities and AZ entities shouldn't be linked.
|
||||
if ((pParent->GetType() == OBJTYPE_AZENTITY) != (pChild->GetType() == OBJTYPE_AZENTITY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CBaseObject* pObj;
|
||||
if (nDir & 1)
|
||||
{
|
||||
pObj = pChild->GetParent();
|
||||
if (pObj)
|
||||
{
|
||||
if (!ChildIsValid(pParent, pObj, 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nDir & 2)
|
||||
{
|
||||
for (int i = 0; i < pChild->GetChildCount(); i++)
|
||||
{
|
||||
pObj = pChild->GetChild(i);
|
||||
if (pObj)
|
||||
{
|
||||
if (!ChildIsValid(pParent, pObj, 2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CLinkTool::OnSetCursor(CViewport* vp)
|
||||
{
|
||||
vp->SetCursor(*m_hCurrCursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
#include <moc_LinkTool.cpp>
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Definition of CLinkTool, tool used to link objects.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_LINKTOOL_H
|
||||
#define CRYINCLUDE_EDITOR_LINKTOOL_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <AzCore/Component/EntityBus.h>
|
||||
#include "EditTool.h"
|
||||
#include "Include/IObjectManager.h"
|
||||
#endif
|
||||
|
||||
class CEntityObject;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CLinkTool
|
||||
: public CEditTool
|
||||
, public IObjectSelectCallback
|
||||
, private AZ::EntitySystemBus::Handler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE CLinkTool(); // IPickObjectCallback *callback,CRuntimeClass *targetClass=NULL );
|
||||
|
||||
// Ovverides from CEditTool
|
||||
bool MouseCallback(CViewport* view, EMouseEvent event, QPoint& point, int flags);
|
||||
|
||||
virtual void BeginEditParams([[maybe_unused]] IEditor* ie, [[maybe_unused]] int flags) {};
|
||||
virtual void EndEditParams() {};
|
||||
|
||||
virtual void Display(DisplayContext& dc);
|
||||
virtual bool OnKeyDown(CViewport* view, uint32 nChar, uint32 nRepCnt, uint32 nFlags);
|
||||
virtual bool OnKeyUp([[maybe_unused]] CViewport* view, [[maybe_unused]] uint32 nChar, [[maybe_unused]] uint32 nRepCnt, [[maybe_unused]] uint32 nFlags) { return false; };
|
||||
|
||||
virtual bool OnSelectObject([[maybe_unused]] CBaseObject* obj) {return false; }
|
||||
virtual bool CanSelectObject([[maybe_unused]] CBaseObject* obj) { return true; };
|
||||
|
||||
virtual bool OnSetCursor(CViewport* vp);
|
||||
|
||||
void LinkSelectedToParent(CBaseObject* pParent);
|
||||
|
||||
protected:
|
||||
virtual ~CLinkTool();
|
||||
// Delete itself.
|
||||
void DeleteThis() { delete this; };
|
||||
|
||||
private:
|
||||
bool IsRelevant([[maybe_unused]] CBaseObject* obj) { return true; }
|
||||
bool ChildIsValid(CBaseObject* pParent, CBaseObject* pChild, int nDir = 3);
|
||||
void LinkObject(CBaseObject* pChild, CBaseObject* pParent);
|
||||
void LinkToNode(CEntityObject* pChild, CEntityObject* pParent, const char* nodeName);
|
||||
|
||||
// AZ::EntitySystemBus::Handler
|
||||
void OnEntityDestruction(const AZ::EntityId& entityId) override;
|
||||
|
||||
|
||||
CBaseObject* m_pChild;
|
||||
Vec3 m_StartDrag;
|
||||
Vec3 m_EndDrag;
|
||||
|
||||
QCursor m_hLinkCursor;
|
||||
QCursor m_hLinkNowCursor;
|
||||
QCursor* m_hCurrCursor;
|
||||
|
||||
const char* m_nodeName;
|
||||
IGeomCacheRenderNode* m_pGeomCacheRenderNode;
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_LINKTOOL_H
|
||||
@@ -1104,15 +1104,6 @@ void MainWindow::InitActions()
|
||||
.RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateSelected)
|
||||
.SetIcon(Style::icon("Align_to_grid"))
|
||||
.SetApplyHoverEffect();
|
||||
am->AddAction(ID_OBJECTMODIFY_ALIGN, tr("Align to object")).SetCheckable(true)
|
||||
#if AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
.SetStatusTip(tr(u8"\u2318: Align an object to a bounding box, \u2325 : Keep Rotation of the moved object, Shift : Keep Scale of the moved object"))
|
||||
#else
|
||||
.SetStatusTip(tr("Ctrl: Align an object to a bounding box, Alt : Keep Rotation of the moved object, Shift : Keep Scale of the moved object"))
|
||||
#endif
|
||||
.RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateAlignObject)
|
||||
.SetIcon(Style::icon("Align_to_Object"))
|
||||
.SetApplyHoverEffect();
|
||||
am->AddAction(ID_MODIFY_ALIGNOBJTOSURF, tr("Align object to surface (Hold CTRL)")).SetCheckable(true)
|
||||
.SetToolTip(tr("Align object to surface (Hold CTRL)"))
|
||||
.RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateAlignToVoxel)
|
||||
@@ -1449,15 +1440,6 @@ void MainWindow::InitActions()
|
||||
.SetApplyHoverEffect();
|
||||
|
||||
// Edit Mode Toolbar Actions
|
||||
am->AddAction(ID_EDITTOOL_LINK, tr("Link an object to parent"))
|
||||
.SetIcon(Style::icon("add_link"))
|
||||
.SetApplyHoverEffect()
|
||||
.SetCheckable(true)
|
||||
.RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateEditToolLink);
|
||||
am->AddAction(ID_EDITTOOL_UNLINK, tr("Unlink all selected objects"))
|
||||
.SetIcon(Style::icon("remove_link"))
|
||||
.SetApplyHoverEffect()
|
||||
.RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateEditToolUnlink);
|
||||
am->AddAction(IDC_SELECTION_MASK, tr("Selected Object Types"));
|
||||
am->AddAction(ID_REF_COORDS_SYS, tr("Reference coordinate system"))
|
||||
.SetShortcut(tr("Ctrl+W"))
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "PickObjectTool.h"
|
||||
|
||||
// Editor
|
||||
#include "Viewport.h"
|
||||
#include "Include/HitContext.h"
|
||||
#include "Objects/BaseObject.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CPickObjectTool::CPickObjectTool(IPickObjectCallback* callback, const QMetaObject* targetClass)
|
||||
{
|
||||
assert(callback != 0);
|
||||
m_callback = callback;
|
||||
m_targetClass = targetClass;
|
||||
m_bMultiPick = false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CPickObjectTool::~CPickObjectTool()
|
||||
{
|
||||
GetIEditor()->GetObjectManager()->SetSelectCallback(0);
|
||||
//m_prevSelectCallback = 0;
|
||||
if (m_callback)
|
||||
{
|
||||
m_callback->OnCancelPick();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CPickObjectTool::BeginEditParams([[maybe_unused]] IEditor* ie, [[maybe_unused]] int flags)
|
||||
{
|
||||
QString str = "Pick object";
|
||||
if (m_targetClass)
|
||||
{
|
||||
str = tr("Pick %1 object").arg(m_targetClass->className());
|
||||
}
|
||||
SetStatusText(str);
|
||||
|
||||
//m_prevSelectCallback =
|
||||
GetIEditor()->GetObjectManager()->SetSelectCallback(this);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CPickObjectTool::MouseCallback(CViewport* view, EMouseEvent event, QPoint& point, [[maybe_unused]] int flags)
|
||||
{
|
||||
if (event == eMouseLDown)
|
||||
{
|
||||
HitContext hitInfo;
|
||||
view->HitTest(point, hitInfo);
|
||||
CBaseObject* obj = hitInfo.object;
|
||||
if (obj)
|
||||
{
|
||||
if (IsRelevant(obj))
|
||||
{
|
||||
if (m_callback)
|
||||
{
|
||||
// Can pick this one.
|
||||
m_callback->OnPick(obj);
|
||||
}
|
||||
if (!m_bMultiPick)
|
||||
{
|
||||
m_callback = 0;
|
||||
GetIEditor()->SetEditTool(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event == eMouseMove)
|
||||
{
|
||||
HitContext hitInfo;
|
||||
view->HitTest(point, hitInfo);
|
||||
CBaseObject* obj = hitInfo.object;
|
||||
if (obj)
|
||||
{
|
||||
if (IsRelevant(obj))
|
||||
{
|
||||
// Set Cursors.
|
||||
view->SetCurrentCursor(STD_CURSOR_HIT, obj->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CPickObjectTool::OnSelectObject(CBaseObject* obj)
|
||||
{
|
||||
if (IsRelevant(obj))
|
||||
{
|
||||
// Can pick this one.
|
||||
if (m_callback)
|
||||
{
|
||||
m_callback->OnPick(obj);
|
||||
m_callback = 0;
|
||||
}
|
||||
if (!m_bMultiPick)
|
||||
{
|
||||
GetIEditor()->SetEditTool(0);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CPickObjectTool::CanSelectObject(CBaseObject* obj)
|
||||
{
|
||||
return IsRelevant(obj);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CPickObjectTool::OnKeyDown([[maybe_unused]] CViewport* view, uint32 nChar, [[maybe_unused]] uint32 nRepCnt, [[maybe_unused]] uint32 nFlags)
|
||||
{
|
||||
if (nChar == VK_ESCAPE)
|
||||
{
|
||||
// Cancel selection.
|
||||
GetIEditor()->SetEditTool(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CPickObjectTool::IsRelevant(CBaseObject* obj)
|
||||
{
|
||||
assert(obj != 0);
|
||||
if (obj == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!m_callback)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_targetClass)
|
||||
{
|
||||
return m_callback->OnPickFilter(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (obj->metaObject() == m_targetClass || m_targetClass->cast(obj))
|
||||
{
|
||||
return m_callback->OnPickFilter(obj);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CPickObjectTool::IsNeedSpecificBehaviorForSpaceAcce()
|
||||
{
|
||||
if (m_callback && m_callback->IsNeedSpecificBehaviorForSpaceAcce())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#include <moc_PickObjectTool.cpp>
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Definition of PickObjectTool, tool used to pick objects.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_PICKOBJECTTOOL_H
|
||||
#define CRYINCLUDE_EDITOR_PICKOBJECTTOOL_H
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include "EditTool.h"
|
||||
#include "IObjectManager.h"
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CPickObjectTool
|
||||
: public CEditTool
|
||||
, public IObjectSelectCallback
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CPickObjectTool(IPickObjectCallback* callback, const QMetaObject* targetClass = NULL);
|
||||
|
||||
//! If set to true, pick tool will not stop picking after first pick.
|
||||
void SetMultiplePicks(bool bEnable) { m_bMultiPick = bEnable; };
|
||||
|
||||
// Ovverides from CEditTool
|
||||
bool MouseCallback(CViewport* view, EMouseEvent event, QPoint& point, int flags);
|
||||
|
||||
virtual void BeginEditParams(IEditor* ie, int flags);
|
||||
virtual void EndEditParams() {};
|
||||
|
||||
virtual void Display([[maybe_unused]] DisplayContext& dc) {};
|
||||
virtual bool OnKeyDown(CViewport* view, uint32 nChar, uint32 nRepCnt, uint32 nFlags);
|
||||
virtual bool OnKeyUp([[maybe_unused]] CViewport* view, [[maybe_unused]] uint32 nChar, [[maybe_unused]] uint32 nRepCnt, [[maybe_unused]] uint32 nFlags) { return false; };
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// IObjectSelectCallback
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual bool OnSelectObject(CBaseObject* obj);
|
||||
virtual bool CanSelectObject(CBaseObject* obj);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool IsNeedSpecificBehaviorForSpaceAcce();
|
||||
|
||||
protected:
|
||||
virtual ~CPickObjectTool();
|
||||
// Delete itself.
|
||||
void DeleteThis() { delete this; };
|
||||
|
||||
private:
|
||||
bool IsRelevant(CBaseObject* obj);
|
||||
|
||||
//! Object that requested pick.
|
||||
IPickObjectCallback* m_callback;
|
||||
|
||||
//! If target class specified, will pick only objects that belongs to that runtime class.
|
||||
const QMetaObject* m_targetClass;
|
||||
|
||||
bool m_bMultiPick;
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_PICKOBJECTTOOL_H
|
||||
@@ -36,6 +36,8 @@
|
||||
#include <algorithm>
|
||||
#include <QScopedValueRollback>
|
||||
|
||||
#include <AzFramework/API/ApplicationAPI.h>
|
||||
|
||||
#include <AzAssetBrowser/AzAssetBrowserWindow.h>
|
||||
#include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
|
||||
#include <AzQtComponents/Utilities/AutoSettingsGroup.h>
|
||||
@@ -983,6 +985,11 @@ bool QtViewPaneManager::ClosePanesWithRollback(const QVector<QString>& panesToKe
|
||||
*/
|
||||
void QtViewPaneManager::RestoreDefaultLayout(bool resetSettings)
|
||||
{
|
||||
// Get whether the prefab system is enabled
|
||||
bool isPrefabSystemEnabled = false;
|
||||
AzFramework::ApplicationRequests::Bus::BroadcastResult(
|
||||
isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled);
|
||||
|
||||
if (resetSettings)
|
||||
{
|
||||
// We're going to do something destructive (removing all of the viewpane settings). Better confirm with the user
|
||||
@@ -1022,7 +1029,11 @@ void QtViewPaneManager::RestoreDefaultLayout(bool resetSettings)
|
||||
state.viewPanes.push_back(LyViewPane::EntityInspector);
|
||||
state.viewPanes.push_back(LyViewPane::AssetBrowser);
|
||||
state.viewPanes.push_back(LyViewPane::Console);
|
||||
state.viewPanes.push_back(LyViewPane::LevelInspector);
|
||||
|
||||
if (!isPrefabSystemEnabled)
|
||||
{
|
||||
state.viewPanes.push_back(LyViewPane::LevelInspector);
|
||||
}
|
||||
|
||||
state.mainWindowState = m_defaultMainWindowState;
|
||||
|
||||
@@ -1047,7 +1058,12 @@ void QtViewPaneManager::RestoreDefaultLayout(bool resetSettings)
|
||||
const QtViewPane* assetBrowserViewPane = OpenPane(LyViewPane::AssetBrowser, QtViewPane::OpenMode::UseDefaultState);
|
||||
const QtViewPane* entityInspectorViewPane = OpenPane(LyViewPane::EntityInspector, QtViewPane::OpenMode::UseDefaultState);
|
||||
const QtViewPane* consoleViewPane = OpenPane(LyViewPane::Console, QtViewPane::OpenMode::UseDefaultState);
|
||||
const QtViewPane* levelInspectorPane = OpenPane(LyViewPane::LevelInspector, QtViewPane::OpenMode::UseDefaultState);
|
||||
|
||||
const QtViewPane* levelInspectorPane = nullptr;
|
||||
if (!isPrefabSystemEnabled)
|
||||
{
|
||||
levelInspectorPane = OpenPane(LyViewPane::LevelInspector, QtViewPane::OpenMode::UseDefaultState);
|
||||
}
|
||||
|
||||
// This class does all kinds of behind the scenes magic to make docking / restore work, especially with groups
|
||||
// so instead of doing our special default layout attach / docking right now, we want to make it happen
|
||||
|
||||
@@ -181,8 +181,6 @@
|
||||
#define ID_TV_STOP 33568
|
||||
#define ID_TV_PAUSE 33569
|
||||
#define ID_ADDNODE 33570
|
||||
#define ID_EDITTOOL_LINK 33571
|
||||
#define ID_EDITTOOL_UNLINK 33572
|
||||
#define ID_ADDSCENETRACK 33573
|
||||
#define ID_FIND 33574
|
||||
#define ID_SNAP_TO_GRID 33575
|
||||
@@ -214,7 +212,6 @@
|
||||
#define ID_TV_JUMPSTART 33601
|
||||
#define ID_TV_PREVKEY 33602
|
||||
#define ID_TV_NEXTKEY 33603
|
||||
#define ID_OBJECTMODIFY_ALIGN 33604
|
||||
#define ID_PLAY_LOOP 33607
|
||||
#define ID_TERRAIN 33611
|
||||
#define ID_OBJECTMODIFY_ALIGNTOGRID 33619
|
||||
|
||||
@@ -585,13 +585,6 @@ AmazonToolbar ToolbarManager::GetEditModeToolbar() const
|
||||
t.AddAction(ID_TOOLBAR_WIDGET_UNDO, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_TOOLBAR_WIDGET_REDO, ORIGINAL_TOOLBAR_VERSION);
|
||||
|
||||
if (!GetIEditor()->IsNewViewportInteractionModelEnabled())
|
||||
{
|
||||
t.AddAction(ID_TOOLBAR_SEPARATOR, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_EDITTOOL_LINK, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_EDITTOOL_UNLINK, ORIGINAL_TOOLBAR_VERSION);
|
||||
}
|
||||
|
||||
t.AddAction(ID_TOOLBAR_SEPARATOR, ORIGINAL_TOOLBAR_VERSION);
|
||||
|
||||
if (!GetIEditor()->IsNewViewportInteractionModelEnabled())
|
||||
@@ -630,7 +623,6 @@ AmazonToolbar ToolbarManager::GetObjectToolbar() const
|
||||
AmazonToolbar t = AmazonToolbar("Object", QObject::tr("Object Toolbar"));
|
||||
t.SetMainToolbar(true);
|
||||
t.AddAction(ID_GOTO_SELECTED, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_OBJECTMODIFY_ALIGN, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_OBJECTMODIFY_ALIGNTOGRID, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_OBJECTMODIFY_SETHEIGHT, ORIGINAL_TOOLBAR_VERSION);
|
||||
t.AddAction(ID_MODIFY_ALIGNOBJTOSURF, ORIGINAL_TOOLBAR_VERSION);
|
||||
|
||||
@@ -95,6 +95,11 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
|
||||
AZStd::optional<MouseButton> overrideButton;
|
||||
AZStd::optional<MouseEvent> eventType;
|
||||
|
||||
// Because we receive events multiple times at separate priorities for manipulator events and
|
||||
// viewport interaction events, we want to avoid updating our "last tick state" until we're on our last event,
|
||||
// which currently is the low priority Interaction processor.
|
||||
const bool finishedProcessingEvents = event.m_priority == InteractionPriority;
|
||||
|
||||
if (IsMouseMove(event.m_inputChannel))
|
||||
{
|
||||
// Cache the ray trace results when doing manipulator interaction checks, no need to recalculate after
|
||||
@@ -120,10 +125,11 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
|
||||
}
|
||||
else if (auto mouseButton = GetMouseButton(event.m_inputChannel); mouseButton != MouseButton::None)
|
||||
{
|
||||
const AZ::u32 mouseButtonValue = static_cast<AZ::u32>(mouseButton);
|
||||
overrideButton = mouseButton;
|
||||
if (event.m_inputChannel.GetState() == InputChannel::State::Began)
|
||||
{
|
||||
m_state.m_mouseButtons.m_mouseButtons |= static_cast<AZ::u32>(mouseButton);
|
||||
m_state.m_mouseButtons.m_mouseButtons |= mouseButtonValue;
|
||||
if (IsDoubleClick(mouseButton))
|
||||
{
|
||||
// Only remove the double click flag once we're done processing both Manipulator and Interaction events
|
||||
@@ -135,8 +141,8 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only insert the double click timing once we're done processing both Manipulator and Interaction events, to avoid a false IsDoubleClick positive
|
||||
if (event.m_priority == InteractionPriority)
|
||||
// Only insert the double click timing once we're done processing events, to avoid a false IsDoubleClick positive
|
||||
if (finishedProcessingEvents)
|
||||
{
|
||||
m_pendingDoubleClicks[mouseButton] = m_curTime;
|
||||
}
|
||||
@@ -145,8 +151,18 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
|
||||
}
|
||||
else if (event.m_inputChannel.GetState() == InputChannel::State::Ended)
|
||||
{
|
||||
m_state.m_mouseButtons.m_mouseButtons &= ~static_cast<AZ::u32>(mouseButton);
|
||||
eventType = MouseEvent::Up;
|
||||
// If we've actually logged a mouse down event, forward a mouse up event.
|
||||
// This prevents corner cases like the context menu thinking it should be opened even though no one clicked in this viewport,
|
||||
// due to RenderViewportWidget ensuring all controllers get InputChannel::State::Ended events.
|
||||
if (m_state.m_mouseButtons.m_mouseButtons & mouseButtonValue)
|
||||
{
|
||||
// Erase the button from our state if we're done processing events.
|
||||
if (event.m_priority == InteractionPriority)
|
||||
{
|
||||
m_state.m_mouseButtons.m_mouseButtons &= ~mouseButtonValue;
|
||||
}
|
||||
eventType = MouseEvent::Up;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (auto keyboardModifier = GetKeyboardModifier(event.m_inputChannel); keyboardModifier != KeyboardModifier::None)
|
||||
@@ -186,6 +202,12 @@ bool ViewportManipulatorControllerInstance::HandleInputChannelEvent(const AzFram
|
||||
return interactionHandled;
|
||||
}
|
||||
|
||||
void ViewportManipulatorControllerInstance::ResetInputChannels()
|
||||
{
|
||||
m_pendingDoubleClicks.clear();
|
||||
m_state = AzToolsFramework::ViewportInteraction::MouseInteraction();
|
||||
}
|
||||
|
||||
void ViewportManipulatorControllerInstance::UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event)
|
||||
{
|
||||
m_curTime = event.m_time;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace SandboxEditor
|
||||
explicit ViewportManipulatorControllerInstance(AzFramework::ViewportId viewport);
|
||||
|
||||
bool HandleInputChannelEvent(const AzFramework::ViewportControllerInputEvent& event) override;
|
||||
void ResetInputChannels() override;
|
||||
void UpdateViewport(const AzFramework::ViewportControllerUpdateEvent& event) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -533,8 +533,6 @@ set(FILES
|
||||
Dialogs/PythonScriptsDialog.ui
|
||||
Dialogs/Generic/UserOptions.cpp
|
||||
Dialogs/Generic/UserOptions.h
|
||||
AlignTool.cpp
|
||||
AlignTool.h
|
||||
ObjectCloneTool.cpp
|
||||
ObjectCloneTool.h
|
||||
EditMode/SubObjectSelectionReferenceFrameCalculator.cpp
|
||||
@@ -545,10 +543,6 @@ set(FILES
|
||||
RotateTool.h
|
||||
EditTool.cpp
|
||||
EditTool.h
|
||||
LinkTool.cpp
|
||||
LinkTool.h
|
||||
PickObjectTool.cpp
|
||||
PickObjectTool.h
|
||||
VoxelAligningTool.cpp
|
||||
VoxelAligningTool.h
|
||||
Export/ExportManager.cpp
|
||||
|
||||
@@ -143,15 +143,6 @@ ComponentEntityEditorPlugin::ComponentEntityEditorPlugin([[maybe_unused]] IEdito
|
||||
LyViewPane::CategoryTools,
|
||||
pinnedInspectorOptions);
|
||||
|
||||
ViewPaneOptions levelInspectorOptions;
|
||||
levelInspectorOptions.canHaveMultipleInstances = false;
|
||||
levelInspectorOptions.preferedDockingArea = Qt::RightDockWidgetArea;
|
||||
levelInspectorOptions.paneRect = QRect(50, 50, 400, 700);
|
||||
RegisterViewPane<QComponentLevelEntityEditorInspectorWindow>(
|
||||
LyViewPane::LevelInspector,
|
||||
LyViewPane::CategoryTools,
|
||||
levelInspectorOptions);
|
||||
|
||||
bool prefabSystemEnabled = false;
|
||||
AzFramework::ApplicationRequests::Bus::BroadcastResult(prefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled);
|
||||
|
||||
@@ -170,8 +161,14 @@ ComponentEntityEditorPlugin::ComponentEntityEditorPlugin([[maybe_unused]] IEdito
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add the Legacy Outliner to the Tools Menu
|
||||
ViewPaneOptions levelInspectorOptions;
|
||||
levelInspectorOptions.canHaveMultipleInstances = false;
|
||||
levelInspectorOptions.preferedDockingArea = Qt::RightDockWidgetArea;
|
||||
levelInspectorOptions.paneRect = QRect(50, 50, 400, 700);
|
||||
RegisterViewPane<QComponentLevelEntityEditorInspectorWindow>(
|
||||
LyViewPane::LevelInspector, LyViewPane::CategoryTools, levelInspectorOptions);
|
||||
|
||||
// Add the Legacy Outliner to the Tools Menu
|
||||
ViewPaneOptions outlinerOptions;
|
||||
outlinerOptions.canHaveMultipleInstances = true;
|
||||
outlinerOptions.preferedDockingArea = Qt::LeftDockWidgetArea;
|
||||
|
||||
Reference in New Issue
Block a user