Work on blueprint components in MCP
This commit is contained in:
@@ -19,6 +19,13 @@ FWingProperty::FWingProperty(FProperty* InProp, void* InContainer)
|
||||
FWingProperty::FWingProperty(FProperty* InProp, UObject* InContainer)
|
||||
: Prop(InProp), Container(static_cast<void*>(InContainer)) {}
|
||||
|
||||
FString FWingProperty::GetCategory()
|
||||
{
|
||||
FString Result = Prop->GetMetaData(TEXT("Category"));
|
||||
if (Result.IsEmpty()) Result = "Unclassified";
|
||||
return Result;
|
||||
}
|
||||
|
||||
FString FWingProperty::GetText() const
|
||||
{
|
||||
void* ValuePtr = Prop->ContainerPtrToValuePtr<void>(Container);
|
||||
@@ -29,6 +36,16 @@ FString FWingProperty::GetText() const
|
||||
return Result;
|
||||
}
|
||||
|
||||
FString FWingProperty::GetTruncatedText(int32 MaxLen) const
|
||||
{
|
||||
FString Result = GetText();
|
||||
for (int i = 0; i < Result.Len(); i++)
|
||||
if (Result[i] == '\n') Result[i] = ' ';
|
||||
if (Result.Len() > MaxLen)
|
||||
Result = Result.Left(MaxLen) + TEXT("...");
|
||||
return Result;
|
||||
}
|
||||
|
||||
bool FWingProperty::SetText(const FString &Value)
|
||||
{
|
||||
void* ValuePtr = Prop->ContainerPtrToValuePtr<void>(Container);
|
||||
@@ -75,19 +92,26 @@ bool FWingProperty::SetText(const FString &Value)
|
||||
|
||||
void FWingProperty::Collect(UStruct* StructType, void* Container, TArray<FWingProperty> &Props, EPropertyFlags Flags)
|
||||
{
|
||||
TMap<FString, TArray<FWingProperty>> Grouped;
|
||||
|
||||
for (TFieldIterator<FProperty> It(StructType); It; ++It)
|
||||
{
|
||||
if (Flags != 0 && !It->HasAnyPropertyFlags(Flags)) continue;
|
||||
Props.Emplace(*It, Container);
|
||||
FString SortCat = *It->GetMetaData(TEXT("Category"));
|
||||
Grouped.FindOrAdd(SortCat).Add(FWingProperty(*It, Container));
|
||||
}
|
||||
}
|
||||
TArray<FString> Categories;
|
||||
|
||||
void FWingProperty::Collect(UObject* Container, TArray<FWingProperty> &Props, EPropertyFlags Flags)
|
||||
{
|
||||
for (TFieldIterator<FProperty> It(Container->GetClass()); It; ++It)
|
||||
Grouped.GetKeys(Categories);
|
||||
Categories.Sort([](const FString& A, const FString& B) {
|
||||
if (A.IsEmpty()) return false;
|
||||
if (B.IsEmpty()) return true;
|
||||
return A < B;
|
||||
});
|
||||
|
||||
for (const FString& Category : Categories)
|
||||
{
|
||||
if (Flags != 0 && !It->HasAnyPropertyFlags(Flags)) continue;
|
||||
Props.Emplace(*It, Container);
|
||||
Props.Append(Grouped[Category]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +123,6 @@ void FWingProperty::Remove(TArray<FWingProperty>& Props, const FString& Name)
|
||||
TArray<FWingProperty> FWingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
|
||||
{
|
||||
if (!Obj) return {};
|
||||
TArray<FWingProperty> Result;
|
||||
|
||||
// Blueprints don't have editable properties. So
|
||||
// instead, we fetch properties from the generated CDO,
|
||||
@@ -115,7 +138,8 @@ TArray<FWingProperty> FWingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
|
||||
Obj = BP->GeneratedClass->GetDefaultObject();
|
||||
}
|
||||
|
||||
Collect(Obj, Result, Flags);
|
||||
TArray<FWingProperty> Result;
|
||||
Collect(Obj->GetClass(), Obj, Result, Flags);
|
||||
|
||||
// If it's a Material Graph node, also collect properties from
|
||||
// the associated material expression.
|
||||
@@ -124,9 +148,10 @@ TArray<FWingProperty> FWingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
|
||||
{
|
||||
if (UMaterialExpression* Expr = MatNode->MaterialExpression)
|
||||
{
|
||||
Collect(Expr, Result, Flags);
|
||||
Collect(Expr->GetClass(), Expr, Result, Flags);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user