OLS/Source/ols/Public/Components/OLSHeroComponent.h
LongLy 57b53b9c0c Implemented OLSCameraMode.
Addressed @TODOs related to custom logs and OLSCameraMode
2025-01-20 14:08:07 -07:00

98 lines
4.0 KiB
C++

// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
#pragma once
#include "CoreMinimal.h"
#include "GameplayAbilitySpecHandle.h"
#include "Components/GameFrameworkInitStateInterface.h"
#include "Components/PawnComponent.h"
#include "OLSHeroComponent.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(LogOLSHeroComponent, Verbose, All);
namespace EEndPlayReason { enum Type : int; }
/**
* Component that sets up input and camera handling for player controlled pawns (or bots that simulate players).
* This depends on a PawnExtensionComponent to coordinate initialization.
*/
UCLASS(Blueprintable, Meta=(BlueprintSpawnableComponent))
class OLS_API UOLSHeroComponent : public UPawnComponent, public IGameFrameworkInitStateInterface
{
GENERATED_BODY()
public:
UOLSHeroComponent(const FObjectInitializer& objectInitializer);
//~ Begin IGameFrameworkInitStateInterface interface
virtual FName GetFeatureName() const override;
virtual bool CanChangeInitState(UGameFrameworkComponentManager* manager, FGameplayTag currentState, FGameplayTag desiredState) const override;
virtual void HandleChangeInitState(UGameFrameworkComponentManager* manager, FGameplayTag currentState, FGameplayTag desiredState) override;
virtual void OnActorInitStateChanged(const FActorInitStateChangedParams& params) override;
virtual void CheckDefaultInitialization() override;
//~ End IGameFrameworkInitStateInterface interface
/** The name of the extension event sent via UGameFrameworkComponentManager when ability inputs are ready to bind */
static const FName NAME_BindInputsNow;
/** The name of this component-implemented feature */
static const FName NAME_ActorFeatureName;
/** Returns the hero component if one exists on the specified actor. */
UFUNCTION(BlueprintPure, Category = "Lyra|Hero")
static UOLSHeroComponent* FindHeroComponent(const AActor* actor);
/** Overrides the camera from an active gameplay ability */
void SetAbilityCameraMode(TSubclassOf<class UOLSCameraMode> CameraMode, const FGameplayAbilitySpecHandle& OwningSpecHandle);
/** Clears the camera override if it is set */
void ClearAbilityCameraMode(const FGameplayAbilitySpecHandle& owningSpecHandle);
/** Adds mode-specific input config */
void AddAdditionalInputConfig(const class UOLSInputConfigDataAsset* inputConfig);
/** Removes a mode-specific input config if it has been added */
void RemoveAdditionalInputConfig(const class UOLSInputConfigDataAsset* inputConfig);
/** True if this is controlled by a real player and has progressed far enough in initialization where additional input bindings can be added */
bool IsReadyToBindInputs() const;
protected:
//~ Begin UActorComponent interface.
virtual void OnRegister() override;
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type endPlayReason) override;
//~ End UActorComponent interface.
virtual void InitializePlayerInput(UInputComponent* playerInputComponent);
void Input_AbilityInputTagPressed(FGameplayTag inputTag);
void Input_AbilityInputTagReleased(FGameplayTag inputTag);
void Input_Move(const struct FInputActionValue& inputActionValue);
void Input_LookMouse(const struct FInputActionValue& inputActionValue);
void Input_LookStick(const struct FInputActionValue& inputActionValue);
void Input_Crouch(const struct FInputActionValue& InputActionValue);
void Input_AutoRun(const struct FInputActionValue& inputActionValue);
TSubclassOf<class UOLSCameraMode> DetermineCameraMode() const;
protected:
UPROPERTY(EditAnywhere)
TArray<struct FOLSInputMappingContextAndPriority> DefaultInputMappings;
/** Camera mode set by an ability. */
UPROPERTY()
TSubclassOf<class UOLSCameraMode> AbilityCameraMode;
/** Spec handle for the last ability to set a camera mode. */
FGameplayAbilitySpecHandle AbilityCameraModeOwningSpecHandle;
/** True when player input bindings have been applied, will never be true for non - players */
bool bIsReadyToBindInputs;
};