/ Source / ReasonablePlanningAIEditor / Private / ResonablePlanningAIEditor.cpp
ResonablePlanningAIEditor.cpp
  1  // Copyright (C) 2025 Radaway Software LLC. All Rights Reserved.
  2  
  3  #include "ReasonablePlanningAIEditor.h"
  4  #include "StateKeyValueReferenceCustom.h"
  5  #include "StateQueryComparisonCustom.h"
  6  #include "StateTypePropertyMultiBindCustom.h"
  7  #include "ComposerBehaviorCustom.h"
  8  #include "Core/RpaiTypes.h"
  9  #include "Composer/RpaiComposerBehavior.h"
 10  #include "Composer/Queries/RpaiStateQuery_CompareToBool.h"
 11  #include "Composer/Queries/RpaiStateQuery_CompareToDistance.h"
 12  #include "Composer/Queries/RpaiStateQuery_CompareToFloat.h"
 13  #include "Composer/Queries/RpaiStateQuery_CompareToInteger.h"
 14  #include "Composer/Queries/RpaiStateQuery_CompareToStateValue.h"
 15  #include "ComposerBehaviorAssetTypeActions.h"
 16  #include "ComposerStateQueryCustom.h"
 17  
 18  #define LOCTEXT_NAMESPACE "ResonablePlanningAIEditor"
 19  
 20  static const FName RpaiMenuCategoryKey(TEXT("Reasonable Planning AI"));
 21  static const FText RpaiMenuCategoryText(NSLOCTEXT("RpaiEditor", "AssetCategory", "Reasonable Planning AI"));
 22  
 23  struct FReasonablePlanningAIEditorModule : public IReasonablePlanningAIEditorModule
 24  {
 25     EAssetTypeCategories::Type ModuleAssetCategoryBit;
 26     TSharedPtr<FComposerBehaviorAssetTypeActions> ComposerBehaviorAssetTypeActions;
 27  
 28     FReasonablePlanningAIEditorModule()
 29        : ModuleAssetCategoryBit(EAssetTypeCategories::Type::Misc)
 30     {
 31  
 32     }
 33  
 34     virtual void StartupModule() override
 35     {
 36        ComposerStateQueryCustom::AddChildCustomization(URpaiStateQuery_CompareToBool::StaticClass()->GetFName(), StateQueryComparisonCustom::MakePropertyInstance(TEXT("bValueToCompare")));
 37        ComposerStateQueryCustom::AddChildCustomization(URpaiStateQuery_CompareToDistance::StaticClass()->GetFName(), StateQueryComparisonCustom::MakePropertyInstance(TEXT("Distance")));
 38        ComposerStateQueryCustom::AddChildCustomization(URpaiStateQuery_CompareToFloat::StaticClass()->GetFName(), StateQueryComparisonCustom::MakePropertyInstance(TEXT("ValueToCompare")));
 39        ComposerStateQueryCustom::AddChildCustomization(URpaiStateQuery_CompareToInteger::StaticClass()->GetFName(), StateQueryComparisonCustom::MakePropertyInstance(TEXT("ValueToCompare")));
 40        ComposerStateQueryCustom::AddChildCustomization(URpaiStateQuery_CompareToStateValue::StaticClass()->GetFName(), StateQueryComparisonCustom::MakePropertyInstance(TEXT("ComparedToState")));
 41  
 42        FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
 43        PropertyModule.RegisterCustomPropertyTypeLayout(FStateKeyValueReference::StaticStruct()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateKeyValueReferenceCustom::MakeInstance));
 44        PropertyModule.RegisterCustomPropertyTypeLayout(FRpaiStateTypePropertyMultiBind::StaticStruct()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateTypePropertyMultiBindCustom::MakeInstance));
 45        PropertyModule.RegisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToBool::StaticClass()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakePropertyInstance, FName(TEXT("bValueToCompare"))));
 46        PropertyModule.RegisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToDistance::StaticClass()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakePropertyInstance, FName(TEXT("Distance"))));
 47        PropertyModule.RegisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToFloat::StaticClass()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakePropertyInstance, FName(TEXT("ValueToCompare"))));
 48        PropertyModule.RegisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToInteger::StaticClass()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakePropertyInstance, FName(TEXT("ValueToCompare"))));
 49        PropertyModule.RegisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToStateValue::StaticClass()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakePropertyInstance, FName(TEXT("ComparedToState"))));
 50        PropertyModule.RegisterCustomPropertyTypeLayout(URpaiComposerStateQuery::StaticClass()->GetFName(), FOnGetPropertyTypeCustomizationInstance::CreateStatic(&ComposerStateQueryCustom::MakeInstance));
 51  
 52        PropertyModule.RegisterCustomClassLayout(URpaiStateQuery_CompareToBool::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakeInstance, FName(TEXT("bValueToCompare"))));
 53        PropertyModule.RegisterCustomClassLayout(URpaiStateQuery_CompareToDistance::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakeInstance, FName(TEXT("Distance"))));
 54        PropertyModule.RegisterCustomClassLayout(URpaiStateQuery_CompareToFloat::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakeInstance, FName(TEXT("ValueToCompare"))));
 55        PropertyModule.RegisterCustomClassLayout(URpaiStateQuery_CompareToInteger::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakeInstance, FName(TEXT("ValueToCompare"))));
 56        PropertyModule.RegisterCustomClassLayout(URpaiStateQuery_CompareToStateValue::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&StateQueryComparisonCustom::MakeInstance, FName(TEXT("ComparedToState"))));
 57        PropertyModule.RegisterCustomClassLayout(URpaiComposerBehavior::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&ComposerBehaviorCustom::MakeInstance));
 58        PropertyModule.NotifyCustomizationModuleChanged();
 59  
 60        IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
 61  
 62        ModuleAssetCategoryBit = AssetTools.RegisterAdvancedAssetCategory(RpaiMenuCategoryKey, RpaiMenuCategoryText);
 63  
 64        ComposerBehaviorAssetTypeActions = MakeShared<FComposerBehaviorAssetTypeActions>(ModuleAssetCategoryBit);
 65        FAssetToolsModule::GetModule().Get().RegisterAssetTypeActions(ComposerBehaviorAssetTypeActions.ToSharedRef());
 66     }
 67  
 68     virtual void ShutdownModule() override
 69     {
 70        if (FModuleManager::Get().IsModuleLoaded("PropertyEditor"))
 71        {
 72           FPropertyEditorModule& PropertyModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
 73           PropertyModule.UnregisterCustomClassLayout(URpaiComposerBehavior::StaticClass()->GetFName());
 74           PropertyModule.UnregisterCustomClassLayout(URpaiStateQuery_CompareToBool::StaticClass()->GetFName());
 75           PropertyModule.UnregisterCustomClassLayout(URpaiStateQuery_CompareToDistance::StaticClass()->GetFName());
 76           PropertyModule.UnregisterCustomClassLayout(URpaiStateQuery_CompareToFloat::StaticClass()->GetFName());
 77           PropertyModule.UnregisterCustomClassLayout(URpaiStateQuery_CompareToInteger::StaticClass()->GetFName());
 78           PropertyModule.UnregisterCustomClassLayout(URpaiStateQuery_CompareToStateValue::StaticClass()->GetFName());
 79           PropertyModule.UnregisterCustomClassLayout(URpaiComposerStateQuery::StaticClass()->GetFName());
 80  
 81           PropertyModule.UnregisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToBool::StaticClass()->GetFName());
 82           PropertyModule.UnregisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToDistance::StaticClass()->GetFName());
 83           PropertyModule.UnregisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToFloat::StaticClass()->GetFName());
 84           PropertyModule.UnregisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToInteger::StaticClass()->GetFName());
 85           PropertyModule.UnregisterCustomPropertyTypeLayout(URpaiStateQuery_CompareToStateValue::StaticClass()->GetFName());
 86           PropertyModule.UnregisterCustomPropertyTypeLayout(FStateKeyValueReference::StaticStruct()->GetFName());
 87           PropertyModule.UnregisterCustomPropertyTypeLayout(FRpaiStateTypePropertyMultiBind::StaticStruct()->GetFName());
 88           PropertyModule.NotifyCustomizationModuleChanged();
 89        }
 90  
 91        if (FModuleManager::Get().IsModuleLoaded("AssetTools"))
 92        {
 93           FAssetToolsModule::GetModule().Get().UnregisterAssetTypeActions(ComposerBehaviorAssetTypeActions.ToSharedRef());
 94        }
 95     }
 96  };
 97  
 98  IMPLEMENT_MODULE(FReasonablePlanningAIEditorModule, IReasonablePlanningAIEditorModule)
 99  
100  #undef LOCTEXT_NAMESPACE