13. "Highlight Enemies"

This commit is contained in:
2024-04-12 22:05:09 -04:00
parent 9a8029c365
commit 0a6bbf1482
19 changed files with 329 additions and 14 deletions

View File

@ -1,12 +1,14 @@
#include "GasaCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/KismetSystemLibrary.h"
void AGasaCharacter::SetHighlight(EHighlight desired)
void AGasaCharacter::SetHighlight(EHighlight Desired)
{
HighlightState = Desired;
}
AGasaCharacter::AGasaCharacter()
@ -48,3 +50,29 @@ void AGasaCharacter::BeginPlay()
{
Super::BeginPlay();
}
void AGasaCharacter::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
switch (HighlightState)
{
case EHighlight::Disabled:
break;
case EHighlight::Enabled:
{
UCapsuleComponent* Capsule = GetCapsuleComponent();
UKismetSystemLibrary::DrawDebugCapsule(this
, Capsule->GetComponentLocation()
, Capsule->GetScaledCapsuleHalfHeight()
, Capsule->GetScaledCapsuleRadius()
, Capsule->GetComponentRotation()
, FLinearColor(0.8, 0.32, 0.05f, 1.f)
, 0.f
, 1.f
);
}
break;
}
}

View File

@ -5,6 +5,13 @@
#include "GasaCharacter.generated.h"
UENUM(BlueprintType)
enum class EHighlight : uint8
{
Disabled,
Enabled,
};
UCLASS(Abstract)
class GASA_API AGasaCharacter : public ACharacter
{
@ -25,10 +32,11 @@ public:
// This will be implemented in the base until it needs to be lifted into an abstraction.
#pragma region Highlighting
void SetHighlight( EHighlight desired );
EHighlight HighlightState;
void SetHighlight( EHighlight Desired );
UFUNCTION(BlueprintCallable)
FORCEINLINE void Highlight() { SetHighlight(EHighlight::Disabled); };
FORCEINLINE void Highlight() { SetHighlight(EHighlight::Enabled); };
UFUNCTION(BlueprintCallable)
FORCEINLINE void Dehighlight() { SetHighlight(EHighlight::Disabled); };
@ -38,5 +46,7 @@ public:
#pragma region Actor
void BeginPlay() override;
void Tick(float DeltaSeconds) override;
#pragma endregion Actor
};

View File

@ -1 +1,6 @@
#include "PlayerCharacter.h"
#include "PlayerCharacter.h"
APlayerCharacter::APlayerCharacter()
{
PrimaryActorTick.bCanEverTick = true;
}

View File

@ -10,5 +10,5 @@ class GASA_API APlayerCharacter : public AGasaCharacter
GENERATED_BODY()
public:
APlayerCharacter();
};

View File

