Added HoldToInitCombat Actor Component for Manual Combat Init
This commit is contained in:
		
							parent
							
								
									99f1f0c5af
								
							
						
					
					
						commit
						1300c99a3f
					
				| @ -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=Gamepad_FaceButton_Bottom) | ||||||
| +ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar) | +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="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 Gamepad",Scale=1.000000,Key=Gamepad_RightY) | ||||||
| +AxisMappings=(AxisName="Look Up / Down Mouse",Scale=-1.000000,Key=MouseY) | +AxisMappings=(AxisName="Look Up / Down Mouse",Scale=-1.000000,Key=MouseY) | ||||||
| +AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=Gamepad_LeftY) | +AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=Gamepad_LeftY) | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								Content/Blueprints/Combat_UI/CombatCharacter.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Blueprints/Combat_UI/CombatCharacter.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Blueprints/Combat_UI/CombatInit.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Blueprints/Combat_UI/CombatInit.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Levels/Prototype.umap
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Levels/Prototype.umap
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -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<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/CombatInit")); | ||||||
|  | 		InitCombatWidgetClass = HUDWidgetClass.Class; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | // Called when the game starts
 | ||||||
|  | void UHoldToInitCombat::BeginPlay() | ||||||
|  | { | ||||||
|  | 	Super::BeginPlay(); | ||||||
|  | 	InitCombatWidget = CreateWidget<UUserWidget>(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<ATurnBaseCombatV2>(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; | ||||||
|  | } | ||||||
| @ -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<UUserWidget> 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; | ||||||
|  | }; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user