diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index 1be73f7..e1b4a21 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -77,6 +77,7 @@ DoubleClickTime=0.200000 +ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Bottom) +ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar) +ActionMappings=(ActionName="Interact",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E) ++ActionMappings=(ActionName="RightClick",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton) +AxisMappings=(AxisName="Look Up / Down Gamepad",Scale=1.000000,Key=Gamepad_RightY) +AxisMappings=(AxisName="Look Up / Down Mouse",Scale=-1.000000,Key=MouseY) +AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=Gamepad_LeftY) diff --git a/Content/Blueprints/Combat_UI/CombatCharacter.uasset b/Content/Blueprints/Combat_UI/CombatCharacter.uasset index 847cd87..1bf0a8a 100644 --- a/Content/Blueprints/Combat_UI/CombatCharacter.uasset +++ b/Content/Blueprints/Combat_UI/CombatCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2d135211e30df2a5bf8e733f7579a67760ccd58c509cf62de841de69499250e5 -size 81312 +oid sha256:8f66eb3eb1eaa1a58024f1991b62f89e67c76f1e90c731f37ad2c466920d53e0 +size 76230 diff --git a/Content/Blueprints/Combat_UI/CombatInit.uasset b/Content/Blueprints/Combat_UI/CombatInit.uasset new file mode 100644 index 0000000..3c61b7c --- /dev/null +++ b/Content/Blueprints/Combat_UI/CombatInit.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a362f19c5501c2b4112c3e0e94d5ce56f0c0a09cd6f68dc798e7c9d303780b3 +size 28160 diff --git a/Content/Levels/Prototype.umap b/Content/Levels/Prototype.umap index df89ebf..0752554 100644 --- a/Content/Levels/Prototype.umap +++ b/Content/Levels/Prototype.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:250daa578415eddc09d0224c3ca80e811f9957dd8158419dd5114c4aec253e73 -size 56706 +oid sha256:c96101bbc03fa6dd68a4cd8b60bcc7b84ef6e09bb770ff1a353a118b893d064f +size 66386 diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/HoldToInitCombat.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/HoldToInitCombat.cpp new file mode 100644 index 0000000..dda2b0b --- /dev/null +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/HoldToInitCombat.cpp @@ -0,0 +1,89 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "HoldToInitCombat.h" +#include "TurnBaseCombatV2.h" +#include "Blueprint/UserWidget.h" + + +// Sets default values for this component's properties +UHoldToInitCombat::UHoldToInitCombat() +{ + PrimaryComponentTick.bCanEverTick = true; + if (InitCombatWidgetClass == nullptr) + { + static ConstructorHelpers::FClassFinder HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/CombatInit")); + InitCombatWidgetClass = HUDWidgetClass.Class; + } +} + + +// Called when the game starts +void UHoldToInitCombat::BeginPlay() +{ + Super::BeginPlay(); + InitCombatWidget = CreateWidget(GetWorld(), InitCombatWidgetClass); + + UInputComponent* playerInputComponent = GetWorld()->GetFirstPlayerController()->InputComponent; + //Bind Right Mouse Button to the function OnRightClickDown + playerInputComponent->BindAction("RightClick", IE_Pressed, this, &UHoldToInitCombat::OnRightClickDown); + //Bind Right Mouse Button to the function OnRightClickUp + playerInputComponent->BindAction("RightClick", IE_Released, this, &UHoldToInitCombat::OnRightClickUp); +} + + +// Called every frame +void UHoldToInitCombat::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + //If the player is holding down the right mouse button for 3 seconds, then the player will enter combat mode + if (bRightClickDown && RightClickDownTime < 3.0f) + { + RightClickDownTime += DeltaTime; + } + else if (bRightClickDown && RightClickDownTime >= 3.0f) + { + //Enter Combat Mode + Cast(GetWorld()->GetGameState())->StartCombat(TargetEnemy); + OnRightClickUp(); + } +} + +void UHoldToInitCombat::OnRightClickDown() +{ + if (AActor* RightClickHit = LookingAtEnemy(); RightClickHit != nullptr) + { + TargetEnemy = RightClickHit; + bRightClickDown = true; + InitCombatWidget->AddToViewport(); + } +} + +void UHoldToInitCombat::OnRightClickUp() +{ + bRightClickDown = false; + RightClickDownTime = 0.0f; + if (InitCombatWidget->IsInViewport()) + { + InitCombatWidget->RemoveFromViewport(); + } +} + +AActor* UHoldToInitCombat::LookingAtEnemy() const +{ + FVector Start = GetOwner()->GetActorLocation(); + FVector End = GetOwner()->GetActorForwardVector() * 3000.0f + Start; + FCollisionQueryParams CollisionParams; + CollisionParams.AddIgnoredActor(GetOwner()); + if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, CollisionParams)) + { + DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 5.0f, 0, 10.0f); + if (HitResult.GetActor()->Tags.Contains("Enemy")) + { + return HitResult.GetActor(); + } + } + DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 5.0f, 0, 10.0f); + return nullptr; +} diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/HoldToInitCombat.h b/Source/the_twilight_abyss/TurnBasedCombatV2/HoldToInitCombat.h new file mode 100644 index 0000000..3cba925 --- /dev/null +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/HoldToInitCombat.h @@ -0,0 +1,40 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "HoldToInitCombat.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class THE_TWILIGHT_ABYSS_API UHoldToInitCombat : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UHoldToInitCombat(); + UPROPERTY() + UUserWidget* InitCombatWidget; + UPROPERTY() + TSubclassOf InitCombatWidgetClass; + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + +private: + void OnRightClickDown(); + void OnRightClickUp(); + bool bRightClickDown = false; + float RightClickDownTime = 0.0f; + + UFUNCTION() + AActor* LookingAtEnemy() const; + AActor* TargetEnemy = nullptr; +};