More work on properties

This commit is contained in:
2026-04-03 11:29:58 -04:00
parent 4f09d6caf0
commit 78a3ca3e72
6 changed files with 118 additions and 86 deletions

View File

@@ -127,7 +127,7 @@ WingPropHandle::FlatTree WingPropHandle::AllTreeNodes(Root& Root)
//
/////////////////////////////////////////////////////////////////////////////
WingPropHandle::Handles WingPropHandle::AllProperties(Root& Root, EPropertyFlags Filter)
WingPropHandle::Handles WingPropHandle::AllProperties(Root& Root, bool RootFilter, EPropertyFlags Filter)
{
Handles Result;
for (IDetailTreeNode* Node : AllTreeNodes(Root))
@@ -137,7 +137,7 @@ WingPropHandle::Handles WingPropHandle::AllProperties(Root& Root, EPropertyFlags
{
if (Filter != CPF_None && !Handle->GetProperty()->HasAllPropertyFlags(Filter))
continue;
if (!IsInsideRootObject(Root, *Handle))
if (RootFilter && !IsInsideRootObject(Root, *Handle))
continue;
Result.Add(Handle);
}
@@ -145,16 +145,16 @@ WingPropHandle::Handles WingPropHandle::AllProperties(Root& Root, EPropertyFlags
return Result;
}
WingPropHandle::Handles WingPropHandle::AllProperties(UObject* Obj, EPropertyFlags Filter)
WingPropHandle::Handles WingPropHandle::AllProperties(UObject* Obj, bool RootFilter, EPropertyFlags Filter)
{
if (!Obj) return {};
return AllProperties(GetRootForObject(Obj), Filter);
return AllProperties(GetRootForObject(Obj), RootFilter, Filter);
}
WingPropHandle::Handles WingPropHandle::AllProperties(const UStruct* ScriptStruct, uint8* Data, EPropertyFlags Filter)
WingPropHandle::Handles WingPropHandle::AllProperties(const UStruct* ScriptStruct, uint8* Data, bool RootFilter, EPropertyFlags Filter)
{
if (!ScriptStruct || !Data) return {};
return AllProperties(GetRootForStruct(ScriptStruct, Data), Filter);
return AllProperties(GetRootForStruct(ScriptStruct, Data), RootFilter, Filter);
}
/////////////////////////////////////////////////////////////////////////////
@@ -163,28 +163,28 @@ WingPropHandle::Handles WingPropHandle::AllProperties(const UStruct* ScriptStruc
//
/////////////////////////////////////////////////////////////////////////////
TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(Root& Root, FName Name)
TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(Root& Root, FName Name, bool RootFilter)
{
for (IDetailTreeNode* Node : AllTreeNodes(Root))
{
if (Node->GetNodeName() != Name) continue;
TSharedPtr<IPropertyHandle> Handle = Node->CreatePropertyHandle();
if (Handle.IsValid() && IsInsideRootObject(Root, *Handle))
if (Handle.IsValid() && (!RootFilter || IsInsideRootObject(Root, *Handle)))
return Handle;
}
return nullptr;
}
TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(UObject* Obj, FName Name)
TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(UObject* Obj, FName Name, bool RootFilter)
{
if (!Obj) return nullptr;
return NamedProperty(GetRootForObject(Obj), Name);
return NamedProperty(GetRootForObject(Obj), Name, RootFilter);
}
TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(const UStruct* ScriptStruct, uint8* Data, FName Name)
TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(const UStruct* ScriptStruct, uint8* Data, FName Name, bool RootFilter)
{
if (!ScriptStruct || !Data) return nullptr;
return NamedProperty(GetRootForStruct(ScriptStruct, Data), Name);
return NamedProperty(GetRootForStruct(ScriptStruct, Data), Name, RootFilter);
}
/////////////////////////////////////////////////////////////////////////////
@@ -193,8 +193,11 @@ TSharedPtr<IPropertyHandle> WingPropHandle::NamedProperty(const UStruct* ScriptS
//
/////////////////////////////////////////////////////////////////////////////
WingPropHandle::Handles WingPropHandle::GetDetails(UObject* Obj, bool Mutable, EPropertyFlags Filter)
WingPropHandle::Handles WingPropHandle::GetDetails(UObject* Obj, bool Mutable)
{
bool RootFilter = false;
EPropertyFlags PropFlags = CPF_Edit;
if (!Obj) return {};
// Blueprints: redirect to the generated class CDO.
@@ -208,7 +211,11 @@ WingPropHandle::Handles WingPropHandle::GetDetails(UObject* Obj, bool Mutable, E
Obj = BP->GeneratedClass->GetDefaultObject();
}
// Component references: redirect to the template.
// UWingComponentReference is a class of our own creation, containing
// a pointer to a blueprint and a component name. Sometimes, the
// component is inherited. If so, and if you want to mutate it, you
// first have to create the override template in the child. If you're
// not mutating, you can just use the existing inherited template.
if (UWingComponentReference* Ref = Cast<UWingComponentReference>(Obj))
{
Obj = Mutable ? Ref->GetMutableTemplate() : Ref->GetImmutableTemplate();
@@ -219,29 +226,34 @@ WingPropHandle::Handles WingPropHandle::GetDetails(UObject* Obj, bool Mutable, E
}
}
Handles Result = AllProperties(Obj, Filter);
// Actors have components, which flood the property listing with hundreds
// of confusing additional properties.
if (Cast<AActor>(Obj)) RootFilter = true;
// Fetch the handles.
Handles Result = AllProperties(Obj, RootFilter, PropFlags);
// Material graph nodes: also collect expression properties.
if (UMaterialGraphNode* MatNode = Cast<UMaterialGraphNode>(Obj))
{
if (UMaterialExpression* Expr = MatNode->MaterialExpression)
{
Result.Append(AllProperties(Expr, Filter));
Result.Append(AllProperties(Expr, true, CPF_Edit));
}
}
// Widgets: hide the Slot property, add slot properties.
if (UWidget* Widget = Cast<UWidget>(Obj))
{
Result.RemoveAll([](const TSharedPtr<IPropertyHandle>& H)
{
return H->GetProperty()->GetFName() == TEXT("Slot");
});
if (UPanelSlot* Slot = Widget->Slot)
{
Result.Append(AllProperties(Slot, Filter));
}
}
// if (UWidget* Widget = Cast<UWidget>(Obj))
// {
// Result.RemoveAll([](const TSharedPtr<IPropertyHandle>& H)
// {
// return H->GetProperty()->GetFName() == TEXT("Slot");
// });
// if (UPanelSlot* Slot = Widget->Slot)
// {
// Result.Append(AllProperties(Slot, false, CPF_Edit));
// }
// }
return Result;
}
@@ -326,3 +338,27 @@ bool WingPropHandle::SetText(IPropertyHandle& Handle, const FString& Text)
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
//
// Print
//
/////////////////////////////////////////////////////////////////////////////
void WingPropHandle::Print(IPropertyHandle& Handle, FStringBuilderBase& Out)
{
FProperty* Prop = Handle.GetProperty();
FString Value = GetText(Handle);
Value.ReplaceInline(TEXT("\r"), TEXT(" "));
Value.ReplaceInline(TEXT("\n"), TEXT(" "));
if (Value.Len() > 100) Value = Value.Left(100) + TEXT("...");
bool bEditable = !Handle.IsEditConst();
Out.Appendf(TEXT(" %s %s %s = %s\n"),
bEditable ? TEXT("editable") : TEXT("readonly"),
*UWingTypes::TypeToText(Prop),
*WingUtils::FormatName(Prop),
*Value);
}