Skip to content

Commit 476bf42

Browse files
committed
Enabled UMG
1 parent 44ee866 commit 476bf42

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

Content/Maps/CollectionLevel.umap

6.21 KB
Binary file not shown.

Source/BatteryCollector/BatteryCollector.Build.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class BatteryCollector : ModuleRules
66
{
77
public BatteryCollector(TargetInfo Target)
88
{
9-
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
10-
}
9+
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" });
10+
11+
PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
12+
}
1113
}

Source/BatteryCollector/BatteryCollector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#ifndef __BATTERYCOLLECTOR_H__
44
#define __BATTERYCOLLECTOR_H__
55

6-
#include "EngineMinimal.h"
6+
#include "Engine.h"
77

88
#endif

Source/BatteryCollector/BatteryCollectorGameMode.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "BatteryCollectorGameMode.h"
55
#include "BatteryCollectorCharacter.h"
66
#include "Kismet/GameplayStatics.h"
7+
#include "Blueprint/UserWidget.h"
78

89
ABatteryCollectorGameMode::ABatteryCollectorGameMode()
910
{
@@ -18,6 +19,27 @@ ABatteryCollectorGameMode::ABatteryCollectorGameMode()
1819
DecayRate = 0.01f;
1920
}
2021

22+
void ABatteryCollectorGameMode::BeginPlay()
23+
{
24+
Super::BeginPlay();
25+
ABatteryCollectorCharacter* MyCharacter = Cast<ABatteryCollectorCharacter>(UGameplayStatics::GetPlayerPawn(this, 0));
26+
if (MyCharacter)
27+
{
28+
PowerToWin = (MyCharacter->GetInitialPower())*1.25f;
29+
}
30+
31+
if (HUDWidgetClass != nullptr)
32+
{
33+
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), HUDWidgetClass);
34+
if (CurrentWidget != nullptr)
35+
{
36+
CurrentWidget->AddToViewport();
37+
}
38+
}
39+
40+
41+
}
42+
2143
void ABatteryCollectorGameMode::Tick(float DeltaTime)
2244
{
2345
Super::Tick(DeltaTime);
@@ -29,7 +51,7 @@ void ABatteryCollectorGameMode::Tick(float DeltaTime)
2951
// if the character's power is positive
3052
if (MyCharacter->GetCurrentPower() > 0)
3153
{
32-
// decrease the character's power
54+
// decrease the character's power using the decay rate
3355
MyCharacter->UpdatePower(-DeltaTime*DecayRate*(MyCharacter->GetInitialPower()));
3456
}
3557
}

Source/BatteryCollector/BatteryCollectorGameMode.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@ class ABatteryCollectorGameMode : public AGameMode
1313

1414
virtual void Tick(float DeltaTime) override;
1515

16+
/** Returns power needed to win - needed for the HUD */
17+
UFUNCTION(BlueprintPure, Category = "Power")
18+
float GetPowerToWin() const;
19+
20+
virtual void BeginPlay() override;
21+
1622
protected:
1723
/**The rate at which the character loses power */
18-
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power")
24+
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power", Meta = (BlueprintProtected = "true"))
1925
float DecayRate;
26+
27+
/**The power needed to win the game */
28+
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power", Meta = (BlueprintProtected = "true"))
29+
float PowerToWin;
30+
31+
/** The Widget class to use for our HUD screen */
32+
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power", Meta = (BlueprintProtected = "true"))
33+
TSubclassOf<class UUserWidget> HUDWidgetClass;
34+
35+
/** The instance of the HUD */
36+
UPROPERTY()
37+
class UUserWidget* CurrentWidget;
2038
};
2139

2240

0 commit comments

Comments
 (0)