Add editing of variable defaults to BlueprrintVariable functions.
This commit is contained in:
@@ -69,7 +69,7 @@ public:
|
||||
// Apply config if provided
|
||||
if (Config.Json && Config.Json->Values.Num() > 0)
|
||||
{
|
||||
if (!Editor.LoadJson(Config.Json.Get()))
|
||||
if (!Editor.ApplyJson(Config.Json.Get()))
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Editor.LoadJson(Properties.Json.Get()))
|
||||
if (!Editor.ApplyJson(Properties.Json.Get()))
|
||||
return;
|
||||
|
||||
UMCPServer::Printf(TEXT("Modified variable %s (%s) in %s\n"),
|
||||
|
||||
@@ -16,11 +16,21 @@ FBPVarEditor::FBPVarEditor(UBlueprint* BP, const FString& VarName)
|
||||
return;
|
||||
}
|
||||
Desc = &BP->NewVariables[VarIndex];
|
||||
|
||||
// Try to find the default value property on the CDO.
|
||||
if (BP->GeneratedClass)
|
||||
{
|
||||
UObject* CDO = BP->GeneratedClass->GetDefaultObject();
|
||||
FProperty* Prop = BP->GeneratedClass->FindPropertyByName(VarFName);
|
||||
if (CDO && Prop)
|
||||
DefaultValueProp = MCPProperty(Prop, CDO);
|
||||
}
|
||||
}
|
||||
|
||||
void FBPVarEditor::Dump()
|
||||
{
|
||||
Load();
|
||||
LoadFlags();
|
||||
LoadDefault();
|
||||
TArray<MCPProperty> Props = MergedProperties();
|
||||
for (MCPProperty& P : Props)
|
||||
{
|
||||
@@ -31,17 +41,22 @@ void FBPVarEditor::Dump()
|
||||
}
|
||||
}
|
||||
|
||||
bool FBPVarEditor::LoadJson(const FJsonObject* Json)
|
||||
bool FBPVarEditor::ApplyJson(const FJsonObject* Json)
|
||||
{
|
||||
Load();
|
||||
LoadFlags();
|
||||
bool bHasDefault = Json->HasField(TEXT("DefaultValue"));
|
||||
|
||||
TArray<MCPProperty> Props = MergedProperties();
|
||||
if (!MCPJson::PopulateFromJson(Props, Json, true))
|
||||
return false;
|
||||
Save();
|
||||
|
||||
SaveFlags();
|
||||
if (bHasDefault)
|
||||
return SaveDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
void FBPVarEditor::Load()
|
||||
void FBPVarEditor::LoadFlags()
|
||||
{
|
||||
InstanceEditable = !(Desc->PropertyFlags & CPF_DisableEditOnInstance);
|
||||
BlueprintReadOnly = (Desc->PropertyFlags & CPF_BlueprintReadOnly) != 0;
|
||||
@@ -49,14 +64,21 @@ void FBPVarEditor::Load()
|
||||
ExposeOnSpawn = Desc->HasMetaData(FBlueprintMetadata::MD_ExposeOnSpawn);
|
||||
Private = Desc->HasMetaData(FBlueprintMetadata::MD_Private);
|
||||
|
||||
FString Tooltip;
|
||||
if (Desc->HasMetaData(TEXT("tooltip")))
|
||||
Description = Desc->GetMetaData(TEXT("tooltip"));
|
||||
else
|
||||
Description.Empty();
|
||||
}
|
||||
|
||||
void FBPVarEditor::Save() const
|
||||
void FBPVarEditor::LoadDefault()
|
||||
{
|
||||
if (DefaultValueProp)
|
||||
DefaultValue = DefaultValueProp.GetText();
|
||||
else
|
||||
DefaultValue.Empty();
|
||||
}
|
||||
|
||||
void FBPVarEditor::SaveFlags()
|
||||
{
|
||||
// CPF flags
|
||||
if (InstanceEditable)
|
||||
@@ -92,6 +114,13 @@ void FBPVarEditor::Save() const
|
||||
Desc->RemoveMetaData(TEXT("tooltip"));
|
||||
}
|
||||
|
||||
bool FBPVarEditor::SaveDefault()
|
||||
{
|
||||
if (DefaultValueProp)
|
||||
return DefaultValueProp.SetText(DefaultValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
TArray<MCPProperty> FBPVarEditor::MergedProperties()
|
||||
{
|
||||
TArray<MCPProperty> Props = MCPProperty::GetAll(
|
||||
@@ -106,5 +135,9 @@ TArray<MCPProperty> FBPVarEditor::MergedProperties()
|
||||
Props.Append(MCPProperty::GetAll(
|
||||
FBPVarEditor::StaticStruct(), this, (EPropertyFlags)0));
|
||||
|
||||
// Remove DefaultValue if we don't have a CDO property to back it.
|
||||
if (!DefaultValueProp)
|
||||
MCPProperty::Remove(Props, TEXT("DefaultValue"));
|
||||
|
||||
return Props;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,16 @@ struct FBPVarEditor
|
||||
GENERATED_BODY()
|
||||
|
||||
FBPVariableDescription* Desc = nullptr;
|
||||
MCPProperty DefaultValueProp;
|
||||
|
||||
FBPVarEditor() = default;
|
||||
FBPVarEditor(FBPVariableDescription* InDesc) : Desc(InDesc) {}
|
||||
FBPVarEditor(UBlueprint* BP, const FString& VarName);
|
||||
|
||||
bool NotFound() const { return Desc == nullptr; }
|
||||
|
||||
UPROPERTY(EditAnywhere, meta=(Optional, Description="Default value in Unreal text format"))
|
||||
FString DefaultValue;
|
||||
|
||||
UPROPERTY(EditAnywhere, meta=(Optional, Description="Variable description/tooltip"))
|
||||
FString Description;
|
||||
|
||||
@@ -41,13 +44,15 @@ struct FBPVarEditor
|
||||
bool ExposeToCinematics = false;
|
||||
|
||||
// Load from Desc, populate from JSON, save back to Desc.
|
||||
bool LoadJson(const FJsonObject* Json);
|
||||
bool ApplyJson(const FJsonObject* Json);
|
||||
|
||||
// Print all properties and their current values.
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
void Load();
|
||||
void Save() const;
|
||||
void LoadFlags();
|
||||
void LoadDefault();
|
||||
void SaveFlags();
|
||||
bool SaveDefault();
|
||||
TArray<MCPProperty> MergedProperties();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user