You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/EMotionFX/Code/Source/Editor/PropertyWidgets/SimulatedObjectNameHandler.cpp

105 lines
4.1 KiB
C++

/*
* 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.
*
*/
#include <EMotionFX/CommandSystem/Source/CommandManager.h>
#include <EMotionFX/Source/SimulatedObjectSetup.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
#include <Editor/PropertyWidgets/SimulatedObjectNameHandler.h>
namespace EMotionFX
{
AZ_CLASS_ALLOCATOR_IMPL(SimulatedObjectNameLineEdit, AZ::SystemAllocator, 0)
AZ_CLASS_ALLOCATOR_IMPL(SimulatedObjectNameHandler, AZ::SystemAllocator, 0)
SimulatedObjectNameLineEdit::SimulatedObjectNameLineEdit(QWidget* parent)
: LineEditValidatable(parent)
, m_simulatedObject(nullptr)
{
SetValidatorFunc([this]() {
if (m_simulatedObject)
{
const SimulatedObjectSetup* setup = m_simulatedObject->GetSimulatedObjectSetup();
AZ_Assert(setup, "Simulated object %s does not belong to a simulated object setup.", m_simulatedObject->GetName().c_str());
return setup->IsSimulatedObjectNameUnique(text().toUtf8().data(), m_simulatedObject);
}
return false;
});
connect(this, &LineEditValidatable::TextEditingFinished, this, [this]() {
EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, this);
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::Bus::Handler::OnEditingFinished, this);
});
}
void SimulatedObjectNameLineEdit::SetSimulatedObject(SimulatedObject* simulatedObject)
{
m_simulatedObject = simulatedObject;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
SimulatedObjectNameHandler::SimulatedObjectNameHandler()
: QObject()
, AzToolsFramework::PropertyHandler<AZStd::string, SimulatedObjectNameLineEdit>()
{
}
AZ::u32 SimulatedObjectNameHandler::GetHandlerName() const
{
return AZ_CRC("SimulatedObjectName", 0xd11d7db9);
}
QWidget* SimulatedObjectNameHandler::CreateGUI(QWidget* parent)
{
SimulatedObjectNameLineEdit* lineEdit = aznew SimulatedObjectNameLineEdit(parent);
return lineEdit;
}
void SimulatedObjectNameHandler::ConsumeAttribute(SimulatedObjectNameLineEdit* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, [[maybe_unused]] const char* debugName)
{
if (attrib == AZ::Edit::Attributes::ReadOnly)
{
bool value;
if (attrValue->Read<bool>(value))
{
GUI->setEnabled(!value);
}
}
}
void SimulatedObjectNameHandler::WriteGUIValuesIntoProperty([[maybe_unused]] size_t index, SimulatedObjectNameLineEdit* GUI, property_t& instance, [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
{
instance = GUI->text().toUtf8().data();
}
bool SimulatedObjectNameHandler::ReadValuesIntoGUI([[maybe_unused]] size_t index, SimulatedObjectNameLineEdit* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node)
{
QSignalBlocker signalBlocker(GUI);
GUI->SetPreviousText(instance.c_str());
GUI->setText(instance.c_str());
if (node && node->GetParent())
{
AzToolsFramework::InstanceDataNode* parentNode = node->GetParent();
m_simulatedObject = static_cast<SimulatedObject*>(parentNode->FirstInstance());
GUI->SetSimulatedObject(m_simulatedObject);
}
else
{
GUI->SetSimulatedObject(nullptr);
}
return true;
}
} // namespace EMotionFX