added ValueGauge.cpp Widget

This commit is contained in:
Caleb Buhungiro
2025-06-23 12:28:21 +08:00
parent b8475c7ba1
commit 638b7c34fa
5 changed files with 76 additions and 2 deletions

Binary file not shown.

View File

@@ -19,7 +19,11 @@ public class Crunch : ModuleRules
"GameplayTags" "GameplayTags"
]); ]);
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange([
"UMG",
"Slate",
"SlateCore"
]);
// Uncomment if you are using Slate UI // Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

View File

@@ -10,6 +10,11 @@ void UCAbilitySystemComponent::ApplyInitialEffects()
for (const auto& EffectClass : InitialEffects) 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())}; auto GameplayEffectSpecHandle{MakeOutgoingSpec(EffectClass, 1, MakeEffectContext())};
ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get()); ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get());
} }

View 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)
));
}

View 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;
};