Notification changes in UE Wingman

This commit is contained in:
2026-03-18 20:08:50 -04:00
parent 230f104fda
commit 809de505b6
16 changed files with 123 additions and 96 deletions

View File

@@ -23,7 +23,7 @@ FWingBlueprintVar::FWingBlueprintVar(UBlueprint* BP, const FString& VarName)
UObject* CDO = BP->GeneratedClass->GetDefaultObject();
FProperty* Prop = BP->GeneratedClass->FindPropertyByName(VarFName);
if (CDO && Prop)
DefaultValueProp = WingProperty(Prop, CDO);
DefaultValueProp = FWingProperty(Prop, CDO);
}
}
@@ -31,8 +31,8 @@ void FWingBlueprintVar::Dump()
{
LoadFlags();
LoadDefault();
TArray<WingProperty> Props = MergedProperties();
for (WingProperty& P : Props)
TArray<FWingProperty> Props = MergedProperties();
for (FWingProperty& P : Props)
{
UWingServer::Printf(TEXT(" %s %s = %s\n"),
*UWingTypes::TypeToText(P.Prop),
@@ -56,7 +56,7 @@ bool FWingBlueprintVar::ApplyJson(const FJsonObject* Json)
LoadFlags();
TArray<WingProperty> Props = MergedProperties();
TArray<FWingProperty> Props = MergedProperties();
if (!WingJson::PopulateFromJson(Props, Json, true))
return false;
@@ -131,23 +131,23 @@ bool FWingBlueprintVar::SaveDefault()
return true;
}
TArray<WingProperty> FWingBlueprintVar::MergedProperties()
TArray<FWingProperty> FWingBlueprintVar::MergedProperties()
{
TArray<WingProperty> Props = WingProperty::GetAll(
TArray<FWingProperty> Props = FWingProperty::GetAll(
FBPVariableDescription::StaticStruct(), Desc, CPF_Edit);
WingProperty::Remove(Props, TEXT("PropertyFlags"));
WingProperty::Remove(Props, TEXT("MetaDataArray"));
WingProperty::Remove(Props, TEXT("VarName"));
WingProperty::Remove(Props, TEXT("VarGuid"));
WingProperty::Remove(Props, TEXT("DefaultValue"));
FWingProperty::Remove(Props, TEXT("PropertyFlags"));
FWingProperty::Remove(Props, TEXT("MetaDataArray"));
FWingProperty::Remove(Props, TEXT("VarName"));
FWingProperty::Remove(Props, TEXT("VarGuid"));
FWingProperty::Remove(Props, TEXT("DefaultValue"));
Props.Append(WingProperty::GetAll(
Props.Append(FWingProperty::GetAll(
FWingBlueprintVar::StaticStruct(), this, (EPropertyFlags)0));
// Remove DefaultValue if we don't have a CDO property to back it.
if (!DefaultValueProp)
WingProperty::Remove(Props, TEXT("DefaultValue"));
FWingProperty::Remove(Props, TEXT("DefaultValue"));
return Props;
}

View File

@@ -27,7 +27,8 @@ WingFetcher::WalkFunc WingFetcher::GetWalker(const FString& Step)
void WingFetcher::SetObj(UObject* InObj)
{
UWingServer::AddTouchedObject(InObj);
if (!bSkipNotify)
UWingServer::AddTouchedObject(InObj);
Obj = InObj;
ResultPin = nullptr;
}

View File

@@ -6,7 +6,7 @@
#include "Dom/JsonValue.h"
bool WingJson::PopulateFromJson(WingProperty& P, const FJsonObject* Json, bool AllOptional)
bool WingJson::PopulateFromJson(FWingProperty& P, const FJsonObject* Json, bool AllOptional)
{
FString JsonKey = P.Prop->GetName();
bool bOptional = AllOptional || P.Prop->HasMetaData(TEXT("Optional"));
@@ -85,13 +85,13 @@ bool WingJson::PopulateFromJson(WingProperty& P, const FJsonObject* Json, bool A
}
bool WingJson::PopulateFromJson(
TArray<WingProperty>& Props, const FJsonObject* Json, bool AllOptional)
TArray<FWingProperty>& Props, const FJsonObject* Json, bool AllOptional)
{
bool Ok = true;
// Build a set of known property names for the unknown-field check.
TSet<FString> KnownKeys;
for (const WingProperty& P : Props)
for (const FWingProperty& P : Props)
KnownKeys.Add(P.Prop->GetName());
// Check for unknown fields in the JSON
@@ -105,7 +105,7 @@ bool WingJson::PopulateFromJson(
}
// Populate each property from JSON
for (WingProperty& P : Props)
for (FWingProperty& P : Props)
{
if (!PopulateFromJson(P, Json, AllOptional)) Ok = false;
}
@@ -115,7 +115,7 @@ bool WingJson::PopulateFromJson(
bool WingJson::PopulateFromJson(
UStruct* StructType, void* Container, const FJsonObject* Json)
{
TArray<WingProperty> Props = WingProperty::GetAll(StructType, Container, (EPropertyFlags)0);
TArray<FWingProperty> Props = FWingProperty::GetAll(StructType, Container, (EPropertyFlags)0);
return PopulateFromJson(Props, Json);
}

View File

@@ -3,29 +3,29 @@
#include "EdGraph/EdGraph.h"
#include "Engine/Blueprint.h"
#include "Materials/Material.h"
#include "Materials/MaterialExpression.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "MaterialEditingLibrary.h"
void WingNotifier::AddTouchedObject(UObject* Obj)
void FWingNotifier::AddTouchedObject(UObject* Obj)
{
if (!Obj) return;
bool bAlreadyInSet = false;
TouchedSet.Add(Obj, &bAlreadyInSet);
if (bAlreadyInSet) return;
TouchedArray.Add(Obj);
Obj->PreEditChange(nullptr);
}
void WingNotifier::SendNotifications()
void FWingNotifier::SendNotifications()
{
TSet<UEdGraphNode*> Nodes;
TSet<UEdGraph*> Graphs;
TSet<UMaterial*> Materials;
TSet<UMaterialExpression*> MaterialExpressions;
TSet<UBlueprint*> Blueprints;
for (int32 i = TouchedArray.Num() - 1; i >= 0; --i)
{
UObject* Obj = TouchedArray[i];
Obj->PostEditChange();
Obj->MarkPackageDirty();
if (UEdGraphNode* Node = ::Cast<UEdGraphNode>(Obj))
@@ -37,12 +37,21 @@ void WingNotifier::SendNotifications()
if (UBlueprint* BP = ::Cast<UBlueprint>(Obj))
Blueprints.Add(BP);
if (UMaterialExpression* Expr = ::Cast<UMaterialExpression>(Obj))
MaterialExpressions.Add(Expr);
if (UMaterial* Mat = ::Cast<UMaterial>(Obj))
Materials.Add(Mat);
if (UMaterialInterface* MatIface = ::Cast<UMaterialInterface>(Obj))
if (UMaterial* BaseMat = MatIface->GetMaterial())
Materials.Add(BaseMat);
}
for (UEdGraphNode* Node : Nodes)
Node->ReconstructNode();
for (UMaterialExpression* Expr : MaterialExpressions)
Expr->RefreshNode(true);
// for (UEdGraphNode* Node : Nodes)
// Node->ReconstructNode();
for (UEdGraph* Graph : Graphs)
Graph->NotifyGraphChanged();
for (UMaterial *Material : Materials)

View File

@@ -3,7 +3,6 @@
#include "WingServer.h"
#include "WingTypes.h"
#include "Engine/Blueprint.h"
#include "Materials/MaterialExpression.h"
#include "MaterialGraph/MaterialGraphNode.h"
#include "EdGraph/EdGraphPin.h"
#include "UObject/EnumProperty.h"
@@ -14,10 +13,13 @@ static bool IsPinTypeProperty(FProperty* Prop)
return StructProp && StructProp->Struct == FEdGraphPinType::StaticStruct();
}
WingProperty::WingProperty(FProperty* InProp, void* InContainer)
FWingProperty::FWingProperty(FProperty* InProp, void* InContainer)
: Prop(InProp), Container(InContainer) {}
FString WingProperty::GetText() const
FWingProperty::FWingProperty(FProperty* InProp, UObject* InContainer)
: Prop(InProp), Container(static_cast<void*>(InContainer)) {}
FString FWingProperty::GetText() const
{
void* ValuePtr = Prop->ContainerPtrToValuePtr<void>(Container);
if (IsPinTypeProperty(Prop))
@@ -27,7 +29,7 @@ FString WingProperty::GetText() const
return Result;
}
bool WingProperty::TryParseEnum(UEnum* Enum, const FString& Text, int64 &OutValue)
bool FWingProperty::TryParseEnum(UEnum* Enum, const FString& Text, int64 &OutValue)
{
int Index = Enum->GetIndexByNameString(Text);
if (Index == INDEX_NONE)
@@ -52,10 +54,14 @@ bool WingProperty::TryParseEnum(UEnum* Enum, const FString& Text, int64 &OutValu
}
}
bool WingProperty::TrySetText(const FString &Value)
bool FWingProperty::SetText(const FString &Value)
{
void* ValuePtr = Prop->ContainerPtrToValuePtr<void>(Container);
// Notify that we're modifying the containing object.
if (Prop->GetOwnerClass())
UWingServer::AddTouchedObject(static_cast<UObject*>(Container));
// Pin types get parsed by UWingTypes.
if (IsPinTypeProperty(Prop))
return UWingTypes::TextToType(Value, *static_cast<FEdGraphPinType*>(ValuePtr));
@@ -92,20 +98,7 @@ bool WingProperty::TrySetText(const FString &Value)
return true;
}
bool WingProperty::SetText(const FString& Value)
{
if (!TrySetText(Value)) return false;
if (Prop->GetOwnerClass()->IsChildOf(UMaterialExpression::StaticClass()))
{
UMaterialExpression* Expr = static_cast<UMaterialExpression*>(Container);
Expr->ForcePropertyValueChanged(Prop);
}
return true;
}
void WingProperty::Collect(UStruct* StructType, void* Container, TArray<WingProperty> &Props, EPropertyFlags Flags)
void FWingProperty::Collect(UStruct* StructType, void* Container, TArray<FWingProperty> &Props, EPropertyFlags Flags)
{
for (TFieldIterator<FProperty> It(StructType); It; ++It)
{
@@ -114,15 +107,24 @@ void WingProperty::Collect(UStruct* StructType, void* Container, TArray<WingProp
}
}
void WingProperty::Remove(TArray<WingProperty>& Props, const FString& Name)
void FWingProperty::Collect(UObject* Container, TArray<FWingProperty> &Props, EPropertyFlags Flags)
{
Props.RemoveAll([&](const WingProperty& P) { return P.Prop->GetName() == Name; });
for (TFieldIterator<FProperty> It(Container->GetClass()); It; ++It)
{
if (Flags != 0 && !It->HasAnyPropertyFlags(Flags)) continue;
Props.Emplace(*It, Container);
}
}
TArray<WingProperty> WingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
void FWingProperty::Remove(TArray<FWingProperty>& Props, const FString& Name)
{
Props.RemoveAll([&](const FWingProperty& P) { return P.Prop->GetName() == Name; });
}
TArray<FWingProperty> FWingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
{
if (!Obj) return {};
TArray<WingProperty> Result;
TArray<FWingProperty> Result;
// Blueprints don't have editable properties. So
// instead, we fetch properties from the generated CDO,
@@ -138,7 +140,7 @@ TArray<WingProperty> WingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
Obj = BP->GeneratedClass->GetDefaultObject();
}
Collect(Obj->GetClass(), Obj, Result, Flags);
Collect(Obj, Result, Flags);
// If it's a Material Graph node, also collect properties from
// the associated material expression.
@@ -147,24 +149,24 @@ TArray<WingProperty> WingProperty::GetAll(UObject* Obj, EPropertyFlags Flags)
{
if (UMaterialExpression* Expr = MatNode->MaterialExpression)
{
Collect(Expr->GetClass(), Expr, Result, Flags);
Collect(Expr, Result, Flags);
}
}
return Result;
}
TArray<WingProperty> WingProperty::GetAll(UStruct* StructType, void* Container, EPropertyFlags Flags)
TArray<FWingProperty> FWingProperty::GetAll(UStruct* StructType, void* Container, EPropertyFlags Flags)
{
TArray<WingProperty> Result;
TArray<FWingProperty> Result;
Collect(StructType, Container, Result, Flags);
return Result;
}
TArray<WingProperty> WingProperty::FindAllSubstring(const TArray<WingProperty>& Props, const FString& Substring)
TArray<FWingProperty> FWingProperty::FindAllSubstring(const TArray<FWingProperty>& Props, const FString& Substring)
{
if (Substring.IsEmpty()) return Props;
TArray<WingProperty> Result;
for (const WingProperty& P : Props)
TArray<FWingProperty> Result;
for (const FWingProperty& P : Props)
{
if (WingUtils::FormatName(P.Prop).Contains(Substring, ESearchCase::IgnoreCase))
Result.Add(P);
@@ -172,10 +174,10 @@ TArray<WingProperty> WingProperty::FindAllSubstring(const TArray<WingProperty>&
return Result;
}
WingProperty WingProperty::FindOneExactMatch(const TArray<WingProperty>& Props, const FString& Name)
FWingProperty FWingProperty::FindOneExactMatch(const TArray<FWingProperty>& Props, const FString& Name)
{
TArray<WingProperty> Matches;
for (const WingProperty& P : Props)
TArray<FWingProperty> Matches;
for (const FWingProperty& P : Props)
{
if (WingUtils::Identifies(Name, P.Prop))
Matches.Add(P);
@@ -183,12 +185,12 @@ WingProperty WingProperty::FindOneExactMatch(const TArray<WingProperty>& Props,
if (Matches.Num() == 0)
{
UWingServer::Printf(TEXT("ERROR: Property '%s' not found\n"), *Name);
return WingProperty();
return FWingProperty();
}
if (Matches.Num() > 1)
{
UWingServer::Printf(TEXT("ERROR: Ambiguous property '%s'\n"), *Name);
return WingProperty();
return FWingProperty();
}
return Matches[0];
}

View File

@@ -304,7 +304,7 @@ void UWingServer::TryCallHandler(const FString &Line)
Request->RemoveField(TEXT("command"));
// Find the handler UClass for the specified command.
UClass** HandlerClass = WingHandlerRegistry.Find(Command);
TObjectPtr<UClass>* HandlerClass = WingHandlerRegistry.Find(Command);
if (!HandlerClass)
{
UWingServer::Printf(TEXT("Unknown command: %s"), *Command);