Skip to content

Commit

Permalink
#37 Added configurable console parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat committed Nov 3, 2023
1 parent f446cf6 commit 1fdd6df
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 41 deletions.
9 changes: 8 additions & 1 deletion Config/DefaultGame.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ ProjectName = Cloud9
[/Script/Cloud9.Cloud9Character]
FixedCameraPitch = -45.0
FixedCameraDistance = 1500.0
bIsDrawHitCursorLine = false

[StartupActions]
bAddPacks = True
InsertPack = (PackSource="StarterContent.upack",PackName="StarterContent")

[/Script/Cloud9.Cloud9DeveloperSettings]
bIsDrawHitCursorLine = False
bIsDrawDeprojectedCursorLine = False
bIsShowMouseCursor = True
NetGraph = 0
bIsShowMouseCursor=False
NetGraph=1

Binary file modified Content/Blueprints/Game/BP_Cloud9Console.uasset
Binary file not shown.
11 changes: 6 additions & 5 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "UObject/ConstructorHelpers.h"
#include "Camera/CameraComponent.h"
#include "Cloud9/Cloud9.h"
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
#include "Cloud9/Game/Cloud9PlayerController.h"
#include "Components/DecalComponent.h"
#include "Components/CapsuleComponent.h"
Expand All @@ -15,6 +16,7 @@
#include "GameFramework/SpringArmComponent.h"
#include "Materials/Material.h"
#include "Engine/World.h"
#include "GameFramework/GameUserSettings.h"
#include "Kismet/KismetMathLibrary.h"

class UCloud9SpringArmComponent;
Expand All @@ -26,9 +28,6 @@ const FName ACloud9Character::InventoryComponentName = TEXT("Inventory");
ACloud9Character::ACloud9Character(const FObjectInitializer& ObjectInitializer) : Super(
ObjectInitializer.SetDefaultSubobjectClass<UCloud9CharacterMovement>(CharacterMovementComponentName))
{
bIsDrawHitCursorLine = false;
bIsDrawDeprojectedCursorLine = false;

bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
Expand Down Expand Up @@ -110,7 +109,9 @@ void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHit
SetCursorIsHidden(false);
}

if (bIsDrawHitCursorLine)
const auto Settings = UCloud9DeveloperSettings::GetCloud9DeveloperSettings();

if (Settings->bIsDrawHitCursorLine)
{
DrawDebugLine(
GetWorld(),
Expand All @@ -121,7 +122,7 @@ void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHit
0.0);
}

if (bIsDrawDeprojectedCursorLine)
if (Settings->bIsDrawDeprojectedCursorLine)
{
FVector WorldLocation;
FVector WorldDirection;
Expand Down
15 changes: 0 additions & 15 deletions Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,6 @@ class ACloud9Character : public ACharacter
UPROPERTY(BlueprintReadOnly, Category=Character)
uint32 bIsSneaking : 1;

// Debug section

UFUNCTION(BlueprintCallable)
void SetIsDrawHitCursorLine(bool Value) { bIsDrawHitCursorLine = Value; }

UFUNCTION(BlueprintCallable)
void SetIsDrawDeprojectedCursorLine(bool Value) { bIsDrawDeprojectedCursorLine = Value; }

protected:
UPROPERTY(Config, BlueprintReadOnly, Category = Debug)
bool bIsDrawHitCursorLine;

UPROPERTY(Config, BlueprintReadOnly, Category = Debug)
bool bIsDrawDeprojectedCursorLine;

private:
UPROPERTY(EditDefaultsOnly)
UMaterial* CursorDecal;
Expand Down
1 change: 1 addition & 0 deletions Source/Cloud9/Cloud9.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public Cloud9(ReadOnlyTargetRules Target) : base(Target)
"InputCore",
"HeadMountedDisplay",
"NavigationSystem",
"DeveloperSettings",
"AIModule",
"Niagara"
});
Expand Down
1 change: 1 addition & 0 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Cloud9DeveloperSettings.h"
47 changes: 47 additions & 0 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "CoreMinimal.h"
#include "Cloud9/Cloud9.h"
#include "Cloud9DeveloperSettings.generated.h"

UCLASS(Config=Game, defaultconfig, meta = (DisplayName="Save Game Settings"))
class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, Category=Settings)
static const UCloud9DeveloperSettings* GetCloud9DeveloperSettings()
{
static auto bIsLoaded = false;
static const auto Settings = GetDefault<UCloud9DeveloperSettings>();

if (!bIsLoaded)
{
UE_LOG(LogCloud9, Display, TEXT("IsDrawHitCursorLine: %d"), Settings->bIsShowMouseCursor);
UE_LOG(LogCloud9, Display, TEXT("IsDrawDeprojectedCursorLine: %d"), Settings->bIsDrawDeprojectedCursorLine);
UE_LOG(LogCloud9, Display, TEXT("IsShowMouseCursor: %d"), Settings->bIsShowMouseCursor);
UE_LOG(LogCloud9, Display, TEXT("NetGraph: %d"), Settings->NetGraph);
bIsLoaded = true;
}

return Settings;
}

UFUNCTION(BlueprintCallable)
void Save() { UpdateDefaultConfigFile(); }

// Debug

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bIsDrawHitCursorLine;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bIsDrawDeprojectedCursorLine;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bIsShowMouseCursor;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
int NetGraph;
};
11 changes: 6 additions & 5 deletions Source/Cloud9/Game/Cloud9GameMode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "Cloud9GameMode.h"

