4#include "CoreMinimal.h"
5#include "Math/UnrealMathUtility.h"
6#include "UObject/Object.h"
7#include "UObject/UnrealType.h"
8#include "UObject/ObjectMacros.h"
15#include "DlgHelper.generated.h"
25 GENERATED_USTRUCT_BODY()
28 UClass* Class =
nullptr;
43 FORCEINLINE
const uint8* GetConstRawPtr(int32 Index = 0)
const
45 return const_cast<Self*
>(
this)->GetRawPtr(Index);
58 :
Super(InProperty, InMap) {}
63 return const_cast<Self*
>(
this)->GetKeyPtr(Index);
68 return const_cast<Self*
>(
this)->GetValuePtr(Index);
77template <
typename KeyType,
typename ValueType>
82 const TMap<KeyType, ValueType>& FirstMap,
83 const TMap<KeyType, ValueType>& SecondMap,
84 std::function<
bool(
const ValueType& FirstMapValue,
85 const ValueType& SecondMapValue)> AreValuesEqual
88 if (FirstMap.Num() == SecondMap.Num())
90 for (
const auto& ElemFirstMap : FirstMap)
92 const auto* FoundValueSecondMap = SecondMap.Find(ElemFirstMap.Key);
93 if (FoundValueSecondMap !=
nullptr)
96 if (!AreValuesEqual(ElemFirstMap.Value, *FoundValueSecondMap))
118template <
typename KeyType,
typename ValueType>
122 static bool IsEqual(
const TMap<KeyType, ValueType>& FirstMap,
const TMap<KeyType, ValueType>& SecondMap)
125 [](
const ValueType& FirstMapValue,
const ValueType& SecondMapValue) ->
bool
127 return FirstMapValue == SecondMapValue;
133template <
typename KeyType>
137 static bool IsEqual(
const TMap<KeyType, float>& FirstMap,
const TMap<KeyType, float>& SecondMap)
140 [](
const float& FirstMapValue,
const float& SecondMapValue) ->
bool
142 return FMath::IsNearlyEqual(FirstMapValue, SecondMapValue, KINDA_SMALL_NUMBER);
148template <
typename ArrayType>
153 const TArray<ArrayType>& FirstArray,
154 const TArray<ArrayType>& SecondArray,
155 std::function<
bool(
const ArrayType& FirstValue,
156 const ArrayType& SecondValue)> AreValuesEqual
159 if (FirstArray.Num() == SecondArray.Num())
162 for (int32 Index = 0; Index < FirstArray.Num(); Index++)
164 if (!AreValuesEqual(FirstArray[Index], SecondArray[Index]))
179template <
typename ArrayType>
183 static bool IsEqual(
const TArray<ArrayType>& FirstArray,
const TArray<ArrayType>& SecondArray)
186 [](
const ArrayType& FirstValue,
const ArrayType& SecondValue) ->
bool
188 return FirstValue == SecondValue;
198 static bool IsEqual(
const TArray<float>& FirstArray,
const TArray<float>& SecondArray)
201 [](
const float& FirstValue,
const float& SecondValue) ->
bool
203 return FMath::IsNearlyEqual(FirstValue, SecondValue, KINDA_SMALL_NUMBER);
216 FORCEINLINE
static int64 RandomInt64() {
return static_cast<int64
>(FMath::Rand()) << 32 | FMath::Rand(); }
217 FORCEINLINE
static bool IsFloatEqual(
const float A,
const float B) {
return FMath::IsNearlyEqual(A, B, KINDA_SMALL_NUMBER); }
218 FORCEINLINE
static bool IsPathInProjectDirectory(
const FString& Path) {
return Path.StartsWith(
"/Game"); }
224 return TEXT(
"nullptr");
233 return TEXT(
"INVALID CLASS");
245 static TSharedPtr<SDockTab> InvokeTab(TSharedPtr<FTabManager> TabManager,
const FTabId& TabID);
249 static FString CleanObjectName(FString
Name);
252 static bool IsClassIgnored(
const UClass* Class);
253 static bool IsABlueprintClass(
const UClass* Class);
257 static bool IsObjectAChildOf(
const UObject*
Object,
const UClass* ParentClass);
260 static bool IsObjectImplementingInterface(
const UObject*
Object,
const UClass* InterfaceClass);
264 static bool GetAllChildClassesOf(
const UClass* ParentClass, TArray<UClass*>& OutNativeClasses, TArray<UClass*>& OutBlueprintClasses);
268 static bool GetAllClassesImplementingInterface(
const UClass* InterfaceClass, TArray<UClass*>& OutNativeClasses, TArray<UClass*>& OutBlueprintClasses);
273 static TMap<FName, TArray<FDlgClassAndObject>> ConvertDialogueParticipantsClassesIntoMap(
const TArray<UClass*>& Classes);
276 static bool DeleteFile(
const FString& PathName,
bool bVerbose =
true);
277 static bool RenameFile(
const FString& OldPathName,
const FString& NewPathName,
bool bOverWrite =
false,
bool bVerbose =
true);
280 static FName GetFunctionNameForEventType(
EDlgEventType EventType)
285 return TEXT(
"OnDialogueEvent");
287 return TEXT(
"ModifyBoolValue");
289 return TEXT(
"ModifyFloatValue");
291 return TEXT(
"ModifyIntValue");
293 return TEXT(
"ModifyIntValue");
303 switch (ConditionType)
306 return TEXT(
"CheckCondition");
308 return TEXT(
"GetBoolValue");
310 return TEXT(
"GetFloatValue");
312 return TEXT(
"GetIntValue");
314 return TEXT(
"GetNameValue");
322 template<
typename TEnum>
323 static bool ConvertEnumToString(
const FString& EnumName, TEnum EnumValue,
bool bWithNameSpace, FString& OutEnumValue)
325 const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, *EnumName,
true);
328 OutEnumValue = FString::Printf(TEXT(
"INVALID EnumName = `%s`"), *EnumName);
332 OutEnumValue = bWithNameSpace ? EnumPtr->GetNameByIndex(
static_cast<int32
>(EnumValue)).ToString()
333 : EnumPtr->GetNameStringByIndex(
static_cast<int32
>(EnumValue));
337 template<
typename TEnum>
338 static bool ConvertStringToEnum(
const FString&
String,
const FString& EnumName, TEnum& OutEnumValue)
340 const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, *EnumName,
true);
346 const int32 Index = EnumPtr->GetIndexByNameString(
String);
347 OutEnumValue =
static_cast<TEnum
>(Index);
351 template<
typename TEnum>
352 static bool ConvertFNameToEnum(FName
Name,
const FString& EnumName, TEnum& OutEnumValue)
354 const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, *EnumName,
true);
360 const int32 Index = EnumPtr->GetIndexByName(
Name);
361 OutEnumValue =
static_cast<TEnum
>(Index);
366 template <
typename SetType>
367 static typename TCopyQualifiersFromTo<SetType, typename SetType::ElementType>::Type* GetFirstSetElement(SetType& Set)
369 for (
auto& Element : Set)
379 template <
typename SetType>
380 static bool IsSetEqual(
const TSet<SetType>& FirstSet,
const TSet<SetType>& SecondSet)
382 if (FirstSet.Num() == SecondSet.Num())
385 TSet<SetType> Set = FirstSet;
386 Set.Append(SecondSet);
388 return Set.Num() == FirstSet.Num();
395 template <
typename ArrayType>
396 static bool IsArrayEqual(
const TArray<ArrayType>& FirstArray,
const TArray<ArrayType>& SecondArray,
397 std::function<
bool(
const ArrayType& FirstValue,
const ArrayType& SecondValue)> AreValuesEqual)
403 template <
typename ArrayType>
404 static bool IsArrayEqual(
const TArray<ArrayType>& FirstArray,
const TArray<ArrayType>& SecondArray)
410 template <
typename ArrayType>
411 static bool IsArrayOfPointersEqual(
const TArray<ArrayType*>& FirstArray,
const TArray<ArrayType*>& SecondArray)
414 [](
const auto* FirstValue,
const auto* SecondValue) ->
bool
416 if (FirstValue ==
nullptr)
418 return SecondValue ==
nullptr;
420 return *FirstValue == *SecondValue;
425 template <
typename KeyType,
typename ValueType>
426 static bool IsMapEqual(
const TMap<KeyType, ValueType>& FirstMap,
const TMap<KeyType, ValueType>& SecondMap,
427 std::function<
bool(
const ValueType& FirstMapValue,
const ValueType& SecondMapValue)> AreValuesEqual)
433 template <
typename KeyType,
typename ValueType>
434 static bool IsMapEqual(
const TMap<KeyType, ValueType>& FirstMap,
const TMap<KeyType, ValueType>& SecondMap)
440 static bool PredicateSortFNameAlphabeticallyAscending(FName A, FName B)
442 return A.Compare(B) < 0;
446 static void SortDefault(TArray<FName>& OutArray)
448 OutArray.Sort(PredicateSortFNameAlphabeticallyAscending);
450 static void SortDefault(TSet<FName>& OutSet)
452 OutSet.Sort(PredicateSortFNameAlphabeticallyAscending);
455 template<
typename ValueType>
458 Map.KeySort(PredicateSortFNameAlphabeticallyAscending);
462 static void AppendSortedSetToArray(
const TSet<FName>& InSet, TArray<FName>& OutArray)
464 TArray<FName> UniqueNamesArray = InSet.Array();
465 SortDefault(UniqueNamesArray);
466 OutArray.Append(UniqueNamesArray);
469 FORCEINLINE
static bool IsPossiblyAllocatedUObjectPointer(
const void* Ptr)
471 auto CountByteValues = [](UPTRINT Val, UPTRINT ByteVal) -> int32
475 for (int32 I = 0; I !=
sizeof(UPTRINT); ++I)
477 if ((Val & 0xFF) == ByteVal)
487 const UPTRINT PtrVal = (UPTRINT)Ptr;
489 return Ptr !=
nullptr && Ptr != ((
void*) - 1) && PtrVal >= 0x1000 && CountByteValues(PtrVal, 0xCD) <
sizeof(UPTRINT) / 2;
502 if (!::IsPossiblyAllocatedUObjectPointer(
const_cast<UObject*
>(
Object)))
508 static const int32 AlignmentCheck = MIN_ALIGNMENT - 1;
509 if ((UPTRINT)
Object & AlignmentCheck)
519 if ((
void**)
Object ==
nullptr || *(
void**)
Object ==
nullptr)
524 if (!
Object->IsValidLowLevelFast())
529 return !
Object->IsPendingKillOrUnreachable();
EDlgConditionType
UENUM(BlueprintType)
EDlgEventType
UENUM(BlueprintType)
UMapProperty FNYMapProperty
UArrayProperty FNYArrayProperty
FDlgConstScriptArrayHelper Self
FORCEINLINE FDlgConstScriptArrayHelper(const FNYArrayProperty *InProperty, const void *InArray)
FORCEINLINE const uint8 * GetConstRawPtr(int32 Index=0) const
FDlgConstScriptMapHelper Self
FORCEINLINE FDlgConstScriptMapHelper(const FNYMapProperty *InProperty, const void *InMap)
FORCEINLINE const uint8 * GetConstValuePtr(int32 Index) const
FORCEINLINE const uint8 * GetConstKeyPtr(int32 Index) const
static bool IsEqual(const TArray< ArrayType > &FirstArray, const TArray< ArrayType > &SecondArray, std::function< bool(const ArrayType &FirstValue, const ArrayType &SecondValue)> AreValuesEqual)
static bool IsEqual(const TArray< float > &FirstArray, const TArray< float > &SecondArray)
static bool IsEqual(const TArray< ArrayType > &FirstArray, const TArray< ArrayType > &SecondArray)
static bool IsEqual(const TMap< KeyType, ValueType > &FirstMap, const TMap< KeyType, ValueType > &SecondMap, std::function< bool(const ValueType &FirstMapValue, const ValueType &SecondMapValue)> AreValuesEqual)
static bool IsEqual(const TMap< KeyType, float > &FirstMap, const TMap< KeyType, float > &SecondMap)
static bool IsEqual(const TMap< KeyType, ValueType > &FirstMap, const TMap< KeyType, ValueType > &SecondMap)
static FORCEINLINE bool IsPathInProjectDirectory(const FString &Path)
static bool IsArrayOfPointersEqual(const TArray< ArrayType * > &FirstArray, const TArray< ArrayType * > &SecondArray)
static bool ConvertStringToEnum(const FString &String, const FString &EnumName, TEnum &OutEnumValue)
static bool ConvertEnumToString(const FString &EnumName, TEnum EnumValue, bool bWithNameSpace, FString &OutEnumValue)
static FORCEINLINE bool IsFloatEqual(const float A, const float B)
static bool IsValidLowLevel(const UObject *Object)
static bool IsMapEqual(const TMap< KeyType, ValueType > &FirstMap, const TMap< KeyType, ValueType > &SecondMap)
static void SortDefault(TArray< FName > &OutArray)
static FString GetFullNameFromObject(const UObject *Object)
static FName GetFunctionNameForConditionType(EDlgConditionType ConditionType)
static bool IsSetEqual(const TSet< SetType > &FirstSet, const TSet< SetType > &SecondSet)
static bool PredicateSortFNameAlphabeticallyAscending(FName A, FName B)
static FString GetClassNameFromObject(const UObject *Object)
static FName GetFunctionNameForEventType(EDlgEventType EventType)
static void AppendSortedSetToArray(const TSet< FName > &InSet, TArray< FName > &OutArray)
static TCopyQualifiersFromTo< SetType, typenameSetType::ElementType >::Type * GetFirstSetElement(SetType &Set)
static void SortDefault(TMap< FName, ValueType > &Map)
static bool ConvertFNameToEnum(FName Name, const FString &EnumName, TEnum &OutEnumValue)
static void SortDefault(TSet< FName > &OutSet)
static FORCEINLINE bool IsPossiblyAllocatedUObjectPointer(const void *Ptr)
static bool IsArrayEqual(const TArray< ArrayType > &FirstArray, const TArray< ArrayType > &SecondArray)
static bool IsArrayEqual(const TArray< ArrayType > &FirstArray, const TArray< ArrayType > &SecondArray, std::function< bool(const ArrayType &FirstValue, const ArrayType &SecondValue)> AreValuesEqual)
static bool IsMapEqual(const TMap< KeyType, ValueType > &FirstMap, const TMap< KeyType, ValueType > &SecondMap, std::function< bool(const ValueType &FirstMapValue, const ValueType &SecondMapValue)> AreValuesEqual)
static FORCEINLINE int64 RandomInt64()
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
UObject * Object
UPROPERTY()
UClass * Class
UPROPERTY()