Add settings and base player class
This commit is contained in:
parent
08330b2263
commit
0b93ede282
@ -2,22 +2,20 @@
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class Lost_Edge : ModuleRules
|
||||
{
|
||||
public Lost_Edge(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
public class Lost_Edge : ModuleRules {
|
||||
public Lost_Edge(ReadOnlyTargetRules Target) : base(Target) {
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
}
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
}
|
||||
}
|
||||
|
111
Source/Lost_Edge/Private/APlayerBase.cpp
Normal file
111
Source/Lost_Edge/Private/APlayerBase.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
// Oleg Petruny proprietary.
|
||||
|
||||
|
||||
#include "APlayerBase.h"
|
||||
|
||||
#include "CustomGameUserSettings.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
APlayerBase::APlayerBase()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
}
|
||||
|
||||
void APlayerBase::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
auto world = GetWorld();
|
||||
|
||||
GetCharacterMovement()->MaxWalkSpeed = moveSpeed;
|
||||
|
||||
auto cameraManager = UGameplayStatics::GetPlayerCameraManager(world, 0);
|
||||
cameraManager->ViewPitchMin = minPitch;
|
||||
cameraManager->ViewPitchMax = maxPitch;
|
||||
|
||||
auto gameSettings = UCustomGameUserSettings::GetCustomGameUserSettings();
|
||||
|
||||
if(auto camera = FindComponentByClass<UCameraComponent>())
|
||||
{
|
||||
camera->PostProcessSettings.MotionBlurAmount = gameSettings->bUseMotionBlur ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
if(gameSettings->bShowFps)
|
||||
world->Exec(world, TEXT("show stats"));
|
||||
|
||||
mouseInvert = gameSettings->bMouseInverted;
|
||||
mouseSensetivity = gameSettings->GetMouseSensetivity();
|
||||
|
||||
if(inputMapping)
|
||||
{
|
||||
if(auto player = Cast<APlayerController>(GetController()))
|
||||
{
|
||||
if(auto inputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(player->GetLocalPlayer()))
|
||||
{
|
||||
inputSubsystem->ClearAllMappings();
|
||||
inputSubsystem->AddMappingContext(inputMapping, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void APlayerBase::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
// stabilize move speed by fps
|
||||
AddActorLocalOffset(ConsumeMovementInputVector() * DeltaTime);
|
||||
}
|
||||
|
||||
void APlayerBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
}
|
||||
|
||||
void APlayerBase::MoveCamera(FVector2D value)
|
||||
{
|
||||
if(cameraLocked)
|
||||
return;
|
||||
|
||||
if(mouseInvert)
|
||||
value.Y *= -1;
|
||||
|
||||
value *= mouseSensetivity;
|
||||
|
||||
AddControllerYawInput(value.X);
|
||||
AddControllerPitchInput(value.Y);
|
||||
}
|
||||
|
||||
void APlayerBase::MoveCharacter(FVector2D value)
|
||||
{
|
||||
if(moveLocked)
|
||||
return;
|
||||
|
||||
AddMovementInput(GetActorRightVector(), value.X);
|
||||
AddMovementInput(GetActorForwardVector(), value.Y);
|
||||
}
|
||||
|
||||
void APlayerBase::Jump()
|
||||
{
|
||||
if(jumpLocked)
|
||||
return;
|
||||
|
||||
Super::Jump();
|
||||
}
|
||||
|
||||
void APlayerBase::SwitchRun(bool run)
|
||||
{
|
||||
if(runLocked)
|
||||
return;
|
||||
|
||||
if(run)
|
||||
GetCharacterMovement()->MaxWalkSpeed = moveSpeed * runSpeedMultiplier;
|
||||
else
|
||||
GetCharacterMovement()->MaxWalkSpeed = moveSpeed;
|
||||
}
|
66
Source/Lost_Edge/Private/APlayerBase.h
Normal file
66
Source/Lost_Edge/Private/APlayerBase.h
Normal file
@ -0,0 +1,66 @@
|
||||
// Oleg Petruny proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "InputMappingContext.h"
|
||||
|
||||
#include "APlayerBase.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class APlayerBase : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
APlayerBase();
|
||||
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = Character)
|
||||
void MoveCamera(FVector2D value);
|
||||
UFUNCTION(BlueprintCallable, Category = Character)
|
||||
void MoveCharacter(FVector2D value);
|
||||
virtual void Jump() override;
|
||||
UFUNCTION(BlueprintCallable, Category = Character)
|
||||
void SwitchRun(bool run);
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
UInputMappingContext* inputMapping;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float moveSpeed = 200;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float runSpeedMultiplier = 4;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
bool moveLocked = false;
|
||||
UPROPERTY(EditAnywhere)
|
||||
bool jumpLocked = false;
|
||||
UPROPERTY(EditAnywhere)
|
||||
bool runLocked = false;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float minPitch = -80;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float maxPitch = 65;
|
||||
|
||||
// not visible :(
|
||||
//UPROPERTY(EditDefaultsOnly)
|
||||
//UCameraComponent* camera;
|
||||
|
||||
bool mouseInvert = false;
|
||||
float mouseSensetivity = 1.0f;
|
||||
UPROPERTY(EditAnywhere)
|
||||
bool cameraLocked = false;
|
||||
|
||||
private:
|
||||
|
||||
};
|
26
Source/Lost_Edge/Private/CustomGameUserSettings.cpp
Normal file
26
Source/Lost_Edge/Private/CustomGameUserSettings.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Oleg Petruny proprietary.
|
||||
|
||||
#include "CustomGameUserSettings.h"
|
||||
|
||||
UCustomGameUserSettings::UCustomGameUserSettings(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)
|
||||
{
|
||||
bUseMotionBlur = false;
|
||||
bShowFps = false;
|
||||
bMouseInverted = false;
|
||||
fMouseSensetivity = 1.0f;
|
||||
}
|
||||
|
||||
UCustomGameUserSettings* UCustomGameUserSettings::GetCustomGameUserSettings()
|
||||
{
|
||||
return Cast<UCustomGameUserSettings>(UGameUserSettings::GetGameUserSettings());
|
||||
}
|
||||
|
||||
void UCustomGameUserSettings::SetMouseSensetivity(float value)
|
||||
{
|
||||
fMouseSensetivity = FMath::Clamp(value, 0.1f, 1.0f);
|
||||
}
|
||||
|
||||
float UCustomGameUserSettings::GetMouseSensetivity() const
|
||||
{
|
||||
return fMouseSensetivity;
|
||||
}
|
44
Source/Lost_Edge/Private/CustomGameUserSettings.h
Normal file
44
Source/Lost_Edge/Private/CustomGameUserSettings.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Oleg Petruny proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
|
||||
#include "CustomGameUserSettings.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class UCustomGameUserSettings : public UGameUserSettings
|
||||
{
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, Category = Settings)
|
||||
static UCustomGameUserSettings* GetCustomGameUserSettings();
|
||||
|
||||
// Sets mouse sensetivity multiplier
|
||||
// @param value [0.1 - 1.0]
|
||||
UFUNCTION(BlueprintCallable, Category = Settings)
|
||||
void SetMouseSensetivity(float value);
|
||||
|
||||
// Returns mouse sensetivity multiplier in [0.1 - 1.0]
|
||||
UFUNCTION(BlueprintCallable, Category = Settings)
|
||||
float GetMouseSensetivity() const;
|
||||
|
||||
UPROPERTY(config)
|
||||
bool bUseMotionBlur;
|
||||
|
||||
UPROPERTY(config)
|
||||
bool bShowFps;
|
||||
|
||||
UPROPERTY(config)
|
||||
bool bMouseInverted;
|
||||
|
||||
protected:
|
||||
UPROPERTY(config)
|
||||
float fMouseSensetivity;
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user