#include "Cloud9DeveloperSettings.h"
#include "Cloud9PlayerController.h"
#include "Cloud9/Character/Cloud9Character.h"
#include "UObject/ConstructorHelpers.h"
Expand All @@ -9,24 +11,23 @@ ACloud9GameMode::ACloud9GameMode()
PrimaryActorTick.bStartWithTickEnabled = true;
PlayerControllerClass = ACloud9PlayerController::StaticClass();
DefaultPawnClass = ACloud9Character::StaticClass();
NetGraph = 1;
}

ACloud9Character* ACloud9GameMode::GetCharacter() const
{
return Cast<ACloud9Character>(GetWorld()->GetFirstPlayerController()->GetCharacter());
}

void ACloud9GameMode::SetNetGraph(int Value) { NetGraph = Value; }

void ACloud9GameMode::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);

if (NetGraph > 0)
const auto Settings = UCloud9DeveloperSettings::GetCloud9DeveloperSettings();

if (Settings->NetGraph > 0)
{
const auto Fps = 1.0f / DeltaSeconds;

const auto Location = GetCharacter()->GetActorLocation();
const auto Velocity = GetCharacter()->GetVelocity();
const auto Text = FString::Printf(
Expand Down
10 changes: 1 addition & 9 deletions Source/Cloud9/Game/Cloud9GameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "GameFramework/GameModeBase.h"
#include "Cloud9GameMode.generated.h"

class UCloud9DeveloperSettings;
class ACloud9Character;

UCLASS(minimalapi)
Expand All @@ -19,15 +20,6 @@ class ACloud9GameMode : public AGameModeBase
UFUNCTION(BlueprintCallable)
ACloud9Character* GetCharacter() const;

UFUNCTION(BlueprintCallable)
void SetNetGraph(int Value);

public:
virtual void Tick(float DeltaSeconds) override;

private:
int NetGraph;
};



26 changes: 20 additions & 6 deletions Source/Cloud9/Game/Cloud9PlayerController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Cloud9PlayerController.h"

#include "Cloud9DeveloperSettings.h"
#include "Cloud9KeyboardController.h"
#include "Cloud9MouseController.h"
#include "Cloud9/Console/Cloud9ConsoleComponent.h"
Expand All @@ -11,7 +12,6 @@ const FName ACloud9PlayerController::MouseControllerName = TEXT("MouseController

ACloud9PlayerController::ACloud9PlayerController()
{
bShowMouseCursor = true;
DefaultMouseCursor = EMouseCursor::Crosshairs;

ConsoleComponent = CreateDefaultSubobject<UCloud9ConsoleComponent>(ConsoleName);
Expand All @@ -22,6 +22,9 @@ ACloud9PlayerController::ACloud9PlayerController()
void ACloud9PlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);

const auto Settings = UCloud9DeveloperSettings::GetCloud9DeveloperSettings();
bShowMouseCursor = Settings->bIsShowMouseCursor;
}

void ACloud9PlayerController::SetupInputComponent()
Expand All @@ -30,7 +33,7 @@ void ACloud9PlayerController::SetupInputComponent()

InputComponent->BindAxis("MoveForward", KeyboardController, &UCloud9KeyboardController::OnMoveForward);
InputComponent->BindAxis("MoveRight", KeyboardController, &UCloud9KeyboardController::OnMoveRight);

InputComponent->BindAction("Crouch", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnCrouchPressed);
InputComponent->BindAction("Crouch", IE_Released, KeyboardController, &UCloud9KeyboardController::OnCrouchReleased);

Expand All @@ -39,17 +42,26 @@ void ACloud9PlayerController::SetupInputComponent()

InputComponent->BindAction("Jump", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnJumpPressed);
InputComponent->BindAction("Jump", IE_Released, KeyboardController, &UCloud9KeyboardController::OnJumpReleased);

InputComponent->BindAxis("CameraZoom", MouseController, &UCloud9MouseController::OnCameraZoom);
InputComponent->BindAction("CameraRotation", IE_Pressed, MouseController, &UCloud9MouseController::OnCameraRotationPressed);
InputComponent->BindAction("CameraRotation", IE_Released, MouseController, &UCloud9MouseController::OnCameraRotationReleased);
InputComponent->BindAction(
"CameraRotation",
IE_Pressed,
MouseController,
&UCloud9MouseController::OnCameraRotationPressed);

InputComponent->BindAction(
"CameraRotation",
IE_Released,
MouseController,
&UCloud9MouseController::OnCameraRotationReleased);

InputComponent->BindAction("Slot1", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot1);
InputComponent->BindAction("Slot2", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot2);
InputComponent->BindAction("Slot3", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot3);
InputComponent->BindAction("Slot4", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot4);
InputComponent->BindAction("Slot5", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot5);

InputComponent->BindAction("Reload", IE_Pressed, KeyboardController, &UCloud9KeyboardController::Reload);

KeyboardController->OnMoveDelegate.AddDynamic(MouseController, &UCloud9MouseController::OnCharacterMove);
Expand All @@ -60,7 +72,9 @@ bool ACloud9PlayerController::ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice
bool bHandled = Super::ProcessConsoleExec(Cmd, Ar, Executor);

if (!bHandled && ConsoleComponent != nullptr)
{
bHandled |= ConsoleComponent->ProcessConsoleExec(Cmd, Ar, Executor);
}

return bHandled;
}

0 comments on commit 1fdd6df

Please sign in to comment.