// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "PropertyEditorModule.h" #include "Editor.h" #include "PropertyHandle.h" #include "ZoneGraphTypes.h" #include "Misc/Guid.h" class IPropertyHandle; #define LOCTEXT_NAMESPACE "ZoneGraphEditor" namespace UE::ZoneGraph::PropertyUtils { // Expects T is struct. template TOptional GetValue(const TSharedPtr& ValueProperty) { if (!ValueProperty) { return TOptional(); } FStructProperty* StructProperty = CastFieldChecked(ValueProperty->GetProperty()); if (!StructProperty) { return TOptional(); } if (StructProperty->Struct != TBaseStructure::Get()) { return TOptional(); } T Value = T(); bool bValueSet = false; TArray RawData; ValueProperty->AccessRawData(RawData); for (void* Data : RawData) { if (Data) { T CurValue = *reinterpret_cast(Data); if (!bValueSet) { bValueSet = true; Value = CurValue; } else if (CurValue != Value) { // Multiple values return TOptional(); } } } return TOptional(Value); } // Expects T is struct. template void SetValue(TSharedPtr& ValueProperty, T NewValue, EPropertyValueSetFlags::Type Flags = 0) { if (!ValueProperty) { return; } FStructProperty* StructProperty = CastFieldChecked(ValueProperty->GetProperty()); if (!StructProperty) { return; } if (StructProperty->Struct != TBaseStructure::Get()) { return; } const bool bTransactable = (Flags & EPropertyValueSetFlags::NotTransactable) == 0; bool bNotifiedPreChange = false; TArray RawData; ValueProperty->AccessRawData(RawData); for (void* Data : RawData) { if (Data) { if (!bNotifiedPreChange) { if (bTransactable && GEditor) { GEditor->BeginTransaction(FText::Format(LOCTEXT("SetPropertyValue", "Set {0}"), ValueProperty->GetPropertyDisplayName())); } ValueProperty->NotifyPreChange(); bNotifiedPreChange = true; } T* Value = reinterpret_cast(Data); *Value = NewValue; } } if (bNotifiedPreChange) { ValueProperty->NotifyPostChange(EPropertyChangeType::ValueSet); if (bTransactable && GEditor) { GEditor->EndTransaction(); } } ValueProperty->NotifyFinishedChangingProperties(); } FLinearColor GetMaskColor(TSharedPtr MaskProperty); FText GetMaskDescription(TSharedPtr MaskProperty); } // UE::ZoneGraph::PropertyUtils #undef LOCTEXT_NAMESPACE