1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
223 lines
8.6 KiB
C++
223 lines
8.6 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#include "EditorCommon.h"
|
|
|
|
#include "PropertyHandlerEntityIdComboBox.h"
|
|
#include <AzToolsFramework/UI/PropertyEditor/PropertyQTConstants.h>
|
|
#include <AzToolsFramework/UI/PropertyEditor/DHQComboBox.hxx>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
void PropertyHandlerEntityIdComboBox::WriteGUIValuesIntoProperty(size_t index, PropertyEntityIdComboBoxCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node)
|
|
{
|
|
Q_UNUSED(index);
|
|
Q_UNUSED(node);
|
|
instance = GUI->value();
|
|
}
|
|
|
|
bool PropertyHandlerEntityIdComboBox::ReadValuesIntoGUI(size_t index, PropertyEntityIdComboBoxCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node)
|
|
{
|
|
Q_UNUSED(index);
|
|
Q_UNUSED(node);
|
|
GUI->setValue(instance);
|
|
return false;
|
|
}
|
|
|
|
QWidget* PropertyHandlerEntityIdComboBox::CreateGUI(QWidget* pParent)
|
|
{
|
|
PropertyEntityIdComboBoxCtrl* newCtrl = aznew PropertyEntityIdComboBoxCtrl(pParent);
|
|
QObject::connect(newCtrl, &PropertyEntityIdComboBoxCtrl::valueChanged, this, [newCtrl]()
|
|
{
|
|
EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl);
|
|
});
|
|
return newCtrl;
|
|
}
|
|
|
|
void PropertyHandlerEntityIdComboBox::ConsumeAttribute(PropertyEntityIdComboBoxCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
|
|
{
|
|
(void)debugName;
|
|
|
|
if (attrib == AZ_CRC("EnumValue", 0xe4f32eed))
|
|
{
|
|
AZStd::pair<AZ::EntityId, AZStd::string> guiEnumValue;
|
|
AZStd::pair<AZ::EntityId, AZStd::string> enumValue;
|
|
AZ::Edit::EnumConstant<AZ::EntityId> enumConstant;
|
|
if (attrValue->Read<AZ::Edit::EnumConstant<AZ::EntityId>>(enumConstant))
|
|
{
|
|
guiEnumValue.first = enumConstant.m_value;
|
|
guiEnumValue.second = enumConstant.m_description;
|
|
GUI->addEnumValue(guiEnumValue);
|
|
}
|
|
else
|
|
{
|
|
// Legacy path. Support temporarily for compatibility.
|
|
if (attrValue->Read< AZStd::pair<AZ::EntityId, AZStd::string> >(enumValue))
|
|
{
|
|
guiEnumValue = static_cast<AZStd::pair<AZ::EntityId, AZStd::string>>(enumValue);
|
|
GUI->addEnumValue(guiEnumValue);
|
|
}
|
|
else
|
|
{
|
|
AZStd::pair<AZ::EntityId, const char*> enumValueConst;
|
|
if (attrValue->Read< AZStd::pair<AZ::EntityId, const char*> >(enumValueConst))
|
|
{
|
|
AZStd::string consted = enumValueConst.second;
|
|
guiEnumValue = AZStd::make_pair(enumValueConst.first, consted);
|
|
GUI->addEnumValue(guiEnumValue);
|
|
}
|
|
else
|
|
{
|
|
AZ_WarningOnce("AzToolsFramework", false, "Failed to read 'EnumValue' attribute from property '%s' into enum combo box. Expected pair<IntegerType, char*> or pair<IntegerType, AZStd::string>, where IntegerType is int or u32 ", debugName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (attrib == AZ::Edit::Attributes::EnumValues)
|
|
{
|
|
AZStd::vector<AZStd::pair<AZ::EntityId, AZStd::string>> guiEnumValues;
|
|
AZStd::vector<AZStd::pair<AZ::EntityId, AZStd::string> > enumValues;
|
|
AZStd::vector<AZ::Edit::EnumConstant<AZ::EntityId>> enumConstantValues;
|
|
if (attrValue->Read<AZStd::vector<AZ::Edit::EnumConstant<AZ::EntityId>>>(enumConstantValues))
|
|
{
|
|
for (const AZ::Edit::EnumConstant<AZ::EntityId>& constantValue : enumConstantValues)
|
|
{
|
|
guiEnumValues.push_back();
|
|
auto& enumValue = guiEnumValues.back();
|
|
enumValue.first = constantValue.m_value;
|
|
enumValue.second = constantValue.m_description;
|
|
}
|
|
|
|
GUI->addEnumValues(guiEnumValues);
|
|
}
|
|
else
|
|
{
|
|
// Legacy path. Support temporarily for compatibility.
|
|
if (attrValue->Read< AZStd::vector<AZStd::pair<AZ::EntityId, AZStd::string> > >(enumValues))
|
|
{
|
|
for (auto it = enumValues.begin(); it != enumValues.end(); ++it)
|
|
guiEnumValues.push_back(static_cast<AZStd::pair<AZ::EntityId, AZStd::string>>(*it));
|
|
GUI->addEnumValues(guiEnumValues);
|
|
}
|
|
else
|
|
{
|
|
AZStd::vector<AZStd::pair<AZ::EntityId, const char*> > attempt2;
|
|
if (attrValue->Read<AZStd::vector<AZStd::pair<AZ::EntityId, const char*> > >(attempt2))
|
|
{
|
|
for (auto it = attempt2.begin(); it != attempt2.end(); ++it)
|
|
guiEnumValues.push_back(AZStd::make_pair<AZ::EntityId, AZStd::string>(it->first, it->second));
|
|
GUI->addEnumValues(guiEnumValues);
|
|
}
|
|
else
|
|
{
|
|
// emit a warning!
|
|
AZ_WarningOnce("AzToolsFramework", false, "Failed to read 'EnumValue' attribute from property '%s' into enum combo box", debugName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void PropertyHandlerEntityIdComboBox::Register()
|
|
{
|
|
EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew PropertyHandlerEntityIdComboBox());
|
|
}
|
|
|
|
PropertyEntityIdComboBoxCtrl::PropertyEntityIdComboBoxCtrl(QWidget* pParent)
|
|
: QWidget(pParent)
|
|
{
|
|
// create the gui, it consists of a layout, and in that layout, a text field for the value
|
|
// and then a slider for the value.
|
|
QHBoxLayout* pLayout = new QHBoxLayout(this);
|
|
m_pComboBox = aznew AzToolsFramework::DHQComboBox(this);
|
|
|
|
// many UI elements hide 1 pixel of their size in a border area that only shows up when they are selected.
|
|
// The combo box used in this layout does not do this, so adding 1 to the left and right margins will make
|
|
// sure that it has the same dimensions as the other UI elements when they are unselected.
|
|
pLayout->setSpacing(4);
|
|
pLayout->setContentsMargins(1, 0, 1, 0);
|
|
|
|
pLayout->addWidget(m_pComboBox);
|
|
|
|
m_pComboBox->setMinimumWidth(AzToolsFramework::PropertyQTConstant_MinimumWidth);
|
|
m_pComboBox->setFixedHeight(AzToolsFramework::PropertyQTConstant_DefaultHeight);
|
|
|
|
m_pComboBox->setFocusPolicy(Qt::StrongFocus);
|
|
setLayout(pLayout);
|
|
setFocusProxy(m_pComboBox);
|
|
setFocusPolicy(m_pComboBox->focusPolicy());
|
|
|
|
connect(m_pComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onChildComboBoxValueChange(int)));
|
|
};
|
|
|
|
void PropertyEntityIdComboBoxCtrl::setValue(AZ::EntityId value)
|
|
{
|
|
m_pComboBox->blockSignals(true);
|
|
bool indexWasFound = false;
|
|
for (size_t enumValIndex = 0; enumValIndex < m_enumValues.size(); enumValIndex++)
|
|
{
|
|
if (m_enumValues[enumValIndex].first == value)
|
|
{
|
|
m_pComboBox->setCurrentIndex(static_cast<int>(enumValIndex));
|
|
indexWasFound = true;
|
|
break;
|
|
}
|
|
}
|
|
AZ_Warning("AzToolsFramework", indexWasFound == true, "No index in property enum for value %d", value);
|
|
|
|
m_pComboBox->blockSignals(false);
|
|
}
|
|
|
|
void PropertyEntityIdComboBoxCtrl::addEnumValue(AZStd::pair<AZ::EntityId, AZStd::string>& val)
|
|
{
|
|
m_pComboBox->blockSignals(true);
|
|
m_enumValues.push_back(val);
|
|
m_pComboBox->addItem(val.second.c_str());
|
|
m_pComboBox->blockSignals(false);
|
|
}
|
|
|
|
void PropertyEntityIdComboBoxCtrl::addEnumValues(AZStd::vector< AZStd::pair<AZ::EntityId, AZStd::string> >& vals)
|
|
{
|
|
m_pComboBox->blockSignals(true);
|
|
for (size_t valIndex = 0; valIndex < vals.size(); valIndex++)
|
|
{
|
|
m_enumValues.push_back(vals[valIndex]);
|
|
m_pComboBox->addItem(vals[valIndex].second.c_str());
|
|
}
|
|
m_pComboBox->blockSignals(false);
|
|
}
|
|
|
|
AZ::EntityId PropertyEntityIdComboBoxCtrl::value() const
|
|
{
|
|
AZ_Assert(m_pComboBox->currentIndex() >= 0 &&
|
|
m_pComboBox->currentIndex() < static_cast<int>(m_enumValues.size()), "Out of range combo box index %d", m_pComboBox->currentIndex());
|
|
return m_enumValues[m_pComboBox->currentIndex()].first;
|
|
}
|
|
|
|
void PropertyEntityIdComboBoxCtrl::onChildComboBoxValueChange(int comboBoxIndex)
|
|
{
|
|
AZ_Assert(comboBoxIndex >= 0 &&
|
|
comboBoxIndex < static_cast<int>(m_enumValues.size()), "Out of range combo box index %d", comboBoxIndex);
|
|
|
|
emit valueChanged(m_enumValues[comboBoxIndex].first);
|
|
}
|
|
|
|
QWidget* PropertyEntityIdComboBoxCtrl::GetFirstInTabOrder()
|
|
{
|
|
return m_pComboBox;
|
|
}
|
|
QWidget* PropertyEntityIdComboBoxCtrl::GetLastInTabOrder()
|
|
{
|
|
return m_pComboBox;
|
|
}
|
|
|
|
void PropertyEntityIdComboBoxCtrl::UpdateTabOrder()
|
|
{
|
|
// There's only one QT widget on this property.
|
|
}
|
|
|
|
#include <moc_PropertyHandlerEntityIdComboBox.cpp>
|