From eb2e75f1276ded722ecf46592b10b7e036449f01 Mon Sep 17 00:00:00 2001 From: Maxime Date: Wed, 2 Aug 2023 20:46:26 +0200 Subject: [PATCH] Prototype of triggers and interaction --- Pawn_Unreal/Content/Characters/BP_Judy.uasset | 4 +- .../Developers/maxim/BP_TriggerTest.uasset | 3 + .../Editor/EditorResources/CameraModule.png | 3 + .../CameraTransitionModule.png | 3 + .../CameraTransitionModule.uasset | 3 + .../EditorResources/S_CameraModule.uasset | 4 +- .../EditorResources/S_CameraTransition.uasset | 3 - .../Editor/EditorResources/S_Trigger.uasset | 3 + .../Editor/EditorResources/Trigger.png | 3 + .../Input/BP_MainPlayerController.uasset | 4 +- Pawn_Unreal/Content/Input/IA_Interact.uasset | 3 + Pawn_Unreal/Content/Input/IMC_Judy.uasset | 4 +- .../Systems/Camera/BP_CameraModule.uasset | 4 +- .../Camera/BP_CameraTransitionModule.uasset | 4 +- .../Instances/Manny/MI_Manny_01.uasset | 4 +- .../Instances/Manny/MI_Manny_02.uasset | 4 +- .../4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset | 3 + .../8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset | 3 + .../Pawn/Private/Interaction/PwnTrigger.cpp | 47 +++++++++++++++ .../Interaction/PwnTriggerRegister.cpp | 46 +++++++++++++++ .../Pawn/Public/Interaction/PwnTrigger.h | 40 +++++++++++++ .../Public/Interaction/PwnTriggerRegister.h | 43 ++++++++++++++ .../Source/PawnEditor/PawnEditorModule.cpp | 9 ++- Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp | 59 +++++++++++++++++++ Pawn_Unreal/Source/PawnEditor/PwnStyle.h | 22 +++++++ 25 files changed, 307 insertions(+), 21 deletions(-) create mode 100644 Pawn_Unreal/Content/Developers/maxim/BP_TriggerTest.uasset create mode 100644 Pawn_Unreal/Content/Editor/EditorResources/CameraModule.png create mode 100644 Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.png create mode 100644 Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.uasset delete mode 100644 Pawn_Unreal/Content/Editor/EditorResources/S_CameraTransition.uasset create mode 100644 Pawn_Unreal/Content/Editor/EditorResources/S_Trigger.uasset create mode 100644 Pawn_Unreal/Content/Editor/EditorResources/Trigger.png create mode 100644 Pawn_Unreal/Content/Input/IA_Interact.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset create mode 100644 Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset create mode 100644 Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTrigger.cpp create mode 100644 Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTriggerRegister.cpp create mode 100644 Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTrigger.h create mode 100644 Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTriggerRegister.h create mode 100644 Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp create mode 100644 Pawn_Unreal/Source/PawnEditor/PwnStyle.h diff --git a/Pawn_Unreal/Content/Characters/BP_Judy.uasset b/Pawn_Unreal/Content/Characters/BP_Judy.uasset index e022d4b..782ae3a 100644 --- a/Pawn_Unreal/Content/Characters/BP_Judy.uasset +++ b/Pawn_Unreal/Content/Characters/BP_Judy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bfc93d8e528f1906e4a4b8f4860b3c0a7e0ffb46cf502da706a0f2e03eb8c42b -size 52573 +oid sha256:a44e15b91ac56ffb61767818625e35481f61b72dfb621b088211bb0e089ae4f0 +size 97296 diff --git a/Pawn_Unreal/Content/Developers/maxim/BP_TriggerTest.uasset b/Pawn_Unreal/Content/Developers/maxim/BP_TriggerTest.uasset new file mode 100644 index 0000000..8d46ede --- /dev/null +++ b/Pawn_Unreal/Content/Developers/maxim/BP_TriggerTest.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73d72c783d6e954807ab780c4aca2325e966dc6183d47d1b34570f451595dab9 +size 109860 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/CameraModule.png b/Pawn_Unreal/Content/Editor/EditorResources/CameraModule.png new file mode 100644 index 0000000..3646f93 --- /dev/null +++ b/Pawn_Unreal/Content/Editor/EditorResources/CameraModule.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2a9980e7a036eaf991f44375b0210c3e1e044054ebe61fc1f3abcb9c41b5c33 +size 4467 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.png b/Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.png new file mode 100644 index 0000000..8c322c0 --- /dev/null +++ b/Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9bc8b501c496813be51425521d76954f3f192d7ebd6ddd05c9a944f5c7b204d +size 5887 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.uasset b/Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.uasset new file mode 100644 index 0000000..2d2faca --- /dev/null +++ b/Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a894ae129a0436439eadccfc748d1e04b141d54cca830e3322ba9fe04b720497 +size 12307 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/S_CameraModule.uasset b/Pawn_Unreal/Content/Editor/EditorResources/S_CameraModule.uasset index 713dd04..bff8c22 100644 --- a/Pawn_Unreal/Content/Editor/EditorResources/S_CameraModule.uasset +++ b/Pawn_Unreal/Content/Editor/EditorResources/S_CameraModule.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ad0c5c8ac608e1cab9dd15d9d657c5dd5e645cb02d0f4880fba971124a5a7964 -size 13510 +oid sha256:bcfa9bd2d7a9df6fd340eff2940565418ab92d007aa11ea6b4ec4a1ee91dac9f +size 9947 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/S_CameraTransition.uasset b/Pawn_Unreal/Content/Editor/EditorResources/S_CameraTransition.uasset deleted file mode 100644 index 69d1cf9..0000000 --- a/Pawn_Unreal/Content/Editor/EditorResources/S_CameraTransition.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c75dfab78fbe25ab4e0b9cacb11e914a0343a3976e0095d1fb9a0b537a6fbf62 -size 15838 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/S_Trigger.uasset b/Pawn_Unreal/Content/Editor/EditorResources/S_Trigger.uasset new file mode 100644 index 0000000..d01e804 --- /dev/null +++ b/Pawn_Unreal/Content/Editor/EditorResources/S_Trigger.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e83f37336118fd86d6d6888c39614dcea9e9ffbe79ca00b1c403e749032e6d10 +size 8082 diff --git a/Pawn_Unreal/Content/Editor/EditorResources/Trigger.png b/Pawn_Unreal/Content/Editor/EditorResources/Trigger.png new file mode 100644 index 0000000..3743c37 --- /dev/null +++ b/Pawn_Unreal/Content/Editor/EditorResources/Trigger.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81c494fdc76035891f7d6a3ab4b1ca05be3fef95f7fde3df646bc22b3fbe5ace +size 1812 diff --git a/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset b/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset index d193833..e432989 100644 --- a/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset +++ b/Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8b5c9ee4a8066b511ef6a01b4c12a0f3473327fb6ec112c6ea50b73361f168f5 -size 99543 +oid sha256:19e8e0064886d3e43537a4da6384d38421c4c82ba7a3f6ea191542981c775986 +size 107073 diff --git a/Pawn_Unreal/Content/Input/IA_Interact.uasset b/Pawn_Unreal/Content/Input/IA_Interact.uasset new file mode 100644 index 0000000..ba1dc54 --- /dev/null +++ b/Pawn_Unreal/Content/Input/IA_Interact.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e0ebcee9d13b7f29d3884b3364ba072a2ba18d8c1b47d57fbfded4cb07c4498 +size 1334 diff --git a/Pawn_Unreal/Content/Input/IMC_Judy.uasset b/Pawn_Unreal/Content/Input/IMC_Judy.uasset index 19df00c..e86f722 100644 --- a/Pawn_Unreal/Content/Input/IMC_Judy.uasset +++ b/Pawn_Unreal/Content/Input/IMC_Judy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:510a06aed58e1484c8c69b2cd6ce1e444730473c9b63def214f9ad18f450a855 -size 6098 +oid sha256:9ee32e50cfcc8a3a6ec74a0ac5256f7638975486b8f9a176a47283a601b15fc5 +size 7470 diff --git a/Pawn_Unreal/Content/Systems/Camera/BP_CameraModule.uasset b/Pawn_Unreal/Content/Systems/Camera/BP_CameraModule.uasset index f322d35..cdc259e 100644 --- a/Pawn_Unreal/Content/Systems/Camera/BP_CameraModule.uasset +++ b/Pawn_Unreal/Content/Systems/Camera/BP_CameraModule.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:78d32a57f9090f8a921369fbcfcc18abae61e0e4e909d6586f371eea2d6bef38 -size 118439 +oid sha256:3eae1712e3dd064ea4e5a1871eaf21e6ca292066c02132260d5606bebeb64e38 +size 119605 diff --git a/Pawn_Unreal/Content/Systems/Camera/BP_CameraTransitionModule.uasset b/Pawn_Unreal/Content/Systems/Camera/BP_CameraTransitionModule.uasset index 2e0efe1..bbc9884 100644 --- a/Pawn_Unreal/Content/Systems/Camera/BP_CameraTransitionModule.uasset +++ b/Pawn_Unreal/Content/Systems/Camera/BP_CameraTransitionModule.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e4355921c369be39167b177adbc563bf2b6747f33ae73b084d60d6f7e5c18ab4 -size 311619 +oid sha256:60fbef7ccf952d75e21a4ef06fc5b78d9ef89fe9d1ce5e92d94f83da25f9cb8b +size 302150 diff --git a/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_01.uasset b/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_01.uasset index 8438d2c..33e5e77 100644 --- a/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_01.uasset +++ b/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_01.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb6a4aa14fe00e8c6fe3ddf000e2b6143216ef8c47e5dbc2fb1788289352ef53 -size 21552 +oid sha256:1fbbe32c6acb396512c7947fde85a30a5861761cc27e9af265906396df93d91f +size 20484 diff --git a/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_02.uasset b/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_02.uasset index d9262b9..d84f52e 100644 --- a/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_02.uasset +++ b/Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_02.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:faf67bdccb0ec8a5ea4079f5e5884b431af25421408490d693685751a5ba6fbd -size 24584 +oid sha256:cfc78fbc6885c617a19bdda86856dd6acb390973443dbdb0528d12745593585d +size 21199 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset new file mode 100644 index 0000000..e0fad16 --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9626873130faf87a21f2acc43c709ef6107f6ae405c62c8286a4e66d419dcf23 +size 6210 diff --git a/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset new file mode 100644 index 0000000..acff50a --- /dev/null +++ b/Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aabd2a7592d6aa2e6ba599469e8d035d39c7aec5b58b51ef054726fece1f646f +size 6412 diff --git a/Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTrigger.cpp b/Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTrigger.cpp new file mode 100644 index 0000000..14cfc76 --- /dev/null +++ b/Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTrigger.cpp @@ -0,0 +1,47 @@ +#include "Pawn/Public/Interaction/PwnTrigger.h" + +#include "Components/ShapeComponent.h" +#include "Pawn/Public/Interaction/PwnTriggerRegister.h" + +UPwnTrigger::UPwnTrigger() { + PrimaryComponentTick.bCanEverTick = false; +} + +void UPwnTrigger::BeginPlay() { + Super::BeginPlay(); + VolumeComponent = Cast(TriggerVolume.GetComponent(GetOwner())); + if (ensure(VolumeComponent)) { + VolumeComponent->OnComponentBeginOverlap.AddDynamic(this, &UPwnTrigger::OnOverlapBegin); + VolumeComponent->OnComponentEndOverlap.AddDynamic(this, &UPwnTrigger::OnOverlapEnd); + } +} + +void UPwnTrigger::EndPlay(const EEndPlayReason::Type EndPlayReason) { + Super::EndPlay(EndPlayReason); + if (VolumeComponent) { + VolumeComponent->OnComponentBeginOverlap.RemoveDynamic(this, &UPwnTrigger::OnOverlapBegin); + VolumeComponent->OnComponentEndOverlap.RemoveDynamic(this, &UPwnTrigger::OnOverlapEnd); + } +} + +void UPwnTrigger::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult) { + if (UPwnTriggerRegister* Register = OtherActor->GetComponentByClass()) { + Register->RegisterTrigger(this); + } +} + +void UPwnTrigger::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) { + if (UPwnTriggerRegister* Register = OtherActor->GetComponentByClass()) { + Register->UnregisterTrigger(this); + } +} + +FVector UPwnTrigger::GetVolumeCenter() const { + if (ensure(VolumeComponent)) { + VolumeComponent->Bounds.Origin; + } + return FVector::ZeroVector; +} diff --git a/Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTriggerRegister.cpp b/Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTriggerRegister.cpp new file mode 100644 index 0000000..305a277 --- /dev/null +++ b/Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTriggerRegister.cpp @@ -0,0 +1,46 @@ +#include "Pawn/Public/Interaction/PwnTriggerRegister.h" + +#include "Pawn/Public/Interaction/PwnTrigger.h" + +UPwnTriggerRegister::UPwnTriggerRegister() { + PrimaryComponentTick.bCanEverTick = true; + PrimaryComponentTick.bStartWithTickEnabled = false; +} + +void UPwnTriggerRegister::BeginPlay() { + Super::BeginPlay(); +} + +void UPwnTriggerRegister::RegisterTrigger(UPwnTrigger* Trigger) { + Triggers.AddUnique(Trigger); + if (!Triggers.IsEmpty()) { + SetComponentTickEnabled(true); + } +} + +void UPwnTriggerRegister::UnregisterTrigger(UPwnTrigger* Trigger) { + Triggers.Remove(Trigger); + if (Triggers.IsEmpty()) { + SetComponentTickEnabled(false); + OnRelevantTriggerChanged.Broadcast(RelevantTrigger, nullptr); + RelevantTrigger = nullptr; + } +} + +void UPwnTriggerRegister::TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) { + UPwnTrigger* ClosestTrigger = nullptr; + float ClosestDistance = TNumericLimits::Max(); + for (UPwnTrigger* PwnTrigger : Triggers) { + const float Distance = FVector::DistSquared2D(GetOwner()->GetActorLocation(), PwnTrigger->GetVolumeCenter()); + if (Distance < ClosestDistance) { + ClosestDistance = Distance; + ClosestTrigger = PwnTrigger; + } + } + + if (ClosestTrigger != RelevantTrigger) { + OnRelevantTriggerChanged.Broadcast(RelevantTrigger, ClosestTrigger); + RelevantTrigger = ClosestTrigger; + } +} diff --git a/Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTrigger.h b/Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTrigger.h new file mode 100644 index 0000000..d71df5e --- /dev/null +++ b/Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTrigger.h @@ -0,0 +1,40 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "PwnTrigger.generated.h" + +UCLASS(ClassGroup="Interaction", + HideCategories=("Activation", "Cooking", "Replication", "Collision"), + meta=(BlueprintSpawnableComponent, DisplayName="Trigger")) +class PAWN_API UPwnTrigger : public UActorComponent { + GENERATED_BODY() + +public: + UPwnTrigger(); + +protected: + virtual void BeginPlay() override; + + virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + + UFUNCTION() + void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); + + UFUNCTION() + void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex); + +public: + UFUNCTION() + FVector GetVolumeCenter() const; + +protected: + UPROPERTY(EditAnywhere, meta=(UseComponentPicker, AllowedClasses="ShapeComponent")) + FComponentReference TriggerVolume; + +private: + UPROPERTY(Transient) + UShapeComponent* VolumeComponent; +}; diff --git a/Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTriggerRegister.h b/Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTriggerRegister.h new file mode 100644 index 0000000..6d7372e --- /dev/null +++ b/Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTriggerRegister.h @@ -0,0 +1,43 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "PwnTriggerRegister.generated.h" + +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FRelevantTriggerChanged, UPwnTrigger*, OldTrigger, UPwnTrigger*, NewTrigger); + +class UPwnTrigger; + +UCLASS(ClassGroup="Interaction", + HideCategories=("Activation", "Cooking", "Replication", "Collision"), + meta=(BlueprintSpawnableComponent, DisplayName="Trigger Register")) +class PAWN_API UPwnTriggerRegister : public UActorComponent { + GENERATED_BODY() + +public: + UPwnTriggerRegister(); + +protected: + virtual void BeginPlay() override; + +public: + UFUNCTION() + void RegisterTrigger(UPwnTrigger* Trigger); + + UFUNCTION() + void UnregisterTrigger(UPwnTrigger* Trigger); + +public: + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; + +protected: + UPROPERTY(BlueprintAssignable) + FRelevantTriggerChanged OnRelevantTriggerChanged; + + UPROPERTY(Transient) + TArray> Triggers; + + UPROPERTY(Transient, BlueprintReadOnly) + UPwnTrigger* RelevantTrigger; +}; diff --git a/Pawn_Unreal/Source/PawnEditor/PawnEditorModule.cpp b/Pawn_Unreal/Source/PawnEditor/PawnEditorModule.cpp index fdc8736..c12fb61 100644 --- a/Pawn_Unreal/Source/PawnEditor/PawnEditorModule.cpp +++ b/Pawn_Unreal/Source/PawnEditor/PawnEditorModule.cpp @@ -1,9 +1,14 @@ #include "PawnEditorModule.h" +#include "PwnStyle.h" #include "Modules/ModuleManager.h" IMPLEMENT_MODULE(FPawnEditorModule, PawnEditor) -void FPawnEditorModule::StartupModule() {} +void FPawnEditorModule::StartupModule() { + FPwnStyle::Initialize(); +} -void FPawnEditorModule::ShutdownModule() {} \ No newline at end of file +void FPawnEditorModule::ShutdownModule() { + FPwnStyle::Shutdown(); +} \ No newline at end of file diff --git a/Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp b/Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp new file mode 100644 index 0000000..353d45c --- /dev/null +++ b/Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp @@ -0,0 +1,59 @@ +#include "PwnStyle.h" + +#include "Brushes/SlateImageBrush.h" +#include "Misc/Paths.h" +#include "Styling/SlateStyle.h" +#include "Styling/SlateStyleRegistry.h" + +TSharedPtr FPwnStyle::StyleInstance = nullptr; + +const FVector2D Icon16x16(16.0f, 16.0f); +const FVector2D Icon20x20(20.0f, 20.0f); +const FVector2D Icon40x40(40.0f, 40.0f); +const FVector2D Icon64x64(64.0f, 64.0f); + +void FPwnStyle::Initialize() { + if (!StyleInstance.IsValid()) { + StyleInstance = Create(); + FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance); + } +} + +void FPwnStyle::Shutdown() { + FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance); + ensure(StyleInstance.IsUnique()); + StyleInstance.Reset(); +} + +FName FPwnStyle::GetStyleSetName() { + static FName StyleSetName(TEXT("PwnStyle")); + return StyleSetName; +} + +#define IMAGE_BRUSH(RelativePath, ...) FSlateImageBrush(StyleRef->GetContentRootDir() / RelativePath + TEXT(".png"), __VA_ARGS__ ) + +#define SET_CPP_CLASS_ICON(ClassName, IconName) Style.Set("ClassIcon.##ClassName##", new IMAGE_BRUSH(IconName, Icon20x20)); +#define SET_BLUEPRINT_CLASS_ICON(ClassName, IconName) Style.Set("ClassIcon.BP_##ClassName##_C", new IMAGE_BRUSH(IconName, Icon20x20)); + +TSharedRef FPwnStyle::Create() { + TSharedRef StyleRef = MakeShareable(new FSlateStyleSet(GetStyleSetName())); + StyleRef->SetContentRoot(FPaths::ProjectContentDir() / TEXT("Editor/EditorResources")); + StyleRef->SetCoreContentRoot(FPaths::ProjectContentDir() / TEXT("Editor/EditorResources")); + + FSlateStyleSet& Style = StyleRef.Get(); + + SET_CPP_CLASS_ICON(PwnTrigger, "Trigger"); + + SET_BLUEPRINT_CLASS_ICON(CameraModule, "CameraModule"); + SET_BLUEPRINT_CLASS_ICON(CameraTransitionModule, "CameraTransitionModule"); + + return StyleRef; +} + +#undef IMAGE_BRUSH +#undef BOX_BRUSH +#undef BORDER_BRUSH + +const ISlateStyle& FPwnStyle::Get() { + return *StyleInstance; +} diff --git a/Pawn_Unreal/Source/PawnEditor/PwnStyle.h b/Pawn_Unreal/Source/PawnEditor/PwnStyle.h new file mode 100644 index 0000000..575bb28 --- /dev/null +++ b/Pawn_Unreal/Source/PawnEditor/PwnStyle.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Templates/SharedPointer.h" + +class ISlateStyle; + +class FPwnStyle { +public: + static void Initialize(); + + static void Shutdown(); + + static const ISlateStyle& Get(); + + static FName GetStyleSetName(); + +private: + static TSharedRef Create(); + +private: + static TSharedPtr StyleInstance; +};