-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP #31 fleshing out UI in C++ - moving healthbar and other widgets t…
…o c++ for better control.
- Loading branch information
Showing
17 changed files
with
225 additions
and
16 deletions.
There are no files selected for viewing
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
Binary file modified
BIN
-241 KB
(73%)
unreal/Content/ThirdPersonBP/Blueprints/ThirdPersonCharacter.uasset
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "UI/WotButton.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,26 @@ | ||
#include "UI/WotUWHealthBar.h" | ||
#include "UI/WotProgressBar.h" | ||
#include "UI/WotTextBlock.h" | ||
#include "WotAttributeComponent.h" | ||
|
||
void UWotUWHealthBar::NativeConstruct() | ||
{ | ||
Super::NativeConstruct(); | ||
} | ||
|
||
void UWotUWHealthBar::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) | ||
{ | ||
Super::NativeTick(MyGeometry, InDeltaTime); | ||
|
||
if (!OwnerAttributeComp.IsValid()) { | ||
return; | ||
} | ||
|
||
float CurrentHealth = OwnerAttributeComp->GetHealth(); | ||
float MaxHealth = OwnerAttributeComp->GetHealthMax(); | ||
HealthBar->SetPercent(CurrentHealth / MaxHealth); | ||
FNumberFormattingOptions Opts; | ||
Opts.SetMaximumFractionalDigits(0); | ||
CurrentHealthLabel->SetText(FText::AsNumber(CurrentHealth, &Opts)); | ||
MaxHealthLabel->SetText(FText::AsNumber(MaxHealth, &Opts)); | ||
} |
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,8 @@ | ||
#include "UI/WotUserWidget.h" | ||
|
||
void UWotUserWidget::NativeConstruct() | ||
{ | ||
Super::NativeConstruct(); | ||
|
||
// bind delegates, and set up default appearance | ||
} |
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,11 @@ | ||
#include "WotGameplayStatics.h" | ||
#include "Engine/UserInterfaceSettings.h" | ||
|
||
void UWotGameplayStatics::SetUIScale( float CustomUIScale ) | ||
{ | ||
UUserInterfaceSettings* UISettings = GetMutableDefault<UUserInterfaceSettings>( UUserInterfaceSettings::StaticClass() ); | ||
|
||
if ( UISettings ) { | ||
UISettings->ApplicationScale = CustomUIScale; | ||
} | ||
} |
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,11 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/Button.h" | ||
#include "WotButton.generated.h" | ||
|
||
UCLASS() | ||
class VOXELRPG_API UWotButton : public UButton | ||
{ | ||
GENERATED_BODY() | ||
}; |
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,11 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/Image.h" | ||
#include "WotImage.generated.h" | ||
|
||
UCLASS() | ||
class VOXELRPG_API UWotImage : public UImage | ||
{ | ||
GENERATED_BODY() | ||
}; |
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,11 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/ProgressBar.h" | ||
#include "WotProgressBar.generated.h" | ||
|
||
UCLASS() | ||
class VOXELRPG_API UWotProgressBar : public UProgressBar | ||
{ | ||
GENERATED_BODY() | ||
}; |
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,11 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/TextBlock.h" | ||
#include "WotTextBlock.generated.h" | ||
|
||
UCLASS() | ||
class VOXELRPG_API UWotTextBlock : public UTextBlock | ||
{ | ||
GENERATED_BODY() | ||
}; |
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,36 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "UI/WotUserWidget.h" | ||
#include "WotAttributeComponent.h" | ||
#include "WotUWHealthBar.generated.h" | ||
|
||
class UWotProgressBar; | ||
class UWotTextBlock; | ||
|
||
UCLASS() | ||
class VOXELRPG_API UWotUWHealthBar : public UWotUserWidget | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
void SetOwnerAttributeComponent(UWotAttributeComponent* InAttributeComponent) { OwnerAttributeComp = InAttributeComponent; } | ||
|
||
protected: | ||
// Doing setup in the C++ constructor is not as | ||
// useful as using NativeConstruct. | ||
void NativeConstruct() override; | ||
|
||
void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; | ||
|
||
TWeakObjectPtr<UWotAttributeComponent> OwnerAttributeComp; | ||
|
||
UPROPERTY( meta = ( BindWidget ) ) | ||
UWotProgressBar* HealthBar; | ||
|
||
UPROPERTY( meta = ( BindWidget ) ) | ||
UWotTextBlock* CurrentHealthLabel; | ||
|
||
UPROPERTY( meta = ( BindWidget ) ) | ||
UWotTextBlock* MaxHealthLabel; | ||
}; |
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,19 @@ | ||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Blueprint/UserWidget.h" | ||
#include "WotUserWidget.generated.h" | ||
|
||
// We make the class abstract, as we don't want to create | ||
// instances of this, instead we want to create instances | ||
// of our UMG Blueprint subclass. | ||
UCLASS(Abstract) | ||
class VOXELRPG_API UWotUserWidget : public UUserWidget | ||
{ | ||
GENERATED_BODY() | ||
|
||
protected: | ||
// Doing setup in the C++ constructor is not as | ||
// useful as using NativeConstruct. | ||
virtual void NativeConstruct() override; | ||
}; |
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,16 @@ | ||
#pragma once | ||
|
||
#include "Kismet/BlueprintFunctionLibrary.h" | ||
#include "EngineMinimal.h" | ||
#include "WotGameplayStatics.generated.h" | ||
|
||
UCLASS() | ||
class UWotGameplayStatics : public UBlueprintFunctionLibrary | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
// Custom UI scale 1.0f == 100%, 2.0f == 200%, 0.5f == 50% etc. | ||
UFUNCTION( BlueprintCallable, Category = "User Interface" ) | ||
static void SetUIScale( float CustomUIScale ); | ||
}; |
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