-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the Combat Text Widget - Wrapped some player classes in blueprints - Added OnCollision callbacks during movement - Added all the necessary event bindings to set the text of the combat text on hit
- Loading branch information
Showing
22 changed files
with
579 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
|
||
#include "PopText.h" | ||
|
||
#include "PopTextWidget.h" | ||
#include "Kismet/GameplayStatics.h" | ||
|
||
|
||
// Sets default values | ||
APopText::APopText() | ||
{ | ||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. | ||
PrimaryActorTick.bCanEverTick = true; | ||
|
||
Billboard = CreateDefaultSubobject<UBillboardComponent>(TEXT("Billboard")); | ||
RootComponent = Billboard; | ||
|
||
Duration = 1.5f; | ||
ZFinalOffset = 10; | ||
} | ||
|
||
// Called when the game starts or when spawned | ||
void APopText::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
UE_LOG(LogTemp, Display, TEXT("Attempting to create widget")); | ||
CurrentWidget = CreateWidget<UPopTextWidget>(GetWorld(), StartingWidgetClass); | ||
CurrentWidget->AddToViewport(); | ||
|
||
CurrentDuration = Duration; | ||
CurrentZOffset = 0; | ||
} | ||
|
||
// Called every frame | ||
void APopText::Tick(float DeltaTime) | ||
{ | ||
Super::Tick(DeltaTime); | ||
UpdatePosition(DeltaTime); | ||
} | ||
|
||
void APopText::UpdatePosition(float DeltaTime) | ||
{ | ||
if (CurrentWidget == nullptr) | ||
{ | ||
return; | ||
} | ||
|
||
CurrentDuration -= DeltaTime; | ||
if (CurrentDuration <= 0) | ||
{ | ||
CurrentWidget->RemoveFromParent(); | ||
CurrentWidget = nullptr; | ||
return; | ||
} | ||
|
||
FVector WorldLocation = GetActorLocation(); | ||
const float Ratio = (Duration - CurrentDuration) / Duration; | ||
CurrentZOffset = ZFinalOffset * Ratio; | ||
WorldLocation.Z += CurrentZOffset; | ||
|
||
FVector2d ScreenPosition; | ||
UGameplayStatics::ProjectWorldToScreen(GetWorld()->GetFirstPlayerController(), WorldLocation, ScreenPosition); | ||
CurrentWidget->SetPositionInViewport(ScreenPosition); | ||
} | ||
|
||
void APopText::SetContent(FString Content) | ||
{ | ||
if (CurrentWidget == nullptr) | ||
{ | ||
return; | ||
} | ||
CurrentWidget->SetContent(Content); | ||
} | ||
|
||
// void APopText::ChangeWidget(TSubclassOf<UUserWidget> NewWidgetClass) | ||
// { | ||
// if (CurrentWidget != nullptr) | ||
// { | ||
// CurrentWidget->RemoveFromViewport(); | ||
// CurrentWidget = nullptr; | ||
// } | ||
// if (NewWidgetClass != nullptr) | ||
// { | ||
// CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), NewWidgetClass); | ||
// if (CurrentWidget != nullptr) | ||
// { | ||
// CurrentWidget->AddToViewport(); | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/BillboardComponent.h" | ||
#include "Components/WidgetComponent.h" | ||
#include "GameFramework/Actor.h" | ||
#include "PopText.generated.h" | ||
|
||
class UPopTextWidget; | ||
|
||
UCLASS() | ||
class TEST2DPLATFORMER_API APopText : public AActor | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
// Sets default values for this actor's properties | ||
APopText(); | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
TObjectPtr<UBillboardComponent> Billboard; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
TSubclassOf<UPopTextWidget> StartingWidgetClass; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadOnly) | ||
TObjectPtr<UPopTextWidget> CurrentWidget; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
float Duration; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
float ZFinalOffset; | ||
|
||
float CurrentDuration; | ||
float CurrentZOffset; | ||
protected: | ||
|
||
|
||
|
||
// Called when the game starts or when spawned | ||
virtual void BeginPlay() override; | ||
|
||
public: | ||
// Called every frame | ||
virtual void Tick(float DeltaTime) override; | ||
|
||
void UpdatePosition(float DeltaTime); | ||
|
||
void SetContent(FString Content); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
|
||
#include "PopTextWidget.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Blueprint/UserWidget.h" | ||
#include "PopTextWidget.generated.h" | ||
|
||
/** | ||
* | ||
*/ | ||
UCLASS() | ||
class TEST2DPLATFORMER_API UPopTextWidget : public UUserWidget | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
UFUNCTION(BlueprintImplementableEvent, Category="Something") | ||
void SetContent(const FString &Content); | ||
|
||
}; |
Oops, something went wrong.