From 954642c1ce0ea6f8bec96cebcc7947ca41e1b6f8 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Fri, 3 Dec 2021 13:40:07 -0600 Subject: [PATCH 1/4] Updated Entity Inspector to changed behavior when an Entity has been marked as read-only. Signed-off-by: Chris Galvan --- .../PropertyEditor/EntityPropertyEditor.cpp | 39 ++++++++++++++++++- .../PropertyEditor/EntityPropertyEditor.hxx | 4 ++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp index fa419d5f14..69368814f7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp @@ -45,6 +45,7 @@ AZ_POP_DISABLE_WARNING #include #include #include +#include #include #include #include @@ -497,6 +498,9 @@ namespace AzToolsFramework m_prefabPublicInterface = AZ::Interface::Get(); AZ_Assert(m_prefabPublicInterface != nullptr, "EntityPropertyEditor requires a PrefabPublicInterface instance on Initialize."); + m_readOnlyEntityPublicInterface = AZ::Interface::Get(); + AZ_Assert(m_readOnlyEntityPublicInterface != nullptr, "EntityPropertyEditor requires a ReadOnlyEntityPublicInterface instance on Initialize."); + setObjectName("EntityPropertyEditor"); setAcceptDrops(true); @@ -973,7 +977,7 @@ namespace AzToolsFramework m_gui->m_entityDetailsLabel->setVisible(false); // If we're in edit mode, make the name field editable. - m_gui->m_entityNameEditor->setReadOnly(!m_gui->m_componentListContents->isEnabled()); + m_gui->m_entityNameEditor->setReadOnly(!m_gui->m_componentListContents->isEnabled() || m_entityIsReadOnly); // get the name of the entity. auto entity = GetSelectedEntityById(entityId); @@ -1062,6 +1066,12 @@ namespace AzToolsFramework bool EntityPropertyEditor::CanAddComponentsToSelection(const SelectionEntityTypeInfo& selectionEntityTypeInfo) const { + if (m_entityIsReadOnly) + { + // Can't add components if there is a read only entity in the selection + return false; + } + if (selectionEntityTypeInfo == SelectionEntityTypeInfo::Mixed || selectionEntityTypeInfo == SelectionEntityTypeInfo::None) { @@ -1126,6 +1136,17 @@ namespace AzToolsFramework m_selectedEntityIds.clear(); GetSelectedEntities(m_selectedEntityIds); + // Check if any of the selected entities are marked as read only + m_entityIsReadOnly = false; + for (const auto& entityId : m_selectedEntityIds) + { + if (m_readOnlyEntityPublicInterface->IsReadOnly(entityId)) + { + m_entityIsReadOnly = true; + break; + } + } + SourceControlFileInfo scFileInfo; ToolsApplicationRequests::Bus::BroadcastResult(scFileInfo, &ToolsApplicationRequests::GetSceneSourceControlInfo); @@ -1681,6 +1702,12 @@ namespace AzToolsFramework componentEditor->UpdateExpandability(); componentEditor->InvalidateAll(!componentInFilter ? m_filterString.c_str() : nullptr); + // If we are in read only mode, then show the components as disabled + if (m_entityIsReadOnly) + { + componentEditor->mockDisabledState(true); + } + if (!componentEditor->GetPropertyEditor()->HasFilteredOutNodes() || componentEditor->GetPropertyEditor()->HasVisibleNodes()) { for (AZ::Component* componentInstance : componentInstances) @@ -3077,6 +3104,7 @@ namespace AzToolsFramework } } + m_gui->m_statusComboBox->setDisabled(m_entityIsReadOnly); m_gui->m_statusComboBox->setVisible(!m_isSystemEntityEditor && !m_isLevelEntityEditor); m_gui->m_statusComboBox->style()->unpolish(m_gui->m_statusComboBox); m_gui->m_statusComboBox->style()->polish(m_gui->m_statusComboBox); @@ -3304,7 +3332,8 @@ namespace AzToolsFramework const auto& componentsToEdit = GetSelectedComponents(); const bool hasComponents = !m_selectedEntityIds.empty() && !componentsToEdit.empty(); - const bool allowRemove = hasComponents && AreComponentsRemovable(componentsToEdit); + // Don't allow components to be removed/cut/enabled/disabled if read only + const bool allowRemove = hasComponents && AreComponentsRemovable(componentsToEdit) && !m_entityIsReadOnly; const bool allowCopy = hasComponents && AreComponentsCopyable(componentsToEdit); m_actionToDeleteComponents->setEnabled(allowRemove); @@ -3366,6 +3395,12 @@ namespace AzToolsFramework return false; } + if (m_entityIsReadOnly) + { + // Can't paste components if there is a read only entity in the selection + return false; + } + // Grab component data from clipboard, if exists const QMimeData* mimeData = ComponentMimeData::GetComponentMimeDataFromClipboard(); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx index 8dd0ffc4ee..3d62d6fe10 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx @@ -62,6 +62,7 @@ namespace AzToolsFramework class ComponentPaletteWidget; class ComponentModeCollectionInterface; struct SourceControlFileInfo; + class ReadOnlyEntityPublicInterface; namespace AssetBrowser { @@ -623,6 +624,9 @@ namespace AzToolsFramework Prefab::PrefabPublicInterface* m_prefabPublicInterface = nullptr; bool m_prefabsAreEnabled = false; + ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr; + bool m_entityIsReadOnly = false; + // Reordering row widgets within the RPE. static constexpr float MoveFadeSeconds = 0.5f; From 273fb87eebbd5bae61dd67c1670d7b0c8e61f8fa Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Fri, 3 Dec 2021 16:21:31 -0600 Subject: [PATCH 2/4] Renamed variable to be more descriptive. Signed-off-by: Chris Galvan --- .../UI/PropertyEditor/EntityPropertyEditor.cpp | 16 ++++++++-------- .../UI/PropertyEditor/EntityPropertyEditor.hxx | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp index 69368814f7..f69aa84709 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp @@ -977,7 +977,7 @@ namespace AzToolsFramework m_gui->m_entityDetailsLabel->setVisible(false); // If we're in edit mode, make the name field editable. - m_gui->m_entityNameEditor->setReadOnly(!m_gui->m_componentListContents->isEnabled() || m_entityIsReadOnly); + m_gui->m_entityNameEditor->setReadOnly(!m_gui->m_componentListContents->isEnabled() || m_selectionContainsReadOnlyEntity); // get the name of the entity. auto entity = GetSelectedEntityById(entityId); @@ -1066,7 +1066,7 @@ namespace AzToolsFramework bool EntityPropertyEditor::CanAddComponentsToSelection(const SelectionEntityTypeInfo& selectionEntityTypeInfo) const { - if (m_entityIsReadOnly) + if (m_selectionContainsReadOnlyEntity) { // Can't add components if there is a read only entity in the selection return false; @@ -1137,12 +1137,12 @@ namespace AzToolsFramework GetSelectedEntities(m_selectedEntityIds); // Check if any of the selected entities are marked as read only - m_entityIsReadOnly = false; + m_selectionContainsReadOnlyEntity = false; for (const auto& entityId : m_selectedEntityIds) { if (m_readOnlyEntityPublicInterface->IsReadOnly(entityId)) { - m_entityIsReadOnly = true; + m_selectionContainsReadOnlyEntity = true; break; } } @@ -1703,7 +1703,7 @@ namespace AzToolsFramework componentEditor->InvalidateAll(!componentInFilter ? m_filterString.c_str() : nullptr); // If we are in read only mode, then show the components as disabled - if (m_entityIsReadOnly) + if (m_selectionContainsReadOnlyEntity) { componentEditor->mockDisabledState(true); } @@ -3104,7 +3104,7 @@ namespace AzToolsFramework } } - m_gui->m_statusComboBox->setDisabled(m_entityIsReadOnly); + m_gui->m_statusComboBox->setDisabled(m_selectionContainsReadOnlyEntity); m_gui->m_statusComboBox->setVisible(!m_isSystemEntityEditor && !m_isLevelEntityEditor); m_gui->m_statusComboBox->style()->unpolish(m_gui->m_statusComboBox); m_gui->m_statusComboBox->style()->polish(m_gui->m_statusComboBox); @@ -3333,7 +3333,7 @@ namespace AzToolsFramework const bool hasComponents = !m_selectedEntityIds.empty() && !componentsToEdit.empty(); // Don't allow components to be removed/cut/enabled/disabled if read only - const bool allowRemove = hasComponents && AreComponentsRemovable(componentsToEdit) && !m_entityIsReadOnly; + const bool allowRemove = hasComponents && AreComponentsRemovable(componentsToEdit) && !m_selectionContainsReadOnlyEntity; const bool allowCopy = hasComponents && AreComponentsCopyable(componentsToEdit); m_actionToDeleteComponents->setEnabled(allowRemove); @@ -3395,7 +3395,7 @@ namespace AzToolsFramework return false; } - if (m_entityIsReadOnly) + if (m_selectionContainsReadOnlyEntity) { // Can't paste components if there is a read only entity in the selection return false; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx index 3d62d6fe10..bf8cac8968 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx @@ -625,7 +625,7 @@ namespace AzToolsFramework bool m_prefabsAreEnabled = false; ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr; - bool m_entityIsReadOnly = false; + bool m_selectionContainsReadOnlyEntity = false; // Reordering row widgets within the RPE. static constexpr float MoveFadeSeconds = 0.5f; From b470f917caae150589aa22b9eecc48e21c3bfcd9 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Fri, 3 Dec 2021 16:37:35 -0600 Subject: [PATCH 3/4] Listen to read-only entity state changes so we can refresh if the read-only state changes on one of our selected entities. Signed-off-by: Chris Galvan --- .../UI/PropertyEditor/EntityPropertyEditor.cpp | 15 +++++++++++++++ .../UI/PropertyEditor/EntityPropertyEditor.hxx | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp index f69aa84709..0b9420a629 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp @@ -569,6 +569,12 @@ namespace AzToolsFramework AZ::EntitySystemBus::Handler::BusConnect(); EntityPropertyEditorRequestBus::Handler::BusConnect(); EditorWindowUIRequestBus::Handler::BusConnect(); + + AzFramework::EntityContextId editorEntityContextId = AzFramework::EntityContextId::CreateNull(); + EditorEntityContextRequestBus::BroadcastResult( + editorEntityContextId, &EditorEntityContextRequests::GetEditorEntityContextId); + ReadOnlyEntityPublicNotificationBus::Handler::BusConnect(editorEntityContextId); + m_spacer = nullptr; m_emptyIcon = QIcon(); @@ -618,6 +624,7 @@ namespace AzToolsFramework { qApp->removeEventFilter(this); + ReadOnlyEntityPublicNotificationBus::Handler::BusDisconnect(); EditorWindowUIRequestBus::Handler::BusDisconnect(); EntityPropertyEditorRequestBus::Handler::BusDisconnect(); ToolsApplicationEvents::Bus::Handler::BusDisconnect(); @@ -5762,6 +5769,14 @@ namespace AzToolsFramework SaveComponentEditorState(); } + void EntityPropertyEditor::OnReadOnlyEntityStatusChanged(const AZ::EntityId& entityId, [[maybe_unused]] bool readOnly) + { + if (IsEntitySelected(entityId)) + { + UpdateContents(); + } + } + void EntityPropertyEditor::OnEditorModeActivated( [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx index bf8cac8968..254b70996b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,7 @@ namespace AzToolsFramework , public AZ::EntitySystemBus::Handler , public AZ::TickBus::Handler , private EditorWindowUIRequestBus::Handler + , private ReadOnlyEntityPublicNotificationBus::Handler { Q_OBJECT; public: @@ -254,6 +256,9 @@ namespace AzToolsFramework // EditorWindowRequestBus overrides void SetEditorUiEnabled(bool enable) override; + // ReadOnlyEntityPublicNotificationBus overrides ... + void OnReadOnlyEntityStatusChanged(const AZ::EntityId& entityId, bool readOnly) override; + bool IsEntitySelected(const AZ::EntityId& id) const; bool IsSingleEntitySelected(const AZ::EntityId& id) const; From a7989df0516daea2e6a1be8140a7869766af0b6e Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Mon, 6 Dec 2021 10:39:49 -0600 Subject: [PATCH 4/4] Fixed status combo box style in Entity Inspector. Signed-off-by: Chris Galvan --- .../UI/PropertyEditor/EntityPropertyEditor.cpp | 4 ---- .../UI/PropertyEditor/EntityPropertyEditor.ui | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp index 0b9420a629..8104aee4fd 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp @@ -539,10 +539,6 @@ namespace AzToolsFramework model->setItem(row, 0, m_comboItems[row]); } m_gui->m_statusComboBox->setModel(model); - m_gui->m_statusComboBox->setStyleSheet("QComboBox {border: 0px; border-radius:3px; background-color:#555555; color:white}" - "QComboBox:on {background-color:#e9e9e9; color:black; border:0px}" - "QComboBox::down-arrow:on {image: url(:/stylesheet/img/dropdowns/black_down_arrow.png)}" - "QComboBox::drop-down {border-radius: 3p}"); AzQtComponents::ComboBox::addCustomCheckStateStyle(m_gui->m_statusComboBox); EnableEditor(true); m_sceneIsNew = true; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.ui b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.ui index 8a86d429f1..b7cb5a0156 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.ui +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.ui @@ -191,7 +191,7 @@ - background-color:rgb(51, 51, 51) + QWidget#m_darkBox { background-color:rgb(51, 51, 51) } @@ -444,6 +444,9 @@ Qt::Horizontal + + background-color:rgb(51, 51, 51) +