/* * 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 #include #include #include 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() { } 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, const char* debugName) { if (attrib == AZ::Edit::Attributes::ReadOnly) { bool value; if (attrValue->Read(value)) { GUI->setEnabled(!value); } } } void SimulatedObjectNameHandler::WriteGUIValuesIntoProperty(size_t index, SimulatedObjectNameLineEdit* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) { instance = GUI->text().toUtf8().data(); } bool SimulatedObjectNameHandler::ReadValuesIntoGUI(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(parentNode->FirstInstance()); GUI->SetSimulatedObject(m_simulatedObject); } else { GUI->SetSimulatedObject(nullptr); } return true; } } // namespace EMotionFX