From e797ecd8dea37c5702ddd966f964ccc84045b215 Mon Sep 17 00:00:00 2001 From: TjgL Date: Fri, 28 Mar 2025 16:32:12 +0100 Subject: [PATCH] Implemented weapon switch scroll limit Signed-off-by: TjgL --- Content/Legumix/Player/BP_PlayerController.uasset | 4 ++-- .../LegumeMix/Private/Player/LMPlayerController.cpp | 12 ++++++++++++ Source/LegumeMix/Public/Player/LMPlayerController.h | 10 +++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Content/Legumix/Player/BP_PlayerController.uasset b/Content/Legumix/Player/BP_PlayerController.uasset index 12d2476..6804311 100644 --- a/Content/Legumix/Player/BP_PlayerController.uasset +++ b/Content/Legumix/Player/BP_PlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fc92081abb28b81e9a56e981284c3e7802f559c318716fe4c5d2f2bba749c6e3 -size 22303 +oid sha256:c394e1e698d9ca42975ee6cc67d1d92372e58e2241b97abbcddf40d23f5c718d +size 22358 diff --git a/Source/LegumeMix/Private/Player/LMPlayerController.cpp b/Source/LegumeMix/Private/Player/LMPlayerController.cpp index 06e4911..adb0930 100644 --- a/Source/LegumeMix/Private/Player/LMPlayerController.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayerController.cpp @@ -35,6 +35,7 @@ void ALMPlayerController::SetupInputComponent() Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire); Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload); Input->BindAction(ScrollAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Scroll); + Input->BindAction(ScrollAction, ETriggerEvent::Canceled, this, &ALMPlayerController::ScrollEnded); Input->BindAction(PauseAction, ETriggerEvent::Triggered, this, &ALMPlayerController::TogglePause); Input->BindAction(SlideAction, ETriggerEvent::Started, this, &ALMPlayerController::SlideInput); Input->BindAction(SlideAction, ETriggerEvent::Completed, this, &ALMPlayerController::SlideCancel); @@ -73,8 +74,19 @@ void ALMPlayerController::Reload(const FInputActionValue& InputValue) void ALMPlayerController::Scroll(const FInputActionValue& InputValue) { + if (bIsScrolling) + return; + const float ScrollAmount = InputValue.Get(); LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount); + bIsScrolling = true; + GetWorldTimerManager().SetTimer(ScrollTimer, this, &ALMPlayerController::ScrollEnded, SwitchWeaponDelay, false); +} + +void ALMPlayerController::ScrollEnded() +{ + GetWorldTimerManager().ClearTimer(ScrollTimer); + bIsScrolling = false; } void ALMPlayerController::PauseInput(const FInputActionValue& InputValue) diff --git a/Source/LegumeMix/Public/Player/LMPlayerController.h b/Source/LegumeMix/Public/Player/LMPlayerController.h index 8497837..bd5f4bf 100644 --- a/Source/LegumeMix/Public/Player/LMPlayerController.h +++ b/Source/LegumeMix/Public/Player/LMPlayerController.h @@ -54,7 +54,6 @@ private: UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr LegumixPlayer; - virtual void SetupInputComponent() override; void Move(const FInputActionValue& InputValue); void Jump(const FInputActionValue& InputValue); @@ -68,6 +67,10 @@ private: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true, UIMin=0.01, ClampMin=0.01, UIMax=10.0, ClampMax=10.0)) float Sensitivity = 1.0f; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true, ClampMin = 0.f)) + float SwitchWeaponDelay = 0.1f; + private: UFUNCTION(BlueprintCallable, Category = Legumix) @@ -75,4 +78,9 @@ private: UFUNCTION(BlueprintCallable, Category = Legumix) void OnSettingsChanged(); + + void ScrollEnded(); + + FTimerHandle ScrollTimer; + bool bIsScrolling; };