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