Resolve #6: Migrate LumiCharacter to C++ #7

Merged
lance1416 merged 8 commits from 6-migrate-lumi-character-to-cpp into main 2024-09-10 20:23:45 +08:00
19 changed files with 603 additions and 64 deletions
+22
View File
@@ -1,4 +1,26 @@
# https://github.com/MOZGIII/ue5-gitignore
# Unreal Engine file types.
*.uasset filter=lfs diff=lfs merge=lfs -text *.uasset filter=lfs diff=lfs merge=lfs -text
*.umap filter=lfs diff=lfs merge=lfs -text *.umap filter=lfs diff=lfs merge=lfs -text
# Raw Content file types.
*.3ds filter=lfs diff=lfs merge=lfs -text
*.bmp filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text *.fbx filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text *.obj filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.xcf filter=lfs diff=lfs merge=lfs -text
# Anything in `/RawContent` dir.
/RawContent/**/* filter=lfs diff=lfs merge=lfs -text
+41 -54
View File
@@ -1,66 +1,53 @@
# Visual Studio 2015 user specific files # https://github.com/MOZGIII/ue5-gitignore
.vs/
# Compiled Object files # Ignore all files by default, but scan all directories.
*.slo *
*.lo !*/
*.o
*.obj
# Precompiled Headers # Do not ignore git files in the root of the repo.
*.gch !/.git*
*.pch
# Compiled Dynamic libraries # Do not ignore current project's `.uproject`.
*.so !/*.uproject
*.dylib
*.dll
# Fortran module files # Do not ignore source, config and plugins dirs.
*.mod !/Source/**
!/Config/**
!/Plugins/**
# Compiled Static libraries # Only allow .uasset and .umap files from /Content dir.
*.lai # They're tracked by git-lfs, don't forget to track other
*.la # files if adding them here.
*.a !/Content/**/*.uasset
*.lib !/Content/**/*.umap
# Executables # Allow any files from /RawContent dir.
*.exe # Any file in /RawContent dir will be managed by git lfs.
*.out !/RawContent/**/*
*.app
*.ipa
# These project files can be generated by the engine # OS/platform generated files.
*.xcodeproj
*.xcworkspace
*.sln
*.suo
*.opensdf
*.sdf
*.VC.db
*.VC.opendb
# Precompiled Assets # Windows
**/SourceArt/**/*.png ehthumbs.db
**/SourceArt/**/*.tga Thumbs.db
# Builds # Mac OS X
**/Build/* .DS_Store
.DS_Store?
.AppleDouble
.LSOverride
._*
# Whitelist PakBlacklist-<BuildConfiguration>.txt files # Linux
!**/Build/*/ *~
**/Build/*/** .directory
!**/Build/*/PakBlacklist*.txt
# Don't ignore icon files in Build # vim
!**/Build/**/*.ico [._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
# Configuration files generated by the Editor # Visual Studio
**/Saved/* .vs
# Compiled source files for the engine to use
**/Intermediate/*
# Cache files for the editor to use
**/DerivedDataCache/*
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+14
View File
@@ -0,0 +1,14 @@
// Copyright Team Lumi. All Rights Reserved.
using UnrealBuildTool;
public class WizardingCentralTarget : TargetRules
{
public WizardingCentralTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V4;
ExtraModuleNames.AddRange(new[] { "WizardingCentral" });
}
}
@@ -0,0 +1,227 @@
// Copyright Team Lumi. All Rights Reserved.
#include "LumiCharacter.h"
#include "Engine/LocalPlayer.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/Controller.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InputActionValue.h"
#include "GameFramework/CharacterMovementComponent.h"
DEFINE_LOG_CATEGORY(LogLumiCharacter);
// Sets default values
ALumiCharacter::ALumiCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
// PrimaryActorTick.bCanEverTick = true;
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(35.0f, 90.0f);
// Allow double jumping
JumpMaxCount = 2;
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Create a camera boom (pulls in towards the player if there is a collision)
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
CameraBoom->SocketOffset = DefaultBoomOffset;
// Create a follow camera
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
// Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
}
ELumiStance ALumiCharacter::GetCurrentStance() const
{
return CurrentStance;
}
// Called when the game starts or when spawned
void ALumiCharacter::BeginPlay()
{
Super::BeginPlay();
// Add Input Mapping Context
if (const APlayerController* PlayerController = Cast<APlayerController>(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<
UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
}
/*
// Called every frame
void ALumiCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
*/
bool ALumiCharacter::IsLastJump()
{
return JumpCurrentCountPreJump == JumpMaxCount - 1;
}
// Called to bind functionality to input
void ALumiCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent))
{
// Grabbing
EnhancedInputComponent->BindAction(GrabAction,
ETriggerEvent::Triggered,
this,
&ALumiCharacter::OnGrabActionTriggered);
// Jumping
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Started,
this,
&ALumiCharacter::OnJumpActionStarted);
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Ongoing,
this,
&ALumiCharacter::OnJumpActionOngoing);
EnhancedInputComponent->BindAction(JumpAction,
ETriggerEvent::Completed,
this,
&ALumiCharacter::OnJumpActionCompleted);
// Moving
EnhancedInputComponent->BindAction(MoveAction,
ETriggerEvent::Triggered,
this,
&ALumiCharacter::OnMoveActionTriggered);
// Looking
EnhancedInputComponent->BindAction(LookAction,
ETriggerEvent::Triggered,
this,
&ALumiCharacter::OnLookActionTriggered);
}
else
{
UE_LOG(
LogLumiCharacter,
Error,
TEXT(
"'%s' Failed to find an Enhanced Input component! "
"This template is built to use the Enhanced Input system. "
"If you intend to use the legacy system, then you will need to update this C++ file."
),
*GetNameSafe(this)
);
}
}
void ALumiCharacter::OnGrabActionTriggered(const FInputActionValue& Value)
{
UE_LOG(LogLumiCharacter, Log, TEXT("Grab Triggered"));
}
void ALumiCharacter::OnJumpActionStarted(const FInputActionValue& Value)
{
// Broadcast that the jump has started
OnJumpStarted.Broadcast();
UE_LOG(LogLumiCharacter, Log, TEXT("Jump Started"));
Jump();
}
void ALumiCharacter::OnJumpActionOngoing(const FInputActionValue& Value)
{
}
void ALumiCharacter::OnJumpActionCompleted(const FInputActionValue& Value)
{
StopJumping();
}
void ALumiCharacter::OnMoveActionTriggered(const FInputActionValue& Value)
{
// input is a Vector2D
const FVector2D MovementVector = Value.Get<FVector2D>();
if (Controller != nullptr)
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
// get right vector
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// add movement
AddMovementInput(ForwardDirection, MovementVector.Y);
AddMovementInput(RightDirection, MovementVector.X);
}
}
void ALumiCharacter::OnLookActionTriggered(const FInputActionValue& Value)
{
// input is a Vector2D
const FVector2D LookAxisVector = Value.Get<FVector2D>();
if (Controller != nullptr)
{
// add yaw and pitch input to controller
AddControllerYawInput(LookAxisVector.X);
AddControllerPitchInput(LookAxisVector.Y);
}
}
void ALumiCharacter::OnDefaultStance_Implementation()
{
UE_LOG(LogLumiCharacter, Log, TEXT("OnDefaultStance_Implementation()"));
}
void ALumiCharacter::OnMagicStance_Implementation()
{
UE_LOG(LogLumiCharacter, Log, TEXT("OnMagicStance_Implementation()"));
}
ELumiStance ALumiCharacter::SetCurrentStance(const ELumiStance NewStance)
{
const ELumiStance OldStance = CurrentStance;
UCharacterMovementComponent* Movement = GetCharacterMovement();
if (NewStance == ELumiStance::Default)
{
Movement->bOrientRotationToMovement = true;
Movement->bUseControllerDesiredRotation = false;
OnDefaultStance();
}
else if (NewStance == ELumiStance::Magic)
{
Movement->bOrientRotationToMovement = false;
Movement->bUseControllerDesiredRotation = true;
OnMagicStance();
}
CurrentStance = NewStance;
return OldStance;
}
@@ -0,0 +1,187 @@
// Copyright Team Lumi. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "LumiStance.h"
#include "GameFramework/Character.h"
#include "Logging/LogMacros.h"
#include "LumiCharacter.generated.h"
class USpringArmComponent;
class UCameraComponent;
class UInputMappingContext;
class UInputAction;
struct FInputActionValue;
DECLARE_LOG_CATEGORY_EXTERN(LogLumiCharacter, Log, All);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FJumpDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FStanceChangedDelegate,
ELumiStance, OldStance,
ELumiStance, NewStance);
static const FString PlayerStanceEnumPath = TEXT("/Game/Player/E_PlayerStance");
UCLASS()
class WIZARDINGCENTRAL_API ALumiCharacter : public ACharacter
{
GENERATED_BODY()
// Private UPROPERTIE'S --------------------------------------------------------------------------------------------
/** Camera boom positioning the camera behind the character */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera, meta = (AllowPrivateAccess = "true"))
UCameraComponent* FollowCamera;
/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputMappingContext* DefaultMappingContext;
/** Grab Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* GrabAction;
/** Jump Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* JumpAction;
/** Move Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* MoveAction;
/** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* LookAction;
/** The default boom offset */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera, meta = (AllowPrivateAccess = "true"))
FVector DefaultBoomOffset = FVector(0.0f, 60.0f, 30.0f);
/** The boom offset when aiming */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Camera, meta = (AllowPrivateAccess = "true"))
FVector AimBoomOffset = FVector(200.0f, 65.0f, 45.0f);
/** The current stance of the character */
UPROPERTY(BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
ELumiStance CurrentStance = ELumiStance::Default;
/** The stamina of the character */
UPROPERTY(BlueprintReadWrite, Category = "Stamina", meta = (AllowPrivateAccess = "true"))
double Stamina = 10.0;
UPROPERTY(BlueprintReadWrite, Category = "Stamina", meta = (AllowPrivateAccess = "true"))
double MaxStamina = 10.0;
protected:
// UFUNCTION's -----------------------------------------------------------------------------------------------------
/**
* Set the stance of the character
*
* @param NewStance The new stance to set
* @return The stance before the new stance was set
*/
UFUNCTION(BlueprintCallable, Category = "Stance")
ELumiStance SetCurrentStance(ELumiStance NewStance);
/**
* Event called when the character switches to the default stance
*/
UFUNCTION(BlueprintNativeEvent, Category = "Stance")
void OnDefaultStance();
/**
* Event called when the character switches to the magic stance
*/
UFUNCTION(BlueprintNativeEvent, Category = "Stance")
void OnMagicStance();
/**
* Check if the character has jumped the maximum number of times
*
* @return True if the character cannot jump anymore, false otherwise
*/
UFUNCTION(BlueprintPure, Category = "LumiCharacter")
bool IsLastJump();
public:
// Public Virtual Functions ----------------------------------------------------------------------------------------
// Called every frame
// virtual void Tick(float DeltaTime) override;
/**
* Called to bind functionality to input
* @param PlayerInputComponent The input component to bind to
*/
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
// Protected Virtual Functions -------------------------------------------------------------------------------------
/**
* Called when the game starts or when spawned
*/
virtual void BeginPlay() override;
public:
// Public Functions ------------------------------------------------------------------------------------------------
/**
* Sets default values for this character's properties
*/
ALumiCharacter();
/**
* Getter for @property CurrentStance
*
* @return The current stance of the character
*/
ELumiStance GetCurrentStance() const;
private:
// Private Functions -----------------------------------------------------------------------------------------------
// Grab
/**
* Callback for when the grab action is triggered
* @param Value The value of the input action
*/
void OnGrabActionTriggered(const FInputActionValue& Value);
// Jump
/**
* Callback for when the jump action is started
* @param Value The value of the input action
*/
void OnJumpActionStarted(const FInputActionValue& Value);
/**
* Callback for when the jump action is ongoing
* @param Value The value of the input action
*/
void OnJumpActionOngoing(const FInputActionValue& Value);
/**
* Callback for when the jump action is completed
* @param Value The value of the input action
*/
void OnJumpActionCompleted(const FInputActionValue& Value);
// Move
/**
* Callback for when the move action is triggered
* @param Value The value of the input action
*/
void OnMoveActionTriggered(const FInputActionValue& Value);
// Look
/**
* Callback for when the look action is triggered
* @param Value The value of the input action
*/
void OnLookActionTriggered(const FInputActionValue& Value);
public:
// Delegates -------------------------------------------------------------------------------------------------------
UPROPERTY(BlueprintAssignable, Category = "Input")
FJumpDelegate OnJumpStarted;
UPROPERTY(BlueprintAssignable, Category = "Stance")
FStanceChangedDelegate OnStanceChanged;
};
@@ -0,0 +1,5 @@
// Copyright Team Lumi. All Rights Reserved.
#include "LumiController.h"
@@ -0,0 +1,17 @@
// Copyright Sorcerers Shenanigans Central. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "LumiController.generated.h"
/**
*
*/
UCLASS()
class WIZARDINGCENTRAL_API ALumiController : public APlayerController
{
GENERATED_BODY()
};
@@ -0,0 +1,14 @@
// Copyright Team Lumi. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "LumiStance.generated.h"
UENUM(BlueprintType)
enum class ELumiStance : uint8
{
Default UMETA(DisplayName = "Default Stance"),
Magic UMETA(DisplayName = "Magic Stance"),
};
@@ -0,0 +1,30 @@
// Copyright Team Lumi. All Rights Reserved.
using UnrealBuildTool;
public class WizardingCentral : ModuleRules
{
public WizardingCentral(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"EnhancedInput"
});
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// 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
}
}
@@ -0,0 +1,6 @@
// Copyright Team Lumi. All Rights Reserved.
#include "WizardingCentral.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, WizardingCentral, "WizardingCentral" );
@@ -0,0 +1,6 @@
// Copyright Team Lumi. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
+14
View File
@@ -0,0 +1,14 @@
// Copyright Team Lumi. All Rights Reserved.
using UnrealBuildTool;
public class WizardingCentralEditorTarget : TargetRules
{
public WizardingCentralEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V4;
ExtraModuleNames.AddRange(new[] { "WizardingCentral" });
}
}
+7
View File
@@ -3,6 +3,13 @@
"EngineAssociation": "5.3", "EngineAssociation": "5.3",
"Category": "", "Category": "",
"Description": "", "Description": "",
"Modules": [
{
"Name": "WizardingCentral",
"Type": "Runtime",
"LoadingPhase": "Default"
}
],
"Plugins": [ "Plugins": [
{ {
"Name": "ModelingToolsEditorMode", "Name": "ModelingToolsEditorMode",