/* * 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. * */ #ifndef CRYINCLUDE_EDITOR_UTILS_PROPERTYGENERICCTRL_H #define CRYINCLUDE_EDITOR_UTILS_PROPERTYGENERICCTRL_H #pragma once #include #include #include #include "ReflectedVar.h" #include "Util/VariablePropertyType.h" #include class QStringListModel; class QListView; class QLabel; class GenericPopupPropertyEditor : public QWidget { Q_OBJECT public: AZ_CLASS_ALLOCATOR(GenericPopupPropertyEditor, AZ::SystemAllocator, 0); GenericPopupPropertyEditor(QWidget* pParent = nullptr, bool showTwoButtons = false); void SetValue(const QString& value, bool notify = true); QString GetValue() const { return m_value; } void SetPropertyType(PropertyType type); PropertyType GetPropertyType() const { return m_propertyType; } //override in derived classes to show appropriate editor virtual void onEditClicked() {}; virtual void onButton2Clicked() {}; signals: void ValueChanged(const QString& value); private: QLabel* m_valueLabel; PropertyType m_propertyType; QString m_value; }; template class GenericPopupWidgetHandler : public QObject , public AzToolsFramework::PropertyHandler < CReflectedVarGenericProperty, GenericPopupPropertyEditor > { public: AZ_CLASS_ALLOCATOR(GenericPopupWidgetHandler, AZ::SystemAllocator, 0); virtual bool IsDefaultHandler() const override { return false; } virtual AZ::u32 GetHandlerName(void) const override { return CRC; } virtual QWidget* CreateGUI(QWidget* pParent) override { GenericPopupPropertyEditor* newCtrl = aznew T(pParent); connect(newCtrl, &GenericPopupPropertyEditor::ValueChanged, newCtrl, [newCtrl]() { EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl); }); return newCtrl; } virtual void ConsumeAttribute(GenericPopupPropertyEditor* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override { Q_UNUSED(GUI); Q_UNUSED(attrib); Q_UNUSED(attrValue); Q_UNUSED(debugName); } virtual void WriteGUIValuesIntoProperty(size_t index, GenericPopupPropertyEditor* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override { Q_UNUSED(index); Q_UNUSED(node); CReflectedVarGenericProperty val = instance; val.m_propertyType = GUI->GetPropertyType(); val.m_value = GUI->GetValue().toUtf8().data(); instance = static_cast(val); } virtual bool ReadValuesIntoGUI(size_t index, GenericPopupPropertyEditor* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override { Q_UNUSED(index); Q_UNUSED(node); CReflectedVarGenericProperty val = instance; GUI->SetPropertyType(val.m_propertyType); GUI->SetValue(val.m_value.c_str(), false); return false; } }; class SOClassPropertyEditor : public GenericPopupPropertyEditor { public: SOClassPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOClassesPropertyEditor : public GenericPopupPropertyEditor { public: SOClassesPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOStatePropertyEditor : public GenericPopupPropertyEditor { public: SOStatePropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOStatesPropertyEditor : public GenericPopupPropertyEditor { public: SOStatesPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOStatePatternPropertyEditor : public GenericPopupPropertyEditor { public: SOStatePatternPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOHelperPropertyEditor : public GenericPopupPropertyEditor { public: SOHelperPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOEventPropertyEditor : public GenericPopupPropertyEditor { public: SOEventPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SOTemplatePropertyEditor : public GenericPopupPropertyEditor { public: SOTemplatePropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class ShaderPropertyEditor : public GenericPopupPropertyEditor { public: ShaderPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class MaterialPropertyEditor : public GenericPopupPropertyEditor { public: MaterialPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent, true){} void onEditClicked() override; void onButton2Clicked() override; }; class AiBehaviorPropertyEditor : public GenericPopupPropertyEditor { public: AiBehaviorPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class AIAnchorPropertyEditor : public GenericPopupPropertyEditor { public: AIAnchorPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; #ifdef USE_DEPRECATED_AI_CHARACTER_SYSTEM class AiCharacterPropertyEditor : public GenericPopupPropertyEditor { public: AiCharacterPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; #endif class EquipPropertyEditor : public GenericPopupPropertyEditor { public: EquipPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class ReverbPresetPropertyEditor : public GenericPopupPropertyEditor { public: ReverbPresetPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class MissionObjPropertyEditor : public GenericPopupPropertyEditor { public: MissionObjPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SequencePropertyEditor : public GenericPopupPropertyEditor { public: SequencePropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class SequenceIdPropertyEditor : public GenericPopupPropertyEditor { public: SequenceIdPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class LocalStringPropertyEditor : public GenericPopupPropertyEditor { public: LocalStringPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class LightAnimationPropertyEditor : public GenericPopupPropertyEditor { public: LightAnimationPropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent){} void onEditClicked() override; }; class ParticleNamePropertyEditor : public GenericPopupPropertyEditor { public: ParticleNamePropertyEditor(QWidget* pParent = nullptr) : GenericPopupPropertyEditor(pParent, true){} void onEditClicked() override; void onButton2Clicked() override; }; // AZ_CRC changed recently - it used to be evaluated by the preprocessor to AZ::u32(value); now it evaluates to Az::Crc32, and can't be used as a const template parameter // So we use our own #define CONST_AZ_CRC(name, value) AZ::u32(value) using SOClassPropertyHandler = GenericPopupWidgetHandler; using SOClassesPropertyHandler = GenericPopupWidgetHandler; using SOStatePropertyHandler = GenericPopupWidgetHandler; using SOStatesPropertyHandler = GenericPopupWidgetHandler; using SOStatePatternPropertyHandler = GenericPopupWidgetHandler; using SOHelperPropertyHandler = GenericPopupWidgetHandler; using SONavHelperPropertyHandler = GenericPopupWidgetHandler; using SOAnimHelperPropertyHandler = GenericPopupWidgetHandler; using SOEventPropertyHandler = GenericPopupWidgetHandler; using SOTemplatePropertyHandler = GenericPopupWidgetHandler; using ShaderPropertyHandler = GenericPopupWidgetHandler; using MaterialPropertyHandler = GenericPopupWidgetHandler; using AiBehaviorPropertyHandler = GenericPopupWidgetHandler; using AIAnchorPropertyHandler = GenericPopupWidgetHandler; #ifdef USE_DEPRECATED_AI_CHARACTER_SYSTEM using AiCharacterPropertyHandler = GenericPopupWidgetHandler; #endif using EquipPropertyHandler = GenericPopupWidgetHandler; using ReverbPresetPropertyHandler = GenericPopupWidgetHandler; using MissionObjPropertyHandler = GenericPopupWidgetHandler; using SequencePropertyHandler = GenericPopupWidgetHandler; using SequenceIdPropertyHandler = GenericPopupWidgetHandler; using LocalStringPropertyHandler = GenericPopupWidgetHandler; using LightAnimationPropertyHandler = GenericPopupWidgetHandler; using ParticleNamePropertyHandler = GenericPopupWidgetHandler; class ListEditWidget : public QWidget { Q_OBJECT public: AZ_CLASS_ALLOCATOR(ListEditWidget, AZ::SystemAllocator, 0); ListEditWidget(QWidget *pParent = nullptr); void SetValue(const QString &value, bool notify = true); QString GetValue() const { return m_value; } QWidget* GetFirstInTabOrder(); QWidget* GetLastInTabOrder(); signals: void ValueChanged(const QString &value); private: void OnModelDataChange(); virtual void OnEditClicked() {}; protected: QLineEdit *m_valueEdit; QString m_value; QListView *m_listView; QStringListModel *m_model; }; class AIPFPropertiesListEdit : public ListEditWidget { public: AIPFPropertiesListEdit(QWidget *pParent = nullptr) : ListEditWidget(pParent){} void OnEditClicked() override; }; class AIEntityClassesListEdit : public ListEditWidget { public: AIEntityClassesListEdit(QWidget *pParent = nullptr) : ListEditWidget(pParent){} void OnEditClicked() override; }; template class ListEditWidgetHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarGenericProperty, ListEditWidget > { public: AZ_CLASS_ALLOCATOR(ListEditWidgetHandler, AZ::SystemAllocator, 0); virtual bool IsDefaultHandler() const override { return false; } virtual AZ::u32 GetHandlerName(void) const override { return CRC; } virtual QWidget* CreateGUI(QWidget *pParent) override { ListEditWidget* newCtrl = aznew T(pParent); connect(newCtrl, &ListEditWidget::ValueChanged, newCtrl, [newCtrl]() { EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl); }); return newCtrl; } virtual void ConsumeAttribute(ListEditWidget* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override { Q_UNUSED(GUI); Q_UNUSED(attrib); Q_UNUSED(attrValue); Q_UNUSED(debugName); } virtual void WriteGUIValuesIntoProperty(size_t index, ListEditWidget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override { Q_UNUSED(index); Q_UNUSED(node); CReflectedVarGenericProperty val = instance; val.m_value = GUI->GetValue().toUtf8().data(); instance = static_cast(val); } virtual bool ReadValuesIntoGUI(size_t index, ListEditWidget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override { Q_UNUSED(index); Q_UNUSED(node); CReflectedVarGenericProperty val = instance; GUI->SetValue(val.m_value.c_str(), false); return false; } QWidget* GetFirstInTabOrder(ListEditWidget* widget) override { return widget->GetFirstInTabOrder(); } QWidget* GetLastInTabOrder(ListEditWidget* widget) override {return widget->GetLastInTabOrder(); } }; using AIPFPropertiesHandler = ListEditWidgetHandler; using AIEntityClassesHandler = ListEditWidgetHandler; #endif // CRYINCLUDE_EDITOR_UTILS_PROPERTYGENERICCTRL_H