added ValueGauge.cpp Widget
This commit is contained in:
BIN
Content/Widgets/Gameplay/ValueGauge/ValueGuage_WBP.uasset
LFS
Normal file
BIN
Content/Widgets/Gameplay/ValueGauge/ValueGuage_WBP.uasset
LFS
Normal file
Binary file not shown.
@@ -19,7 +19,11 @@ public class Crunch : ModuleRules
|
||||
"GameplayTags"
|
||||
]);
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
PrivateDependencyModuleNames.AddRange([
|
||||
"UMG",
|
||||
"Slate",
|
||||
"SlateCore"
|
||||
]);
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
@@ -10,6 +10,11 @@ void UCAbilitySystemComponent::ApplyInitialEffects()
|
||||
|
||||
for (const auto& EffectClass : InitialEffects)
|
||||
{
|
||||
/**
|
||||
* this will work as well
|
||||
* const auto Effect{EffectClass->GetDefaultObject<UGameplayEffect>()};
|
||||
* ApplyGameplayEffectToSelf(Effect, 0.f, MakeEffectContext());
|
||||
**/
|
||||
auto GameplayEffectSpecHandle{MakeOutgoingSpec(EffectClass, 1, MakeEffectContext())};
|
||||
ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get());
|
||||
}
|
||||
|
||||
31
Source/Crunch/Private/Widgets/ValueGauge.cpp
Normal file
31
Source/Crunch/Private/Widgets/ValueGauge.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
|
||||
#include "Widgets/ValueGauge.h"
|
||||
|
||||
#include "Components/ProgressBar.h"
|
||||
#include "Components/TextBlock.h"
|
||||
|
||||
void UValueGauge::NativePreConstruct()
|
||||
{
|
||||
Super::NativePreConstruct();
|
||||
ProgressBar->SetFillColorAndOpacity(BarColor);
|
||||
}
|
||||
|
||||
void UValueGauge::SetValue(float NewValue, float NewMaxValue)
|
||||
{
|
||||
if (NewMaxValue == 0)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Value Gauge: %s, NewMaxValue can't be 0"), *GetName());
|
||||
return;
|
||||
}
|
||||
|
||||
const float NewPercentage{NewValue / NewMaxValue};
|
||||
ProgressBar->SetPercent(NewPercentage);
|
||||
const auto FormatOps{FNumberFormattingOptions().SetMaximumFractionalDigits(0)};
|
||||
ValueText->SetText(FText::Format(
|
||||
FTextFormat::FromString("{0}/{1}"),
|
||||
FText::AsNumber(NewValue, &FormatOps),
|
||||
FText::AsNumber(NewMaxValue, &FormatOps)
|
||||
));
|
||||
}
|
||||
31
Source/Crunch/Public/Widgets/ValueGauge.h
Normal file
31
Source/Crunch/Public/Widgets/ValueGauge.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// Multiplayer By Caleb
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "ValueGauge.generated.h"
|
||||
|
||||
class UTextBlock;
|
||||
class UProgressBar;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CRUNCH_API UValueGauge : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
virtual void NativePreConstruct() override;
|
||||
void SetValue(float NewValue, float NewMaxValue);
|
||||
|
||||
private:
|
||||
UPROPERTY(EditAnywhere, Category="Visual")
|
||||
FLinearColor BarColor;
|
||||
UPROPERTY(EditAnywhere, meta=(BindWidget))
|
||||
UProgressBar* ProgressBar;
|
||||
UPROPERTY(EditAnywhere, meta=(BindWidget))
|
||||
UTextBlock* ValueText;
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user