diff --git a/Content/Example/BP_InteractionExample_Character.uasset b/Content/Example/BP_InteractionExample_Character.uasset index c4f60c3..da5e29e 100644 Binary files a/Content/Example/BP_InteractionExample_Character.uasset and b/Content/Example/BP_InteractionExample_Character.uasset differ diff --git a/Content/Example/BP_InteractionExample_NPC.uasset b/Content/Example/BP_InteractionExample_NPC.uasset index 3082853..cc8deef 100644 Binary files a/Content/Example/BP_InteractionExample_NPC.uasset and b/Content/Example/BP_InteractionExample_NPC.uasset differ diff --git a/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp b/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp index e077333..b2902ae 100644 --- a/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp +++ b/Source/ActorInteractionPlugin/Private/Components/Interactable/ActorInteractableComponentBase.cpp @@ -66,20 +66,6 @@ UActorInteractableComponentBase::UActorInteractableComponentBase() : #if WITH_EDITORONLY_DATA bVisualizeComponent = true; #endif - -#if WITH_EDITOR && !UE_GAME - - if (!bInteractableInitialized) - { - if (GetOwner() == nullptr) - { - SetDefaultValues(); - } - - bInteractableInitialized = true; - } -#endif - } void UActorInteractableComponentBase::BeginPlay() @@ -200,9 +186,7 @@ void UActorInteractableComponentBase::InitWidget() void UActorInteractableComponentBase::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); } void UActorInteractableComponentBase::OnComponentCreated() diff --git a/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h b/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h index 429faaa..bdbe668 100644 --- a/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h +++ b/Source/ActorInteractionPlugin/Public/Components/Interactable/ActorInteractableComponentBase.h @@ -241,9 +241,9 @@ class ACTORINTERACTIONPLUGIN_API UActorInteractableComponentBase : public UWidge /** * Overrides data with default values from Project Settings. - * Interactable Defaults are set automatically! + * Project Settings must be defined! */ - UFUNCTION(BlueprintCallable, CallInEditor, Category="MounteaInteraction") + UFUNCTION(BlueprintCallable, Category="MounteaInteraction") void SetDefaultValues(); #endif diff --git a/Source/ActorInteractionPluginEditor/Private/ActorInteractionPluginEditor.cpp b/Source/ActorInteractionPluginEditor/Private/ActorInteractionPluginEditor.cpp index c8ee9a5..6568ef0 100644 --- a/Source/ActorInteractionPluginEditor/Private/ActorInteractionPluginEditor.cpp +++ b/Source/ActorInteractionPluginEditor/Private/ActorInteractionPluginEditor.cpp @@ -22,6 +22,7 @@ #include "ToolMenus.h" #include "AssetActions/InteractionSettingsConfig.h" +#include "DetailsPanel/MounteaInteractableBase_DetailsPanel.h" #include "Helpers/MounteaInteractionSystemEditorLog.h" #include "Interfaces/IHttpResponse.h" @@ -138,6 +139,25 @@ void FActorInteractionPluginEditor::StartupModule() ); } + // Register Custom Detail Panels + { + FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked("PropertyEditor"); + { + TArray CustomClassLayouts = + { + FOnGetDetailCustomizationInstance::CreateStatic(&MounteaInteractableBase_DetailsPanel::MakeInstance), + }; + RegisteredCustomClassLayouts = + { + UActorInteractableComponentBase::StaticClass()->GetFName(), + }; + for (int32 i = 0; i < RegisteredCustomClassLayouts.Num(); i++) + { + PropertyModule.RegisterCustomClassLayout(RegisteredCustomClassLayouts[i], CustomClassLayouts[i]); + } + } + } + // Register Help Button { FAIntPHelpStyle::Initialize(); diff --git a/Source/ActorInteractionPluginEditor/Private/DetailsPanel/MounteaInteractableBase_DetailsPanel.cpp b/Source/ActorInteractionPluginEditor/Private/DetailsPanel/MounteaInteractableBase_DetailsPanel.cpp new file mode 100644 index 0000000..5d2429d --- /dev/null +++ b/Source/ActorInteractionPluginEditor/Private/DetailsPanel/MounteaInteractableBase_DetailsPanel.cpp @@ -0,0 +1,72 @@ +// All rights reserved Dominik Morse (Pavlicek) 2024 + +#include "MounteaInteractableBase_DetailsPanel.h" +#include "DetailCategoryBuilder.h" +#include "DetailLayoutBuilder.h" +#include "DetailWidgetRow.h" +#include "Components/Interactable/ActorInteractableComponentBase.h" +#include "Widgets/Layout/SScaleBox.h" + +#define LOCTEXT_NAMESPACE "InteractableComponentsPanel" + +void MounteaInteractableBase_DetailsPanel::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) +{ + TArray> ObjectsBeingCustomized; + DetailBuilder.GetObjectsBeingCustomized(ObjectsBeingCustomized); + + // Only support one object being customized + if (ObjectsBeingCustomized.Num() != 1) return; + + const TWeakObjectPtr weakComponent = Cast(ObjectsBeingCustomized[0].Get()); + if (!weakComponent.IsValid()) return; + + EditingComponent = weakComponent.Get(); + if (!EditingComponent) return; + + // Only edit if editing from Actor Editor + /*if (DetailBuilder.GetBaseClass()->IsChildOf(AActor::StaticClass()) == false) + { return; };*/ + + IDetailCategoryBuilder& ItrCategoryBuild = DetailBuilder.EditCategory(TEXT("MounteaInteraction"), FText::GetEmpty(), ECategoryPriority::Important); + ItrCategoryBuild.AddCustomRow(LOCTEXT("InteractableComponentsPanel_Defaults", "Load Defaults"), false) + .WholeRowWidget + [ + SNew(SBox) + .HAlign(HAlign_Fill) + [ + SNew(SScaleBox) + .HAlign(EHorizontalAlignment::HAlign_Fill) + .Stretch(EStretch::ScaleToFit) + [ + SAssignNew(DefaultsButton, SButton) + .HAlign(HAlign_Fill) + .Text(LOCTEXT("InteractableComponentsPanel_Defaults_Text", "Load Defaults")) + .ToolTipText(LOCTEXT("InteractableComponentsPanel_Defaults_Tooltip", "Overrides data with default values from Project Settings.\nProject Settings must be defined!")) + .OnClicked(this, &MounteaInteractableBase_DetailsPanel::OnDefaultsClicked) + .OnHovered(this, &MounteaInteractableBase_DetailsPanel::OnDefaultsHovered) + .OnUnhovered(this, &MounteaInteractableBase_DetailsPanel::OnDefaultsHovered) + + ] + ] + ]; +} + +FReply MounteaInteractableBase_DetailsPanel::OnDefaultsClicked() const +{ + if (EditingComponent) + { + EditingComponent->SetDefaultValues(); + + if (SavedLayoutBuilder) SavedLayoutBuilder->ForceRefreshDetails(); + + return FReply::Handled(); + } + return FReply::Unhandled(); +} + +void MounteaInteractableBase_DetailsPanel::OnDefaultsHovered() +{ + +} + +#undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/Source/ActorInteractionPluginEditor/Private/DetailsPanel/MounteaInteractableBase_DetailsPanel.h b/Source/ActorInteractionPluginEditor/Private/DetailsPanel/MounteaInteractableBase_DetailsPanel.h new file mode 100644 index 0000000..64fc8df --- /dev/null +++ b/Source/ActorInteractionPluginEditor/Private/DetailsPanel/MounteaInteractableBase_DetailsPanel.h @@ -0,0 +1,31 @@ +// All rights reserved Dominik Morse (Pavlicek) 2024 + +#pragma once + +#include "IDetailCustomization.h" + +class UActorInteractableComponentBase; + +class MounteaInteractableBase_DetailsPanel : public IDetailCustomization +{ + typedef MounteaInteractableBase_DetailsPanel Self; + +public: + // Makes a new instance of this detail layout class for a specific detail view requesting it + static TSharedRef MakeInstance() { return MakeShared(); } + + // IDetailCustomization interface + /** Called when details should be customized */ + virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override; + + FReply OnDefaultsClicked() const; + void OnDefaultsHovered(); + +private: + + IDetailLayoutBuilder* SavedLayoutBuilder = nullptr; + + UActorInteractableComponentBase* EditingComponent = nullptr; + + TSharedPtr DefaultsButton; +}; diff --git a/Source/ActorInteractionPluginEditor/Private/Factories/InteractableComponentAssetFactory.cpp b/Source/ActorInteractionPluginEditor/Private/Factories/InteractableComponentAssetFactory.cpp index 0c37298..bf6c325 100644 --- a/Source/ActorInteractionPluginEditor/Private/Factories/InteractableComponentAssetFactory.cpp +++ b/Source/ActorInteractionPluginEditor/Private/Factories/InteractableComponentAssetFactory.cpp @@ -10,7 +10,7 @@ #include "Kismet2/KismetEditorUtilities.h" #include "Engine/DataTable.h" -#define LOCTEXT_NAMESPACE "ActorInteraction" +#define LOCTEXT_NAMESPACE "InteractableComponentAssetFactory" UInteractableComponentAssetFactory::UInteractableComponentAssetFactory(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { diff --git a/Source/ActorInteractionPluginEditor/Public/ActorInteractionPluginEditor.h b/Source/ActorInteractionPluginEditor/Public/ActorInteractionPluginEditor.h index c8d6a52..85da3d8 100644 --- a/Source/ActorInteractionPluginEditor/Public/ActorInteractionPluginEditor.h +++ b/Source/ActorInteractionPluginEditor/Public/ActorInteractionPluginEditor.h @@ -46,6 +46,6 @@ class FActorInteractionPluginEditor : public IModuleInterface private: TSharedPtr PluginCommands; - + TArray RegisteredCustomClassLayouts; FHttpModule* Http; };