Skip to content

Commit

Permalink
Added Group attribute to allow grouping properties
Browse files Browse the repository at this point in the history
-ezGroupAttribute("") will reset to the default group
-ezGroupAttribute("Name", "Icon") will name the group "Name" and set an icon named ":GroupIcons/Icon.png"
-An order can be given. If left at -1, groups will be set to 0, 1, 2 etc in order of appearance in the type info.
  • Loading branch information
Sanakan8472 committed Feb 16, 2020
1 parent c847b55 commit e6b3ecb
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 83 deletions.
Expand Up @@ -11,28 +11,28 @@ EZ_IMPLEMENT_SINGLETON(ezShaderTypeRegistry);
// clang-format off
EZ_BEGIN_SUBSYSTEM_DECLARATION(EditorFramework, ShaderTypeRegistry)

BEGIN_SUBSYSTEM_DEPENDENCIES
"PluginAssets", "ReflectedTypeManager"
END_SUBSYSTEM_DEPENDENCIES
BEGIN_SUBSYSTEM_DEPENDENCIES
"PluginAssets", "ReflectedTypeManager"
END_SUBSYSTEM_DEPENDENCIES

ON_CORESYSTEMS_STARTUP
{
EZ_DEFAULT_NEW(ezShaderTypeRegistry);
}
ON_CORESYSTEMS_STARTUP
{
EZ_DEFAULT_NEW(ezShaderTypeRegistry);
}

ON_CORESYSTEMS_SHUTDOWN
{
ezShaderTypeRegistry* pDummy = ezShaderTypeRegistry::GetSingleton();
EZ_DEFAULT_DELETE(pDummy);
}
ON_CORESYSTEMS_SHUTDOWN
{
ezShaderTypeRegistry* pDummy = ezShaderTypeRegistry::GetSingleton();
EZ_DEFAULT_DELETE(pDummy);
}

ON_HIGHLEVELSYSTEMS_STARTUP
{
}
ON_HIGHLEVELSYSTEMS_STARTUP
{
}

ON_HIGHLEVELSYSTEMS_SHUTDOWN
{
}
ON_HIGHLEVELSYSTEMS_SHUTDOWN
{
}

EZ_END_SUBSYSTEM_DECLARATION;
// clang-format on
Expand Down Expand Up @@ -227,18 +227,29 @@ namespace
}
}

attributes.PushBack(EZ_DEFAULT_NEW(ezDefaultValueAttribute, attributeDef.m_Values[0]));
attributes.PushBack(EZ_DEFAULT_NEW(ezDefaultValueAttribute, attributeDef.m_Values[0]));
}
else if (attributeDef.m_sType.IsEqual("Clamp") && attributeDef.m_Values.GetCount() >= 2)
{
attributes.PushBack(EZ_DEFAULT_NEW(ezClampValueAttribute, attributeDef.m_Values[0], attributeDef.m_Values[1]));
}
else if (attributeDef.m_sType.IsEqual("Group"))
{
if (attributeDef.m_Values.GetCount() >= 1 && attributeDef.m_Values[0].CanConvertTo<ezString>())
{
attributes.PushBack(EZ_DEFAULT_NEW(ezGroupAttribute, attributeDef.m_Values[0].ConvertTo<ezString>()));
}
else
{
attributes.PushBack(EZ_DEFAULT_NEW(ezGroupAttribute));
}
}
}
}
}

ezShaderTypeRegistry::ezShaderTypeRegistry()
: m_SingletonRegistrar(this)
: m_SingletonRegistrar(this)
{
ezShaderTypeRegistry::GetSingleton();
ezReflectedTypeDescriptor desc;
Expand Down Expand Up @@ -312,7 +323,7 @@ void ezShaderTypeRegistry::UpdateShaderType(ShaderData& data)

ezHybridArray<ezShaderParser::ParameterDefinition, 16> parameters;
ezHybridArray<ezShaderParser::EnumDefinition, 4> enumDefinitions;

{
ezFileStats Stats;
bool bStat = ezOSFile::GetFileStats(data.m_sAbsShaderPath, Stats).Succeeded();
Expand Down Expand Up @@ -385,7 +396,7 @@ void ezShaderTypeRegistry::PhantomTypeRegistryEventHandler(const ezPhantomRttiMa
}
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

#include <Foundation/Serialization/GraphPatch.h>

Expand All @@ -395,7 +406,7 @@ class ezShaderTypePatch_1_2 : public ezGraphPatch
{
public:
ezShaderTypePatch_1_2()
: ezGraphPatch(nullptr, 2, ezGraphPatch::PatchType::GraphPatch)
: ezGraphPatch(nullptr, 2, ezGraphPatch::PatchType::GraphPatch)
{
}

Expand Down Expand Up @@ -451,7 +462,7 @@ class ezShaderBaseTypePatch_1_2 : public ezGraphPatch
{
public:
ezShaderBaseTypePatch_1_2()
: ezGraphPatch("ezShaderTypeBase", 2)
: ezGraphPatch("ezShaderTypeBase", 2)
{
}

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -65,5 +65,8 @@
<file>ezStageSpaceComponent.png</file>
<file>ezSrmRenderComponent.png</file>
<file>ezMotionMatchingComponent.png</file>
</qresource>
</qresource>
<qresource prefix="GroupIcons">
<file>Size.png</file>
</qresource>
</RCC>
Expand Up @@ -124,6 +124,40 @@ EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezClampValueAttribute, 1, ezRTTIDefaultAllocator
}
EZ_END_DYNAMIC_REFLECTED_TYPE;

EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezGroupAttribute, 1, ezRTTIDefaultAllocator<ezGroupAttribute>)
{
EZ_BEGIN_PROPERTIES
{
EZ_MEMBER_PROPERTY("Group", m_sGroup),
}
EZ_END_PROPERTIES;
EZ_BEGIN_FUNCTIONS
{
EZ_CONSTRUCTOR_PROPERTY(const char*, float),
EZ_CONSTRUCTOR_PROPERTY(const char*, const char*, float),
}
EZ_END_FUNCTIONS;
}
EZ_END_DYNAMIC_REFLECTED_TYPE;

ezGroupAttribute::ezGroupAttribute()
{

}

ezGroupAttribute::ezGroupAttribute(const char* szGroup, float fOrder)
{
m_sGroup = szGroup;
m_fOrder = fOrder;
}

ezGroupAttribute::ezGroupAttribute(const char* szGroup, const char* szIconName, float fOrder)
{
m_sGroup = szGroup;
m_sIconName = szIconName;
m_fOrder = fOrder;
}

EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezTypeWidgetAttribute, 1, ezRTTINoAllocator)
EZ_END_DYNAMIC_REFLECTED_TYPE;

Expand Down
Expand Up @@ -46,7 +46,9 @@ class EZ_FOUNDATION_DLL ezCategoryAttribute : public ezPropertyAttribute
ezUntrackedString m_sCategory;
};