@ -10,6 +10,8 @@ public class Gasa : ModuleRules
{
public Gasa(ReadOnlyTargetRules Target) : base(Target)
{
bUseUnity = false;
#region Engine
PrivateIncludePathModuleNames.AddRange(new string[] {
"Core",
@ -29,12 +31,18 @@ public class Gasa : ModuleRules
"InputCore",
"NetCore",
"Niagara",
"UMG",
});
#endregion Engine
#region Plugins
if (Target.Configuration != UnrealTargetConfiguration.Shipping && Target.Type != TargetRules.TargetType.Server)
{
PrivateDefinitions.AddRange(new string[]
{
"ENABLE_COG=true",
});
PrivateIncludePathModuleNames.AddRange( new string[]
{
"CogCommon",

View File

@ -2,15 +2,21 @@
#include "CoreMinimal.h"
// #define private protected
UENUM(BlueprintType)
enum class EHighlight
{
Disabled,
Enabled,
};
#include "CogCommon.h"
#pragma region Engine Forwards
class UCameraComponent;
class UInputAction;
struct FInputActionValue;
class UInputMappingContext;
class USpringArmComponent;
#pragma endregion Engine Forwards
#pragma region Engine Plugin Forwards
class UCogWindowManager;
#pragma endregion Engine Plugin Forwards
#pragma region Gasa Forwards
class AGasaCharacter;
#pragma endregion Gasa Forwards

View File

@ -0,0 +1,34 @@
#include "GasaGameState.h"
#include "CogAll.h"
#include "CogWindowManager.h"
AGasaGameState::AGasaGameState()
{
// Enable ticking
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.SetTickFunctionEnable(true);
PrimaryActorTick.bStartWithTickEnabled = true;
}
#pragma region GameState
void AGasaGameState::BeginPlay()
{
#if ENABLE_COG
CogWindowManager = NewObject<UCogWindowManager>(this);
CogWindowManagerRef = CogWindowManager;
// Add all the built-in windows
Cog::AddAllWindows(*CogWindowManager);
#endif //ENABLE_COG
}
void AGasaGameState::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
#if ENABLE_COG
CogWindowManager->Tick(DeltaSeconds);
#endif //ENABLE_COG
}
#pragma endregion GameState

View File

@ -0,0 +1,30 @@
#pragma once
#include "GameFramework/GameState.h"
#include "GasaCommon.h"
#include "GasaGameState.generated.h"
UCLASS(Blueprintable)
class GASA_API AGasaGameState : public AGameState
{
GENERATED_BODY()
public:
#pragma region Cog
// To make sure it doesn't get garbage collected.
UPROPERTY()
TObjectPtr<UObject> CogWindowManagerRef = nullptr;
#if ENABLE_COG
TObjectPtr<UCogWindowManager> CogWindowManager = nullptr;
#endif // ENABLE_COG
#pragma endregion Cog
AGasaGameState();
#pragma region GameState
void BeginPlay() override;
void Tick(float DeltaSeconds) override;
#pragma endregion GameState
};

View File

@ -3,6 +3,7 @@
#include "Engine/LocalPlayer.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Character/GasaCharacter.h"
AGasaPlayerController::AGasaPlayerController()
{
@ -53,6 +54,44 @@ void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
}
#pragma region PlayerController
void AGasaPlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);
// Cursor Trace
for (int32 do_once = 0; do_once != 1; ++ do_once)
{
FHitResult CursorHit;
GetHitResultUnderCursor(ECC_Pawn, false, CursorHit);
if (! CursorHit.bBlockingHit)
break;
HoverPrev = HoverCurr;
HoverCurr = Cast<AGasaCharacter>(CursorHit.GetActor());
if (HoverPrev == nullptr)
{
// We didn't have a prev to de-highlight so we just need to highlight newly detected character.
if (HoverCurr)
HoverCurr->Highlight();
// No matter what we need to not go to the next case as there is no previous.
break;
}
//else Previous is valid...
// We are no longer hovering the previous with no new character, we just need to de-highlight previous.
if ( HoverCurr == nullptr )
HoverPrev->Dehighlight();
// We had a prev and curr change between frames. They both don't match; we need to switch highlighting.
else if ( HoverPrev != HoverCurr )
{
HoverPrev->Dehighlight();
HoverCurr->Highlight();
}
}
}
void AGasaPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();

View File

@ -13,6 +13,12 @@ class GASA_API AGasaPlayerController : public APlayerController
public:
#pragma region Input
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
AGasaCharacter* HoverPrev;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
AGasaCharacter* HoverCurr;
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputMappingContext> IMC;
@ -25,6 +31,8 @@ public:
void Move(FInputActionValue const& ActionValue);
#pragma region PlayerController
void PlayerTick(float DeltaTime) override;
void SetupInputComponent() override;
#pragma endregion PlayerController

View File

View File

@ -0,0 +1,15 @@
#pragma once
#include "Blueprint/GameViewportSubsystem.h"
#include "GasaViewport.generated.h"
UCLASS()
class GASA_API UGasaViewportSubsystem : public UGameViewportSubsystem
{
GENERATED_BODY()
public:
// UGasaViewportSubsystem();
};

View File

@ -11,6 +11,8 @@ public class GasaEditorTarget : TargetRules
DefaultBuildSettings = BuildSettingsVersion.Latest;
bUseUnityBuild = false;
ExtraModuleNames.Add("Gasa");
ExtraModuleNames.Add("GasaEditor");
}