diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 9971466..0897174 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -49,6 +49,7 @@ r.ReflectionMethod=1 r.Shadow.Virtual.Enable=1 r.DefaultFeature.AutoExposure.ExtendDefaultLuminanceRange=True r.DefaultFeature.MotionBlur=False +r.CustomDepth=3 [/Script/WorldPartitionEditor.WorldPartitionEditorSettings] CommandletClass=Class'/Script/UnrealEd.WorldPartitionConvertCommandlet' diff --git a/Content/Blueprints/Characters/BP_Player.uasset b/Content/Blueprints/Characters/BP_Player.uasset index c2bc16c..e9a5c03 100644 Binary files a/Content/Blueprints/Characters/BP_Player.uasset and b/Content/Blueprints/Characters/BP_Player.uasset differ diff --git a/Content/Blueprints/Other/BP_CustomGameInstance.uasset b/Content/Blueprints/Other/BP_CustomGameInstance.uasset index 3e91a9a..9a44e6f 100644 Binary files a/Content/Blueprints/Other/BP_CustomGameInstance.uasset and b/Content/Blueprints/Other/BP_CustomGameInstance.uasset differ diff --git a/Content/Input/Actions/IA_Look.uasset b/Content/Input/Actions/IA_Look.uasset index 3f2a0f2..2b1fc7c 100644 Binary files a/Content/Input/Actions/IA_Look.uasset and b/Content/Input/Actions/IA_Look.uasset differ diff --git a/Content/Input/Actions/IA_Run.uasset b/Content/Input/Actions/IA_Run.uasset index 3c79f7d..41a69d2 100644 Binary files a/Content/Input/Actions/IA_Run.uasset and b/Content/Input/Actions/IA_Run.uasset differ diff --git a/Content/Input/Interactables/Actions/IA_InteractableActivate.uasset b/Content/Input/Interactables/Actions/IA_InteractableActivate.uasset new file mode 100644 index 0000000..e9a1a99 Binary files /dev/null and b/Content/Input/Interactables/Actions/IA_InteractableActivate.uasset differ diff --git a/Content/Input/Interactables/Actions/IA_InteractableMoveActivateL.uasset b/Content/Input/Interactables/Actions/IA_InteractableMoveActivateL.uasset new file mode 100644 index 0000000..83e84fd Binary files /dev/null and b/Content/Input/Interactables/Actions/IA_InteractableMoveActivateL.uasset differ diff --git a/Content/Input/Interactables/Actions/IA_InteractableMoveActivateR.uasset b/Content/Input/Interactables/Actions/IA_InteractableMoveActivateR.uasset new file mode 100644 index 0000000..2357996 Binary files /dev/null and b/Content/Input/Interactables/Actions/IA_InteractableMoveActivateR.uasset differ diff --git a/Content/Input/Interactables/Actions/IA_InteractableMoveRotate.uasset b/Content/Input/Interactables/Actions/IA_InteractableMoveRotate.uasset new file mode 100644 index 0000000..66c3eee Binary files /dev/null and b/Content/Input/Interactables/Actions/IA_InteractableMoveRotate.uasset differ diff --git a/Content/Input/Interactables/Actions/IA_InteractableMoveZoom.uasset b/Content/Input/Interactables/Actions/IA_InteractableMoveZoom.uasset new file mode 100644 index 0000000..456902b Binary files /dev/null and b/Content/Input/Interactables/Actions/IA_InteractableMoveZoom.uasset differ diff --git a/Content/Input/Interactables/IMC_InteractableActivate.uasset b/Content/Input/Interactables/IMC_InteractableActivate.uasset new file mode 100644 index 0000000..ec6803f Binary files /dev/null and b/Content/Input/Interactables/IMC_InteractableActivate.uasset differ diff --git a/Content/Input/Interactables/IMC_InteractableMove.uasset b/Content/Input/Interactables/IMC_InteractableMove.uasset new file mode 100644 index 0000000..cb4fcf7 Binary files /dev/null and b/Content/Input/Interactables/IMC_InteractableMove.uasset differ diff --git a/Content/Levels/Test/L_Test.umap b/Content/Levels/Test/L_Test.umap index 6cdd946..483a116 100644 Binary files a/Content/Levels/Test/L_Test.umap and b/Content/Levels/Test/L_Test.umap differ diff --git a/Content/Misc/Interactables/M_InteractableScreencapturerPP.uasset b/Content/Misc/Interactables/M_InteractableScreencapturerPP.uasset index 8a552bb..8a98b7b 100644 Binary files a/Content/Misc/Interactables/M_InteractableScreencapturerPP.uasset and b/Content/Misc/Interactables/M_InteractableScreencapturerPP.uasset differ diff --git a/Content/UI/BP_MainWidgetManager.uasset b/Content/UI/BP_MainWidgetManager.uasset index 06a5140..5c3fdcf 100644 Binary files a/Content/UI/BP_MainWidgetManager.uasset and b/Content/UI/BP_MainWidgetManager.uasset differ diff --git a/Content/UI/Blueprints/Overlays/UI_Crosshair.uasset b/Content/UI/Blueprints/Overlays/UI_Crosshair.uasset index 914a7b6..3d11d25 100644 Binary files a/Content/UI/Blueprints/Overlays/UI_Crosshair.uasset and b/Content/UI/Blueprints/Overlays/UI_Crosshair.uasset differ diff --git a/Lost_Edge.uproject b/Lost_Edge.uproject index 4a34664..951acfb 100644 --- a/Lost_Edge.uproject +++ b/Lost_Edge.uproject @@ -1,6 +1,6 @@ { "FileVersion": 3, - "EngineAssociation": "5.4", + "EngineAssociation": "{42CC8720-4DDD-EF11-BECE-CEBF292119D8}", "Category": "", "Description": "", "Modules": [ diff --git a/Source/Lost_Edge/Lost_Edge.Build.cs b/Source/Lost_Edge/Lost_Edge.Build.cs index 3b65c26..d1292e2 100644 --- a/Source/Lost_Edge/Lost_Edge.Build.cs +++ b/Source/Lost_Edge/Lost_Edge.Build.cs @@ -19,6 +19,7 @@ public class Lost_Edge : ModuleRules { // UE_LOG(LogTemp, Log, TEXT("capture: %s"), (capture ? TEXT("true") : TEXT("false"))); // GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("1")); // GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::Printf(TEXT("Rescaled: %f"), scale)); + // DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Red, false, PrimaryComponentTick.TickInterval, 0, 0.1f); } } diff --git a/Source/Lost_Edge/Private/CameraModeBase.cpp b/Source/Lost_Edge/Private/CameraModeBase.cpp index 6ef3bfe..53501c4 100644 --- a/Source/Lost_Edge/Private/CameraModeBase.cpp +++ b/Source/Lost_Edge/Private/CameraModeBase.cpp @@ -10,6 +10,7 @@ #include "InputMappingContext.h" #include "Kismet/GameplayStatics.h" +#include "CustomGameInstanceBase.h" #include "CustomGameUserSettings.h" #include "MainGameModeBase.h" @@ -34,18 +35,20 @@ void ACameraModeBase::BeginPlay() camera->PostProcessSettings.MotionBlurAmount = gameSettings->bUseMotionBlur ? 1.0f : 0.0f; } - if(inputMapping) + if(auto PC = Cast(GetController())) { - if(auto PC = Cast(GetController())) + if(auto inputSubsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer())) { - if(auto inputSubsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer())) + if(auto GI = Cast(GetWorld()->GetGameInstance())) { inputSubsystem->ClearAllMappings(); - inputSubsystem->AddMappingContext(inputMapping.LoadSynchronous(), 0); + for(auto& inputContext : GI->inputContexts) + { + inputSubsystem->AddMappingContext(inputContext.LoadSynchronous(), 0); + } } } } - } void ACameraModeBase::Tick(float DeltaTime) diff --git a/Source/Lost_Edge/Private/CameraModeBase.h b/Source/Lost_Edge/Private/CameraModeBase.h index 4986a61..ca1ae6f 100644 --- a/Source/Lost_Edge/Private/CameraModeBase.h +++ b/Source/Lost_Edge/Private/CameraModeBase.h @@ -29,14 +29,8 @@ protected: UFUNCTION(BlueprintCallable, Category = Pawn) void SwitchRun(bool run); - UPROPERTY(EditDefaultsOnly) - TSoftObjectPtr inputMapping; - UPROPERTY(EditDefaultsOnly) float moveSpeed = 200; UPROPERTY(EditDefaultsOnly) float runSpeedMultiplier = 4; - -private: - }; diff --git a/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp b/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp index 64048f6..8fcb7ae 100644 --- a/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp +++ b/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp @@ -4,19 +4,31 @@ #include "CustomGameInstanceBase.h" #include "EnhancedInputLibrary.h" +#include "EnhancedInputSubsystems.h" #include "InputMappingContext.h" +#include "Kismet/GameplayStatics.h" #include "CustomGameUserSettings.h" #include "Interactable/Activators/InCameraInteractableActivator.h" #include "Interactable/Activators/RaycastInteractableActivator.h" +#include "Interactable/Modificators/ActivateInteractableModificator.h" +#include "Interactable/Modificators/SawInteractableModificator.h" void UCustomGameInstanceBase::Init() { + UGameInstance::Init(); + // IN FUTURE ASSIGN FROM CONTENT LOADER MEMBER interactionsActivators.Add(URaycastInteractableActivator::StaticClass()); interactionsActivators.Add(UInCameraInteractableActivator::StaticClass()); - UGameInstance::Init(); + for(auto& modificator : interactionsModificators) + { + if(modificator.GetDefaultObject()->GetMappingContext()) + { + inputContexts.Add(modificator.GetDefaultObject()->GetMappingContext()); + } + } ApplyMouseSettings(); } @@ -25,27 +37,49 @@ void UCustomGameInstanceBase::ApplyMouseSettings() { if(auto gameSettings = UCustomGameUserSettings::GetCustomGameUserSettings()) { - for(auto context_it = defaultInputContexts.begin(); context_it != defaultInputContexts.end(); ++context_it) + for(auto& context : inputContexts) { - auto& mappings = (*context_it).LoadSynchronous()->GetMappings(); - for(auto mapping_it = mappings.begin(); mapping_it != mappings.end(); ++mapping_it) + if(!context.LoadSynchronous()) + continue; + + for(auto& mapping : context.LoadSynchronous()->GetMappings()) { - if((*mapping_it).Key == EKeys::Mouse2D) + if(mapping.Key == EKeys::Mouse2D) { - for(auto modifiers_it = (*mapping_it).Modifiers.begin(); modifiers_it != (*mapping_it).Modifiers.end(); ++modifiers_it) + for(auto& modifier : mapping.Modifiers) { - if(auto negate_modifier = Cast(*modifiers_it)) + if(auto negate_modifier = Cast(modifier)) { negate_modifier->bY = !gameSettings->bMouseInverted; } - if(auto scalar_modifier = Cast(*modifiers_it)) + if(auto scalar_modifier = Cast(modifier)) { scalar_modifier->Scalar = FVector{ gameSettings->GetMouseSensetivity() * 0.5 }; } } } } - UEnhancedInputLibrary::RequestRebuildControlMappingsUsingContext((*context_it).LoadSynchronous()); + UEnhancedInputLibrary::RequestRebuildControlMappingsUsingContext(context.LoadSynchronous()); + } + } +} + +void UCustomGameInstanceBase::AppendInteractableModificatorClass(TSubclassOf modificator) +{ + bool alreadyPresent = false; + interactionsModificators.Add(modificator, &alreadyPresent); + if(!alreadyPresent) + { + if(auto IC = modificator.GetDefaultObject()->GetMappingContext()) + { + inputContexts.Add(IC); + if(auto PC = UGameplayStatics::GetPlayerController(GetWorld(), 0)) + { + if(auto inputSubsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer())) + { + inputSubsystem->AddMappingContext(IC, 0); + } + } } } } \ No newline at end of file diff --git a/Source/Lost_Edge/Private/CustomGameInstanceBase.h b/Source/Lost_Edge/Private/CustomGameInstanceBase.h index 77d9803..fb46e84 100644 --- a/Source/Lost_Edge/Private/CustomGameInstanceBase.h +++ b/Source/Lost_Edge/Private/CustomGameInstanceBase.h @@ -18,10 +18,13 @@ public: UFUNCTION(BlueprintCallable, Category = Settings) void ApplyMouseSettings(); - UPROPERTY(EditDefaultsOnly) - TArray> interactionsActivators; + void AppendInteractableModificatorClass(TSubclassOf modificator); -protected: UPROPERTY(EditDefaultsOnly) - TArray> defaultInputContexts; + TSet> interactionsActivators; + TSet> interactionsModificators; + + UPROPERTY(EditDefaultsOnly) + TSet> inputContexts; + }; diff --git a/Source/Lost_Edge/Private/Interactable/Activators/InteractableActivator.h b/Source/Lost_Edge/Private/Interactable/Activators/InteractableActivator.h index 5d357f1..9a3011c 100644 --- a/Source/Lost_Edge/Private/Interactable/Activators/InteractableActivator.h +++ b/Source/Lost_Edge/Private/Interactable/Activators/InteractableActivator.h @@ -33,7 +33,7 @@ protected: EActivatorType activatorType; UPROPERTY(EditDefaultsOnly) - float scanDistance = 200; + float scanDistance = 250; class UWorld* world; class APlayerBase* player; diff --git a/Source/Lost_Edge/Private/Interactable/Activators/InteractableScreenCapturer.cpp b/Source/Lost_Edge/Private/Interactable/Activators/InteractableScreenCapturer.cpp index 24f65aa..40de7e5 100644 --- a/Source/Lost_Edge/Private/Interactable/Activators/InteractableScreenCapturer.cpp +++ b/Source/Lost_Edge/Private/Interactable/Activators/InteractableScreenCapturer.cpp @@ -47,6 +47,7 @@ UInteractableScreenCapturer::UInteractableScreenCapturer(const FObjectInitialize PostProcessBlendWeight = 1; auto ppMaterial = LoadObject(this, TEXT("/Game/Misc/Interactables/M_InteractableScreencapturerPP")); PostProcessSettings.AddBlendable(ppMaterial, 1.0f); + PostProcessSettings.Sharpen = 0; bUseCustomProjectionMatrix = false; bAlwaysPersistRenderingState = true; @@ -81,7 +82,7 @@ void UInteractableScreenCapturer::TickComponent(float DeltaTime, enum ELevelTick USceneCaptureComponent2D::TickComponent(DeltaTime, TickType, ThisTickFunction); CaptureScene(); GetCameraView(DeltaTime, _view); - //Process(); + Process(); } break; default: @@ -261,15 +262,15 @@ void UInteractableScreenCapturer::Process() } } #ifdef INTERACTABLE_ACTIVATOR_DEBUG - DrawDebugLine(world, startLocation, endLocation, FColor::Green, false, tickInterval, 0, 0.5f); + DrawDebugLine(world, startLocation, endLocation, FColor::Green, false, tickInterval, 0, 0.1f); #endif // INTERACTABLE_ACTIVATOR_DEBUG } #ifdef INTERACTABLE_ACTIVATOR_DEBUG else { - DrawDebugLine(world, startLocation, endLocation, FColor::Red, false, tickInterval, 10, 0.5f); - } + DrawDebugLine(world, startLocation, endLocation, FColor::Red, false, tickInterval, 10, 0.1f); + } #endif // INTERACTABLE_ACTIVATOR_DEBUG } @@ -277,7 +278,7 @@ void UInteractableScreenCapturer::Process() GEngine->AddOnScreenDebugMessage(30 + (int)EActivatorType::Saw, 0.5f, FColor::Yellow, FString::Printf(TEXT("ScreenCapturer calltime: %f"), FPlatformTime::Seconds() - StartTime)); #endif // INTERACTABLE_ACTIVATOR_DEBUG running = false; - } + } ); - } -} \ No newline at end of file + } + } \ No newline at end of file diff --git a/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.cpp b/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.cpp index d202226..12e2a14 100644 --- a/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.cpp +++ b/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.cpp @@ -25,8 +25,6 @@ void URaycastInteractableActivator::Scan_Implementation() collisionChannel ); - static AInteractable* _last = nullptr; - static bool _activated = false; if(result.bBlockingHit) { if(_last != result.GetActor()) @@ -44,13 +42,13 @@ void URaycastInteractableActivator::Scan_Implementation() { interactableActivatedDelegate.Execute(interactable, activatorType); } - } } + } #ifdef INTERACTABLE_ACTIVATOR_DEBUG - DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Green, false, 0.5f, 0, 0.5f); + DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Green, false, PrimaryComponentTick.TickInterval, 0, 0.1f); #endif // INTERACTABLE_ACTIVATOR_DEBUG - } + } else { if(_activated) @@ -61,10 +59,10 @@ void URaycastInteractableActivator::Scan_Implementation() } _activated = false; _last = nullptr; - } + } #ifdef INTERACTABLE_ACTIVATOR_DEBUG - DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Red, false, 0.5f, 10, 0.5f); + DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Red, false, PrimaryComponentTick.TickInterval, 10, 0.1f); #endif // INTERACTABLE_ACTIVATOR_DEBUG - } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.h b/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.h index 6be85dc..7161a4f 100644 --- a/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.h +++ b/Source/Lost_Edge/Private/Interactable/Activators/RaycastInteractableActivator.h @@ -18,4 +18,8 @@ public: protected: void Scan(); virtual void Scan_Implementation() override; + +private: + class AInteractable* _last = nullptr; + bool _activated = false; }; diff --git a/Source/Lost_Edge/Private/Interactable/Interactable.cpp b/Source/Lost_Edge/Private/Interactable/Interactable.cpp index 14adcf9..3dc6c31 100644 --- a/Source/Lost_Edge/Private/Interactable/Interactable.cpp +++ b/Source/Lost_Edge/Private/Interactable/Interactable.cpp @@ -6,11 +6,19 @@ #include "Kismet/GameplayStatics.h" #include "../MainGameModeBase.h" +#include "../PlayerBase.h" #include "../Widgets/WidgetsManager.h" #include "Modificators/InteractableModificator.h" +int32 AInteractable::GetActivatedFlags() +{ + return activated; +} + void AInteractable::BeginPlay() { + AActor::BeginPlay(); + // FOR ADRESS TO COLOR //if(auto m = material.LoadSynchronous()) //{ @@ -20,29 +28,77 @@ void AInteractable::BeginPlay() // } //} + TArray instancedModificators; + GetComponents(instancedModificators); + + uint8 activatorTypes = 0; + for(auto& modificator : instancedModificators) + { + uint8 modificatorActivatorTypes = static_cast(modificator->GetActivatorTypes()); + activatorTypes |= modificatorActivatorTypes; + + switch(modificatorActivatorTypes & static_cast(EActivatorType::Use)) + { + case static_cast(EActivatorType::Use): + modificators.Add({ EActivatorType::Use, modificator }); + break; + default: + break; + } + switch(modificatorActivatorTypes & static_cast(EActivatorType::Saw)) + { + case static_cast(EActivatorType::Saw): + modificators.Add({ EActivatorType::Saw, modificator }); + break; + default: + break; + } + } + TArray meshes; GetComponents(meshes); for(auto mesh : meshes) { - mesh->CustomDepthStencilValue = 0; - mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; - mesh->SetRenderCustomDepth(true); + if(activatorTypes) + { + mesh->SetCollisionProfileName(TEXT("Interactable")); + } + + if(activatorTypes & static_cast(EActivatorType::Saw)) + { + mesh->CustomDepthStencilValue = 128; + mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; + mesh->SetRenderCustomDepth(true); + } } - for(auto& modificatorClass : modificatorsClasses) - { - _modificators.Add(NewObject(this, modificatorClass)); - } + if(auto PC = UGameplayStatics::GetPlayerController(GetWorld(), 0)) + player = Cast(PC->GetPawn()); } void AInteractable::_Activate(EActivatorType type) { +#ifdef INTERACTABLE_DEBUG + GEngine->AddOnScreenDebugMessage(30 + (int)type, 5.0f, FColor::Cyan, TEXT("Player activate: ") + this->GetName() + + TEXT(" by: ") + StaticEnum()->GetNameByValue(static_cast(type)).ToString()); +#endif // INTERACTABLE_DEBUG + + if(!player) + return; + + if(modificators.Num() == 0) + return; + activated |= static_cast(type); if(auto WM = AMainGameModeBase::GetWidgetManager()) { - for(const auto modificator : _modificators) + for(const auto& modificator : modificators) { - WM->ShowInteractionHints(modificator); + if(static_cast(modificator.Value->GetActivatorTypes()) & static_cast(type)) + { + WM->ShowInteractionHints(modificator.Value); + modificator.Value->Bind_Implementation(player->inputComponent); + } } } @@ -51,10 +107,28 @@ void AInteractable::_Activate(EActivatorType type) void AInteractable::_Deactivate(EActivatorType type) { +#ifdef INTERACTABLE_DEBUG + GEngine->AddOnScreenDebugMessage(30 + (int)type, 5.0f, FColor::Magenta, TEXT("Player deactivate: ") + this->GetName() + + TEXT(" by: ") + StaticEnum()->GetNameByValue(static_cast(type)).ToString()); +#endif // INTERACTABLE_DEBUG + + if(!player) + return; + + if(modificators.Num() == 0) + return; + activated &= ~static_cast(type); if(auto WM = AMainGameModeBase::GetWidgetManager()) { WM->HideInteractionHints(type); + for(const auto& modificator : modificators) + { + if(static_cast(modificator.Value->GetActivatorTypes()) & static_cast(type)) + { + modificator.Value->Unbind_Implementation(); + } + } } Deactivate_Implementation(type); diff --git a/Source/Lost_Edge/Private/Interactable/Interactable.h b/Source/Lost_Edge/Private/Interactable/Interactable.h index 3163038..95ffd2b 100644 --- a/Source/Lost_Edge/Private/Interactable/Interactable.h +++ b/Source/Lost_Edge/Private/Interactable/Interactable.h @@ -10,18 +10,19 @@ #define INTERACTABLE_DEBUG //#define INTERACTABLE_ACTIVATOR_DEBUG -UENUM(BlueprintType, meta = (Bitflags)) +UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor = "true")) enum class EActivatorType : uint8 { - None = 0, + None = 0 UMETA(Hidden), Use = 1 << 0, Saw = 1 << 1, - Custom1 = 1 << 2 UMETA(DisplayName = "Custom 1"), - Custom2 = 1 << 3 UMETA(DisplayName = "Custom 2"), - Custom3 = 1 << 4 UMETA(DisplayName = "Custom 3"), - Custom4 = 1 << 5 UMETA(DisplayName = "Custom 4"), - Custom5 = 1 << 6 UMETA(DisplayName = "Custom 5"), - Custom6 = 1 << 7 UMETA(DisplayName = "Custom 6") + Collide = 1 << 2, + Custom1 = 1 << 3 UMETA(DisplayName = "Custom 1"), + Custom2 = 1 << 4 UMETA(DisplayName = "Custom 2"), + Custom3 = 1 << 5 UMETA(DisplayName = "Custom 3"), + Custom4 = 1 << 6 UMETA(DisplayName = "Custom 4"), + Custom5 = 1 << 7 UMETA(DisplayName = "Custom 5") + }; ENUM_CLASS_FLAGS(EActivatorType) @@ -31,6 +32,8 @@ class AInteractable : public AActor GENERATED_BODY() public: + int32 GetActivatedFlags(); + void _Activate(EActivatorType type); UFUNCTION(BlueprintNativeEvent, BlueprintCallable) void Activate(EActivatorType type); @@ -44,15 +47,12 @@ public: protected: virtual void BeginPlay() override; - UPROPERTY(BlueprintReadWrite, meta = (Bitmask, BitmaskEnum = "EActivatorType")) - uint8 activated = 0; + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (Bitmask, BitmaskEnum = "EActivatorType")) + int32 activated = 0; - UPROPERTY(EditDefaultsOnly) - TArray> modificatorsClasses; + TMap modificators = {}; + + class APlayerBase* player; -private: - //UPROPERTY(EditDefaultsOnly) - //TSoftObjectPtr material; - TArray _modificators; }; diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/ActivateInteractableModificator.cpp b/Source/Lost_Edge/Private/Interactable/Modificators/ActivateInteractableModificator.cpp new file mode 100644 index 0000000..3ba0297 --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/ActivateInteractableModificator.cpp @@ -0,0 +1,46 @@ +// Oleg Petruny proprietary. + + +#include "ActivateInteractableModificator.h" + +#include "EnhancedInputComponent.h" +#include "InputMappingContext.h" + +#include "../Interactable.h" + +UActivateInteractableModificator::UActivateInteractableModificator(const FObjectInitializer& ObjectInitializer) + : UInteractableModificator(ObjectInitializer) +{ + activatorTypes |= static_cast(EActivatorType::Use); + + inputMapping = LoadObject(this, TEXT("/Game/Input/Interactables/IMC_InteractableActivate")); +} + +void UActivateInteractableModificator::Bind_Implementation(class UEnhancedInputComponent* input) +{ + if(!input && !inputMapping) + return; + + for(auto& mapping : inputMapping->GetMappings()) + { + auto handle = input->BindAction(mapping.Action, ETriggerEvent::Triggered, this, &UActivateInteractableModificator::ActivateInteractable).GetHandle(); + bindindingHandlers.Add(handle); + } +} + +void UActivateInteractableModificator::Unbind_Implementation() +{ + if(!lastInput) + return; + + for(auto handle : bindindingHandlers) + { + lastInput->RemoveBindingByHandle(handle); + } + bindindingHandlers.Empty(); +} + +void UActivateInteractableModificator::ActivateInteractable() +{ + OnActivated.Broadcast(); +} diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/ActivateInteractableModificator.h b/Source/Lost_Edge/Private/Interactable/Modificators/ActivateInteractableModificator.h new file mode 100644 index 0000000..39be034 --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/ActivateInteractableModificator.h @@ -0,0 +1,32 @@ +// Oleg Petruny proprietary. + +#pragma once + +#include "CoreMinimal.h" +#include "InteractableModificator.h" + +#include "ActivateInteractableModificator.generated.h" + +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FActivateInteractableModificatorActivatedDelegate); + +UCLASS(ClassGroup = InteractableModificator, meta = (BlueprintSpawnableComponent), Blueprintable, BlueprintType) +class UActivateInteractableModificator : public UInteractableModificator +{ + GENERATED_BODY() + +public: + UActivateInteractableModificator(const FObjectInitializer& ObjectInitializer); + + void Bind_Implementation(class UEnhancedInputComponent* input) override; + void Unbind_Implementation() override; + + UPROPERTY(BlueprintAssignable) + FActivateInteractableModificatorActivatedDelegate OnActivated; + +protected: + void ActivateInteractable(); + +private: + class UEnhancedInputComponent* lastInput; + TArray bindindingHandlers; +}; diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/EditInteractableModificator.cpp b/Source/Lost_Edge/Private/Interactable/Modificators/EditInteractableModificator.cpp new file mode 100644 index 0000000..804caa2 --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/EditInteractableModificator.cpp @@ -0,0 +1,14 @@ +// Oleg Petruny proprietary. + + +#include "EditInteractableModificator.h" + +#include "../Interactable.h" + +UEditInteractableModificator::UEditInteractableModificator(const FObjectInitializer& ObjectInitializer) + : UInteractableModificator(ObjectInitializer) +{ + activatorTypes |= static_cast(EActivatorType::Collide); + + +} diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/EditInteractableModificator.h b/Source/Lost_Edge/Private/Interactable/Modificators/EditInteractableModificator.h new file mode 100644 index 0000000..d2a6a4b --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/EditInteractableModificator.h @@ -0,0 +1,18 @@ +// Oleg Petruny proprietary. + +#pragma once + +#include "CoreMinimal.h" +#include "InteractableModificator.h" + +#include "EditInteractableModificator.generated.h" + +UCLASS(ClassGroup = InteractableModificator, meta = (BlueprintSpawnableComponent), Blueprintable, BlueprintType) +class UEditInteractableModificator : public UInteractableModificator +{ + GENERATED_BODY() + +public: + UEditInteractableModificator(const FObjectInitializer& ObjectInitializer); + +}; diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp b/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp index aeb0054..c9a782c 100644 --- a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp +++ b/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp @@ -5,9 +5,24 @@ #include "InputMappingContext.h" +#include "CustomGameInstanceBase.h" + +void UInteractableModificator::OnRegister() +{ + UActorComponent::OnRegister(); + + if(auto world = GetWorld()) + { + if(auto GI = Cast(world->GetGameInstance())) + { + GI->AppendInteractableModificatorClass(this->GetClass()); + } + } +} + const UInputMappingContext* UInteractableModificator::GetMappingContext() const { - return inputMapping.LoadSynchronous(); + return inputMapping; } EActivatorType UInteractableModificator::GetActivatorTypes() const diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.h b/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.h index 43408b6..6f346d0 100644 --- a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.h +++ b/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.h @@ -15,13 +15,24 @@ class UInteractableModificator : public UActorComponent GENERATED_BODY() public: + void OnRegister() override; + const class UInputMappingContext* GetMappingContext() const; EActivatorType GetActivatorTypes() const; + UFUNCTION(BlueprintNativeEvent, BlueprintCallable) + void Bind(class UEnhancedInputComponent* input); + virtual void Bind_Implementation(class UEnhancedInputComponent* input) {} + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable) + void Unbind(); + virtual void Unbind_Implementation() {} + protected: UPROPERTY(EditDefaultsOnly) - TSoftObjectPtr inputMapping; + class UInputMappingContext* inputMapping; UPROPERTY(EditAnywhere, meta = (Bitmask, BitmaskEnum = "EActivatorType")) - uint8 activatorTypes = 0; + int32 activatorTypes = 0; + }; diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableUsableModificator.cpp b/Source/Lost_Edge/Private/Interactable/Modificators/InteractableUsableModificator.cpp deleted file mode 100644 index 40048d3..0000000 --- a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableUsableModificator.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// Oleg Petruny proprietary. - - -#include "InteractableUsableModificator.h" - diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableUsableModificator.h b/Source/Lost_Edge/Private/Interactable/Modificators/InteractableUsableModificator.h deleted file mode 100644 index f78fa39..0000000 --- a/Source/Lost_Edge/Private/Interactable/Modificators/InteractableUsableModificator.h +++ /dev/null @@ -1,18 +0,0 @@ -// Oleg Petruny proprietary. - -#pragma once - -#include "InteractableModificator.h" - -#include "InteractableUsableModificator.generated.h" - - -UCLASS(Blueprintable, BlueprintType) -class UInteractableUsableModificator : public UInteractableModificator -{ - GENERATED_BODY() - -public: - -protected: -}; diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/MoveInteractableModificator.cpp b/Source/Lost_Edge/Private/Interactable/Modificators/MoveInteractableModificator.cpp new file mode 100644 index 0000000..10bb92c --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/MoveInteractableModificator.cpp @@ -0,0 +1,171 @@ +// Oleg Petruny proprietary. + + +#include "MoveInteractableModificator.h" + +#include "EnhancedInputComponent.h" +#include "InputMappingContext.h" + +#include "Interactable/Interactable.h" +#include "PlayerBase.h" + +UMoveInteractableModificator::UMoveInteractableModificator(const FObjectInitializer& ObjectInitializer) + : UInteractableModificator(ObjectInitializer) +{ + activatorTypes |= static_cast(EActivatorType::Use); + + inputMapping = LoadObject(this, TEXT("/Game/Input/Interactables/IMC_InteractableMove")); + actor = Cast(GetOwner()); + + PrimaryComponentTick.bCanEverTick = true; + PrimaryComponentTick.bStartWithTickEnabled = false; +} +void UMoveInteractableModificator::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + UpdatePosition(DeltaTime); +} + + +void UMoveInteractableModificator::Bind_Implementation(class UEnhancedInputComponent* input) +{ + if(!input && !inputMapping) + return; + + if(state != State::Nothing) + return; + + for(auto& mapping : inputMapping->GetMappings()) + { + if(mapping.Key == EKeys::LeftMouseButton + || mapping.Key == EKeys::RightMouseButton) + { + auto handle = input->BindAction(mapping.Action, ETriggerEvent::Started, this, &UMoveInteractableModificator::IncreaseState).GetHandle(); + bindindingHandlers.Add(handle); + handle = input->BindAction(mapping.Action, ETriggerEvent::Completed, this, &UMoveInteractableModificator::DecreaseState).GetHandle(); + bindindingHandlers.Add(handle); + } + else if(mapping.Key == EKeys::MouseWheelAxis) + { + auto handle = input->BindAction(mapping.Action, ETriggerEvent::Triggered, this, &UMoveInteractableModificator::Zooming).GetHandle(); + bindindingHandlers.Add(handle); + } + else if(mapping.Key == EKeys::Mouse2D) + { + auto handle = input->BindAction(mapping.Action, ETriggerEvent::Triggered, this, &UMoveInteractableModificator::Rotating).GetHandle(); + bindindingHandlers.Add(handle); + } + } + + lastInput = input; + player = Cast(Cast(lastInput->GetOwner())->GetPawn()); + SetComponentTickEnabled(true); + + OnMoveActivated.Broadcast(); +} + +void UMoveInteractableModificator::Unbind_Implementation() +{ + if(!lastInput) + return; + + if(state != State::Nothing) + return; + + for(auto handle : bindindingHandlers) + { + lastInput->RemoveBindingByHandle(handle); + } + bindindingHandlers.Empty(); + + state = static_cast(0); + ProcessState(); + SetComponentTickEnabled(false); + OnMoveDeactivated.Broadcast(); +} + +void UMoveInteractableModificator::IncreaseState() +{ + state = static_cast(static_cast(state) + 1); + if(static_cast(state) > static_cast(State::Rotating)) + state = State::Rotating; + ProcessState(); +} +void UMoveInteractableModificator::DecreaseState() +{ + state = static_cast(static_cast(state) - 1); + if(static_cast(state) > static_cast(State::Rotating)) + state = State::Nothing; + ProcessState(); +} + +void UMoveInteractableModificator::ProcessState() +{ + switch(state) + { + case State::Nothing: + { + player->cameraLocked = false; + break; + } + case State::Holding: + { + player->cameraLocked = false; + OnHolding.Broadcast(); + break; + } + case State::Rotating: + { + player->cameraLocked = true; + OnRotating.Broadcast(); + break; + } + default: + break; + } + if(state == State::Nothing) + { + if((actor->GetActivatedFlags() & static_cast(EActivatorType::Use)) == 0 + && bindindingHandlers.Num() > 0) + { + Unbind_Implementation(); + } + } +} + +void UMoveInteractableModificator::UpdatePosition(float deltaTime) +{ + if(!player) + return; + if(state == State::Nothing) + { + distance = (player->GetCameraLocation() - actor->GetActorLocation()).Length(); + return; + } + auto camLoc = player->GetCameraLocation(); + auto dir = player->GetCameraDirection(); + auto newLoc = camLoc + dir * distance; + auto currentLoc = actor->GetActorLocation(); + auto interpLoc = FMath::VInterpTo(currentLoc, newLoc, deltaTime, 20.0f); + actor->SetActorLocation(interpLoc, true, nullptr, ETeleportType::None); +} + +void UMoveInteractableModificator::Zooming(const FInputActionValue& value) +{ + if(state != State::Holding) + return; + + distance += value.Get() * zoomSpeed; + distance = FMath::Clamp(distance, minDistance, maxDistance); +} + +void UMoveInteractableModificator::Rotating(const FInputActionValue& axis) +{ + if(state != State::Rotating) + return; + + auto v = axis.Get(); + auto vec = player->GetCameraDirection(); + actor->AddActorWorldRotation(FRotator{ v.Y * vec.X, v.X, v.Y * vec.Y * -1 }, true, nullptr, ETeleportType::None); +} diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/MoveInteractableModificator.h b/Source/Lost_Edge/Private/Interactable/Modificators/MoveInteractableModificator.h new file mode 100644 index 0000000..2916ca9 --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/MoveInteractableModificator.h @@ -0,0 +1,66 @@ +// Oleg Petruny proprietary. + +#pragma once + +#include "CoreMinimal.h" +#include "InputActionValue.h" +#include "InteractableModificator.h" + +#include "MoveInteractableModificator.generated.h" + +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FActivateMoveInteractableModificatorActivatedDelegate); +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDeactivateMoveInteractableModificatorActivatedDelegate); +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FHoldingMoveInteractableModificatorActivatedDelegate); +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRotatingMoveInteractableModificatorActivatedDelegate); + +UCLASS(ClassGroup = InteractableModificator, meta = (BlueprintSpawnableComponent), Blueprintable, BlueprintType) +class UMoveInteractableModificator : public UInteractableModificator +{ + GENERATED_BODY() + +public: + UMoveInteractableModificator(const FObjectInitializer& ObjectInitializer); + virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + + void Bind_Implementation(class UEnhancedInputComponent* input) override; + void Unbind_Implementation() override; + + UPROPERTY(BlueprintAssignable) + FActivateMoveInteractableModificatorActivatedDelegate OnMoveActivated; + UPROPERTY(BlueprintAssignable) + FDeactivateMoveInteractableModificatorActivatedDelegate OnMoveDeactivated; + UPROPERTY(BlueprintAssignable) + FHoldingMoveInteractableModificatorActivatedDelegate OnHolding; + UPROPERTY(BlueprintAssignable) + FRotatingMoveInteractableModificatorActivatedDelegate OnRotating; + +protected: + float distance = 0; + float minDistance = 100.0f; + float maxDistance = 200.0f; + float zoomSpeed = 10.0f; + float moveSpeed = 1.0f; + float rotateSpeed = 10.0f; + +private: + void IncreaseState(); + void DecreaseState(); + void ProcessState(); + void UpdatePosition(float deltaTime); + void Zooming(const FInputActionValue& value); + void Rotating(const FInputActionValue& axis); + + enum class State : uint8 + { + Nothing = 0, + Holding, + Rotating + }; + + class UEnhancedInputComponent* lastInput; + TArray bindindingHandlers; + State state = State::Nothing; + class AInteractable* actor; + class APlayerBase* player; +}; diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/SawInteractableModificator.cpp b/Source/Lost_Edge/Private/Interactable/Modificators/SawInteractableModificator.cpp new file mode 100644 index 0000000..de1baeb --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/SawInteractableModificator.cpp @@ -0,0 +1,17 @@ +// Oleg Petruny proprietary. + + +#include "SawInteractableModificator.h" + +#include "../Interactable.h" + +USawInteractableModificator::USawInteractableModificator(const FObjectInitializer& ObjectInitializer) + : UInteractableModificator(ObjectInitializer) +{ + activatorTypes |= static_cast(EActivatorType::Saw); +} + +void USawInteractableModificator::Bind_Implementation(class UEnhancedInputComponent* input) +{ + OnSaw.Broadcast(); +} diff --git a/Source/Lost_Edge/Private/Interactable/Modificators/SawInteractableModificator.h b/Source/Lost_Edge/Private/Interactable/Modificators/SawInteractableModificator.h new file mode 100644 index 0000000..368d213 --- /dev/null +++ b/Source/Lost_Edge/Private/Interactable/Modificators/SawInteractableModificator.h @@ -0,0 +1,24 @@ +// Oleg Petruny proprietary. + +#pragma once + +#include "CoreMinimal.h" +#include "InteractableModificator.h" + +#include "SawInteractableModificator.generated.h" + +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FSawInteractableModificatorActivatedDelegate); + +UCLASS(ClassGroup = InteractableModificator, meta = (BlueprintSpawnableComponent), Blueprintable, BlueprintType) +class USawInteractableModificator : public UInteractableModificator +{ + GENERATED_BODY() + +public: + USawInteractableModificator(const FObjectInitializer& ObjectInitializer); + + void Bind_Implementation(class UEnhancedInputComponent* input) override; + + UPROPERTY(BlueprintAssignable) + FSawInteractableModificatorActivatedDelegate OnSaw; +}; diff --git a/Source/Lost_Edge/Private/PlayerBase.cpp b/Source/Lost_Edge/Private/PlayerBase.cpp index 5f715b1..1882508 100644 --- a/Source/Lost_Edge/Private/PlayerBase.cpp +++ b/Source/Lost_Edge/Private/PlayerBase.cpp @@ -4,6 +4,7 @@ #include "PlayerBase.h" #include "Camera/CameraComponent.h" +#include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" #include "GameFramework/CharacterMovementComponent.h" #include "InputMappingContext.h" @@ -11,9 +12,8 @@ #include "Kismet/KismetMathLibrary.h" #include "CustomGameInstanceBase.h" -#include "Interactable/Activators/InteractableActivator.h" - #include "CustomGameUserSettings.h" +#include "Interactable/Activators/InteractableActivator.h" #include "MainGameModeBase.h" APlayerBase::APlayerBase() @@ -27,6 +27,12 @@ void APlayerBase::Tick(float DeltaTime) // stabilize move speed by fps AddActorLocalOffset(ConsumeMovementInputVector() * DeltaTime); + + if(moved) + { + moved = false; + //OnPlayerMoved.Broadcast(); + } } void APlayerBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) @@ -57,14 +63,20 @@ void APlayerBase::BeginPlay() camera->PostProcessSettings.MotionBlurAmount = gameSettings->bUseMotionBlur ? 1.0f : 0.0f; } - if(inputMapping) + + if(auto PC = Cast(GetController())) { - if(auto PC = Cast(GetController())) + inputComponent = Cast(PC->InputComponent);; + + if(auto inputSubsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer())) { - if(auto inputSubsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer())) + if(auto GI = Cast(GetWorld()->GetGameInstance())) { inputSubsystem->ClearAllMappings(); - inputSubsystem->AddMappingContext(inputMapping.LoadSynchronous(), 0); + for(auto& inputContext : GI->inputContexts) + { + inputSubsystem->AddMappingContext(inputContext.LoadSynchronous(), 0); + } } } } @@ -72,6 +84,37 @@ void APlayerBase::BeginPlay() LoadInteractablesActivators(); } +APlayerBase* APlayerBase::LockCamera(UWorld* world, bool locked) +{ + if(auto PC = UGameplayStatics::GetPlayerController(world, 0)) + { + if(auto pawn = Cast(PC->GetPawn())) + { + pawn->cameraLocked = locked; + return pawn; + } + } + + return nullptr; +} + +void APlayerBase::AttachToCamera(AActor* actor) +{ + if(!actor) + return; + + actor->AttachToComponent(camera, FAttachmentTransformRules::KeepWorldTransform); +} + +FVector APlayerBase::GetCameraDirection() +{ + return camera->GetComponentRotation().Vector(); +} +FVector APlayerBase::GetCameraLocation() +{ + return camera->GetComponentLocation(); +} + void APlayerBase::SwitchToCameraPawn() { if(auto gamemode_base = UGameplayStatics::GetGameMode(GetWorld())) @@ -90,6 +133,8 @@ void APlayerBase::MoveCamera(FVector2D value) AddControllerYawInput(value.X); AddControllerPitchInput(value.Y); + + moved = true; } void APlayerBase::MoveCharacter(FVector2D value) @@ -99,6 +144,8 @@ void APlayerBase::MoveCharacter(FVector2D value) AddMovementInput(GetActorRightVector(), value.X); AddMovementInput(GetActorForwardVector(), value.Y); + + moved = true; } void APlayerBase::Jump() @@ -107,6 +154,8 @@ void APlayerBase::Jump() return; ACharacter::Jump(); + + moved = true; } void APlayerBase::SwitchRun(bool run) @@ -154,24 +203,22 @@ void APlayerBase::LoadInteractablesActivators() void APlayerBase::InteractableActivated(AInteractable* interactable, EActivatorType type) { + if(!interactable) + return; + if(interactionLocked) return; - interactable->Activate(type); -#ifdef INTERACTABLE_DEBUG - GEngine->AddOnScreenDebugMessage(30 + (int)type, 5.0f, FColor::Cyan, TEXT("Player activate: ") + interactable->GetName() - + TEXT(" by: ") + StaticEnum()->GetNameByValue(static_cast(type)).ToString()); -#endif // INTERACTABLE_DEBUG + interactable->_Activate(type); } void APlayerBase::InteractableDeactivated(AInteractable* interactable, EActivatorType type) { + if(!interactable) + return; + if(interactionLocked) return; - interactable->Deactivate(type); -#ifdef INTERACTABLE_DEBUG - GEngine->AddOnScreenDebugMessage(30 + (int)type, 5.0f, FColor::Magenta, TEXT("Player deactivate: ") + interactable->GetName() - + TEXT(" by: ") + StaticEnum()->GetNameByValue(static_cast(type)).ToString()); -#endif // INTERACTABLE_DEBUG + interactable->_Deactivate(type); } \ No newline at end of file diff --git a/Source/Lost_Edge/Private/PlayerBase.h b/Source/Lost_Edge/Private/PlayerBase.h index 6a30d28..f87fd9f 100644 --- a/Source/Lost_Edge/Private/PlayerBase.h +++ b/Source/Lost_Edge/Private/PlayerBase.h @@ -9,6 +9,8 @@ #include "PlayerBase.generated.h" +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FPlayerMovedDelegate); + UCLASS() class APlayerBase : public ACharacter { @@ -20,6 +22,20 @@ public: virtual void Tick(float DeltaTime) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + static APlayerBase* LockCamera(UWorld* world, bool locked); + void AttachToCamera(AActor* actor); + FVector GetCameraLocation(); + FVector GetCameraDirection(); + + UPROPERTY(BlueprintAssignable) + FPlayerMovedDelegate OnPlayerMoved; + + class UEnhancedInputComponent* inputComponent; + UPROPERTY(EditAnywhere) + bool interactionLocked = false; + UPROPERTY(EditAnywhere) + bool cameraLocked = false; + protected: virtual void BeginPlay() override; @@ -37,9 +53,6 @@ protected: UFUNCTION(BlueprintCallable, Category = Character) void UpdatePitch(float min, float max); - UPROPERTY(EditDefaultsOnly) - TSoftObjectPtr inputMapping; - UPROPERTY(EditAnywhere) float moveSpeed = 200; UPROPERTY(EditAnywhere) @@ -51,18 +64,16 @@ protected: bool jumpLocked = false; UPROPERTY(EditAnywhere) bool runLocked = false; - UPROPERTY(EditAnywhere) - bool interactionLocked = false; APlayerCameraManager* cameraManager; class UCameraComponent* camera; - UPROPERTY(EditAnywhere) - bool cameraLocked = false; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) float minPitch = -80; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) float maxPitch = 65; + bool moved = false; + private: void LoadInteractablesActivators(); void InteractableActivated(AInteractable* interactable, EActivatorType type); diff --git a/Source/Lost_Edge/Private/ResolutionResponsiveUserWidget.cpp b/Source/Lost_Edge/Private/Widgets/ResolutionResponsiveUserWidget.cpp similarity index 100% rename from Source/Lost_Edge/Private/ResolutionResponsiveUserWidget.cpp rename to Source/Lost_Edge/Private/Widgets/ResolutionResponsiveUserWidget.cpp diff --git a/Source/Lost_Edge/Private/ResolutionResponsiveUserWidget.h b/Source/Lost_Edge/Private/Widgets/ResolutionResponsiveUserWidget.h similarity index 100% rename from Source/Lost_Edge/Private/ResolutionResponsiveUserWidget.h rename to Source/Lost_Edge/Private/Widgets/ResolutionResponsiveUserWidget.h diff --git a/Source/Lost_Edge/Private/Widgets/WidgetsManager.cpp b/Source/Lost_Edge/Private/Widgets/WidgetsManager.cpp index 3fe1502..44141b6 100644 --- a/Source/Lost_Edge/Private/Widgets/WidgetsManager.cpp +++ b/Source/Lost_Edge/Private/Widgets/WidgetsManager.cpp @@ -34,9 +34,12 @@ void UWidgetsManager::Init() instance->AddToViewport(); } } + if(auto instance = CreateWidget(PC, interactableHintWidgetManagerClass)) + { + interactableHintWidgetManager = instance; + instance->AddToViewport(); + } } - - interactableHintWidgetManager = NewObject(this, interactableHintWidgetManagerClass); } void UWidgetsManager::HideOverlayWidgets() @@ -84,9 +87,11 @@ void UWidgetsManager::UpdateOverlayWidgetsOwner() void UWidgetsManager::ShowInteractionHints(const UInteractableModificator* modificator) { - interactableHintWidgetManager->Append(modificator); + if(interactableHintWidgetManager.IsValid()) + interactableHintWidgetManager->Append_Implementation(modificator); } void UWidgetsManager::HideInteractionHints(const EActivatorType type) { - interactableHintWidgetManager->Remove(type); + if(interactableHintWidgetManager.IsValid()) + interactableHintWidgetManager->Remove_Implementation(type); } \ No newline at end of file diff --git a/Source/Lost_Edge/Private/Widgets/WidgetsManager.h b/Source/Lost_Edge/Private/Widgets/WidgetsManager.h index 48bb35c..39386d6 100644 --- a/Source/Lost_Edge/Private/Widgets/WidgetsManager.h +++ b/Source/Lost_Edge/Private/Widgets/WidgetsManager.h @@ -26,14 +26,14 @@ public: protected: UPROPERTY(EditDefaultsOnly) - TArray> permaOverlayWidgets; // never hidden + TSet> permaOverlayWidgets; // never hidden TArray> permaOverlayWidgetsInstances; UPROPERTY(EditDefaultsOnly) - TArray> overlayWidgets; // hidden in pause + TSet> overlayWidgets; // hidden in pause TArray> overlayWidgetsInstances; UPROPERTY(EditDefaultsOnly) TSubclassOf interactableHintWidgetManagerClass; - class UInteractableHintWidgetManager* interactableHintWidgetManager; + TWeakObjectPtr interactableHintWidgetManager; };