/// \brief Used to categorize types (e.g. add component menu)
/// \brief Used for dynamic titles of visual script nodes.
/// E.g. "Set Bool Property '{Name}'" will allow the title to by dynamic
/// by reading the current value of the 'Name' property.
class EZ_FOUNDATION_DLL ezTitleAttribute : public ezPropertyAttribute
{
EZ_ADD_DYNAMIC_REFLECTION(ezTitleAttribute, ezPropertyAttribute);
Expand Down Expand Up @@ -149,6 +151,25 @@ class EZ_FOUNDATION_DLL ezClampValueAttribute : public ezPropertyAttribute
ezVariant m_MaxValue;
};

/// \brief Used to categorize properties into groups
class EZ_FOUNDATION_DLL ezGroupAttribute : public ezPropertyAttribute
{
EZ_ADD_DYNAMIC_REFLECTION(ezGroupAttribute, ezPropertyAttribute);

public:
ezGroupAttribute();
ezGroupAttribute(const char* szGroup, float fOrder = -1.0f);
ezGroupAttribute(const char* szGroup, const char* szIconName, float fOrder = -1.0f);

const char* GetGroup() const { return m_sGroup; }
const char* GetIconName() const { return m_sIconName; }
float GetOrder() const { return m_fOrder; }

private:
ezUntrackedString m_sGroup;
ezUntrackedString m_sIconName;
float m_fOrder = -1.0f;
};

/// \brief Derive from this class if you want to define an attribute that replaces the property type widget.
///
Expand Down
Expand Up @@ -22,13 +22,13 @@ EZ_BEGIN_COMPONENT_TYPE(ezGreyBoxComponent, 3, ezComponentMode::Static)
EZ_ENUM_ACCESSOR_PROPERTY("Shape", ezGreyBoxShape, GetShape, SetShape),
EZ_ACCESSOR_PROPERTY("Material", GetMaterialFile, SetMaterialFile)->AddAttributes(new ezAssetBrowserAttribute("Material")),
EZ_MEMBER_PROPERTY("Color", m_Color)->AddAttributes(new ezDefaultValueAttribute(ezColor::White)),
EZ_ACCESSOR_PROPERTY("SizeNegX", GetSizeNegX, SetSizeNegX),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SizeNegX", GetSizeNegX, SetSizeNegX)->AddAttributes(new ezGroupAttribute("Size", "Size")),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SizePosX", GetSizePosX, SetSizePosX),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SizeNegY", GetSizeNegY, SetSizeNegY),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SizePosY", GetSizePosY, SetSizePosY),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SizeNegZ", GetSizeNegZ, SetSizeNegZ),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SizePosZ", GetSizePosZ, SetSizePosZ),//->AddAttributes(new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("Detail", GetDetail, SetDetail)->AddAttributes(new ezDefaultValueAttribute(16), new ezClampValueAttribute(3, 32)),
EZ_ACCESSOR_PROPERTY("Detail", GetDetail, SetDetail)->AddAttributes(new ezGroupAttribute("Misc"), new ezDefaultValueAttribute(16), new ezClampValueAttribute(3, 32)),
EZ_ACCESSOR_PROPERTY("Curvature", GetCurvature, SetCurvature),
EZ_ACCESSOR_PROPERTY("Thickness", GetThickness, SetThickness)->AddAttributes(new ezDefaultValueAttribute(0.5f), new ezClampValueAttribute(0.0f, ezVariant())),
EZ_ACCESSOR_PROPERTY("SlopedTop", GetSlopedTop, SetSlopedTop),
Expand Down
Expand Up @@ -525,7 +525,7 @@ ezUInt32 ezQtPropertyGridWidget::GetGroupBoxHash(ezQtGroupBoxBase* pBox) const
if (pCurBox != nullptr)
{
const QByteArray name = pCurBox->GetTitle().toUtf8().data();
uiHash = ezHashingUtils::xxHash32(name, name.length());
uiHash += ezHashingUtils::xxHash32(name, name.length());
}
pCur = pCur->parentWidget();
}
Expand Down

0 comments on commit e6b3ecb

Please sign in to comment.